diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/crypto_init.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/lib/libcrypto/crypto_init.c b/src/lib/libcrypto/crypto_init.c index 67e7920890..69ba62991e 100644 --- a/src/lib/libcrypto/crypto_init.c +++ b/src/lib/libcrypto/crypto_init.c | |||
| @@ -19,17 +19,21 @@ | |||
| 19 | #include <pthread.h> | 19 | #include <pthread.h> |
| 20 | #include <stdio.h> | 20 | #include <stdio.h> |
| 21 | 21 | ||
| 22 | #include <openssl/objects.h> | ||
| 23 | #include <openssl/conf.h> | 22 | #include <openssl/conf.h> |
| 24 | #include <openssl/evp.h> | 23 | #include <openssl/engine.h> |
| 25 | #include <openssl/err.h> | 24 | #include <openssl/err.h> |
| 25 | #include <openssl/evp.h> | ||
| 26 | #include <openssl/objects.h> | ||
| 26 | 27 | ||
| 27 | #include "cryptlib.h" | 28 | #include "cryptlib.h" |
| 29 | #include "x509_issuer_cache.h" | ||
| 28 | 30 | ||
| 29 | int OpenSSL_config(const char *); | 31 | int OpenSSL_config(const char *); |
| 30 | int OpenSSL_no_config(void); | 32 | int OpenSSL_no_config(void); |
| 31 | 33 | ||
| 34 | static pthread_once_t crypto_init_once = PTHREAD_ONCE_INIT; | ||
| 32 | static pthread_t crypto_init_thread; | 35 | static pthread_t crypto_init_thread; |
| 36 | static int crypto_init_cleaned_up; | ||
| 33 | 37 | ||
| 34 | static void | 38 | static void |
| 35 | OPENSSL_init_crypto_internal(void) | 39 | OPENSSL_init_crypto_internal(void) |
| @@ -45,12 +49,15 @@ OPENSSL_init_crypto_internal(void) | |||
| 45 | int | 49 | int |
| 46 | OPENSSL_init_crypto(uint64_t opts, const void *settings) | 50 | OPENSSL_init_crypto(uint64_t opts, const void *settings) |
| 47 | { | 51 | { |
| 48 | static pthread_once_t once = PTHREAD_ONCE_INIT; | 52 | if (crypto_init_cleaned_up) { |
| 53 | CRYPTOerror(ERR_R_INIT_FAIL); | ||
| 54 | return 0; | ||
| 55 | } | ||
| 49 | 56 | ||
| 50 | if (pthread_equal(pthread_self(), crypto_init_thread)) | 57 | if (pthread_equal(pthread_self(), crypto_init_thread)) |
| 51 | return 1; /* don't recurse */ | 58 | return 1; /* don't recurse */ |
| 52 | 59 | ||
| 53 | if (pthread_once(&once, OPENSSL_init_crypto_internal) != 0) | 60 | if (pthread_once(&crypto_init_once, OPENSSL_init_crypto_internal) != 0) |
| 54 | return 0; | 61 | return 0; |
| 55 | 62 | ||
| 56 | if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) && | 63 | if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) && |
| @@ -63,3 +70,16 @@ OPENSSL_init_crypto(uint64_t opts, const void *settings) | |||
| 63 | 70 | ||
| 64 | return 1; | 71 | return 1; |
| 65 | } | 72 | } |
| 73 | |||
| 74 | void | ||
| 75 | OPENSSL_cleanup(void) | ||
| 76 | { | ||
| 77 | /* This currently calls init... */ | ||
| 78 | ERR_free_strings(); | ||
| 79 | |||
| 80 | ENGINE_cleanup(); | ||
| 81 | EVP_cleanup(); | ||
| 82 | x509_issuer_cache_free(); | ||
| 83 | |||
| 84 | crypto_init_cleaned_up = 1; | ||
| 85 | } | ||
