|
1 |
| -#include "init.h" |
2 |
| - |
3 |
| -#include <util/generic/singleton.h> |
4 |
| -#include <util/generic/vector.h> |
5 |
| -#include <util/generic/ptr.h> |
6 |
| -#include <util/generic/buffer.h> |
7 |
| - |
8 |
| -#include <util/system/yassert.h> |
9 |
| -#include <util/system/mutex.h> |
10 |
| -#include <util/system/thread.h> |
11 |
| - |
12 |
| -#include <util/random/entropy.h> |
13 |
| -#include <util/stream/input.h> |
14 |
| - |
15 |
| -#include <openssl/bio.h> |
16 |
| -#include <openssl/ssl.h> |
17 |
| -#include <openssl/err.h> |
18 |
| -#include <openssl/rand.h> |
19 |
| -#include <openssl/conf.h> |
20 | 1 | #include <openssl/crypto.h>
|
21 | 2 |
|
22 | 3 | namespace {
|
23 |
| - struct TInitSsl { |
24 |
| - struct TOpensslLocks { |
25 |
| - inline TOpensslLocks() |
26 |
| - : Mutexes(CRYPTO_num_locks()) |
27 |
| - { |
28 |
| - for (auto& mpref : Mutexes) { |
29 |
| - mpref.Reset(new TMutex()); |
30 |
| - } |
31 |
| - } |
32 |
| - |
33 |
| - inline void LockOP(int mode, int n) { |
34 |
| - auto& mutex = *Mutexes.at(n); |
35 |
| - |
36 |
| - if (mode & CRYPTO_LOCK) { |
37 |
| - mutex.Acquire(); |
38 |
| - } else { |
39 |
| - mutex.Release(); |
40 |
| - } |
41 |
| - } |
42 |
| - |
43 |
| - TVector<TAutoPtr<TMutex>> Mutexes; |
44 |
| - }; |
45 |
| - |
46 |
| - inline TInitSsl() { |
47 |
| - OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, nullptr); |
48 |
| - } |
49 |
| - |
50 |
| - inline ~TInitSsl() { |
51 |
| - OPENSSL_cleanup(); |
52 |
| - } |
53 |
| - |
54 |
| - static void LockingFunction(int mode, int n, const char* /*file*/, int /*line*/) { |
55 |
| - Singleton<TOpensslLocks>()->LockOP(mode, n); |
56 |
| - } |
57 |
| - |
58 |
| - static unsigned long ThreadIdFunction() { |
59 |
| - return TThread::CurrentThreadId(); |
60 |
| - } |
61 |
| - }; |
| 4 | + // Initialize OpenSSL as early as possible |
| 5 | + // in order to prevent any further initializations with different flags. |
| 6 | + // |
| 7 | + // Initialize it with OPENSSL_INIT_NO_ATEXIT thus omitting the cleanup routine at process exit |
| 8 | + // (it looks like it does nothing when openssl is linked statically). |
| 9 | + [[maybe_unused]] auto _ = OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN | OPENSSL_INIT_NO_ATEXIT, nullptr); |
62 | 10 | }
|
63 | 11 |
|
64 | 12 | void InitOpenSSL() {
|
65 |
| - (void)SingletonWithPriority<TInitSsl, 0>(); |
66 | 13 | }
|
0 commit comments