summaryrefslogtreecommitdiff
path: root/lib/libcrypto/conf
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2018-03-17 16:20:02 +0000
committerBob Beck <beck@cvs.openbsd.org>2018-03-17 16:20:02 +0000
commitd83b0021084a06853c2e11f06f5db729bf3d6b63 (patch)
tree9bc3c82ef5d22ad7695889a5ca723dc30571fe51 /lib/libcrypto/conf
parentf1c695dbced730499b0200286f944d2c271be41d (diff)
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 'lib/libcrypto/conf')
-rw-r--r--lib/libcrypto/conf/conf_sap.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/libcrypto/conf/conf_sap.c b/lib/libcrypto/conf/conf_sap.c
index a29acea7c1e..f1844f69f4d 100644
--- a/lib/libcrypto/conf/conf_sap.c
+++ b/lib/libcrypto/conf/conf_sap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conf_sap.c,v 1.11 2015/02/11 03:19:37 doug Exp $ */
+/* $OpenBSD: conf_sap.c,v 1.12 2018/03/17 16:20:01 beck Exp $ */
/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
* project 2001.
*/
@@ -56,6 +56,7 @@
*
*/
+#include <pthread.h>
#include <stdio.h>
#include <openssl/opensslconf.h>
@@ -75,23 +76,24 @@
* unless this is overridden by calling OPENSSL_no_config()
*/
-static int openssl_configured = 0;
+static pthread_once_t openssl_configured = PTHREAD_ONCE_INIT;
-void
-OPENSSL_config(const char *config_name)
-{
- if (openssl_configured)
- return;
+static const char *openssl_config_name;
+void ENGINE_load_builtin_engines_internal(void);
+
+static void
+OPENSSL_config_internal(void)
+{
OPENSSL_load_builtin_modules();
#ifndef OPENSSL_NO_ENGINE
/* Need to load ENGINEs */
- ENGINE_load_builtin_engines();
+ ENGINE_load_builtin_engines_internal();
#endif
/* Add others here? */
ERR_clear_error();
- if (CONF_modules_load_file(NULL, config_name,
+ if (CONF_modules_load_file(NULL, openssl_config_name,
CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
BIO *bio_err;
ERR_load_crypto_strings();
@@ -107,7 +109,31 @@ OPENSSL_config(const char *config_name)
}
void
+OPENSSL_config(const char *config_name)
+{
+ /* Don't override if NULL */
+ /*
+ * Note - multiple threads calling this with *different* config names
+ * is probably not advisable. One thread will win, but you don't know
+ * if it will be the same thread as wins the pthread_once.
+ */
+ if (config_name != NULL)
+ openssl_config_name = config_name;
+
+ (void) OPENSSL_init_crypto(0, NULL);
+
+ (void) pthread_once(&openssl_configured, OPENSSL_config_internal);
+
+ return;
+}
+
+static void
+OPENSSL_no_config_internal(void)
+{
+}
+
+void
OPENSSL_no_config(void)
{
- openssl_configured = 1;
+ (void) pthread_once(&openssl_configured, OPENSSL_no_config_internal);
}