From a6a098b473de2a37526fe036e88301e5ac9265dc Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 6 Nov 2012 16:05:04 +0100 Subject: [PATCH] Thread-safe initialization for OpenSSL. --- src/net/tls/openssl/TLSSession_OpenSSL.cpp | 7 +++---- src/security/cert/openssl/X509Certificate_OpenSSL.cpp | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/net/tls/openssl/TLSSession_OpenSSL.cpp b/src/net/tls/openssl/TLSSession_OpenSSL.cpp index e03c90f6..5d7e1052 100755 --- a/src/net/tls/openssl/TLSSession_OpenSSL.cpp +++ b/src/net/tls/openssl/TLSSession_OpenSSL.cpp @@ -47,10 +47,6 @@ namespace net { namespace tls { -// Thread-safe OpenSSL initialization -static OpenSSLInitializer g_openSSLGlobal; - - // static ref TLSSession::create(ref cv) { @@ -61,6 +57,9 @@ ref TLSSession::create(ref cv TLSSession_OpenSSL::TLSSession_OpenSSL(ref cv) : m_sslctx(0), m_certVerifier(cv) { + // Thread-safe OpenSSL initialization + static OpenSSLInitializer openSSLInitialization; + m_sslctx = SSL_CTX_new(SSLv23_client_method()); SSL_CTX_set_options(m_sslctx, SSL_OP_ALL | SSL_OP_NO_SSLv2); } diff --git a/src/security/cert/openssl/X509Certificate_OpenSSL.cpp b/src/security/cert/openssl/X509Certificate_OpenSSL.cpp index dacb006e..e47a19a4 100755 --- a/src/security/cert/openssl/X509Certificate_OpenSSL.cpp +++ b/src/security/cert/openssl/X509Certificate_OpenSSL.cpp @@ -34,6 +34,8 @@ #include "vmime/security/cert/openssl/X509Certificate_OpenSSL.hpp" +#include "vmime/net/tls/openssl/OpenSSLInitializer.hpp" + #include "vmime/utility/outputStreamByteArrayAdapter.hpp" #include "vmime/exception.hpp" @@ -97,6 +99,9 @@ struct OpenSSLX509CertificateInternalData { OpenSSLX509CertificateInternalData() { + // Thread-safe OpenSSL initialization + static net::tls::OpenSSLInitializer openSSLInitialization; + cert = 0; }