Migrate to openssl 1.1 71/211071/2 submit/tizen/20190829.105349 submit/tizen/20190909.061136 submit/tizen/20190918.155207 submit/tizen/20190919.092452 submit/tizen_5.5/20191202.105532
authorDariusz Michaluk <d.michaluk@samsung.com>
Mon, 29 Jul 2019 14:55:38 +0000 (16:55 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 26 Aug 2019 12:16:47 +0000 (12:16 +0000)
Locking/initalization mechanism is not needed anymore

Change-Id: Id15e7a48456537a79b99b6573f930e56b0b0f2f5

email-api/email-api-smime.c
email-common-use/include/email-internal-types.h
email-core/CMakeLists.txt
email-core/email-core-smime.c
email-core/include/email-core-smime.h
email-daemon/CMakeLists.txt
email-daemon/email-daemon-event.c
email-daemon/email-daemon-init.c
email-daemon/include/email-daemon-event.h
packaging/email-service.spec

index 40b9fcf..07c8d18 100755 (executable)
@@ -137,13 +137,10 @@ EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output
         }
 
        if (p_output_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || p_output_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) {
-                emcore_init_openssl_library();
                if (!emcore_smime_get_decrypt_message(p_output_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) {
                        EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed");
-                        emcore_clean_openssl_library();
                        goto FINISH_OFF;
                }
-                emcore_clean_openssl_library();
        } else if (p_output_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) {
                if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, false, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
@@ -250,13 +247,10 @@ EXPORT_API int email_get_decrypt_message_ex(email_mail_data_t *input_mail_data,
         }
 
        if (input_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || input_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) {
-               emcore_init_openssl_library();
                if (!emcore_smime_get_decrypt_message(input_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) {
                        EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed");
-                       emcore_clean_openssl_library();
                        goto FINISH_OFF;
                }
-               emcore_clean_openssl_library();
        } else if (input_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) {
                if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, false, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
@@ -380,11 +374,9 @@ EXPORT_API int email_verify_signature_ex(email_mail_data_t *input_mail_data, ema
        }
 
        if (input_mail_data->smime_type == EMAIL_SMIME_SIGNED) {
-               emcore_init_openssl_library();
                if (!emcore_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, verify, &err))
                        EM_DEBUG_EXCEPTION("emcore_verify_signature failed : [%d]", err);
 
-               emcore_clean_openssl_library();
        } else if (input_mail_data->smime_type == EMAIL_PGP_SIGNED) {
                if ((err = emcore_pgp_get_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, input_mail_data->digest_type, verify)) != EMAIL_ERROR_NONE)
                        EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_siganture failed : [%d]", err);
index a9d839a..6c8b691 100755 (executable)
@@ -90,7 +90,6 @@ extern "C"
 #define __FEATURE_BODY_SEARCH__
 #define __FEATURE_ACCESS_CONTROL__
 #define __FEATURE_UPDATE_DB_TABLE_SCHEMA__
-#define __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
 /* #define __FEATURE_COMPARE_DOMAIN__ */
 /* #define __FEATURE_FORK_FOR_CURL__ */
 /* #define __FEATURE_USE_DRM_API__ */
index 6a111cc..f4bd068 100755 (executable)
@@ -71,7 +71,7 @@ INCLUDE_DIRECTORIES(
 
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(storage_pkgs REQUIRED glib-2.0 dlog openssl vconf dbus-1 contacts-service2 libtzplatform-config)
+pkg_check_modules(storage_pkgs REQUIRED glib-2.0 dlog openssl1.1 vconf dbus-1 contacts-service2 libtzplatform-config)
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${storage_pkgs_CFLAGS})
@@ -110,7 +110,7 @@ INCLUDE_DIRECTORIES(
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(network_pkgs REQUIRED glib-2.0 uw-imap-toolkit dbus-1 vconf dlog openssl)
+pkg_check_modules(network_pkgs REQUIRED glib-2.0 uw-imap-toolkit dbus-1 vconf dlog openssl1.1)
 
 FOREACH(flag ${network_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -234,8 +234,8 @@ INCLUDE_DIRECTORIES(
 
 INCLUDE(FindPkgConfig)
 SET(PKG_MODULES glib-2.0 dlog dbus-1 gthread-2.0 key-manager tpkp-curl
-                       uw-imap-toolkit vconf vconf-internal-keys contacts-service2 
-                       openssl accounts-svc alarm-service notification libcurl libxml-2.0 
+                       uw-imap-toolkit vconf vconf-internal-keys contacts-service2
+                       openssl1.1 accounts-svc alarm-service notification libcurl libxml-2.0
                        cert-svc-vcore badge capi-appfw-application icu-i18n gmime-2.6 storage dpm cryptsvc)
 
 pkg_check_modules(core_pkgs REQUIRED ${PKG_MODULES})
index 3ee8862..2127d34 100755 (executable)
@@ -1038,18 +1038,3 @@ FINISH_OFF:
        return err;
 }
 
-INTERNAL_FUNC void emcore_init_openssl_library()
-{
-        EM_DEBUG_FUNC_BEGIN();
-        SSL_library_init();
-        ERR_load_crypto_strings();
-        EM_DEBUG_FUNC_END();
-}
-
-INTERNAL_FUNC void emcore_clean_openssl_library()
-{
-        EM_DEBUG_FUNC_BEGIN();
-        ERR_free_strings();
-        EVP_cleanup();
-        EM_DEBUG_FUNC_END();
-}
index 5aa3587..1af0872 100755 (executable)
@@ -47,7 +47,4 @@ INTERNAL_FUNC int emcore_smime_get_decrypt_message(char *encrypt_message, char *
 
 INTERNAL_FUNC int emcore_convert_mail_data_to_smime_data(char *multi_user_name, emstorage_account_tbl_t *account_tbl_item, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data_list, int *output_attachment_count);
 
-INTERNAL_FUNC void emcore_init_openssl_library();
-INTERNAL_FUNC void emcore_clean_openssl_library();
-
 #endif /* EM_CORE_SMIME_H_ */
index e697880..fa6f7dc 100755 (executable)
@@ -48,9 +48,9 @@ INCLUDE_DIRECTORIES(
 )
 
 INCLUDE(FindPkgConfig)
-SET(PKG_MODULES glib-2.0 dlog dbus-1 gthread-2.0 openssl uw-imap-toolkit 
-                               vconf vconf-internal-keys contacts-service2 alarm-service 
-                               msg-service libwbxml2 libsmack notification 
+SET(PKG_MODULES glib-2.0 dlog dbus-1 gthread-2.0 uw-imap-toolkit
+                               vconf vconf-internal-keys contacts-service2 alarm-service
+                               msg-service libwbxml2 libsmack notification
                                capi-network-connection gmime-2.6)
 
 pkg_check_modules(main_pkgs REQUIRED ${PKG_MODULES})
index a7d9e70..8409a26 100644 (file)
@@ -130,66 +130,6 @@ extern email_event_t *sync_failed_event_data;
 
 static gpointer partial_body_download_thread(gpointer data);
 
-#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
-
-#include <openssl/crypto.h>
-
-#define MAX_THREAD_NUMBER   100
-
-static pthread_mutex_t *lock_cs;
-static long *lock_count;
-
-void pthreads_locking_callback(int mode, int type, char *file, int line)
-{
-       if (mode & CRYPTO_LOCK) {
-               pthread_mutex_lock(&(lock_cs[type]));
-               lock_count[type]++;
-       } else {
-               pthread_mutex_unlock(&(lock_cs[type]));
-       }
-}
-
-unsigned long pthreads_thread_id(void)
-{
-       return (unsigned long)pthread_self();
-}
-
-INTERNAL_FUNC void emdaemon_setup_handler_for_open_ssl_multithread(void)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       int i = 0;
-
-       lock_cs    = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
-       lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
-
-       for (i = 0; i < CRYPTO_num_locks(); i++) {
-               lock_count[i] = 0;
-               pthread_mutex_init(&(lock_cs[i]), NULL);
-       }
-
-       CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
-       CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
-       EM_DEBUG_FUNC_END();
-}
-
-INTERNAL_FUNC void emdaemon_cleanup_handler_for_open_ssl_multithread(void)
-{
-       EM_DEBUG_FUNC_BEGIN();
-       int i = 0;
-
-       CRYPTO_set_locking_callback(NULL);
-       for (i = 0; i < CRYPTO_num_locks(); i++) {
-               pthread_mutex_destroy(&(lock_cs[i]));
-               EM_DEBUG_LOG("%8ld:%s", lock_count[i], CRYPTO_get_lock_name(i));
-       }
-       OPENSSL_free(lock_cs);
-       OPENSSL_free(lock_count);
-
-       EM_DEBUG_FUNC_END();
-}
-
-#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
-
 /* start api event_data loop */
 INTERNAL_FUNC int emdaemon_start_event_loop(int *err_code)
 {
index f61de58..96745b8 100755 (executable)
@@ -99,10 +99,6 @@ static int _emdaemon_load_email_core()
        if (!emdaemon_core_init(&err))
                goto FINISH_OFF;
 
-#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
-       emdaemon_setup_handler_for_open_ssl_multithread();
-#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
-
        if (emdaemon_start_event_loop(&err) < 0)
                goto FINISH_OFF;
 
@@ -156,10 +152,6 @@ static int _emdaemon_unload_email_core()
        emcore_stop_auto_download_loop(&err);
 #endif
 
-#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
-       emdaemon_cleanup_handler_for_open_ssl_multithread();
-#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
-
        EM_DEBUG_FUNC_END("err [%d]", err);
        return err;
 }
@@ -659,9 +651,6 @@ INTERNAL_FUNC int emdaemon_finalize(int* err_code)
                goto FINISH_OFF;
        }
 
-        /* Openssl clean up */
-        emcore_clean_openssl_library();
-
        ret = true;
 
 FINISH_OFF:
@@ -749,9 +738,6 @@ INTERNAL_FUNC int emdaemon_core_init(int *err_code)
 
        emdaemon_init_alarm_data_list();
 
-       /* Openssl library init */
-       emcore_init_openssl_library();
-
        if (err_code)
                *err_code = EMAIL_ERROR_NONE;
 
index 799338e..13cfd22 100755 (executable)
@@ -34,11 +34,6 @@ INTERNAL_FUNC int emdaemon_start_event_loop(int *err_code);
 INTERNAL_FUNC int emdaemon_start_event_loop_for_sending_mails(int *err_code);
 INTERNAL_FUNC int emdaemon_start_thread_for_downloading_partial_body(int *err_code);
 
-#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
-INTERNAL_FUNC void emdaemon_setup_handler_for_open_ssl_multithread(void);
-INTERNAL_FUNC void emdaemon_cleanup_handler_for_open_ssl_multithread(void);
-#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 3f93a85..387a5f6 100755 (executable)
@@ -31,7 +31,7 @@ BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(uw-imap-toolkit)
-BuildRequires:  pkgconfig(openssl)
+BuildRequires:  pkgconfig(openssl1.1)
 BuildRequires:  pkgconfig(alarm-service)
 BuildRequires:  pkgconfig(key-manager)
 BuildRequires:  pkgconfig(notification)