File openssl-1.1.1-system-cipherlist.patch of Package openssl-1_1
311
1
diff -up openssl-1.1.1c/Configurations/unix-Makefile.tmpl.system-cipherlist openssl-1.1.1c/Configurations/unix-Makefile.tmpl
2
--- openssl-1.1.1c/Configurations/unix-Makefile.tmpl.system-cipherlist 2019-05-29 15:42:27.951329271 +0200
3
+++ openssl-1.1.1c/Configurations/unix-Makefile.tmpl 2019-05-29 15:42:27.974328867 +0200
4
5
DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
6
HTMLDIR=$(DOCDIR)/html
7
8
+{- output_off() if $config{system_ciphers_file} eq ""; "" -}
9
+SYSTEM_CIPHERS_FILE_DEFINE=-DSYSTEM_CIPHERS_FILE="\"{- $config{system_ciphers_file} -}\""
10
+{- output_on() if $config{system_ciphers_file} eq ""; "" -}
11
+
12
# MANSUFFIX is for the benefit of anyone who may want to have a suffix
13
# appended after the manpage file section number. "ssl" is popular,
14
# resulting in files such as config.5ssl rather than config.5.
15
16
CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -}
17
CPPFLAGS={- our $cppflags1 = join(" ",
18
(map { "-D".$_} @{$config{CPPDEFINES}}),
19
+ "\$(SYSTEM_CIPHERS_FILE_DEFINE)",
20
(map { "-I".$_} @{$config{CPPINCLUDES}}),
21
@{$config{CPPFLAGS}}) -}
22
CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
23
diff -up openssl-1.1.1c/Configure.system-cipherlist openssl-1.1.1c/Configure
24
--- openssl-1.1.1c/Configure.system-cipherlist 2019-05-28 15:12:21.000000000 +0200
25
+++ openssl-1.1.1c/Configure 2019-05-29 15:45:10.465469533 +0200
26
27
my $orig_death_handler = $SIG{__DIE__};
28
$SIG{__DIE__} = \&death_handler;
29
30
-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";
31
+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";
32
33
# Options:
34
#
35
36
# This becomes the value of OPENSSLDIR in Makefile and in C.
37
# (Default: PREFIX/ssl)
38
#
39
+# --system-ciphers-file A file to read cipher string from when the PROFILE=SYSTEM
40
+# cipher is specified (default).
41
+#
42
# --cross-compile-prefix Add specified prefix to binutils components.
43
#
44
# --api One of 0.9.8, 1.0.0 or 1.1.0. Do not compile support for
45
46
$config{openssldir}="";
47
$config{processor}="";
48
$config{libdir}="";
49
+$config{system_ciphers_file}="";
50
my $auto_threads=1; # enable threads automatically? true by default
51
my $default_ranlib;
52
53
54
push @seed_sources, $x;
55
}
56
}
57
+ elsif (/^--system-ciphers-file=(.*)$/)
58
+ {
59
+ $config{system_ciphers_file}=$1;
60
+ }
61
elsif (/^--cross-compile-prefix=(.*)$/)
62
{
63
$user{CROSS_COMPILE}=$1;
64
65
exit 0;
66
}
67
68
+chop $config{system_ciphers_file} if $config{system_ciphers_file} =~ /\/$/;
69
+
70
print "Configuring OpenSSL version $config{version} ($config{version_num}) ";
71
print "for $target\n";
72
73
diff -up openssl-1.1.1c/doc/man1/ciphers.pod.system-cipherlist openssl-1.1.1c/doc/man1/ciphers.pod
74
--- openssl-1.1.1c/doc/man1/ciphers.pod.system-cipherlist 2019-05-28 15:12:21.000000000 +0200
75
+++ openssl-1.1.1c/doc/man1/ciphers.pod 2019-05-29 15:42:27.975328849 +0200
76
77
78
The cipher suites not enabled by B<ALL>, currently B<eNULL>.
79
80
+=item B<PROFILE=SYSTEM>
81
+
82
+The list of enabled cipher suites will be loaded from the system crypto policy
83
+configuration file B</etc/crypto-policies/back-ends/openssl.config>.
84
+See also L<update-crypto-policies(8)>.
85
+This is the default behavior unless an application explicitly sets a cipher
86
+list. If used in a cipher list configuration value this string must be at the
87
+beginning of the cipher list, otherwise it will not be recognized.
88
+
89
=item B<HIGH>
90
91
"High" encryption cipher suites. This currently means those with key lengths
92
diff -up openssl-1.1.1c/include/openssl/ssl.h.system-cipherlist openssl-1.1.1c/include/openssl/ssl.h
93
--- openssl-1.1.1c/include/openssl/ssl.h.system-cipherlist 2019-05-28 15:12:21.000000000 +0200
94
+++ openssl-1.1.1c/include/openssl/ssl.h 2019-05-29 15:42:27.975328849 +0200
95
96
* throwing out anonymous and unencrypted ciphersuites! (The latter are not
97
* actually enabled by ALL, but "ALL:RSA" would enable some of them.)
98
*/
99
+# ifdef SYSTEM_CIPHERS_FILE
100
+# define SSL_SYSTEM_DEFAULT_CIPHER_LIST "PROFILE=SYSTEM"
101
+# else
102
+# define SSL_SYSTEM_DEFAULT_CIPHER_LIST SSL_DEFAULT_CIPHER_LIST
103
+# endif
104
105
/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
106
# define SSL_SENT_SHUTDOWN 1
107
diff -up openssl-1.1.1c/ssl/ssl_ciph.c.system-cipherlist openssl-1.1.1c/ssl/ssl_ciph.c
108
--- openssl-1.1.1c/ssl/ssl_ciph.c.system-cipherlist 2019-05-28 15:12:21.000000000 +0200
109
+++ openssl-1.1.1c/ssl/ssl_ciph.c 2019-05-29 15:42:27.976328831 +0200
110
111
* https://www.openssl.org/source/license.html
112
*/
113
114
+/* for secure_getenv */
115
+#define _GNU_SOURCE
116
#include <stdio.h>
117
#include <ctype.h>
118
#include <openssl/objects.h>
119
120
return ret;
121
}
122
123
+#ifdef SYSTEM_CIPHERS_FILE
124
+static char *load_system_str(const char *suffix)
125
+{
126
+ FILE *fp;
127
+ char buf[1024];
128
+ char *new_rules;
129
+ const char *ciphers_path;
130
+ unsigned len, slen;
131
+
132
+ if ((ciphers_path = secure_getenv("OPENSSL_SYSTEM_CIPHERS_OVERRIDE")) == NULL)
133
+ ciphers_path = SYSTEM_CIPHERS_FILE;
134
+ fp = fopen(ciphers_path, "r");
135
+ if (fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) {
136
+ /* cannot open or file is empty */
137
+ snprintf(buf, sizeof(buf), "%s", SSL_DEFAULT_CIPHER_LIST);
138
+ }
139
+
140
+ if (fp)
141
+ fclose(fp);
142
+
143
+ slen = strlen(suffix);
144
+ len = strlen(buf);
145
+
146
+ if (buf[len - 1] == '\n') {
147
+ len--;
148
+ buf[len] = 0;
149
+ }
150
+ if (buf[len - 1] == '\r') {
151
+ len--;
152
+ buf[len] = 0;
153
+ }
154
+
155
+ new_rules = OPENSSL_malloc(len + slen + 1);
156
+ if (new_rules == 0)
157
+ return NULL;
158
+
159
+ memcpy(new_rules, buf, len);
160
+ if (slen > 0) {
161
+ memcpy(&new_rules[len], suffix, slen);
162
+ len += slen;
163
+ }
164
+ new_rules[len] = 0;
165
+
166
+ return new_rules;
167
+}
168
+#endif
169
+
170
STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
171
STACK_OF(SSL_CIPHER) *tls13_ciphersuites,
172
STACK_OF(SSL_CIPHER) **cipher_list,
173
174
const char *rule_p;
175
CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
176
const SSL_CIPHER **ca_list = NULL;
177
+#ifdef SYSTEM_CIPHERS_FILE
178
+ char *new_rules = NULL;
179
+
180
+ if (rule_str != NULL && strncmp(rule_str, "PROFILE=SYSTEM", 14) == 0) {
181
+ char *p = rule_str + 14;
182
+
183
+ new_rules = load_system_str(p);
184
+ rule_str = new_rules;
185
+ }
186
+#endif
187
188
/*
189
* Return with error if nothing to do.
190
*/
191
if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)
192
- return NULL;
193
+ goto err;
194
#ifndef OPENSSL_NO_EC
195
if (!check_suiteb_cipher_list(ssl_method, c, &rule_str))
196
- return NULL;
197
+ goto err;
198
#endif
199
200
/*
201
202
co_list = OPENSSL_malloc(sizeof(*co_list) * num_of_ciphers);
203
if (co_list == NULL) {
204
SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
205
- return NULL; /* Failure */
206
+ goto err;
207
}
208
209
ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,
210
211
* in force within each class
212
*/
213
if (!ssl_cipher_strength_sort(&head, &tail)) {
214
- OPENSSL_free(co_list);
215
- return NULL;
216
+ goto err;
217
}
218
219
/*
220
221
num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
222
ca_list = OPENSSL_malloc(sizeof(*ca_list) * num_of_alias_max);
223
if (ca_list == NULL) {
224
- OPENSSL_free(co_list);
225
SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
226
- return NULL; /* Failure */
227
+ goto err;
228
}
229
ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,
230
disabled_mkey, disabled_auth, disabled_enc,
231
232
OPENSSL_free(ca_list); /* Not needed anymore */
233
234
if (!ok) { /* Rule processing failure */
235
- OPENSSL_free(co_list);
236
- return NULL;
237
+ goto err;
238
}
239
240
/*
241
242
* if we cannot get one.
243
*/
244
if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) {
245
- OPENSSL_free(co_list);
246
- return NULL;
247
+ goto err;
248
}
249
250
+#ifdef SYSTEM_CIPHERS_FILE
251
+ OPENSSL_free(new_rules); /* Not needed anymore */
252
+#endif
253
+
254
/* Add TLSv1.3 ciphers first - we always prefer those if possible */
255
for (i = 0; i < sk_SSL_CIPHER_num(tls13_ciphersuites); i++) {
256
if (!sk_SSL_CIPHER_push(cipherstack,
257
sk_SSL_CIPHER_value(tls13_ciphersuites, i))) {
258
+ OPENSSL_free(co_list);
259
sk_SSL_CIPHER_free(cipherstack);
260
return NULL;
261
}
262
263
*cipher_list = cipherstack;
264
265
return cipherstack;
266
+
267
+err:
268
+ OPENSSL_free(co_list);
269
+#ifdef SYSTEM_CIPHERS_FILE
270
+ OPENSSL_free(new_rules);
271
+#endif
272
+ return NULL;
273
+
274
}
275
276
char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
277
diff -up openssl-1.1.1c/ssl/ssl_lib.c.system-cipherlist openssl-1.1.1c/ssl/ssl_lib.c
278
--- openssl-1.1.1c/ssl/ssl_lib.c.system-cipherlist 2019-05-29 15:42:27.970328937 +0200
279
+++ openssl-1.1.1c/ssl/ssl_lib.c 2019-05-29 15:42:27.977328814 +0200
280
281
ctx->tls13_ciphersuites,
282
&(ctx->cipher_list),
283
&(ctx->cipher_list_by_id),
284
- SSL_DEFAULT_CIPHER_LIST, ctx->cert);
285
+ SSL_SYSTEM_DEFAULT_CIPHER_LIST, ctx->cert);
286
if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) {
287
SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
288
return 0;
289
290
if (!ssl_create_cipher_list(ret->method,
291
ret->tls13_ciphersuites,
292
&ret->cipher_list, &ret->cipher_list_by_id,
293
- SSL_DEFAULT_CIPHER_LIST, ret->cert)
294
+ SSL_SYSTEM_DEFAULT_CIPHER_LIST, ret->cert)
295
|| sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {
296
SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);
297
goto err2;
298
diff -up openssl-1.1.1c/test/cipherlist_test.c.system-cipherlist openssl-1.1.1c/test/cipherlist_test.c
299
--- openssl-1.1.1c/test/cipherlist_test.c.system-cipherlist 2019-05-28 15:12:21.000000000 +0200
300
+++ openssl-1.1.1c/test/cipherlist_test.c 2019-05-29 15:42:27.977328814 +0200
301
302
303
int setup_tests(void)
304
{
305
+#ifndef SYSTEM_CIPHERS_FILE
306
ADD_TEST(test_default_cipherlist_implicit);
307
+#endif
308
ADD_TEST(test_default_cipherlist_explicit);
309
ADD_TEST(test_default_cipherlist_clear);
310
return 1;
311