mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-23 07:12:45 +01:00
Allow caller to disable SSL Initialization, so it can be done outside of Poco.
This commit is contained in:
parent
b565d72d4c
commit
6ccfaa53d0
@ -44,7 +44,7 @@ namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API OpenSSLInitializer
|
||||
/// Initializes the OpenSSL library.
|
||||
/// Initalizes the OpenSSL library.
|
||||
///
|
||||
/// The class ensures the earliest initialization and the
|
||||
/// latest shutdown of the OpenSSL library.
|
||||
@ -68,6 +68,8 @@ public:
|
||||
static void enableFIPSMode(bool enabled);
|
||||
// Enable or disable FIPS mode. If FIPS is not available, this method doesn't do anything.
|
||||
|
||||
static void disableSSLInitialization(); // Call if OpenSSL is already being initialized by another component before constructing any OpenSSLInitializers.
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
@ -84,6 +86,8 @@ protected:
|
||||
private:
|
||||
static Poco::FastMutex* _mutexes;
|
||||
static Poco::AtomicCounter _rc;
|
||||
static bool _disableSSLInitialization;
|
||||
static bool _setupMultiThreadSupport;
|
||||
};
|
||||
|
||||
|
||||
@ -110,6 +114,11 @@ inline void OpenSSLInitializer::enableFIPSMode(bool /*enabled*/)
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void OpenSSLInitializer::disableSSLInitialization()
|
||||
{
|
||||
_disableSSLInitialization = true;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace Crypto {
|
||||
|
||||
Poco::FastMutex* OpenSSLInitializer::_mutexes(0);
|
||||
Poco::AtomicCounter OpenSSLInitializer::_rc;
|
||||
|
||||
bool OpenSSLInitializer::_disableSSLInitialization = false;
|
||||
|
||||
OpenSSLInitializer::OpenSSLInitializer()
|
||||
{
|
||||
@ -64,15 +64,18 @@ void OpenSSLInitializer::initialize()
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
|
||||
OPENSSL_config(NULL);
|
||||
#endif
|
||||
if(! _disableSSLInitialization) {
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
OpenSSL_add_all_algorithms();
|
||||
}
|
||||
|
||||
char seed[SEEDSIZE];
|
||||
RandomInputStream rnd;
|
||||
rnd.read(seed, sizeof(seed));
|
||||
RAND_seed(seed, SEEDSIZE);
|
||||
|
||||
if(CRYPTO_get_locking_callback() == NULL) {
|
||||
int nMutexes = CRYPTO_num_locks();
|
||||
_mutexes = new Poco::FastMutex[nMutexes];
|
||||
CRYPTO_set_locking_callback(&OpenSSLInitializer::lock);
|
||||
@ -91,23 +94,30 @@ void OpenSSLInitializer::initialize()
|
||||
CRYPTO_set_dynlock_destroy_callback(&OpenSSLInitializer::dynlockDestroy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::uninitialize()
|
||||
{
|
||||
if (--_rc == 0)
|
||||
{
|
||||
EVP_cleanup();
|
||||
ERR_free_strings();
|
||||
if(_mutexes != NULL) {
|
||||
CRYPTO_set_dynlock_create_callback(0);
|
||||
CRYPTO_set_dynlock_lock_callback(0);
|
||||
CRYPTO_set_dynlock_destroy_callback(0);
|
||||
CRYPTO_set_locking_callback(0);
|
||||
#ifndef POCO_OS_FAMILY_WINDOWS
|
||||
CRYPTO_set_id_callback(0);
|
||||
#endif
|
||||
delete [] _mutexes;
|
||||
|
||||
}
|
||||
if(! _disableSSLInitialization) {
|
||||
EVP_cleanup();
|
||||
ERR_free_strings();
|
||||
CONF_modules_free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::lock(int mode, int n, const char* file, int line)
|
||||
|
Loading…
x
Reference in New Issue
Block a user