1 |
From 736d709ec194b3a763e004696df22792c62a11fc Mon Sep 17 00:00:00 2001 |
2 |
From: Tomas Mraz <tmraz@fedoraproject.org> |
3 |
Date: Thu, 24 Sep 2020 10:16:46 +0200 |
4 |
Subject: Add support for PROFILE=SYSTEM system default cipherlist |
5 |
|
6 |
(was openssl-1.1.1-system-cipherlist.patch) |
7 |
--- |
8 |
Configurations/unix-Makefile.tmpl | 5 ++ |
9 |
Configure | 10 +++- |
10 |
doc/man1/openssl-ciphers.pod.in | 9 ++++ |
11 |
include/openssl/ssl.h.in | 5 ++ |
12 |
ssl/ssl_ciph.c | 88 +++++++++++++++++++++++++++---- |
13 |
ssl/ssl_lib.c | 4 +- |
14 |
test/cipherlist_test.c | 2 + |
15 |
util/libcrypto.num | 1 + |
16 |
8 files changed, 110 insertions(+), 14 deletions(-) |
17 |
|
18 |
diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl |
19 |
index 9f369edf0e..c52389f831 100644 |
20 |
--- a/Configurations/unix-Makefile.tmpl |
21 |
+++ b/Configurations/unix-Makefile.tmpl |
22 |
@@ -269,6 +269,10 @@ MANDIR=$(INSTALLTOP)/share/man |
23 |
DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME) |
24 |
HTMLDIR=$(DOCDIR)/html |
25 |
|
26 |
+{- output_off() if $config{system_ciphers_file} eq ""; "" -} |
27 |
+SYSTEM_CIPHERS_FILE_DEFINE=-DSYSTEM_CIPHERS_FILE="\"{- $config{system_ciphers_file} -}\"" |
28 |
+{- output_on() if $config{system_ciphers_file} eq ""; "" -} |
29 |
+ |
30 |
# MANSUFFIX is for the benefit of anyone who may want to have a suffix |
31 |
# appended after the manpage file section number. "ssl" is popular, |
32 |
# resulting in files such as config.5ssl rather than config.5. |
33 |
@@ -292,6 +296,7 @@ CC=$(CROSS_COMPILE){- $config{CC} -} |
34 |
CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -} |
35 |
CPPFLAGS={- our $cppflags1 = join(" ", |
36 |
(map { "-D".$_} @{$config{CPPDEFINES}}), |
37 |
+ "\$(SYSTEM_CIPHERS_FILE_DEFINE)", |
38 |
(map { "-I".$_} @{$config{CPPINCLUDES}}), |
39 |
@{$config{CPPFLAGS}}) -} |
40 |
CFLAGS={- join(' ', @{$config{CFLAGS}}) -} |
41 |
diff --git a/doc/man1/openssl-ciphers.pod.in b/doc/man1/openssl-ciphers.pod.in |
42 |
index b4ed3e51d5..2122e6bdfd 100644 |
43 |
--- a/doc/man1/openssl-ciphers.pod.in |
44 |
+++ b/doc/man1/openssl-ciphers.pod.in |
45 |
@@ -187,6 +187,15 @@ As of OpenSSL 1.0.0, the B<ALL> cipher suites are sensibly ordered by default. |
46 |
|
47 |
The cipher suites not enabled by B<ALL>, currently B<eNULL>. |
48 |
|
49 |
+=item B<PROFILE=SYSTEM> |
50 |
+ |
51 |
+The list of enabled cipher suites will be loaded from the system crypto policy |
52 |
+configuration file B</etc/crypto-policies/back-ends/openssl.config>. |
53 |
+See also L<update-crypto-policies(8)>. |
54 |
+This is the default behavior unless an application explicitly sets a cipher |
55 |
+list. If used in a cipher list configuration value this string must be at the |
56 |
+beginning of the cipher list, otherwise it will not be recognized. |
57 |
+ |
58 |
=item B<HIGH> |
59 |
|
60 |
"High" encryption cipher suites. This currently means those with key lengths |
61 |
diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in |
62 |
index f9a61609e4..c6f95fed3f 100644 |
63 |
--- a/include/openssl/ssl.h.in |
64 |
+++ b/include/openssl/ssl.h.in |
65 |
@@ -209,6 +209,11 @@ extern "C" { |
66 |
* throwing out anonymous and unencrypted ciphersuites! (The latter are not |
67 |
* actually enabled by ALL, but "ALL:RSA" would enable some of them.) |
68 |
*/ |
69 |
+# ifdef SYSTEM_CIPHERS_FILE |
70 |
+# define SSL_SYSTEM_DEFAULT_CIPHER_LIST "PROFILE=SYSTEM" |
71 |
+# else |
72 |
+# define SSL_SYSTEM_DEFAULT_CIPHER_LIST OSSL_default_cipher_list() |
73 |
+# endif |
74 |
|
75 |
/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ |
76 |
# define SSL_SENT_SHUTDOWN 1 |
77 |
diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c |
78 |
index b1d3f7919e..f7cc7fed48 100644 |
79 |
--- a/ssl/ssl_ciph.c |
80 |
+++ b/ssl/ssl_ciph.c |
81 |
@@ -1411,6 +1411,53 @@ int SSL_set_ciphersuites(SSL *s, const char *str) |
82 |
return ret; |
83 |
} |
84 |
|
85 |
+#ifdef SYSTEM_CIPHERS_FILE |
86 |
+static char *load_system_str(const char *suffix) |
87 |
+{ |
88 |
+ FILE *fp; |
89 |
+ char buf[1024]; |
90 |
+ char *new_rules; |
91 |
+ const char *ciphers_path; |
92 |
+ unsigned len, slen; |
93 |
+ |
94 |
+ if ((ciphers_path = ossl_safe_getenv("OPENSSL_SYSTEM_CIPHERS_OVERRIDE")) == NULL) |
95 |
+ ciphers_path = SYSTEM_CIPHERS_FILE; |
96 |
+ fp = fopen(ciphers_path, "r"); |
97 |
+ if (fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) { |
98 |
+ /* cannot open or file is empty */ |
99 |
+ snprintf(buf, sizeof(buf), "%s", SSL_DEFAULT_CIPHER_LIST); |
100 |
+ } |
101 |
+ |
102 |
+ if (fp) |
103 |
+ fclose(fp); |
104 |
+ |
105 |
+ slen = strlen(suffix); |
106 |
+ len = strlen(buf); |
107 |
+ |
108 |
+ if (buf[len - 1] == '\n') { |
109 |
+ len--; |
110 |
+ buf[len] = 0; |
111 |
+ } |
112 |
+ if (buf[len - 1] == '\r') { |
113 |
+ len--; |
114 |
+ buf[len] = 0; |
115 |
+ } |
116 |
+ |
117 |
+ new_rules = OPENSSL_malloc(len + slen + 1); |
118 |
+ if (new_rules == 0) |
119 |
+ return NULL; |
120 |
+ |
121 |
+ memcpy(new_rules, buf, len); |
122 |
+ if (slen > 0) { |
123 |
+ memcpy(&new_rules[len], suffix, slen); |
124 |
+ len += slen; |
125 |
+ } |
126 |
+ new_rules[len] = 0; |
127 |
+ |
128 |
+ return new_rules; |
129 |
+} |
130 |
+#endif |
131 |
+ |
132 |
STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
133 |
STACK_OF(SSL_CIPHER) *tls13_ciphersuites, |
134 |
STACK_OF(SSL_CIPHER) **cipher_list, |
135 |
@@ -1425,15 +1472,25 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
136 |
CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr; |
137 |
const SSL_CIPHER **ca_list = NULL; |
138 |
const SSL_METHOD *ssl_method = ctx->method; |
139 |
+#ifdef SYSTEM_CIPHERS_FILE |
140 |
+ char *new_rules = NULL; |
141 |
+ |
142 |
+ if (rule_str != NULL && strncmp(rule_str, "PROFILE=SYSTEM", 14) == 0) { |
143 |
+ char *p = rule_str + 14; |
144 |
+ |
145 |
+ new_rules = load_system_str(p); |
146 |
+ rule_str = new_rules; |
147 |
+ } |
148 |
+#endif |
149 |
|
150 |
/* |
151 |
* Return with error if nothing to do. |
152 |
*/ |
153 |
if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL) |
154 |
- return NULL; |
155 |
+ goto err; |
156 |
|
157 |
if (!check_suiteb_cipher_list(ssl_method, c, &rule_str)) |
158 |
- return NULL; |
159 |
+ goto err; |
160 |
|
161 |
/* |
162 |
* To reduce the work to do we only want to process the compiled |
163 |
@@ -1456,7 +1513,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
164 |
co_list = OPENSSL_malloc(sizeof(*co_list) * num_of_ciphers); |
165 |
if (co_list == NULL) { |
166 |
ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE); |
167 |
- return NULL; /* Failure */ |
168 |
+ goto err; |
169 |
} |
170 |
|
171 |
ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, |
172 |
@@ -1522,8 +1579,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
173 |
* in force within each class |
174 |
*/ |
175 |
if (!ssl_cipher_strength_sort(&head, &tail)) { |
176 |
- OPENSSL_free(co_list); |
177 |
- return NULL; |
178 |
+ goto err; |
179 |
} |
180 |
|
181 |
/* |
182 |
@@ -1568,9 +1624,8 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
183 |
num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1; |
184 |
ca_list = OPENSSL_malloc(sizeof(*ca_list) * num_of_alias_max); |
185 |
if (ca_list == NULL) { |
186 |
- OPENSSL_free(co_list); |
187 |
ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE); |
188 |
- return NULL; /* Failure */ |
189 |
+ goto err; |
190 |
} |
191 |
ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, |
192 |
disabled_mkey, disabled_auth, disabled_enc, |
193 |
@@ -1596,8 +1651,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
194 |
OPENSSL_free(ca_list); /* Not needed anymore */ |
195 |
|
196 |
if (!ok) { /* Rule processing failure */ |
197 |
- OPENSSL_free(co_list); |
198 |
- return NULL; |
199 |
+ goto err; |
200 |
} |
201 |
|
202 |
/* |
203 |
@@ -1605,10 +1659,13 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
204 |
* if we cannot get one. |
205 |
*/ |
206 |
if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) { |
207 |
- OPENSSL_free(co_list); |
208 |
- return NULL; |
209 |
+ goto err; |
210 |
} |
211 |
|
212 |
+#ifdef SYSTEM_CIPHERS_FILE |
213 |
+ OPENSSL_free(new_rules); /* Not needed anymore */ |
214 |
+#endif |
215 |
+ |
216 |
/* Add TLSv1.3 ciphers first - we always prefer those if possible */ |
217 |
for (i = 0; i < sk_SSL_CIPHER_num(tls13_ciphersuites); i++) { |
218 |
const SSL_CIPHER *sslc = sk_SSL_CIPHER_value(tls13_ciphersuites, i); |
219 |
@@ -1656,6 +1714,14 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx, |
220 |
*cipher_list = cipherstack; |
221 |
|
222 |
return cipherstack; |
223 |
+ |
224 |
+err: |
225 |
+ OPENSSL_free(co_list); |
226 |
+#ifdef SYSTEM_CIPHERS_FILE |
227 |
+ OPENSSL_free(new_rules); |
228 |
+#endif |
229 |
+ return NULL; |
230 |
+ |
231 |
} |
232 |
|
233 |
char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len) |
234 |
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c |
235 |
index d14d5819ba..48d491219a 100644 |
236 |
--- a/ssl/ssl_lib.c |
237 |
+++ b/ssl/ssl_lib.c |
238 |
@@ -660,7 +660,7 @@ int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth) |
239 |
ctx->tls13_ciphersuites, |
240 |
&(ctx->cipher_list), |
241 |
&(ctx->cipher_list_by_id), |
242 |
- OSSL_default_cipher_list(), ctx->cert); |
243 |
+ SSL_SYSTEM_DEFAULT_CIPHER_LIST, ctx->cert); |
244 |
if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) { |
245 |
ERR_raise(ERR_LIB_SSL, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); |
246 |
return 0; |
247 |
@@ -3193,7 +3193,7 @@ SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq, |
248 |
if (!ssl_create_cipher_list(ret, |
249 |
ret->tls13_ciphersuites, |
250 |
&ret->cipher_list, &ret->cipher_list_by_id, |
251 |
- OSSL_default_cipher_list(), ret->cert) |
252 |
+ SSL_SYSTEM_DEFAULT_CIPHER_LIST, ret->cert) |
253 |
|| sk_SSL_CIPHER_num(ret->cipher_list) <= 0) { |
254 |
ERR_raise(ERR_LIB_SSL, SSL_R_LIBRARY_HAS_NO_CIPHERS); |
255 |
goto err2; |
256 |
diff --git a/test/cipherlist_test.c b/test/cipherlist_test.c |
257 |
index 380f0727fc..6922a87c30 100644 |
258 |
--- a/test/cipherlist_test.c |
259 |
+++ b/test/cipherlist_test.c |
260 |
@@ -244,7 +244,9 @@ end: |
261 |
|
262 |
int setup_tests(void) |
263 |
{ |
264 |
+#ifndef SYSTEM_CIPHERS_FILE |
265 |
ADD_TEST(test_default_cipherlist_implicit); |
266 |
+#endif |
267 |
ADD_TEST(test_default_cipherlist_explicit); |
268 |
ADD_TEST(test_default_cipherlist_clear); |
269 |
return 1; |
270 |
diff --git a/util/libcrypto.num b/util/libcrypto.num |
271 |
index 404a706fab..e81fa9ec3e 100644 |
272 |
--- a/util/libcrypto.num |
273 |
+++ b/util/libcrypto.num |
274 |
@@ -5282,3 +5282,4 @@ OSSL_DECODER_CTX_set_input_structure ? 3_0_0 EXIST::FUNCTION: |
275 |
EVP_PKEY_CTX_get0_provider 5555 3_0_0 EXIST::FUNCTION: |
276 |
OPENSSL_strcasecmp 5556 3_0_3 EXIST::FUNCTION: |
277 |
OPENSSL_strncasecmp 5557 3_0_3 EXIST::FUNCTION: |
278 |
+ossl_safe_getenv ? 3_0_0 EXIST::FUNCTION: |
279 |
-- |
280 |
2.26.2 |
281 |
|
282 |
diff -up openssl-3.0.0-beta1/Configure.sys-default openssl-3.0.0-beta1/Configure |
283 |
--- openssl-3.0.0-beta1/Configure.sys-default 2021-06-29 11:47:58.978144386 +0200 |
284 |
+++ openssl-3.0.0-beta1/Configure 2021-06-29 11:52:01.631126260 +0200 |
285 |
@@ -27,7 +27,7 @@ use OpenSSL::config; |
286 |
my $orig_death_handler = $SIG{__DIE__}; |
287 |
$SIG{__DIE__} = \&death_handler; |
288 |
|
289 |
-my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n"; |
290 |
+my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--system-ciphers-file=SYSTEMCIPHERFILE] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n"; |
291 |
|
292 |
my $banner = <<"EOF"; |
293 |
|
294 |
@@ -61,6 +61,10 @@ EOF |
295 |
# given with --prefix. |
296 |
# This becomes the value of OPENSSLDIR in Makefile and in C. |
297 |
# (Default: PREFIX/ssl) |
298 |
+# |
299 |
+# --system-ciphers-file A file to read cipher string from when the PROFILE=SYSTEM |
300 |
+# cipher is specified (default). |
301 |
+# |
302 |
# --banner=".." Output specified text instead of default completion banner |
303 |
# |
304 |
# -w Don't wait after showing a Configure warning |
305 |
@@ -385,6 +389,7 @@ $config{prefix}=""; |
306 |
$config{openssldir}=""; |
307 |
$config{processor}=""; |
308 |
$config{libdir}=""; |
309 |
+$config{system_ciphers_file}=""; |
310 |
my $auto_threads=1; # enable threads automatically? true by default |
311 |
my $default_ranlib; |
312 |
|
313 |
@@ -987,6 +992,10 @@ while (@argvcopy) |
314 |
die "FIPS key too long (64 bytes max)\n" |
315 |
if length $1 > 64; |
316 |
} |
317 |
+ elsif (/^--system-ciphers-file=(.*)$/) |
318 |
+ { |
319 |
+ $config{system_ciphers_file}=$1; |
320 |
+ } |
321 |
elsif (/^--banner=(.*)$/) |
322 |
{ |
323 |
$banner = $1 . "\n"; |