Set OpenSSL locking callback.

Refs #4865
This commit is contained in:
Gunnar Beutner 2014-04-12 21:22:59 +02:00
parent edf82f7b4d
commit 0ea144a64d
3 changed files with 14 additions and 5 deletions

View File

@ -38,11 +38,9 @@ bool I2_EXPORT TlsStream::m_SSLIndexInitialized = false;
* @param sslContext The SSL context for the client. * @param sslContext The SSL context for the client.
*/ */
TlsStream::TlsStream(const Stream::Ptr& innerStream, TlsRole role, shared_ptr<SSL_CTX> sslContext) TlsStream::TlsStream(const Stream::Ptr& innerStream, TlsRole role, shared_ptr<SSL_CTX> sslContext)
: m_InnerStream(innerStream), m_SSLContext(sslContext), m_Role(role) : m_InnerStream(innerStream), m_Role(role)
{ {
m_SSL = shared_ptr<SSL>(SSL_new(m_SSLContext.get()), SSL_free); m_SSL = shared_ptr<SSL>(SSL_new(sslContext.get()), SSL_free);
m_SSLContext.reset();
if (!m_SSL) { if (!m_SSL) {
BOOST_THROW_EXCEPTION(openssl_error() BOOST_THROW_EXCEPTION(openssl_error()

View File

@ -59,7 +59,6 @@ public:
virtual bool IsEof(void) const; virtual bool IsEof(void) const;
private: private:
shared_ptr<SSL_CTX> m_SSLContext;
shared_ptr<SSL> m_SSL; shared_ptr<SSL> m_SSL;
BIO *m_BIO; BIO *m_BIO;

View File

@ -23,6 +23,15 @@ namespace icinga
{ {
static bool l_SSLInitialized = false; static bool l_SSLInitialized = false;
static boost::mutex *l_Mutexes;
static void OpenSSLLockingCallback(int mode, int type, const char *file, int line)
{
if (mode & CRYPTO_LOCK)
l_Mutexes[type].lock();
else
l_Mutexes[type].unlock();
}
/** /**
* Initializes the OpenSSL library. * Initializes the OpenSSL library.
@ -37,6 +46,9 @@ static void InitializeOpenSSL(void)
SSL_COMP_get_compression_methods(); SSL_COMP_get_compression_methods();
l_Mutexes = new boost::mutex[CRYPTO_num_locks()];
CRYPTO_set_locking_callback(&OpenSSLLockingCallback);
l_SSLInitialized = true; l_SSLInitialized = true;
} }