diff options
author | Alexander Smirnov <alex@ydb.tech> | 2025-05-29 11:09:23 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2025-05-29 11:09:23 +0000 |
commit | a34a6816abefdcfe2c00295edb510cc5c99ad52c (patch) | |
tree | a264baadccf7add09a1b285786307ddd774472a5 /library/cpp/openssl/init/init.cpp | |
parent | 84ec9093e10073ab151bfe5f81037a0d017c2362 (diff) | |
parent | fdbc38349df2ee0ddc678fa2bffe84786f9639a3 (diff) | |
download | ydb-a34a6816abefdcfe2c00295edb510cc5c99ad52c.tar.gz |
Merge branch 'rightlib' into merge-libs-250529-1108
Diffstat (limited to 'library/cpp/openssl/init/init.cpp')
-rw-r--r-- | library/cpp/openssl/init/init.cpp | 65 |
1 files changed, 6 insertions, 59 deletions
diff --git a/library/cpp/openssl/init/init.cpp b/library/cpp/openssl/init/init.cpp index ae68ef08eaa..9a4e285ea35 100644 --- a/library/cpp/openssl/init/init.cpp +++ b/library/cpp/openssl/init/init.cpp @@ -1,66 +1,13 @@ -#include "init.h" - -#include <util/generic/singleton.h> -#include <util/generic/vector.h> -#include <util/generic/ptr.h> -#include <util/generic/buffer.h> - -#include <util/system/yassert.h> -#include <util/system/mutex.h> -#include <util/system/thread.h> - -#include <util/random/entropy.h> -#include <util/stream/input.h> - -#include <openssl/bio.h> -#include <openssl/ssl.h> -#include <openssl/err.h> -#include <openssl/rand.h> -#include <openssl/conf.h> #include <openssl/crypto.h> namespace { - struct TInitSsl { - struct TOpensslLocks { - inline TOpensslLocks() - : Mutexes(CRYPTO_num_locks()) - { - for (auto& mpref : Mutexes) { - mpref.Reset(new TMutex()); - } - } - - inline void LockOP(int mode, int n) { - auto& mutex = *Mutexes.at(n); - - if (mode & CRYPTO_LOCK) { - mutex.Acquire(); - } else { - mutex.Release(); - } - } - - TVector<TAutoPtr<TMutex>> Mutexes; - }; - - inline TInitSsl() { - OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, nullptr); - } - - inline ~TInitSsl() { - OPENSSL_cleanup(); - } - - static void LockingFunction(int mode, int n, const char* /*file*/, int /*line*/) { - Singleton<TOpensslLocks>()->LockOP(mode, n); - } - - static unsigned long ThreadIdFunction() { - return TThread::CurrentThreadId(); - } - }; + // Initialize OpenSSL as early as possible + // in order to prevent any further initializations with different flags. + // + // Initialize it with OPENSSL_INIT_NO_ATEXIT thus omitting the cleanup routine at process exit + // (it looks like it does nothing when openssl is linked statically). + [[maybe_unused]] auto _ = OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN | OPENSSL_INIT_NO_ATEXIT, nullptr); } void InitOpenSSL() { - (void)SingletonWithPriority<TInitSsl, 0>(); } |