summaryrefslogtreecommitdiff
path: root/src/lib/emile
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2015-03-17 08:49:58 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 09:58:17 +0100
commit2d342c281473cc9f03b76dfe234f60fc60377c4a (patch)
tree6ad521eb6c92070b3a3c61362fc31164a148580b /src/lib/emile
parent0b04186a7fd530bc36dccfd27930a18506313ee4 (diff)
emile: move GNUTLS and OpenSSL initialization logic from Eet to Emile.
Diffstat (limited to 'src/lib/emile')
-rw-r--r--src/lib/emile/emile_main.c75
1 files changed, 73 insertions, 2 deletions
diff --git a/src/lib/emile/emile_main.c b/src/lib/emile/emile_main.c
index 389f66022b..5aa80acd66 100644
--- a/src/lib/emile/emile_main.c
+++ b/src/lib/emile/emile_main.c
@@ -1,6 +1,27 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif /* ifdef HAVE_CONFIG_H */
4
5#ifdef HAVE_GNUTLS
6# include <gnutls/gnutls.h>
7# include <gnutls/x509.h>
8# include <gcrypt.h>
9#endif /* ifdef HAVE_GNUTLS */
10
11#ifdef HAVE_OPENSSL
12# include <openssl/ssl.h>
13# include <openssl/err.h>
14# include <openssl/evp.h>
15#endif /* ifdef HAVE_OPENSSL */
16
1#include <Eina.h> 17#include <Eina.h>
2 18
3#include "Emile.h" 19#include "Emile.h"
20#include "emile_private.h"
21
22#ifdef HAVE_GNUTLS
23GCRY_THREAD_OPTION_PTHREAD_IMPL;
24#endif /* ifdef HAVE_GNUTLS */
4 25
5static unsigned int _emile_init_count = 0; 26static unsigned int _emile_init_count = 0;
6int _emile_log_dom_global = -1; 27int _emile_log_dom_global = -1;
@@ -21,7 +42,38 @@ emile_init(void)
21 goto shutdown_eina; 42 goto shutdown_eina;
22 } 43 }
23 44
24 // FIXME: Init the rest here. 45#ifdef HAVE_GNUTLS
46 /* Before the library can be used, it must initialize itself if needed. */
47 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
48 {
49 gcry_check_version(NULL);
50 /* Disable warning messages about problems with the secure memory subsystem.
51 This command should be run right after gcry_check_version. */
52 if (gcry_control(GCRYCTL_DISABLE_SECMEM_WARN))
53 goto shutdown_eet; /* This command is used to allocate a pool of secure memory and thus
54 enabling the use of secure memory. It also drops all extra privileges the
55 process has (i.e. if it is run as setuid (root)). If the argument nbytes
56 is 0, secure memory will be disabled. The minimum amount of secure memory
57 allocated is currently 16384 bytes; you may thus use a value of 1 to
58 request that default size. */
59
60 if (gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0))
61 WRN(
62 "BIG FAT WARNING: I AM UNABLE TO REQUEST SECMEM, Cryptographic operation are at risk !");
63 }
64
65 if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread))
66 WRN(
67 "YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!");
68
69 if (gnutls_global_init())
70 goto shutdown_eet;
71
72#endif /* ifdef HAVE_GNUTLS */
73#ifdef HAVE_OPENSSL
74 ERR_load_crypto_strings();
75 OpenSSL_add_all_algorithms();
76#endif /* ifdef HAVE_OPENSSL */
25 77
26 eina_log_timing(_emile_log_dom_global, 78 eina_log_timing(_emile_log_dom_global,
27 EINA_LOG_STATE_STOP, 79 EINA_LOG_STATE_STOP,
@@ -45,7 +97,26 @@ emile_shutdown(void)
45 EINA_LOG_STATE_START, 97 EINA_LOG_STATE_START,
46 EINA_LOG_STATE_SHUTDOWN); 98 EINA_LOG_STATE_SHUTDOWN);
47 99
48 // FIXME: Shutdown the rest here. 100#ifdef HAVE_GNUTLS
101 /* Note that gnutls has a leak where it doesnt free stuff it alloced
102 * on init. valgrind trace here:
103 * 21 bytes in 1 blocks are definitely lost in loss record 24 of 194
104 * at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
105 * by 0x68AC801: strdup (strdup.c:43)
106 * by 0xD215B6A: p11_kit_registered_module_to_name (in /usr/lib/x86_64-linux-gnu/libp11-kit.so.0.0.0)
107 * by 0x9571574: gnutls_pkcs11_init (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.21.8)
108 * by 0x955B031: gnutls_global_init (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.21.8)
109 * by 0x6DFD6D0: eet_init (eet_lib.c:608)
110 *
111 * yes - i've tried calling gnutls_pkcs11_deinit() by hand but no luck.
112 * the leak is in there.
113 */
114 gnutls_global_deinit();
115#endif /* ifdef HAVE_GNUTLS */
116#ifdef HAVE_OPENSSL
117 EVP_cleanup();
118 ERR_free_strings();
119#endif /* ifdef HAVE_OPENSSL */
49 120
50 eina_log_domain_unregister(_emile_log_dom_global); 121 eina_log_domain_unregister(_emile_log_dom_global);
51 _emile_log_dom_global = -1; 122 _emile_log_dom_global = -1;