Removed
Link Here
|
1 |
From 62b97c2ecf148ee86053d82e5509e4c3a5a20054 Mon Sep 17 00:00:00 2001 |
2 |
From: Jeremy Harris <jgh146exb@wizmail.org> |
3 |
Date: Sat, 29 Oct 2022 22:33:43 +0100 |
4 |
Subject: [PATCH 2/2] OpenSSL: fix double-expansion of tls_verify_certificates |
5 |
|
6 |
--- |
7 |
src/tls-openssl.c | 66 +++++++++++++++++++++---------------------- |
8 |
1 file changed, 33 insertions(+), 33 deletions(-) |
9 |
|
10 |
diff --git a/src/tls-openssl.c b/src/tls-openssl.c |
11 |
index fdf0d92b2..2e09882d2 100644 |
12 |
--- a/src/tls-openssl.c |
13 |
+++ b/src/tls-openssl.c |
14 |
@@ -435,15 +435,15 @@ typedef struct exim_openssl_state { |
15 |
/* should figure out a cleanup of API to handle state preserved per |
16 |
implementation, for various reasons, which can be void * in the APIs. |
17 |
For now, we hack around it. */ |
18 |
exim_openssl_state_st *client_static_state = NULL; /*XXX should not use static; multiple concurrent clients! */ |
19 |
exim_openssl_state_st state_server = {.is_server = TRUE}; |
20 |
|
21 |
static int |
22 |
-setup_certs(SSL_CTX *sctx, uschar *certs, uschar *crl, host_item *host, |
23 |
+setup_certs(SSL_CTX * sctx, uschar ** certs, uschar * crl, host_item * host, |
24 |
uschar ** errstr ); |
25 |
|
26 |
/* Callbacks */ |
27 |
#ifndef DISABLE_OCSP |
28 |
static int tls_server_stapling_cb(SSL *s, void *arg); |
29 |
static void x509_stack_dump_cert_s_names(const STACK_OF(X509) * sk); |
30 |
static void x509_store_dump_cert_s_names(X509_STORE * store); |
31 |
@@ -1762,18 +1762,18 @@ if ( opt_set_and_noexpand(tls_verify_certificates) |
32 |
{ |
33 |
/* Watch the default dir also as they are always included */ |
34 |
|
35 |
if ( tls_set_watch(CUS X509_get_default_cert_file(), FALSE) |
36 |
&& tls_set_watch(tls_verify_certificates, FALSE) |
37 |
&& tls_set_watch(tls_crl, FALSE)) |
38 |
{ |
39 |
+ uschar * v_certs = tls_verify_certificates; |
40 |
DEBUG(D_tls) debug_printf("TLS: preloading CA bundle for server\n"); |
41 |
|
42 |
- if (setup_certs(ctx, tls_verify_certificates, tls_crl, NULL, &dummy_errstr) |
43 |
- == OK) |
44 |
+ if (setup_certs(ctx, &v_certs, tls_crl, NULL, &dummy_errstr) == OK) |
45 |
state_server.lib_state.cabundle = TRUE; |
46 |
|
47 |
/* If we can, preload the server-side cert, key and ocsp */ |
48 |
|
49 |
if ( opt_set_and_noexpand(tls_certificate) |
50 |
# ifndef DISABLE_OCSP |
51 |
&& opt_unset_or_noexpand(tls_ocsp_file) |
52 |
@@ -1897,18 +1897,19 @@ if ( opt_set_and_noexpand(ob->tls_verify_certificates) |
53 |
{ |
54 |
if ( !watch |
55 |
|| tls_set_watch(CUS X509_get_default_cert_file(), FALSE) |
56 |
&& tls_set_watch(ob->tls_verify_certificates, FALSE) |
57 |
&& tls_set_watch(ob->tls_crl, FALSE) |
58 |
) |
59 |
{ |
60 |
+ uschar * v_certs = ob->tls_verify_certificates; |
61 |
DEBUG(D_tls) |
62 |
debug_printf("TLS: preloading CA bundle for transport '%s'\n", t->name); |
63 |
|
64 |
- if (setup_certs(ctx, ob->tls_verify_certificates, |
65 |
+ if (setup_certs(ctx, &v_certs, |
66 |
ob->tls_crl, dummy_host, &dummy_errstr) == OK) |
67 |
ob->tls_preload.cabundle = TRUE; |
68 |
} |
69 |
} |
70 |
else |
71 |
DEBUG(D_tls) |
72 |
debug_printf("TLS: not preloading CA bundle, for transport '%s'\n", t->name); |
73 |
@@ -2238,22 +2239,20 @@ if (state->u_ocsp.server.file) |
74 |
{ |
75 |
SSL_CTX_set_tlsext_status_cb(server_sni, tls_server_stapling_cb); |
76 |
SSL_CTX_set_tlsext_status_arg(server_sni, state); |
77 |
} |
78 |
#endif |
79 |
|
80 |
{ |
81 |
- uschar * expcerts; |
82 |
- if ( !expand_check(tls_verify_certificates, US"tls_verify_certificates", |
83 |
- &expcerts, &dummy_errstr) |
84 |
- || (rc = setup_certs(server_sni, expcerts, tls_crl, NULL, |
85 |
+ uschar * v_certs = tls_verify_certificates; |
86 |
+ if ((rc = setup_certs(server_sni, &v_certs, tls_crl, NULL, |
87 |
&dummy_errstr)) != OK) |
88 |
goto bad; |
89 |
|
90 |
- if (expcerts && *expcerts) |
91 |
+ if (v_certs && *v_certs) |
92 |
setup_cert_verify(server_sni, FALSE, verify_callback_server); |
93 |
} |
94 |
|
95 |
/* do this after setup_certs, because this can require the certs for verifying |
96 |
OCSP information. */ |
97 |
if ((rc = tls_expand_session_files(server_sni, state, &dummy_errstr)) != OK) |
98 |
goto bad; |
99 |
@@ -3017,32 +3016,33 @@ return TRUE; |
100 |
|
101 |
|
102 |
/* Called by both client and server startup; on the server possibly |
103 |
repeated after a Server Name Indication. |
104 |
|
105 |
Arguments: |
106 |
sctx SSL_CTX* to initialise |
107 |
- certs certs file, expanded |
108 |
+ certs certs file, returned expanded |
109 |
crl CRL file or NULL |
110 |
host NULL in a server; the remote host in a client |
111 |
errstr error string pointer |
112 |
|
113 |
Returns: OK/DEFER/FAIL |
114 |
*/ |
115 |
|
116 |
static int |
117 |
-setup_certs(SSL_CTX *sctx, uschar *certs, uschar *crl, host_item *host, |
118 |
+setup_certs(SSL_CTX * sctx, uschar ** certsp, uschar * crl, host_item * host, |
119 |
uschar ** errstr) |
120 |
{ |
121 |
-uschar *expcerts, *expcrl; |
122 |
+uschar * expcerts, * expcrl; |
123 |
|
124 |
-if (!expand_check(certs, US"tls_verify_certificates", &expcerts, errstr)) |
125 |
+if (!expand_check(*certsp, US"tls_verify_certificates", &expcerts, errstr)) |
126 |
return DEFER; |
127 |
DEBUG(D_tls) debug_printf("tls_verify_certificates: %s\n", expcerts); |
128 |
|
129 |
+*certsp = expcerts; |
130 |
if (expcerts && *expcerts) |
131 |
{ |
132 |
/* Tell the library to use its compiled-in location for the system default |
133 |
CA bundle. Then add the ones specified in the config, if any. */ |
134 |
|
135 |
if (!SSL_CTX_set_default_verify_paths(sctx)) |
136 |
return tls_error(US"SSL_CTX_set_default_verify_paths", host, NULL, errstr); |
137 |
@@ -3330,28 +3330,28 @@ if (verify_check_host(&tls_verify_hosts) == OK) |
138 |
server_verify_optional = FALSE; |
139 |
else if (verify_check_host(&tls_try_verify_hosts) == OK) |
140 |
server_verify_optional = TRUE; |
141 |
else |
142 |
goto skip_certs; |
143 |
|
144 |
{ |
145 |
- uschar * expcerts; |
146 |
- if (!expand_check(tls_verify_certificates, US"tls_verify_certificates", |
147 |
- &expcerts, errstr)) |
148 |
- return DEFER; |
149 |
- DEBUG(D_tls) debug_printf("tls_verify_certificates: %s\n", expcerts); |
150 |
+ uschar * v_certs = tls_verify_certificates; |
151 |
|
152 |
if (state_server.lib_state.cabundle) |
153 |
- { DEBUG(D_tls) debug_printf("TLS: CA bundle for server was preloaded\n"); } |
154 |
+ { |
155 |
+ DEBUG(D_tls) debug_printf("TLS: CA bundle for server was preloaded\n"); |
156 |
+ setup_cert_verify(ctx, server_verify_optional, verify_callback_server); |
157 |
+ } |
158 |
else |
159 |
- if ((rc = setup_certs(ctx, expcerts, tls_crl, NULL, errstr)) != OK) |
160 |
+ { |
161 |
+ if ((rc = setup_certs(ctx, &v_certs, tls_crl, NULL, errstr)) != OK) |
162 |
return rc; |
163 |
- |
164 |
- if (expcerts && *expcerts) |
165 |
- setup_cert_verify(ctx, server_verify_optional, verify_callback_server); |
166 |
+ if (v_certs && *v_certs) |
167 |
+ setup_cert_verify(ctx, server_verify_optional, verify_callback_server); |
168 |
+ } |
169 |
} |
170 |
skip_certs: ; |
171 |
|
172 |
#ifndef DISABLE_TLS_RESUME |
173 |
# if OPENSSL_VERSION_NUMBER < 0x30000000L |
174 |
SSL_CTX_set_tlsext_ticket_key_cb(ctx, ticket_key_callback); |
175 |
/* despite working, appears to always return failure, so ignoring */ |
176 |
@@ -3606,28 +3606,28 @@ if ( ( ( !ob->tls_verify_hosts || !ob->tls_verify_hosts |
177 |
client_verify_optional = FALSE; |
178 |
else if (verify_check_given_host(CUSS &ob->tls_try_verify_hosts, host) == OK) |
179 |
client_verify_optional = TRUE; |
180 |
else |
181 |
return OK; |
182 |
|
183 |
{ |
184 |
- uschar * expcerts; |
185 |
- if (!expand_check(ob->tls_verify_certificates, US"tls_verify_certificates", |
186 |
- &expcerts, errstr)) |
187 |
- return DEFER; |
188 |
- DEBUG(D_tls) debug_printf("tls_verify_certificates: %s\n", expcerts); |
189 |
+ uschar * v_certs = ob->tls_verify_certificates; |
190 |
|
191 |
if (state->lib_state.cabundle) |
192 |
- { DEBUG(D_tls) debug_printf("TLS: CA bundle was preloaded\n"); } |
193 |
+ { |
194 |
+ DEBUG(D_tls) debug_printf("TLS: CA bundle for tpt was preloaded\n"); |
195 |
+ setup_cert_verify(ctx, client_verify_optional, verify_callback_client); |
196 |
+ } |
197 |
else |
198 |
- if ((rc = setup_certs(ctx, expcerts, ob->tls_crl, host, errstr)) != OK) |
199 |
+ { |
200 |
+ if ((rc = setup_certs(ctx, &v_certs, ob->tls_crl, host, errstr)) != OK) |
201 |
return rc; |
202 |
- |
203 |
- if (expcerts && *expcerts) |
204 |
- setup_cert_verify(ctx, client_verify_optional, verify_callback_client); |
205 |
+ if (v_certs && *v_certs) |
206 |
+ setup_cert_verify(ctx, client_verify_optional, verify_callback_client); |
207 |
+ } |
208 |
} |
209 |
|
210 |
if (verify_check_given_host(CUSS &ob->tls_verify_cert_hostnames, host) == OK) |
211 |
{ |
212 |
state->verify_cert_hostnames = |
213 |
#ifdef SUPPORT_I18N |
214 |
string_domain_utf8_to_alabel(host->certname, NULL); |
215 |
-- |
216 |
2.35.1 |
217 |
|