diff options
author | beck <> | 2018-03-19 03:35:38 +0000 |
---|---|---|
committer | beck <> | 2018-03-19 03:35:38 +0000 |
commit | e464d58452a0842aa8954833a7d46480949f5a6b (patch) | |
tree | c2587bdba8d5d81576ed1d6536ed36f021b869cf /src | |
parent | 564b3a21a369968f47b3ff19408fbd270a6ac8f2 (diff) | |
download | openbsd-e464d58452a0842aa8954833a7d46480949f5a6b.tar.gz openbsd-e464d58452a0842aa8954833a7d46480949f5a6b.tar.bz2 openbsd-e464d58452a0842aa8954833a7d46480949f5a6b.zip |
Correct mistake of loading the default openssl.conf by default during autoinit.
This brings in the OPENSSL_INIT_LOAD_CONFIG flag with the same semantics as
OpenSSL. As a result, by default the openssl.conf file is not loaded during
autoinit, which makes autoinit safe for pledge(stdio).
ok jsing@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/conf/conf_sap.c | 31 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto_init.c | 15 |
3 files changed, 37 insertions, 13 deletions
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c index f1844f69f4..98497025ee 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.12 2018/03/17 16:20:01 beck Exp $ */ | 1 | /* $OpenBSD: conf_sap.c,v 1.13 2018/03/19 03:35:38 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 | */ |
@@ -108,8 +108,8 @@ OPENSSL_config_internal(void) | |||
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | 110 | ||
111 | void | 111 | int |
112 | OPENSSL_config(const char *config_name) | 112 | OpenSSL_config(const char *config_name) |
113 | { | 113 | { |
114 | /* Don't override if NULL */ | 114 | /* Don't override if NULL */ |
115 | /* | 115 | /* |
@@ -120,11 +120,19 @@ OPENSSL_config(const char *config_name) | |||
120 | if (config_name != NULL) | 120 | if (config_name != NULL) |
121 | openssl_config_name = config_name; | 121 | openssl_config_name = config_name; |
122 | 122 | ||
123 | (void) OPENSSL_init_crypto(0, NULL); | 123 | if (OPENSSL_init_crypto(0, NULL) == 0) |
124 | return 0; | ||
124 | 125 | ||
125 | (void) pthread_once(&openssl_configured, OPENSSL_config_internal); | 126 | if (pthread_once(&openssl_configured, OPENSSL_config_internal) != 0) |
127 | return 0; | ||
126 | 128 | ||
127 | return; | 129 | return 1; |
130 | } | ||
131 | |||
132 | void | ||
133 | OPENSSL_config(const char *config_name) | ||
134 | { | ||
135 | (void) OpenSSL_config(config_name); | ||
128 | } | 136 | } |
129 | 137 | ||
130 | static void | 138 | static void |
@@ -132,8 +140,17 @@ OPENSSL_no_config_internal(void) | |||
132 | { | 140 | { |
133 | } | 141 | } |
134 | 142 | ||
143 | int | ||
144 | OpenSSL_no_config(void) | ||
145 | { | ||
146 | if (pthread_once(&openssl_configured, OPENSSL_no_config_internal) != 0) | ||
147 | return 0; | ||
148 | |||
149 | return 1; | ||
150 | } | ||
151 | |||
135 | void | 152 | void |
136 | OPENSSL_no_config(void) | 153 | OPENSSL_no_config(void) |
137 | { | 154 | { |
138 | (void) pthread_once(&openssl_configured, OPENSSL_no_config_internal); | 155 | (void) OpenSSL_no_config(); |
139 | } | 156 | } |
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index f13ce92584..67e06a1509 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: crypto.h,v 1.44 2018/03/18 01:39:26 tb Exp $ */ | 1 | /* $OpenBSD: crypto.h,v 1.45 2018/03/19 03:35:38 beck Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -547,6 +547,7 @@ void ERR_load_CRYPTO_strings(void); | |||
547 | */ | 547 | */ |
548 | 548 | ||
549 | #define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000001L | 549 | #define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000001L |
550 | #define OPENSSL_INIT_LOAD_CONFIG 0x00000002L | ||
550 | 551 | ||
551 | /* LibreSSL specific */ | 552 | /* LibreSSL specific */ |
552 | #define _OPENSSL_INIT_FLAG_NOOP 0x80000000L | 553 | #define _OPENSSL_INIT_FLAG_NOOP 0x80000000L |
@@ -555,7 +556,6 @@ void ERR_load_CRYPTO_strings(void); | |||
555 | * These are provided for compatibiliy, but have no effect | 556 | * These are provided for compatibiliy, but have no effect |
556 | * on how LibreSSL is initialized. | 557 | * on how LibreSSL is initialized. |
557 | */ | 558 | */ |
558 | #define OPENSSL_INIT_LOAD_CONFIG _OPENSSL_INIT_FLAG_NOOP | ||
559 | #define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS _OPENSSL_INIT_FLAG_NOOP | 559 | #define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS _OPENSSL_INIT_FLAG_NOOP |
560 | #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS _OPENSSL_INIT_FLAG_NOOP | 560 | #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS _OPENSSL_INIT_FLAG_NOOP |
561 | #define OPENSSL_INIT_ADD_ALL_CIPHERS _OPENSSL_INIT_FLAG_NOOP | 561 | #define OPENSSL_INIT_ADD_ALL_CIPHERS _OPENSSL_INIT_FLAG_NOOP |
diff --git a/src/lib/libcrypto/crypto_init.c b/src/lib/libcrypto/crypto_init.c index f3d1a2bce9..ed2b5d4810 100644 --- a/src/lib/libcrypto/crypto_init.c +++ b/src/lib/libcrypto/crypto_init.c | |||
@@ -25,6 +25,9 @@ | |||
25 | #include <openssl/err.h> | 25 | #include <openssl/err.h> |
26 | #include "cryptlib.h" | 26 | #include "cryptlib.h" |
27 | 27 | ||
28 | int OpenSSL_config(char *); | ||
29 | int OpenSSL_no_config(char *); | ||
30 | |||
28 | static pthread_t crypto_init_thread; | 31 | static pthread_t crypto_init_thread; |
29 | 32 | ||
30 | static void | 33 | static void |
@@ -35,7 +38,6 @@ OPENSSL_init_crypto_internal(void) | |||
35 | ERR_load_crypto_strings(); | 38 | ERR_load_crypto_strings(); |
36 | OpenSSL_add_all_ciphers(); | 39 | OpenSSL_add_all_ciphers(); |
37 | OpenSSL_add_all_digests(); | 40 | OpenSSL_add_all_digests(); |
38 | OPENSSL_config(NULL); | ||
39 | } | 41 | } |
40 | 42 | ||
41 | int | 43 | int |
@@ -46,11 +48,16 @@ OPENSSL_init_crypto(uint64_t opts, const void *settings) | |||
46 | if (pthread_equal(pthread_self(), crypto_init_thread)) | 48 | if (pthread_equal(pthread_self(), crypto_init_thread)) |
47 | return 1; /* don't recurse */ | 49 | return 1; /* don't recurse */ |
48 | 50 | ||
49 | if (opts & OPENSSL_INIT_NO_LOAD_CONFIG) | ||
50 | OPENSSL_no_config(); | ||
51 | |||
52 | if (pthread_once(&once, OPENSSL_init_crypto_internal) != 0) | 51 | if (pthread_once(&once, OPENSSL_init_crypto_internal) != 0) |
53 | return 0; | 52 | return 0; |
54 | 53 | ||
54 | if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) && | ||
55 | (OpenSSL_no_config(NULL) == 0)) | ||
56 | return 0; | ||
57 | |||
58 | if ((opts & OPENSSL_INIT_LOAD_CONFIG) && | ||
59 | (OpenSSL_config(NULL) == 0)) | ||
60 | return 0; | ||
61 | |||
55 | return 1; | 62 | return 1; |
56 | } | 63 | } |