diff options
| author | beck <> | 2018-03-17 16:20:01 +0000 |
|---|---|---|
| committer | beck <> | 2018-03-17 16:20:01 +0000 |
| commit | d18ae25f28e72831dc3c51f78e0735342540098b (patch) | |
| tree | 12cc674e7652f4d67e57ec9e1882e6e824b4808d /src/lib/libcrypto/conf | |
| parent | 736fdc7bedf7fe8b17717032f7380c5c6e247d0d (diff) | |
| download | openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.tar.gz openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.tar.bz2 openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.zip | |
Bring in compatibility for OpenSSL 1.1 style init functions.
This adds OPENSSL_init_crypto and OPENSSL_init_ssl, as well
thread safety modifications for the existing LibreSSL init
functions. The initialization routines are called automatically
by the normal entry points into the library, as in newer OpenSSL
ok jsing@, nits by tb@ and deraadt@
Diffstat (limited to 'src/lib/libcrypto/conf')
| -rw-r--r-- | src/lib/libcrypto/conf/conf_sap.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c index a29acea7c1..f1844f69f4 100644 --- a/src/lib/libcrypto/conf/conf_sap.c +++ b/src/lib/libcrypto/conf/conf_sap.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: conf_sap.c,v 1.11 2015/02/11 03:19:37 doug Exp $ */ | 1 | /* $OpenBSD: conf_sap.c,v 1.12 2018/03/17 16:20:01 beck Exp $ */ |
| 2 | /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2001. | 3 | * project 2001. |
| 4 | */ | 4 | */ |
| @@ -56,6 +56,7 @@ | |||
| 56 | * | 56 | * |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <pthread.h> | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 60 | 61 | ||
| 61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
| @@ -75,23 +76,24 @@ | |||
| 75 | * unless this is overridden by calling OPENSSL_no_config() | 76 | * unless this is overridden by calling OPENSSL_no_config() |
| 76 | */ | 77 | */ |
| 77 | 78 | ||
| 78 | static int openssl_configured = 0; | 79 | static pthread_once_t openssl_configured = PTHREAD_ONCE_INIT; |
| 79 | 80 | ||
| 80 | void | 81 | static const char *openssl_config_name; |
| 81 | OPENSSL_config(const char *config_name) | ||
| 82 | { | ||
| 83 | if (openssl_configured) | ||
| 84 | return; | ||
| 85 | 82 | ||
| 83 | void ENGINE_load_builtin_engines_internal(void); | ||
| 84 | |||
| 85 | static void | ||
| 86 | OPENSSL_config_internal(void) | ||
| 87 | { | ||
| 86 | OPENSSL_load_builtin_modules(); | 88 | OPENSSL_load_builtin_modules(); |
| 87 | #ifndef OPENSSL_NO_ENGINE | 89 | #ifndef OPENSSL_NO_ENGINE |
| 88 | /* Need to load ENGINEs */ | 90 | /* Need to load ENGINEs */ |
| 89 | ENGINE_load_builtin_engines(); | 91 | ENGINE_load_builtin_engines_internal(); |
| 90 | #endif | 92 | #endif |
| 91 | /* Add others here? */ | 93 | /* Add others here? */ |
| 92 | 94 | ||
| 93 | ERR_clear_error(); | 95 | ERR_clear_error(); |
| 94 | if (CONF_modules_load_file(NULL, config_name, | 96 | if (CONF_modules_load_file(NULL, openssl_config_name, |
| 95 | CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) { | 97 | CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) { |
| 96 | BIO *bio_err; | 98 | BIO *bio_err; |
| 97 | ERR_load_crypto_strings(); | 99 | ERR_load_crypto_strings(); |
| @@ -107,7 +109,31 @@ OPENSSL_config(const char *config_name) | |||
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | void | 111 | void |
| 112 | OPENSSL_config(const char *config_name) | ||
| 113 | { | ||
| 114 | /* Don't override if NULL */ | ||
| 115 | /* | ||
| 116 | * Note - multiple threads calling this with *different* config names | ||
| 117 | * is probably not advisable. One thread will win, but you don't know | ||
| 118 | * if it will be the same thread as wins the pthread_once. | ||
| 119 | */ | ||
| 120 | if (config_name != NULL) | ||
| 121 | openssl_config_name = config_name; | ||
| 122 | |||
| 123 | (void) OPENSSL_init_crypto(0, NULL); | ||
| 124 | |||
| 125 | (void) pthread_once(&openssl_configured, OPENSSL_config_internal); | ||
| 126 | |||
| 127 | return; | ||
| 128 | } | ||
| 129 | |||
| 130 | static void | ||
| 131 | OPENSSL_no_config_internal(void) | ||
| 132 | { | ||
| 133 | } | ||
| 134 | |||
| 135 | void | ||
| 110 | OPENSSL_no_config(void) | 136 | OPENSSL_no_config(void) |
| 111 | { | 137 | { |
| 112 | openssl_configured = 1; | 138 | (void) pthread_once(&openssl_configured, OPENSSL_no_config_internal); |
| 113 | } | 139 | } |
