Removed
Link Here
|
1 |
From ca4014de81e6aa367aa0a54c49b4c3d4b137814c Mon Sep 17 00:00:00 2001 |
2 |
From: Jeremy Harris <jgh146exb@wizmail.org> |
3 |
Date: Sun, 1 Jan 2023 12:18:38 +0000 |
4 |
Subject: [PATCH] OpenSSL: fix tls_eccurve setting explicit curve/group. Bug |
5 |
2954 |
6 |
|
7 |
--- |
8 |
doc/ChangeLog | 4 +++ |
9 |
src/tls-openssl.c | 39 ++++++++++++++---------- |
10 |
test/confs/2148 | 54 ++++++++++++++++++++++++++++++++++ |
11 |
test/confs/2149 | 39 +++++++++++++----------- |
12 |
test/log/2148 | 48 ++++++++++++++++++++++++++++++ |
13 |
test/log/2149 | 39 ++++++++++++------------ |
14 |
test/paniclog/{2149 => 2148} | 0 |
15 |
test/scripts/2100-OpenSSL/2148 | 50 +++++++++++++++++++++++++++++++ |
16 |
test/scripts/2100-OpenSSL/2149 | 50 ++++++++++++++++--------------- |
17 |
test/stderr/2148 | 5 ++++ |
18 |
test/stderr/2149 | 3 -- |
19 |
11 files changed, 250 insertions(+), 81 deletions(-) |
20 |
create mode 100644 test/confs/2148 |
21 |
create mode 100644 test/log/2148 |
22 |
rename test/paniclog/{2149 => 2148} (100%) |
23 |
create mode 100644 test/scripts/2100-OpenSSL/2148 |
24 |
create mode 100644 test/stderr/2148 |
25 |
|
26 |
--- a/doc/ChangeLog |
27 |
+++ b/doc/ChangeLog |
28 |
@@ -41,10 +41,14 @@ JH/19 Bug 2911: Fix a recursion in DNS l |
29 |
included (though probably not limited to) a process crash from stack |
30 |
memory limit, or from excessive open files. Replace this with a paniclog |
31 |
whine (as this is likely a configuration error), and returning |
32 |
DNS_NOMATCH. |
33 |
|
34 |
+JH/20 Bug 2954: (OpenSSL) Fix setting of explicit EC curve/group. Previously |
35 |
+ this always failed, probably leading to the usual downgrade to in-clear |
36 |
+ connections. |
37 |
+ |
38 |
|
39 |
|
40 |
Exim version 4.96 |
41 |
----------------- |
42 |
|
43 |
--- a/src/tls-openssl.c |
44 |
+++ b/src/tls-openssl.c |
45 |
@@ -657,16 +657,16 @@ if (dh_bitsize <= tls_dh_max_bits) |
46 |
/* EVP_PKEY_free(pkey); crashes */ |
47 |
#endif |
48 |
} |
49 |
else |
50 |
DEBUG(D_tls) |
51 |
- debug_printf("Diffie-Hellman initialized from %s with %d-bit prime\n", |
52 |
+ debug_printf(" Diffie-Hellman initialized from %s with %d-bit prime\n", |
53 |
dhexpanded ? dhexpanded : US"default", dh_bitsize); |
54 |
} |
55 |
else |
56 |
DEBUG(D_tls) |
57 |
- debug_printf("dhparams '%s' %d bits, is > tls_dh_max_bits limit of %d\n", |
58 |
+ debug_printf(" dhparams '%s' %d bits, is > tls_dh_max_bits limit of %d\n", |
59 |
dhexpanded ? dhexpanded : US"default", dh_bitsize, tls_dh_max_bits); |
60 |
|
61 |
#if OPENSSL_VERSION_NUMBER < 0x30000000L |
62 |
DH_free(dh); |
63 |
#endif |
64 |
@@ -712,23 +712,31 @@ init_ecdh(SSL_CTX * sctx, uschar ** errs |
65 |
#ifdef OPENSSL_NO_ECDH |
66 |
return TRUE; |
67 |
#else |
68 |
|
69 |
uschar * exp_curve; |
70 |
-int nid; |
71 |
-BOOL rv; |
72 |
+int nid, rc; |
73 |
|
74 |
# ifndef EXIM_HAVE_ECDH |
75 |
DEBUG(D_tls) |
76 |
- debug_printf("No OpenSSL API to define ECDH parameters, skipping\n"); |
77 |
+ debug_printf(" No OpenSSL API to define ECDH parameters, skipping\n"); |
78 |
return TRUE; |
79 |
# else |
80 |
|
81 |
if (!expand_check(tls_eccurve, US"tls_eccurve", &exp_curve, errstr)) |
82 |
return FALSE; |
83 |
+ |
84 |
+/* Is the option deliberately empty? */ |
85 |
+ |
86 |
if (!exp_curve || !*exp_curve) |
87 |
+ { |
88 |
+#if OPENSSL_VERSION_NUMBER >= 0x10002000L |
89 |
+ DEBUG(D_tls) debug_printf( " ECDH OpenSSL 1.0.2+: clearing curves list\n"); |
90 |
+ (void) SSL_CTX_set1_curves(sctx, &nid, 0); |
91 |
+#endif |
92 |
return TRUE; |
93 |
+ } |
94 |
|
95 |
/* "auto" needs to be handled carefully. |
96 |
* OpenSSL < 1.0.2: we do not select anything, but fallback to prime256v1 |
97 |
* OpenSSL < 1.1.0: we have to call SSL_CTX_set_ecdh_auto |
98 |
* (openssl/ssl.h defines SSL_CTRL_SET_ECDH_AUTO) |
99 |
@@ -737,27 +745,26 @@ if (!exp_curve || !*exp_curve) |
100 |
*/ |
101 |
if (Ustrcmp(exp_curve, "auto") == 0) |
102 |
{ |
103 |
#if OPENSSL_VERSION_NUMBER < 0x10002000L |
104 |
DEBUG(D_tls) debug_printf( |
105 |
- "ECDH OpenSSL < 1.0.2: temp key parameter settings: overriding \"auto\" with \"prime256v1\"\n"); |
106 |
+ " ECDH OpenSSL < 1.0.2: temp key parameter settings: overriding \"auto\" with \"prime256v1\"\n"); |
107 |
exp_curve = US"prime256v1"; |
108 |
#else |
109 |
# if defined SSL_CTRL_SET_ECDH_AUTO |
110 |
DEBUG(D_tls) debug_printf( |
111 |
- "ECDH OpenSSL 1.0.2+: temp key parameter settings: autoselection\n"); |
112 |
+ " ECDH OpenSSL 1.0.2+: temp key parameter settings: autoselection\n"); |
113 |
SSL_CTX_set_ecdh_auto(sctx, 1); |
114 |
return TRUE; |
115 |
# else |
116 |
DEBUG(D_tls) debug_printf( |
117 |
- "ECDH OpenSSL 1.1.0+: temp key parameter settings: default selection\n"); |
118 |
+ " ECDH OpenSSL 1.1.0+: temp key parameter settings: library default selection\n"); |
119 |
return TRUE; |
120 |
# endif |
121 |
#endif |
122 |
} |
123 |
|
124 |
-DEBUG(D_tls) debug_printf("ECDH: curve '%s'\n", exp_curve); |
125 |
if ( (nid = OBJ_sn2nid (CCS exp_curve)) == NID_undef |
126 |
# ifdef EXIM_HAVE_OPENSSL_EC_NIST2NID |
127 |
&& (nid = EC_curve_nist2nid(CCS exp_curve)) == NID_undef |
128 |
# endif |
129 |
) |
130 |
@@ -777,27 +784,27 @@ if ( (nid = OBJ_sn2nid (CCS exp_c |
131 |
} |
132 |
|
133 |
/* The "tmp" in the name here refers to setting a temporary key |
134 |
not to the stability of the interface. */ |
135 |
|
136 |
- if ((rv = SSL_CTX_set_tmp_ecdh(sctx, ecdh) == 0)) |
137 |
+ if ((rc = SSL_CTX_set_tmp_ecdh(sctx, ecdh) == 0)) |
138 |
tls_error(string_sprintf("Error enabling '%s' curve", exp_curve), NULL, NULL, errstr); |
139 |
else |
140 |
- DEBUG(D_tls) debug_printf("ECDH: enabled '%s' curve\n", exp_curve); |
141 |
+ DEBUG(D_tls) debug_printf(" ECDH: enabled '%s' curve\n", exp_curve); |
142 |
EC_KEY_free(ecdh); |
143 |
} |
144 |
|
145 |
#else /* v 3.0.0 + */ |
146 |
|
147 |
-if ((rv = SSL_CTX_set1_groups(sctx, &nid, 1)) == 0) |
148 |
+if ((rc = SSL_CTX_set1_groups(sctx, &nid, 1)) == 0) |
149 |
tls_error(string_sprintf("Error enabling '%s' group", exp_curve), NULL, NULL, errstr); |
150 |
else |
151 |
- DEBUG(D_tls) debug_printf("ECDH: enabled '%s' group\n", exp_curve); |
152 |
+ DEBUG(D_tls) debug_printf(" ECDH: enabled '%s' group\n", exp_curve); |
153 |
|
154 |
#endif |
155 |
|
156 |
-return !rv; |
157 |
+return !!rc; |
158 |
|
159 |
# endif /*EXIM_HAVE_ECDH*/ |
160 |
#endif /*OPENSSL_NO_ECDH*/ |
161 |
} |
162 |
|
163 |
@@ -1719,19 +1726,19 @@ state_server.lib_state.lib_ctx = ctx; |
164 |
|
165 |
/* Preload DH params and EC curve */ |
166 |
|
167 |
if (opt_unset_or_noexpand(tls_dhparam)) |
168 |
{ |
169 |
- DEBUG(D_tls) debug_printf("TLS: preloading DH params for server\n"); |
170 |
+ DEBUG(D_tls) debug_printf("TLS: preloading DH params '%s' for server\n", tls_dhparam); |
171 |
if (init_dh(ctx, tls_dhparam, &dummy_errstr)) |
172 |
state_server.lib_state.dh = TRUE; |
173 |
} |
174 |
else |
175 |
DEBUG(D_tls) debug_printf("TLS: not preloading DH params for server\n"); |
176 |
if (opt_unset_or_noexpand(tls_eccurve)) |
177 |
{ |
178 |
- DEBUG(D_tls) debug_printf("TLS: preloading ECDH curve for server\n"); |
179 |
+ DEBUG(D_tls) debug_printf("TLS: preloading ECDH curve '%s' for server\n", tls_eccurve); |
180 |
if (init_ecdh(ctx, &dummy_errstr)) |
181 |
state_server.lib_state.ecdh = TRUE; |
182 |
} |
183 |
else |
184 |
DEBUG(D_tls) debug_printf("TLS: not preloading ECDH curve for server\n"); |