File: | out/../deps/openssl/openssl/ssl/statem/extensions_clnt.c |
Warning: | line 287, column 17 Dereference of null pointer |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved. | |||
3 | * | |||
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |||
5 | * this file except in compliance with the License. You can obtain a copy | |||
6 | * in the file LICENSE in the source distribution or at | |||
7 | * https://www.openssl.org/source/license.html | |||
8 | */ | |||
9 | ||||
10 | #include <openssl/ocsp.h> | |||
11 | #include "../ssl_local.h" | |||
12 | #include "internal/cryptlib.h" | |||
13 | #include "statem_local.h" | |||
14 | ||||
15 | EXT_RETURN tls_construct_ctos_renegotiate(SSL *s, WPACKET *pkt, | |||
16 | unsigned int context, X509 *x, | |||
17 | size_t chainidx) | |||
18 | { | |||
19 | /* Add RI if renegotiating */ | |||
20 | if (!s->renegotiate) | |||
21 | return EXT_RETURN_NOT_SENT; | |||
22 | ||||
23 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)WPACKET_put_bytes__((pkt), (0xff01), 2) | |||
24 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
25 | || !WPACKET_sub_memcpy_u8(pkt, s->s3.previous_client_finished,WPACKET_sub_memcpy__((pkt), (s->s3.previous_client_finished ), (s->s3.previous_client_finished_len), 1) | |||
26 | s->s3.previous_client_finished_len)WPACKET_sub_memcpy__((pkt), (s->s3.previous_client_finished ), (s->s3.previous_client_finished_len), 1) | |||
27 | || !WPACKET_close(pkt)) { | |||
28 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 28, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
29 | return EXT_RETURN_FAIL; | |||
30 | } | |||
31 | ||||
32 | return EXT_RETURN_SENT; | |||
33 | } | |||
34 | ||||
35 | EXT_RETURN tls_construct_ctos_server_name(SSL *s, WPACKET *pkt, | |||
36 | unsigned int context, X509 *x, | |||
37 | size_t chainidx) | |||
38 | { | |||
39 | if (s->ext.hostname == NULL((void*)0)) | |||
40 | return EXT_RETURN_NOT_SENT; | |||
41 | ||||
42 | /* Add TLS extension servername to the Client Hello message */ | |||
43 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)WPACKET_put_bytes__((pkt), (0), 2) | |||
44 | /* Sub-packet for server_name extension */ | |||
45 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
46 | /* Sub-packet for servername list (always 1 hostname)*/ | |||
47 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
48 | || !WPACKET_put_bytes_u8(pkt, TLSEXT_NAMETYPE_host_name)WPACKET_put_bytes__((pkt), (0), 1) | |||
49 | || !WPACKET_sub_memcpy_u16(pkt, s->ext.hostname,WPACKET_sub_memcpy__((pkt), (s->ext.hostname), (strlen(s-> ext.hostname)), 2) | |||
50 | strlen(s->ext.hostname))WPACKET_sub_memcpy__((pkt), (s->ext.hostname), (strlen(s-> ext.hostname)), 2) | |||
51 | || !WPACKET_close(pkt) | |||
52 | || !WPACKET_close(pkt)) { | |||
53 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 53, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
54 | return EXT_RETURN_FAIL; | |||
55 | } | |||
56 | ||||
57 | return EXT_RETURN_SENT; | |||
58 | } | |||
59 | ||||
60 | /* Push a Max Fragment Len extension into ClientHello */ | |||
61 | EXT_RETURN tls_construct_ctos_maxfragmentlen(SSL *s, WPACKET *pkt, | |||
62 | unsigned int context, X509 *x, | |||
63 | size_t chainidx) | |||
64 | { | |||
65 | if (s->ext.max_fragment_len_mode == TLSEXT_max_fragment_length_DISABLED0) | |||
66 | return EXT_RETURN_NOT_SENT; | |||
67 | ||||
68 | /* Add Max Fragment Length extension if client enabled it. */ | |||
69 | /*- | |||
70 | * 4 bytes for this extension type and extension length | |||
71 | * 1 byte for the Max Fragment Length code value. | |||
72 | */ | |||
73 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_max_fragment_length)WPACKET_put_bytes__((pkt), (1), 2) | |||
74 | /* Sub-packet for Max Fragment Length extension (1 byte) */ | |||
75 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
76 | || !WPACKET_put_bytes_u8(pkt, s->ext.max_fragment_len_mode)WPACKET_put_bytes__((pkt), (s->ext.max_fragment_len_mode), 1) | |||
77 | || !WPACKET_close(pkt)) { | |||
78 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 78, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
79 | return EXT_RETURN_FAIL; | |||
80 | } | |||
81 | ||||
82 | return EXT_RETURN_SENT; | |||
83 | } | |||
84 | ||||
85 | #ifndef OPENSSL_NO_SRP | |||
86 | EXT_RETURN tls_construct_ctos_srp(SSL *s, WPACKET *pkt, unsigned int context, | |||
87 | X509 *x, size_t chainidx) | |||
88 | { | |||
89 | /* Add SRP username if there is one */ | |||
90 | if (s->srp_ctx.login == NULL((void*)0)) | |||
91 | return EXT_RETURN_NOT_SENT; | |||
92 | ||||
93 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)WPACKET_put_bytes__((pkt), (12), 2) | |||
94 | /* Sub-packet for SRP extension */ | |||
95 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
96 | || !WPACKET_start_sub_packet_u8(pkt)WPACKET_start_sub_packet_len__((pkt), 1) | |||
97 | /* login must not be zero...internal error if so */ | |||
98 | || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH1) | |||
99 | || !WPACKET_memcpy(pkt, s->srp_ctx.login, | |||
100 | strlen(s->srp_ctx.login)) | |||
101 | || !WPACKET_close(pkt) | |||
102 | || !WPACKET_close(pkt)) { | |||
103 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 103, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
104 | return EXT_RETURN_FAIL; | |||
105 | } | |||
106 | ||||
107 | return EXT_RETURN_SENT; | |||
108 | } | |||
109 | #endif | |||
110 | ||||
111 | static int use_ecc(SSL *s, int min_version, int max_version) | |||
112 | { | |||
113 | int i, end, ret = 0; | |||
114 | unsigned long alg_k, alg_a; | |||
115 | STACK_OF(SSL_CIPHER)struct stack_st_SSL_CIPHER *cipher_stack = NULL((void*)0); | |||
116 | const uint16_t *pgroups = NULL((void*)0); | |||
117 | size_t num_groups, j; | |||
118 | ||||
119 | /* See if we support any ECC ciphersuites */ | |||
120 | if (s->version == SSL3_VERSION0x0300) | |||
121 | return 0; | |||
122 | ||||
123 | cipher_stack = SSL_get1_supported_ciphers(s); | |||
124 | end = sk_SSL_CIPHER_num(cipher_stack)OPENSSL_sk_num(ossl_check_const_SSL_CIPHER_sk_type(cipher_stack )); | |||
125 | for (i = 0; i < end; i++) { | |||
126 | const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i)((const SSL_CIPHER *)OPENSSL_sk_value(ossl_check_const_SSL_CIPHER_sk_type (cipher_stack), (i))); | |||
127 | ||||
128 | alg_k = c->algorithm_mkey; | |||
129 | alg_a = c->algorithm_auth; | |||
130 | if ((alg_k & (SSL_kECDHE0x00000004U | SSL_kECDHEPSK0x00000080U)) | |||
131 | || (alg_a & SSL_aECDSA0x00000008U) | |||
132 | || c->min_tls >= TLS1_3_VERSION0x0304) { | |||
133 | ret = 1; | |||
134 | break; | |||
135 | } | |||
136 | } | |||
137 | sk_SSL_CIPHER_free(cipher_stack)OPENSSL_sk_free(ossl_check_SSL_CIPHER_sk_type(cipher_stack)); | |||
138 | if (!ret) | |||
139 | return 0; | |||
140 | ||||
141 | /* Check we have at least one EC supported group */ | |||
142 | tls1_get_supported_groups(s, &pgroups, &num_groups); | |||
143 | for (j = 0; j < num_groups; j++) { | |||
144 | uint16_t ctmp = pgroups[j]; | |||
145 | ||||
146 | if (tls_valid_group(s, ctmp, min_version, max_version, 1, NULL((void*)0)) | |||
147 | && tls_group_allowed(s, ctmp, SSL_SECOP_CURVE_SUPPORTED(4 | (2 << 16)))) | |||
148 | return 1; | |||
149 | } | |||
150 | ||||
151 | return 0; | |||
152 | } | |||
153 | ||||
154 | EXT_RETURN tls_construct_ctos_ec_pt_formats(SSL *s, WPACKET *pkt, | |||
155 | unsigned int context, X509 *x, | |||
156 | size_t chainidx) | |||
157 | { | |||
158 | const unsigned char *pformats; | |||
159 | size_t num_formats; | |||
160 | int reason, min_version, max_version; | |||
161 | ||||
162 | reason = ssl_get_min_max_version(s, &min_version, &max_version, NULL((void*)0)); | |||
163 | if (reason != 0) { | |||
164 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, reason)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 164, __func__), ossl_statem_fatal)((s), (80), (reason), ((void *)0)); | |||
165 | return EXT_RETURN_FAIL; | |||
166 | } | |||
167 | if (!use_ecc(s, min_version, max_version)) | |||
168 | return EXT_RETURN_NOT_SENT; | |||
169 | ||||
170 | /* Add TLS extension ECPointFormats to the ClientHello message */ | |||
171 | tls1_get_formatlist(s, &pformats, &num_formats); | |||
172 | ||||
173 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)WPACKET_put_bytes__((pkt), (11), 2) | |||
174 | /* Sub-packet for formats extension */ | |||
175 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
176 | || !WPACKET_sub_memcpy_u8(pkt, pformats, num_formats)WPACKET_sub_memcpy__((pkt), (pformats), (num_formats), 1) | |||
177 | || !WPACKET_close(pkt)) { | |||
178 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 178, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
179 | return EXT_RETURN_FAIL; | |||
180 | } | |||
181 | ||||
182 | return EXT_RETURN_SENT; | |||
183 | } | |||
184 | ||||
185 | EXT_RETURN tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt, | |||
186 | unsigned int context, X509 *x, | |||
187 | size_t chainidx) | |||
188 | { | |||
189 | const uint16_t *pgroups = NULL((void*)0); | |||
190 | size_t num_groups = 0, i, tls13added = 0, added = 0; | |||
191 | int min_version, max_version, reason; | |||
192 | ||||
193 | reason = ssl_get_min_max_version(s, &min_version, &max_version, NULL((void*)0)); | |||
194 | if (reason != 0) { | |||
195 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, reason)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 195, __func__), ossl_statem_fatal)((s), (80), (reason), ((void *)0)); | |||
196 | return EXT_RETURN_FAIL; | |||
197 | } | |||
198 | ||||
199 | /* | |||
200 | * We only support EC groups in TLSv1.2 or below, and in DTLS. Therefore | |||
201 | * if we don't have EC support then we don't send this extension. | |||
202 | */ | |||
203 | if (!use_ecc(s, min_version, max_version) | |||
204 | && (SSL_IS_DTLS(s)(s->method->ssl3_enc->enc_flags & 0x8) || max_version < TLS1_3_VERSION0x0304)) | |||
205 | return EXT_RETURN_NOT_SENT; | |||
206 | ||||
207 | /* | |||
208 | * Add TLS extension supported_groups to the ClientHello message | |||
209 | */ | |||
210 | tls1_get_supported_groups(s, &pgroups, &num_groups); | |||
211 | ||||
212 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_groups)WPACKET_put_bytes__((pkt), (10), 2) | |||
213 | /* Sub-packet for supported_groups extension */ | |||
214 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
215 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
216 | || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH1)) { | |||
217 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 217, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
218 | return EXT_RETURN_FAIL; | |||
219 | } | |||
220 | /* Copy group ID if supported */ | |||
221 | for (i = 0; i < num_groups; i++) { | |||
222 | uint16_t ctmp = pgroups[i]; | |||
223 | int okfortls13; | |||
224 | ||||
225 | if (tls_valid_group(s, ctmp, min_version, max_version, 0, &okfortls13) | |||
226 | && tls_group_allowed(s, ctmp, SSL_SECOP_CURVE_SUPPORTED(4 | (2 << 16)))) { | |||
227 | if (!WPACKET_put_bytes_u16(pkt, ctmp)WPACKET_put_bytes__((pkt), (ctmp), 2)) { | |||
228 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 228, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
229 | return EXT_RETURN_FAIL; | |||
230 | } | |||
231 | if (okfortls13 && max_version == TLS1_3_VERSION0x0304) | |||
232 | tls13added++; | |||
233 | added++; | |||
234 | } | |||
235 | } | |||
236 | if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) { | |||
237 | if (added == 0) | |||
238 | SSLfatal_data(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 238, __func__), ossl_statem_fatal)(s, SSL_AD_INTERNAL_ERROR80, SSL_R_NO_SUITABLE_GROUPS295, | |||
239 | "No groups enabled for max supported SSL/TLS version"); | |||
240 | else | |||
241 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 241, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
242 | return EXT_RETURN_FAIL; | |||
243 | } | |||
244 | ||||
245 | if (tls13added == 0 && max_version == TLS1_3_VERSION0x0304) { | |||
246 | SSLfatal_data(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 246, __func__), ossl_statem_fatal)(s, SSL_AD_INTERNAL_ERROR80, SSL_R_NO_SUITABLE_GROUPS295, | |||
247 | "No groups enabled for max supported SSL/TLS version"); | |||
248 | return EXT_RETURN_FAIL; | |||
249 | } | |||
250 | ||||
251 | return EXT_RETURN_SENT; | |||
252 | } | |||
253 | ||||
254 | EXT_RETURN tls_construct_ctos_session_ticket(SSL *s, WPACKET *pkt, | |||
255 | unsigned int context, X509 *x, | |||
256 | size_t chainidx) | |||
257 | { | |||
258 | size_t ticklen; | |||
259 | ||||
260 | if (!tls_use_ticket(s)) | |||
| ||||
261 | return EXT_RETURN_NOT_SENT; | |||
262 | ||||
263 | if (!s->new_session && s->session != NULL((void*)0) | |||
264 | && s->session->ext.tick != NULL((void*)0) | |||
265 | && s->session->ssl_version != TLS1_3_VERSION0x0304) { | |||
266 | ticklen = s->session->ext.ticklen; | |||
267 | } else if (s->session && s->ext.session_ticket != NULL((void*)0) | |||
268 | && s->ext.session_ticket->data != NULL((void*)0)) { | |||
269 | ticklen = s->ext.session_ticket->length; | |||
270 | s->session->ext.tick = OPENSSL_malloc(ticklen)CRYPTO_malloc(ticklen, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 270); | |||
271 | if (s->session->ext.tick == NULL((void*)0)) { | |||
272 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 272, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
273 | return EXT_RETURN_FAIL; | |||
274 | } | |||
275 | memcpy(s->session->ext.tick, | |||
276 | s->ext.session_ticket->data, ticklen); | |||
277 | s->session->ext.ticklen = ticklen; | |||
278 | } else { | |||
279 | ticklen = 0; | |||
280 | } | |||
281 | ||||
282 | if (ticklen
| |||
283 | s->ext.session_ticket->data == NULL((void*)0)) | |||
284 | return EXT_RETURN_NOT_SENT; | |||
285 | ||||
286 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)WPACKET_put_bytes__((pkt), (35), 2) | |||
287 | || !WPACKET_sub_memcpy_u16(pkt, s->session->ext.tick, ticklen)WPACKET_sub_memcpy__((pkt), (s->session->ext.tick), (ticklen ), 2)) { | |||
| ||||
288 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 288, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
289 | return EXT_RETURN_FAIL; | |||
290 | } | |||
291 | ||||
292 | return EXT_RETURN_SENT; | |||
293 | } | |||
294 | ||||
295 | EXT_RETURN tls_construct_ctos_sig_algs(SSL *s, WPACKET *pkt, | |||
296 | unsigned int context, X509 *x, | |||
297 | size_t chainidx) | |||
298 | { | |||
299 | size_t salglen; | |||
300 | const uint16_t *salg; | |||
301 | ||||
302 | if (!SSL_CLIENT_USE_SIGALGS(s)((!(s->method->ssl3_enc->enc_flags & 0x8) && s->client_version >= 0x0303) || ((s->method->ssl3_enc ->enc_flags & 0x8) && ((((s->client_version ) == 0x0100) ? 0xff00 : (s->client_version)) <= (((0xFEFD ) == 0x0100) ? 0xff00 : (0xFEFD)))))) | |||
303 | return EXT_RETURN_NOT_SENT; | |||
304 | ||||
305 | salglen = tls12_get_psigalgs(s, 1, &salg); | |||
306 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)WPACKET_put_bytes__((pkt), (13), 2) | |||
307 | /* Sub-packet for sig-algs extension */ | |||
308 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
309 | /* Sub-packet for the actual list */ | |||
310 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
311 | || !tls12_copy_sigalgs(s, pkt, salg, salglen) | |||
312 | || !WPACKET_close(pkt) | |||
313 | || !WPACKET_close(pkt)) { | |||
314 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 314, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
315 | return EXT_RETURN_FAIL; | |||
316 | } | |||
317 | ||||
318 | return EXT_RETURN_SENT; | |||
319 | } | |||
320 | ||||
321 | #ifndef OPENSSL_NO_OCSP | |||
322 | EXT_RETURN tls_construct_ctos_status_request(SSL *s, WPACKET *pkt, | |||
323 | unsigned int context, X509 *x, | |||
324 | size_t chainidx) | |||
325 | { | |||
326 | int i; | |||
327 | ||||
328 | /* This extension isn't defined for client Certificates */ | |||
329 | if (x != NULL((void*)0)) | |||
330 | return EXT_RETURN_NOT_SENT; | |||
331 | ||||
332 | if (s->ext.status_type != TLSEXT_STATUSTYPE_ocsp1) | |||
333 | return EXT_RETURN_NOT_SENT; | |||
334 | ||||
335 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)WPACKET_put_bytes__((pkt), (5), 2) | |||
336 | /* Sub-packet for status request extension */ | |||
337 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
338 | || !WPACKET_put_bytes_u8(pkt, TLSEXT_STATUSTYPE_ocsp)WPACKET_put_bytes__((pkt), (1), 1) | |||
339 | /* Sub-packet for the ids */ | |||
340 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2)) { | |||
341 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 341, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
342 | return EXT_RETURN_FAIL; | |||
343 | } | |||
344 | for (i = 0; i < sk_OCSP_RESPID_num(s->ext.ocsp.ids)OPENSSL_sk_num(ossl_check_const_OCSP_RESPID_sk_type(s->ext .ocsp.ids)); i++) { | |||
345 | unsigned char *idbytes; | |||
346 | OCSP_RESPID *id = sk_OCSP_RESPID_value(s->ext.ocsp.ids, i)((OCSP_RESPID *)OPENSSL_sk_value(ossl_check_const_OCSP_RESPID_sk_type (s->ext.ocsp.ids), (i))); | |||
347 | int idlen = i2d_OCSP_RESPID(id, NULL((void*)0)); | |||
348 | ||||
349 | if (idlen <= 0 | |||
350 | /* Sub-packet for an individual id */ | |||
351 | || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)WPACKET_sub_allocate_bytes__((pkt), (idlen), (&idbytes), 2 ) | |||
352 | || i2d_OCSP_RESPID(id, &idbytes) != idlen) { | |||
353 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 353, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
354 | return EXT_RETURN_FAIL; | |||
355 | } | |||
356 | } | |||
357 | if (!WPACKET_close(pkt) | |||
358 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2)) { | |||
359 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 359, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
360 | return EXT_RETURN_FAIL; | |||
361 | } | |||
362 | if (s->ext.ocsp.exts) { | |||
363 | unsigned char *extbytes; | |||
364 | int extlen = i2d_X509_EXTENSIONS(s->ext.ocsp.exts, NULL((void*)0)); | |||
365 | ||||
366 | if (extlen < 0) { | |||
367 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 367, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
368 | return EXT_RETURN_FAIL; | |||
369 | } | |||
370 | if (!WPACKET_allocate_bytes(pkt, extlen, &extbytes) | |||
371 | || i2d_X509_EXTENSIONS(s->ext.ocsp.exts, &extbytes) | |||
372 | != extlen) { | |||
373 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 373, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
374 | return EXT_RETURN_FAIL; | |||
375 | } | |||
376 | } | |||
377 | if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) { | |||
378 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 378, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
379 | return EXT_RETURN_FAIL; | |||
380 | } | |||
381 | ||||
382 | return EXT_RETURN_SENT; | |||
383 | } | |||
384 | #endif | |||
385 | ||||
386 | #ifndef OPENSSL_NO_NEXTPROTONEG | |||
387 | EXT_RETURN tls_construct_ctos_npn(SSL *s, WPACKET *pkt, unsigned int context, | |||
388 | X509 *x, size_t chainidx) | |||
389 | { | |||
390 | if (s->ctx->ext.npn_select_cb == NULL((void*)0) || !SSL_IS_FIRST_HANDSHAKE(s)((s)->s3.tmp.finish_md_len == 0 || (s)->s3.tmp.peer_finish_md_len == 0)) | |||
391 | return EXT_RETURN_NOT_SENT; | |||
392 | ||||
393 | /* | |||
394 | * The client advertises an empty extension to indicate its support | |||
395 | * for Next Protocol Negotiation | |||
396 | */ | |||
397 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)WPACKET_put_bytes__((pkt), (13172), 2) | |||
398 | || !WPACKET_put_bytes_u16(pkt, 0)WPACKET_put_bytes__((pkt), (0), 2)) { | |||
399 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 399, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
400 | return EXT_RETURN_FAIL; | |||
401 | } | |||
402 | ||||
403 | return EXT_RETURN_SENT; | |||
404 | } | |||
405 | #endif | |||
406 | ||||
407 | EXT_RETURN tls_construct_ctos_alpn(SSL *s, WPACKET *pkt, unsigned int context, | |||
408 | X509 *x, size_t chainidx) | |||
409 | { | |||
410 | s->s3.alpn_sent = 0; | |||
411 | ||||
412 | if (s->ext.alpn == NULL((void*)0) || !SSL_IS_FIRST_HANDSHAKE(s)((s)->s3.tmp.finish_md_len == 0 || (s)->s3.tmp.peer_finish_md_len == 0)) | |||
413 | return EXT_RETURN_NOT_SENT; | |||
414 | ||||
415 | if (!WPACKET_put_bytes_u16(pkt,WPACKET_put_bytes__((pkt), (16), 2) | |||
416 | TLSEXT_TYPE_application_layer_protocol_negotiation)WPACKET_put_bytes__((pkt), (16), 2) | |||
417 | /* Sub-packet ALPN extension */ | |||
418 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
419 | || !WPACKET_sub_memcpy_u16(pkt, s->ext.alpn, s->ext.alpn_len)WPACKET_sub_memcpy__((pkt), (s->ext.alpn), (s->ext.alpn_len ), 2) | |||
420 | || !WPACKET_close(pkt)) { | |||
421 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 421, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
422 | return EXT_RETURN_FAIL; | |||
423 | } | |||
424 | s->s3.alpn_sent = 1; | |||
425 | ||||
426 | return EXT_RETURN_SENT; | |||
427 | } | |||
428 | ||||
429 | ||||
430 | #ifndef OPENSSL_NO_SRTP | |||
431 | EXT_RETURN tls_construct_ctos_use_srtp(SSL *s, WPACKET *pkt, | |||
432 | unsigned int context, X509 *x, | |||
433 | size_t chainidx) | |||
434 | { | |||
435 | STACK_OF(SRTP_PROTECTION_PROFILE)struct stack_st_SRTP_PROTECTION_PROFILE *clnt = SSL_get_srtp_profiles(s); | |||
436 | int i, end; | |||
437 | ||||
438 | if (clnt == NULL((void*)0)) | |||
439 | return EXT_RETURN_NOT_SENT; | |||
440 | ||||
441 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)WPACKET_put_bytes__((pkt), (14), 2) | |||
442 | /* Sub-packet for SRTP extension */ | |||
443 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
444 | /* Sub-packet for the protection profile list */ | |||
445 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2)) { | |||
446 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 446, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
447 | return EXT_RETURN_FAIL; | |||
448 | } | |||
449 | ||||
450 | end = sk_SRTP_PROTECTION_PROFILE_num(clnt)OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type (clnt)); | |||
451 | for (i = 0; i < end; i++) { | |||
452 | const SRTP_PROTECTION_PROFILE *prof = | |||
453 | sk_SRTP_PROTECTION_PROFILE_value(clnt, i)((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type (clnt), (i))); | |||
454 | ||||
455 | if (prof == NULL((void*)0) || !WPACKET_put_bytes_u16(pkt, prof->id)WPACKET_put_bytes__((pkt), (prof->id), 2)) { | |||
456 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 456, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
457 | return EXT_RETURN_FAIL; | |||
458 | } | |||
459 | } | |||
460 | if (!WPACKET_close(pkt) | |||
461 | /* Add an empty use_mki value */ | |||
462 | || !WPACKET_put_bytes_u8(pkt, 0)WPACKET_put_bytes__((pkt), (0), 1) | |||
463 | || !WPACKET_close(pkt)) { | |||
464 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 464, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
465 | return EXT_RETURN_FAIL; | |||
466 | } | |||
467 | ||||
468 | return EXT_RETURN_SENT; | |||
469 | } | |||
470 | #endif | |||
471 | ||||
472 | EXT_RETURN tls_construct_ctos_etm(SSL *s, WPACKET *pkt, unsigned int context, | |||
473 | X509 *x, size_t chainidx) | |||
474 | { | |||
475 | if (s->options & SSL_OP_NO_ENCRYPT_THEN_MAC((uint64_t)1 << (uint64_t)19)) | |||
476 | return EXT_RETURN_NOT_SENT; | |||
477 | ||||
478 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)WPACKET_put_bytes__((pkt), (22), 2) | |||
479 | || !WPACKET_put_bytes_u16(pkt, 0)WPACKET_put_bytes__((pkt), (0), 2)) { | |||
480 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 480, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
481 | return EXT_RETURN_FAIL; | |||
482 | } | |||
483 | ||||
484 | return EXT_RETURN_SENT; | |||
485 | } | |||
486 | ||||
487 | #ifndef OPENSSL_NO_CT | |||
488 | EXT_RETURN tls_construct_ctos_sct(SSL *s, WPACKET *pkt, unsigned int context, | |||
489 | X509 *x, size_t chainidx) | |||
490 | { | |||
491 | if (s->ct_validation_callback == NULL((void*)0)) | |||
492 | return EXT_RETURN_NOT_SENT; | |||
493 | ||||
494 | /* Not defined for client Certificates */ | |||
495 | if (x != NULL((void*)0)) | |||
496 | return EXT_RETURN_NOT_SENT; | |||
497 | ||||
498 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signed_certificate_timestamp)WPACKET_put_bytes__((pkt), (18), 2) | |||
499 | || !WPACKET_put_bytes_u16(pkt, 0)WPACKET_put_bytes__((pkt), (0), 2)) { | |||
500 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 500, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
501 | return EXT_RETURN_FAIL; | |||
502 | } | |||
503 | ||||
504 | return EXT_RETURN_SENT; | |||
505 | } | |||
506 | #endif | |||
507 | ||||
508 | EXT_RETURN tls_construct_ctos_ems(SSL *s, WPACKET *pkt, unsigned int context, | |||
509 | X509 *x, size_t chainidx) | |||
510 | { | |||
511 | if (s->options & SSL_OP_NO_EXTENDED_MASTER_SECRET((uint64_t)1 << (uint64_t)0)) | |||
512 | return EXT_RETURN_NOT_SENT; | |||
513 | ||||
514 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)WPACKET_put_bytes__((pkt), (23), 2) | |||
515 | || !WPACKET_put_bytes_u16(pkt, 0)WPACKET_put_bytes__((pkt), (0), 2)) { | |||
516 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 516, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
517 | return EXT_RETURN_FAIL; | |||
518 | } | |||
519 | ||||
520 | return EXT_RETURN_SENT; | |||
521 | } | |||
522 | ||||
523 | EXT_RETURN tls_construct_ctos_supported_versions(SSL *s, WPACKET *pkt, | |||
524 | unsigned int context, X509 *x, | |||
525 | size_t chainidx) | |||
526 | { | |||
527 | int currv, min_version, max_version, reason; | |||
528 | ||||
529 | reason = ssl_get_min_max_version(s, &min_version, &max_version, NULL((void*)0)); | |||
530 | if (reason != 0) { | |||
531 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, reason)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 531, __func__), ossl_statem_fatal)((s), (80), (reason), ((void *)0)); | |||
532 | return EXT_RETURN_FAIL; | |||
533 | } | |||
534 | ||||
535 | /* | |||
536 | * Don't include this if we can't negotiate TLSv1.3. We can do a straight | |||
537 | * comparison here because we will never be called in DTLS. | |||
538 | */ | |||
539 | if (max_version < TLS1_3_VERSION0x0304) | |||
540 | return EXT_RETURN_NOT_SENT; | |||
541 | ||||
542 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_versions)WPACKET_put_bytes__((pkt), (43), 2) | |||
543 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
544 | || !WPACKET_start_sub_packet_u8(pkt)WPACKET_start_sub_packet_len__((pkt), 1)) { | |||
545 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 545, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
546 | return EXT_RETURN_FAIL; | |||
547 | } | |||
548 | ||||
549 | for (currv = max_version; currv >= min_version; currv--) { | |||
550 | if (!WPACKET_put_bytes_u16(pkt, currv)WPACKET_put_bytes__((pkt), (currv), 2)) { | |||
551 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 551, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
552 | return EXT_RETURN_FAIL; | |||
553 | } | |||
554 | } | |||
555 | if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) { | |||
556 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 556, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
557 | return EXT_RETURN_FAIL; | |||
558 | } | |||
559 | ||||
560 | return EXT_RETURN_SENT; | |||
561 | } | |||
562 | ||||
563 | /* | |||
564 | * Construct a psk_kex_modes extension. | |||
565 | */ | |||
566 | EXT_RETURN tls_construct_ctos_psk_kex_modes(SSL *s, WPACKET *pkt, | |||
567 | unsigned int context, X509 *x, | |||
568 | size_t chainidx) | |||
569 | { | |||
570 | #ifndef OPENSSL_NO_TLS1_3 | |||
571 | int nodhe = s->options & SSL_OP_ALLOW_NO_DHE_KEX((uint64_t)1 << (uint64_t)10); | |||
572 | ||||
573 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_psk_kex_modes)WPACKET_put_bytes__((pkt), (45), 2) | |||
574 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
575 | || !WPACKET_start_sub_packet_u8(pkt)WPACKET_start_sub_packet_len__((pkt), 1) | |||
576 | || !WPACKET_put_bytes_u8(pkt, TLSEXT_KEX_MODE_KE_DHE)WPACKET_put_bytes__((pkt), (0x01), 1) | |||
577 | || (nodhe && !WPACKET_put_bytes_u8(pkt, TLSEXT_KEX_MODE_KE)WPACKET_put_bytes__((pkt), (0x00), 1)) | |||
578 | || !WPACKET_close(pkt) | |||
579 | || !WPACKET_close(pkt)) { | |||
580 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 580, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
581 | return EXT_RETURN_FAIL; | |||
582 | } | |||
583 | ||||
584 | s->ext.psk_kex_mode = TLSEXT_KEX_MODE_FLAG_KE_DHE2; | |||
585 | if (nodhe) | |||
586 | s->ext.psk_kex_mode |= TLSEXT_KEX_MODE_FLAG_KE1; | |||
587 | #endif | |||
588 | ||||
589 | return EXT_RETURN_SENT; | |||
590 | } | |||
591 | ||||
592 | #ifndef OPENSSL_NO_TLS1_3 | |||
593 | static int add_key_share(SSL *s, WPACKET *pkt, unsigned int curve_id) | |||
594 | { | |||
595 | unsigned char *encoded_point = NULL((void*)0); | |||
596 | EVP_PKEY *key_share_key = NULL((void*)0); | |||
597 | size_t encodedlen; | |||
598 | ||||
599 | if (s->s3.tmp.pkey != NULL((void*)0)) { | |||
600 | if (!ossl_assert(s->hello_retry_request == SSL_HRR_PENDING)((s->hello_retry_request == SSL_HRR_PENDING) != 0)) { | |||
601 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 601, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
602 | return 0; | |||
603 | } | |||
604 | /* | |||
605 | * Could happen if we got an HRR that wasn't requesting a new key_share | |||
606 | */ | |||
607 | key_share_key = s->s3.tmp.pkey; | |||
608 | } else { | |||
609 | key_share_key = ssl_generate_pkey_group(s, curve_id); | |||
610 | if (key_share_key == NULL((void*)0)) { | |||
611 | /* SSLfatal() already called */ | |||
612 | return 0; | |||
613 | } | |||
614 | } | |||
615 | ||||
616 | /* Encode the public key. */ | |||
617 | encodedlen = EVP_PKEY_get1_encoded_public_key(key_share_key, | |||
618 | &encoded_point); | |||
619 | if (encodedlen == 0) { | |||
620 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EC_LIB)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 620, __func__), ossl_statem_fatal)((s), (80), ((16 | (0x2 << 18L))), ((void*)0)); | |||
621 | goto err; | |||
622 | } | |||
623 | ||||
624 | /* Create KeyShareEntry */ | |||
625 | if (!WPACKET_put_bytes_u16(pkt, curve_id)WPACKET_put_bytes__((pkt), (curve_id), 2) | |||
626 | || !WPACKET_sub_memcpy_u16(pkt, encoded_point, encodedlen)WPACKET_sub_memcpy__((pkt), (encoded_point), (encodedlen), 2)) { | |||
627 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 627, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
628 | goto err; | |||
629 | } | |||
630 | ||||
631 | /* | |||
632 | * When changing to send more than one key_share we're | |||
633 | * going to need to be able to save more than one EVP_PKEY. For now | |||
634 | * we reuse the existing tmp.pkey | |||
635 | */ | |||
636 | s->s3.tmp.pkey = key_share_key; | |||
637 | s->s3.group_id = curve_id; | |||
638 | OPENSSL_free(encoded_point)CRYPTO_free(encoded_point, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 638); | |||
639 | ||||
640 | return 1; | |||
641 | err: | |||
642 | if (s->s3.tmp.pkey == NULL((void*)0)) | |||
643 | EVP_PKEY_free(key_share_key); | |||
644 | OPENSSL_free(encoded_point)CRYPTO_free(encoded_point, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 644); | |||
645 | return 0; | |||
646 | } | |||
647 | #endif | |||
648 | ||||
649 | EXT_RETURN tls_construct_ctos_key_share(SSL *s, WPACKET *pkt, | |||
650 | unsigned int context, X509 *x, | |||
651 | size_t chainidx) | |||
652 | { | |||
653 | #ifndef OPENSSL_NO_TLS1_3 | |||
654 | size_t i, num_groups = 0; | |||
655 | const uint16_t *pgroups = NULL((void*)0); | |||
656 | uint16_t curve_id = 0; | |||
657 | ||||
658 | /* key_share extension */ | |||
659 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_key_share)WPACKET_put_bytes__((pkt), (51), 2) | |||
660 | /* Extension data sub-packet */ | |||
661 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
662 | /* KeyShare list sub-packet */ | |||
663 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2)) { | |||
664 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 664, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
665 | return EXT_RETURN_FAIL; | |||
666 | } | |||
667 | ||||
668 | tls1_get_supported_groups(s, &pgroups, &num_groups); | |||
669 | ||||
670 | /* | |||
671 | * Make the number of key_shares sent configurable. For | |||
672 | * now, we just send one | |||
673 | */ | |||
674 | if (s->s3.group_id != 0) { | |||
675 | curve_id = s->s3.group_id; | |||
676 | } else { | |||
677 | for (i = 0; i < num_groups; i++) { | |||
678 | ||||
679 | if (!tls_group_allowed(s, pgroups[i], SSL_SECOP_CURVE_SUPPORTED(4 | (2 << 16)))) | |||
680 | continue; | |||
681 | ||||
682 | curve_id = pgroups[i]; | |||
683 | break; | |||
684 | } | |||
685 | } | |||
686 | ||||
687 | if (curve_id == 0) { | |||
688 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_NO_SUITABLE_KEY_SHARE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 688, __func__), ossl_statem_fatal)((s), (80), (101), ((void *)0)); | |||
689 | return EXT_RETURN_FAIL; | |||
690 | } | |||
691 | ||||
692 | if (!add_key_share(s, pkt, curve_id)) { | |||
693 | /* SSLfatal() already called */ | |||
694 | return EXT_RETURN_FAIL; | |||
695 | } | |||
696 | ||||
697 | if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) { | |||
698 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 698, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
699 | return EXT_RETURN_FAIL; | |||
700 | } | |||
701 | return EXT_RETURN_SENT; | |||
702 | #else | |||
703 | return EXT_RETURN_NOT_SENT; | |||
704 | #endif | |||
705 | } | |||
706 | ||||
707 | EXT_RETURN tls_construct_ctos_cookie(SSL *s, WPACKET *pkt, unsigned int context, | |||
708 | X509 *x, size_t chainidx) | |||
709 | { | |||
710 | EXT_RETURN ret = EXT_RETURN_FAIL; | |||
711 | ||||
712 | /* Should only be set if we've had an HRR */ | |||
713 | if (s->ext.tls13_cookie_len == 0) | |||
714 | return EXT_RETURN_NOT_SENT; | |||
715 | ||||
716 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_cookie)WPACKET_put_bytes__((pkt), (44), 2) | |||
717 | /* Extension data sub-packet */ | |||
718 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
719 | || !WPACKET_sub_memcpy_u16(pkt, s->ext.tls13_cookie,WPACKET_sub_memcpy__((pkt), (s->ext.tls13_cookie), (s-> ext.tls13_cookie_len), 2) | |||
720 | s->ext.tls13_cookie_len)WPACKET_sub_memcpy__((pkt), (s->ext.tls13_cookie), (s-> ext.tls13_cookie_len), 2) | |||
721 | || !WPACKET_close(pkt)) { | |||
722 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 722, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
723 | goto end; | |||
724 | } | |||
725 | ||||
726 | ret = EXT_RETURN_SENT; | |||
727 | end: | |||
728 | OPENSSL_free(s->ext.tls13_cookie)CRYPTO_free(s->ext.tls13_cookie, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 728); | |||
729 | s->ext.tls13_cookie = NULL((void*)0); | |||
730 | s->ext.tls13_cookie_len = 0; | |||
731 | ||||
732 | return ret; | |||
733 | } | |||
734 | ||||
735 | EXT_RETURN tls_construct_ctos_early_data(SSL *s, WPACKET *pkt, | |||
736 | unsigned int context, X509 *x, | |||
737 | size_t chainidx) | |||
738 | { | |||
739 | #ifndef OPENSSL_NO_PSK | |||
740 | char identity[PSK_MAX_IDENTITY_LEN256 + 1]; | |||
741 | #endif /* OPENSSL_NO_PSK */ | |||
742 | const unsigned char *id = NULL((void*)0); | |||
743 | size_t idlen = 0; | |||
744 | SSL_SESSION *psksess = NULL((void*)0); | |||
745 | SSL_SESSION *edsess = NULL((void*)0); | |||
746 | const EVP_MD *handmd = NULL((void*)0); | |||
747 | ||||
748 | if (s->hello_retry_request == SSL_HRR_PENDING) | |||
749 | handmd = ssl_handshake_md(s); | |||
750 | ||||
751 | if (s->psk_use_session_cb != NULL((void*)0) | |||
752 | && (!s->psk_use_session_cb(s, handmd, &id, &idlen, &psksess) | |||
753 | || (psksess != NULL((void*)0) | |||
754 | && psksess->ssl_version != TLS1_3_VERSION0x0304))) { | |||
755 | SSL_SESSION_free(psksess); | |||
756 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_PSK)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 756, __func__), ossl_statem_fatal)((s), (80), (219), ((void *)0)); | |||
757 | return EXT_RETURN_FAIL; | |||
758 | } | |||
759 | ||||
760 | #ifndef OPENSSL_NO_PSK | |||
761 | if (psksess == NULL((void*)0) && s->psk_client_callback != NULL((void*)0)) { | |||
762 | unsigned char psk[PSK_MAX_PSK_LEN512]; | |||
763 | size_t psklen = 0; | |||
764 | ||||
765 | memset(identity, 0, sizeof(identity)); | |||
766 | psklen = s->psk_client_callback(s, NULL((void*)0), identity, sizeof(identity) - 1, | |||
767 | psk, sizeof(psk)); | |||
768 | ||||
769 | if (psklen > PSK_MAX_PSK_LEN512) { | |||
770 | SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 770, __func__), ossl_statem_fatal)((s), (40), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
771 | return EXT_RETURN_FAIL; | |||
772 | } else if (psklen > 0) { | |||
773 | const unsigned char tls13_aes128gcmsha256_id[] = { 0x13, 0x01 }; | |||
774 | const SSL_CIPHER *cipher; | |||
775 | ||||
776 | idlen = strlen(identity); | |||
777 | if (idlen > PSK_MAX_IDENTITY_LEN256) { | |||
778 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 778, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
779 | return EXT_RETURN_FAIL; | |||
780 | } | |||
781 | id = (unsigned char *)identity; | |||
782 | ||||
783 | /* | |||
784 | * We found a PSK using an old style callback. We don't know | |||
785 | * the digest so we default to SHA256 as per the TLSv1.3 spec | |||
786 | */ | |||
787 | cipher = SSL_CIPHER_find(s, tls13_aes128gcmsha256_id); | |||
788 | if (cipher == NULL((void*)0)) { | |||
789 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 789, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
790 | return EXT_RETURN_FAIL; | |||
791 | } | |||
792 | ||||
793 | psksess = SSL_SESSION_new(); | |||
794 | if (psksess == NULL((void*)0) | |||
795 | || !SSL_SESSION_set1_master_key(psksess, psk, psklen) | |||
796 | || !SSL_SESSION_set_cipher(psksess, cipher) | |||
797 | || !SSL_SESSION_set_protocol_version(psksess, TLS1_3_VERSION0x0304)) { | |||
798 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 798, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
799 | OPENSSL_cleanse(psk, psklen); | |||
800 | return EXT_RETURN_FAIL; | |||
801 | } | |||
802 | OPENSSL_cleanse(psk, psklen); | |||
803 | } | |||
804 | } | |||
805 | #endif /* OPENSSL_NO_PSK */ | |||
806 | ||||
807 | SSL_SESSION_free(s->psksession); | |||
808 | s->psksession = psksess; | |||
809 | if (psksess != NULL((void*)0)) { | |||
810 | OPENSSL_free(s->psksession_id)CRYPTO_free(s->psksession_id, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 810); | |||
811 | s->psksession_id = OPENSSL_memdup(id, idlen)CRYPTO_memdup((id), idlen, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 811); | |||
812 | if (s->psksession_id == NULL((void*)0)) { | |||
813 | s->psksession_id_len = 0; | |||
814 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 814, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
815 | return EXT_RETURN_FAIL; | |||
816 | } | |||
817 | s->psksession_id_len = idlen; | |||
818 | } | |||
819 | ||||
820 | if (s->early_data_state != SSL_EARLY_DATA_CONNECTING | |||
821 | || (s->session->ext.max_early_data == 0 | |||
822 | && (psksess == NULL((void*)0) || psksess->ext.max_early_data == 0))) { | |||
823 | s->max_early_data = 0; | |||
824 | return EXT_RETURN_NOT_SENT; | |||
825 | } | |||
826 | edsess = s->session->ext.max_early_data != 0 ? s->session : psksess; | |||
827 | s->max_early_data = edsess->ext.max_early_data; | |||
828 | ||||
829 | if (edsess->ext.hostname != NULL((void*)0)) { | |||
830 | if (s->ext.hostname == NULL((void*)0) | |||
831 | || (s->ext.hostname != NULL((void*)0) | |||
832 | && strcmp(s->ext.hostname, edsess->ext.hostname) != 0)) { | |||
833 | SSLfatal(s, SSL_AD_INTERNAL_ERROR,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 834, __func__), ossl_statem_fatal)((s), (80), (231), ((void *)0)) | |||
834 | SSL_R_INCONSISTENT_EARLY_DATA_SNI)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 834, __func__), ossl_statem_fatal)((s), (80), (231), ((void *)0)); | |||
835 | return EXT_RETURN_FAIL; | |||
836 | } | |||
837 | } | |||
838 | ||||
839 | if ((s->ext.alpn == NULL((void*)0) && edsess->ext.alpn_selected != NULL((void*)0))) { | |||
840 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_INCONSISTENT_EARLY_DATA_ALPN)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 840, __func__), ossl_statem_fatal)((s), (80), (222), ((void *)0)); | |||
841 | return EXT_RETURN_FAIL; | |||
842 | } | |||
843 | ||||
844 | /* | |||
845 | * Verify that we are offering an ALPN protocol consistent with the early | |||
846 | * data. | |||
847 | */ | |||
848 | if (edsess->ext.alpn_selected != NULL((void*)0)) { | |||
849 | PACKET prots, alpnpkt; | |||
850 | int found = 0; | |||
851 | ||||
852 | if (!PACKET_buf_init(&prots, s->ext.alpn, s->ext.alpn_len)) { | |||
853 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 853, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
854 | return EXT_RETURN_FAIL; | |||
855 | } | |||
856 | while (PACKET_get_length_prefixed_1(&prots, &alpnpkt)) { | |||
857 | if (PACKET_equal(&alpnpkt, edsess->ext.alpn_selected, | |||
858 | edsess->ext.alpn_selected_len)) { | |||
859 | found = 1; | |||
860 | break; | |||
861 | } | |||
862 | } | |||
863 | if (!found) { | |||
864 | SSLfatal(s, SSL_AD_INTERNAL_ERROR,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 865, __func__), ossl_statem_fatal)((s), (80), (222), ((void *)0)) | |||
865 | SSL_R_INCONSISTENT_EARLY_DATA_ALPN)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 865, __func__), ossl_statem_fatal)((s), (80), (222), ((void *)0)); | |||
866 | return EXT_RETURN_FAIL; | |||
867 | } | |||
868 | } | |||
869 | ||||
870 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_early_data)WPACKET_put_bytes__((pkt), (42), 2) | |||
871 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
872 | || !WPACKET_close(pkt)) { | |||
873 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 873, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
874 | return EXT_RETURN_FAIL; | |||
875 | } | |||
876 | ||||
877 | /* | |||
878 | * We set this to rejected here. Later, if the server acknowledges the | |||
879 | * extension, we set it to accepted. | |||
880 | */ | |||
881 | s->ext.early_data = SSL_EARLY_DATA_REJECTED1; | |||
882 | s->ext.early_data_ok = 1; | |||
883 | ||||
884 | return EXT_RETURN_SENT; | |||
885 | } | |||
886 | ||||
887 | #define F5_WORKAROUND_MIN_MSG_LEN0xff 0xff | |||
888 | #define F5_WORKAROUND_MAX_MSG_LEN0x200 0x200 | |||
889 | ||||
890 | /* | |||
891 | * PSK pre binder overhead = | |||
892 | * 2 bytes for TLSEXT_TYPE_psk | |||
893 | * 2 bytes for extension length | |||
894 | * 2 bytes for identities list length | |||
895 | * 2 bytes for identity length | |||
896 | * 4 bytes for obfuscated_ticket_age | |||
897 | * 2 bytes for binder list length | |||
898 | * 1 byte for binder length | |||
899 | * The above excludes the number of bytes for the identity itself and the | |||
900 | * subsequent binder bytes | |||
901 | */ | |||
902 | #define PSK_PRE_BINDER_OVERHEAD(2 + 2 + 2 + 2 + 4 + 2 + 1) (2 + 2 + 2 + 2 + 4 + 2 + 1) | |||
903 | ||||
904 | EXT_RETURN tls_construct_ctos_padding(SSL *s, WPACKET *pkt, | |||
905 | unsigned int context, X509 *x, | |||
906 | size_t chainidx) | |||
907 | { | |||
908 | unsigned char *padbytes; | |||
909 | size_t hlen; | |||
910 | ||||
911 | if ((s->options & SSL_OP_TLSEXT_PADDING((uint64_t)1 << (uint64_t)4)) == 0) | |||
912 | return EXT_RETURN_NOT_SENT; | |||
913 | ||||
914 | /* | |||
915 | * Add padding to workaround bugs in F5 terminators. See RFC7685. | |||
916 | * This code calculates the length of all extensions added so far but | |||
917 | * excludes the PSK extension (because that MUST be written last). Therefore | |||
918 | * this extension MUST always appear second to last. | |||
919 | */ | |||
920 | if (!WPACKET_get_total_written(pkt, &hlen)) { | |||
921 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 921, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
922 | return EXT_RETURN_FAIL; | |||
923 | } | |||
924 | ||||
925 | /* | |||
926 | * If we're going to send a PSK then that will be written out after this | |||
927 | * extension, so we need to calculate how long it is going to be. | |||
928 | */ | |||
929 | if (s->session->ssl_version == TLS1_3_VERSION0x0304 | |||
930 | && s->session->ext.ticklen != 0 | |||
931 | && s->session->cipher != NULL((void*)0)) { | |||
932 | const EVP_MD *md = ssl_md(s->ctx, s->session->cipher->algorithm2); | |||
933 | ||||
934 | if (md != NULL((void*)0)) { | |||
935 | /* | |||
936 | * Add the fixed PSK overhead, the identity length and the binder | |||
937 | * length. | |||
938 | */ | |||
939 | hlen += PSK_PRE_BINDER_OVERHEAD(2 + 2 + 2 + 2 + 4 + 2 + 1) + s->session->ext.ticklen | |||
940 | + EVP_MD_get_size(md); | |||
941 | } | |||
942 | } | |||
943 | ||||
944 | if (hlen > F5_WORKAROUND_MIN_MSG_LEN0xff && hlen < F5_WORKAROUND_MAX_MSG_LEN0x200) { | |||
945 | /* Calculate the amount of padding we need to add */ | |||
946 | hlen = F5_WORKAROUND_MAX_MSG_LEN0x200 - hlen; | |||
947 | ||||
948 | /* | |||
949 | * Take off the size of extension header itself (2 bytes for type and | |||
950 | * 2 bytes for length bytes), but ensure that the extension is at least | |||
951 | * 1 byte long so as not to have an empty extension last (WebSphere 7.x, | |||
952 | * 8.x are intolerant of that condition) | |||
953 | */ | |||
954 | if (hlen > 4) | |||
955 | hlen -= 4; | |||
956 | else | |||
957 | hlen = 1; | |||
958 | ||||
959 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_padding)WPACKET_put_bytes__((pkt), (21), 2) | |||
960 | || !WPACKET_sub_allocate_bytes_u16(pkt, hlen, &padbytes)WPACKET_sub_allocate_bytes__((pkt), (hlen), (&padbytes), 2 )) { | |||
961 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 961, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
962 | return EXT_RETURN_FAIL; | |||
963 | } | |||
964 | memset(padbytes, 0, hlen); | |||
965 | } | |||
966 | ||||
967 | return EXT_RETURN_SENT; | |||
968 | } | |||
969 | ||||
970 | /* | |||
971 | * Construct the pre_shared_key extension | |||
972 | */ | |||
973 | EXT_RETURN tls_construct_ctos_psk(SSL *s, WPACKET *pkt, unsigned int context, | |||
974 | X509 *x, size_t chainidx) | |||
975 | { | |||
976 | #ifndef OPENSSL_NO_TLS1_3 | |||
977 | uint32_t now, agesec, agems = 0; | |||
978 | size_t reshashsize = 0, pskhashsize = 0, binderoffset, msglen; | |||
979 | unsigned char *resbinder = NULL((void*)0), *pskbinder = NULL((void*)0), *msgstart = NULL((void*)0); | |||
980 | const EVP_MD *handmd = NULL((void*)0), *mdres = NULL((void*)0), *mdpsk = NULL((void*)0); | |||
981 | int dores = 0; | |||
982 | ||||
983 | s->ext.tick_identity = 0; | |||
984 | ||||
985 | /* | |||
986 | * Note: At this stage of the code we only support adding a single | |||
987 | * resumption PSK. If we add support for multiple PSKs then the length | |||
988 | * calculations in the padding extension will need to be adjusted. | |||
989 | */ | |||
990 | ||||
991 | /* | |||
992 | * If this is an incompatible or new session then we have nothing to resume | |||
993 | * so don't add this extension. | |||
994 | */ | |||
995 | if (s->session->ssl_version != TLS1_3_VERSION0x0304 | |||
996 | || (s->session->ext.ticklen == 0 && s->psksession == NULL((void*)0))) | |||
997 | return EXT_RETURN_NOT_SENT; | |||
998 | ||||
999 | if (s->hello_retry_request == SSL_HRR_PENDING) | |||
1000 | handmd = ssl_handshake_md(s); | |||
1001 | ||||
1002 | if (s->session->ext.ticklen != 0) { | |||
1003 | /* Get the digest associated with the ciphersuite in the session */ | |||
1004 | if (s->session->cipher == NULL((void*)0)) { | |||
1005 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1005, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1006 | return EXT_RETURN_FAIL; | |||
1007 | } | |||
1008 | mdres = ssl_md(s->ctx, s->session->cipher->algorithm2); | |||
1009 | if (mdres == NULL((void*)0)) { | |||
1010 | /* | |||
1011 | * Don't recognize this cipher so we can't use the session. | |||
1012 | * Ignore it | |||
1013 | */ | |||
1014 | goto dopsksess; | |||
1015 | } | |||
1016 | ||||
1017 | if (s->hello_retry_request == SSL_HRR_PENDING && mdres != handmd) { | |||
1018 | /* | |||
1019 | * Selected ciphersuite hash does not match the hash for the session | |||
1020 | * so we can't use it. | |||
1021 | */ | |||
1022 | goto dopsksess; | |||
1023 | } | |||
1024 | ||||
1025 | /* | |||
1026 | * Technically the C standard just says time() returns a time_t and says | |||
1027 | * nothing about the encoding of that type. In practice most | |||
1028 | * implementations follow POSIX which holds it as an integral type in | |||
1029 | * seconds since epoch. We've already made the assumption that we can do | |||
1030 | * this in multiple places in the code, so portability shouldn't be an | |||
1031 | * issue. | |||
1032 | */ | |||
1033 | now = (uint32_t)time(NULL((void*)0)); | |||
1034 | agesec = now - (uint32_t)s->session->time; | |||
1035 | /* | |||
1036 | * We calculate the age in seconds but the server may work in ms. Due to | |||
1037 | * rounding errors we could overestimate the age by up to 1s. It is | |||
1038 | * better to underestimate it. Otherwise, if the RTT is very short, when | |||
1039 | * the server calculates the age reported by the client it could be | |||
1040 | * bigger than the age calculated on the server - which should never | |||
1041 | * happen. | |||
1042 | */ | |||
1043 | if (agesec > 0) | |||
1044 | agesec--; | |||
1045 | ||||
1046 | if (s->session->ext.tick_lifetime_hint < agesec) { | |||
1047 | /* Ticket is too old. Ignore it. */ | |||
1048 | goto dopsksess; | |||
1049 | } | |||
1050 | ||||
1051 | /* | |||
1052 | * Calculate age in ms. We're just doing it to nearest second. Should be | |||
1053 | * good enough. | |||
1054 | */ | |||
1055 | agems = agesec * (uint32_t)1000; | |||
1056 | ||||
1057 | if (agesec != 0 && agems / (uint32_t)1000 != agesec) { | |||
1058 | /* | |||
1059 | * Overflow. Shouldn't happen unless this is a *really* old session. | |||
1060 | * If so we just ignore it. | |||
1061 | */ | |||
1062 | goto dopsksess; | |||
1063 | } | |||
1064 | ||||
1065 | /* | |||
1066 | * Obfuscate the age. Overflow here is fine, this addition is supposed | |||
1067 | * to be mod 2^32. | |||
1068 | */ | |||
1069 | agems += s->session->ext.tick_age_add; | |||
1070 | ||||
1071 | reshashsize = EVP_MD_get_size(mdres); | |||
1072 | s->ext.tick_identity++; | |||
1073 | dores = 1; | |||
1074 | } | |||
1075 | ||||
1076 | dopsksess: | |||
1077 | if (!dores && s->psksession == NULL((void*)0)) | |||
1078 | return EXT_RETURN_NOT_SENT; | |||
1079 | ||||
1080 | if (s->psksession != NULL((void*)0)) { | |||
1081 | mdpsk = ssl_md(s->ctx, s->psksession->cipher->algorithm2); | |||
1082 | if (mdpsk == NULL((void*)0)) { | |||
1083 | /* | |||
1084 | * Don't recognize this cipher so we can't use the session. | |||
1085 | * If this happens it's an application bug. | |||
1086 | */ | |||
1087 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_PSK)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1087, __func__), ossl_statem_fatal)((s), (80), (219), ((void *)0)); | |||
1088 | return EXT_RETURN_FAIL; | |||
1089 | } | |||
1090 | ||||
1091 | if (s->hello_retry_request == SSL_HRR_PENDING && mdpsk != handmd) { | |||
1092 | /* | |||
1093 | * Selected ciphersuite hash does not match the hash for the PSK | |||
1094 | * session. This is an application bug. | |||
1095 | */ | |||
1096 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_PSK)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1096, __func__), ossl_statem_fatal)((s), (80), (219), ((void *)0)); | |||
1097 | return EXT_RETURN_FAIL; | |||
1098 | } | |||
1099 | ||||
1100 | pskhashsize = EVP_MD_get_size(mdpsk); | |||
1101 | } | |||
1102 | ||||
1103 | /* Create the extension, but skip over the binder for now */ | |||
1104 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_psk)WPACKET_put_bytes__((pkt), (41), 2) | |||
1105 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
1106 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2)) { | |||
1107 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1107, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1108 | return EXT_RETURN_FAIL; | |||
1109 | } | |||
1110 | ||||
1111 | if (dores) { | |||
1112 | if (!WPACKET_sub_memcpy_u16(pkt, s->session->ext.tick,WPACKET_sub_memcpy__((pkt), (s->session->ext.tick), (s-> session->ext.ticklen), 2) | |||
1113 | s->session->ext.ticklen)WPACKET_sub_memcpy__((pkt), (s->session->ext.tick), (s-> session->ext.ticklen), 2) | |||
1114 | || !WPACKET_put_bytes_u32(pkt, agems)WPACKET_put_bytes__((pkt), (agems), 4)) { | |||
1115 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1115, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1116 | return EXT_RETURN_FAIL; | |||
1117 | } | |||
1118 | } | |||
1119 | ||||
1120 | if (s->psksession != NULL((void*)0)) { | |||
1121 | if (!WPACKET_sub_memcpy_u16(pkt, s->psksession_id,WPACKET_sub_memcpy__((pkt), (s->psksession_id), (s->psksession_id_len ), 2) | |||
1122 | s->psksession_id_len)WPACKET_sub_memcpy__((pkt), (s->psksession_id), (s->psksession_id_len ), 2) | |||
1123 | || !WPACKET_put_bytes_u32(pkt, 0)WPACKET_put_bytes__((pkt), (0), 4)) { | |||
1124 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1124, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1125 | return EXT_RETURN_FAIL; | |||
1126 | } | |||
1127 | s->ext.tick_identity++; | |||
1128 | } | |||
1129 | ||||
1130 | if (!WPACKET_close(pkt) | |||
1131 | || !WPACKET_get_total_written(pkt, &binderoffset) | |||
1132 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
1133 | || (dores | |||
1134 | && !WPACKET_sub_allocate_bytes_u8(pkt, reshashsize, &resbinder)WPACKET_sub_allocate_bytes__((pkt), (reshashsize), (&resbinder ), 1)) | |||
1135 | || (s->psksession != NULL((void*)0) | |||
1136 | && !WPACKET_sub_allocate_bytes_u8(pkt, pskhashsize, &pskbinder)WPACKET_sub_allocate_bytes__((pkt), (pskhashsize), (&pskbinder ), 1)) | |||
1137 | || !WPACKET_close(pkt) | |||
1138 | || !WPACKET_close(pkt) | |||
1139 | || !WPACKET_get_total_written(pkt, &msglen) | |||
1140 | /* | |||
1141 | * We need to fill in all the sub-packet lengths now so we can | |||
1142 | * calculate the HMAC of the message up to the binders | |||
1143 | */ | |||
1144 | || !WPACKET_fill_lengths(pkt)) { | |||
1145 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1145, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1146 | return EXT_RETURN_FAIL; | |||
1147 | } | |||
1148 | ||||
1149 | msgstart = WPACKET_get_curr(pkt) - msglen; | |||
1150 | ||||
1151 | if (dores | |||
1152 | && tls_psk_do_binder(s, mdres, msgstart, binderoffset, NULL((void*)0), | |||
1153 | resbinder, s->session, 1, 0) != 1) { | |||
1154 | /* SSLfatal() already called */ | |||
1155 | return EXT_RETURN_FAIL; | |||
1156 | } | |||
1157 | ||||
1158 | if (s->psksession != NULL((void*)0) | |||
1159 | && tls_psk_do_binder(s, mdpsk, msgstart, binderoffset, NULL((void*)0), | |||
1160 | pskbinder, s->psksession, 1, 1) != 1) { | |||
1161 | /* SSLfatal() already called */ | |||
1162 | return EXT_RETURN_FAIL; | |||
1163 | } | |||
1164 | ||||
1165 | return EXT_RETURN_SENT; | |||
1166 | #else | |||
1167 | return EXT_RETURN_NOT_SENT; | |||
1168 | #endif | |||
1169 | } | |||
1170 | ||||
1171 | EXT_RETURN tls_construct_ctos_post_handshake_auth(SSL *s, WPACKET *pkt, | |||
1172 | ossl_unused__attribute__((unused)) unsigned int context, | |||
1173 | ossl_unused__attribute__((unused)) X509 *x, | |||
1174 | ossl_unused__attribute__((unused)) size_t chainidx) | |||
1175 | { | |||
1176 | #ifndef OPENSSL_NO_TLS1_3 | |||
1177 | if (!s->pha_enabled) | |||
1178 | return EXT_RETURN_NOT_SENT; | |||
1179 | ||||
1180 | /* construct extension - 0 length, no contents */ | |||
1181 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_post_handshake_auth)WPACKET_put_bytes__((pkt), (49), 2) | |||
1182 | || !WPACKET_start_sub_packet_u16(pkt)WPACKET_start_sub_packet_len__((pkt), 2) | |||
1183 | || !WPACKET_close(pkt)) { | |||
1184 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1184, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1185 | return EXT_RETURN_FAIL; | |||
1186 | } | |||
1187 | ||||
1188 | s->post_handshake_auth = SSL_PHA_EXT_SENT; | |||
1189 | ||||
1190 | return EXT_RETURN_SENT; | |||
1191 | #else | |||
1192 | return EXT_RETURN_NOT_SENT; | |||
1193 | #endif | |||
1194 | } | |||
1195 | ||||
1196 | #ifndef OPENSSL_NO_QUIC | |||
1197 | EXT_RETURN tls_construct_ctos_quic_transport_params_draft(SSL *s, WPACKET *pkt, | |||
1198 | unsigned int context, X509 *x, | |||
1199 | size_t chainidx) | |||
1200 | { | |||
1201 | if (s->quic_transport_version == TLSEXT_TYPE_quic_transport_parameters0x0039 | |||
1202 | || s->ext.quic_transport_params == NULL((void*)0) | |||
1203 | || s->ext.quic_transport_params_len == 0) { | |||
1204 | return EXT_RETURN_NOT_SENT; | |||
1205 | } | |||
1206 | ||||
1207 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_quic_transport_parameters_draft)WPACKET_put_bytes__((pkt), (0xffa5), 2) | |||
1208 | || !WPACKET_sub_memcpy_u16(pkt, s->ext.quic_transport_params,WPACKET_sub_memcpy__((pkt), (s->ext.quic_transport_params) , (s->ext.quic_transport_params_len), 2) | |||
1209 | s->ext.quic_transport_params_len)WPACKET_sub_memcpy__((pkt), (s->ext.quic_transport_params) , (s->ext.quic_transport_params_len), 2)) { | |||
1210 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1210, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1211 | return EXT_RETURN_FAIL; | |||
1212 | } | |||
1213 | ||||
1214 | return EXT_RETURN_SENT; | |||
1215 | } | |||
1216 | ||||
1217 | EXT_RETURN tls_construct_ctos_quic_transport_params(SSL *s, WPACKET *pkt, | |||
1218 | unsigned int context, X509 *x, | |||
1219 | size_t chainidx) | |||
1220 | { | |||
1221 | if (s->quic_transport_version == TLSEXT_TYPE_quic_transport_parameters_draft0xffa5 | |||
1222 | || s->ext.quic_transport_params == NULL((void*)0) | |||
1223 | || s->ext.quic_transport_params_len == 0) { | |||
1224 | return EXT_RETURN_NOT_SENT; | |||
1225 | } | |||
1226 | ||||
1227 | if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_quic_transport_parameters)WPACKET_put_bytes__((pkt), (0x0039), 2) | |||
1228 | || !WPACKET_sub_memcpy_u16(pkt, s->ext.quic_transport_params,WPACKET_sub_memcpy__((pkt), (s->ext.quic_transport_params) , (s->ext.quic_transport_params_len), 2) | |||
1229 | s->ext.quic_transport_params_len)WPACKET_sub_memcpy__((pkt), (s->ext.quic_transport_params) , (s->ext.quic_transport_params_len), 2)) { | |||
1230 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1230, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1231 | return EXT_RETURN_FAIL; | |||
1232 | } | |||
1233 | ||||
1234 | return EXT_RETURN_SENT; | |||
1235 | } | |||
1236 | #endif | |||
1237 | /* | |||
1238 | * Parse the server's renegotiation binding and abort if it's not right | |||
1239 | */ | |||
1240 | int tls_parse_stoc_renegotiate(SSL *s, PACKET *pkt, unsigned int context, | |||
1241 | X509 *x, size_t chainidx) | |||
1242 | { | |||
1243 | size_t expected_len = s->s3.previous_client_finished_len | |||
1244 | + s->s3.previous_server_finished_len; | |||
1245 | size_t ilen; | |||
1246 | const unsigned char *data; | |||
1247 | ||||
1248 | /* Check for logic errors */ | |||
1249 | if (!ossl_assert(expected_len == 0((expected_len == 0 || s->s3.previous_client_finished_len != 0) != 0) | |||
1250 | || s->s3.previous_client_finished_len != 0)((expected_len == 0 || s->s3.previous_client_finished_len != 0) != 0) | |||
1251 | || !ossl_assert(expected_len == 0((expected_len == 0 || s->s3.previous_server_finished_len != 0) != 0) | |||
1252 | || s->s3.previous_server_finished_len != 0)((expected_len == 0 || s->s3.previous_server_finished_len != 0) != 0)) { | |||
1253 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1253, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1254 | return 0; | |||
1255 | } | |||
1256 | ||||
1257 | /* Parse the length byte */ | |||
1258 | if (!PACKET_get_1_len(pkt, &ilen)) { | |||
1259 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_RENEGOTIATION_ENCODING_ERR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1259, __func__), ossl_statem_fatal)((s), (50), (336), ((void *)0)); | |||
1260 | return 0; | |||
1261 | } | |||
1262 | ||||
1263 | /* Consistency check */ | |||
1264 | if (PACKET_remaining(pkt) != ilen) { | |||
1265 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_RENEGOTIATION_ENCODING_ERR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1265, __func__), ossl_statem_fatal)((s), (50), (336), ((void *)0)); | |||
1266 | return 0; | |||
1267 | } | |||
1268 | ||||
1269 | /* Check that the extension matches */ | |||
1270 | if (ilen != expected_len) { | |||
1271 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_RENEGOTIATION_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1271, __func__), ossl_statem_fatal)((s), (47), (337), ((void *)0)); | |||
1272 | return 0; | |||
1273 | } | |||
1274 | ||||
1275 | if (!PACKET_get_bytes(pkt, &data, s->s3.previous_client_finished_len) | |||
1276 | || memcmp(data, s->s3.previous_client_finished, | |||
1277 | s->s3.previous_client_finished_len) != 0) { | |||
1278 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_RENEGOTIATION_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1278, __func__), ossl_statem_fatal)((s), (47), (337), ((void *)0)); | |||
1279 | return 0; | |||
1280 | } | |||
1281 | ||||
1282 | if (!PACKET_get_bytes(pkt, &data, s->s3.previous_server_finished_len) | |||
1283 | || memcmp(data, s->s3.previous_server_finished, | |||
1284 | s->s3.previous_server_finished_len) != 0) { | |||
1285 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_RENEGOTIATION_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1285, __func__), ossl_statem_fatal)((s), (47), (337), ((void *)0)); | |||
1286 | return 0; | |||
1287 | } | |||
1288 | s->s3.send_connection_binding = 1; | |||
1289 | ||||
1290 | return 1; | |||
1291 | } | |||
1292 | ||||
1293 | /* Parse the server's max fragment len extension packet */ | |||
1294 | int tls_parse_stoc_maxfragmentlen(SSL *s, PACKET *pkt, unsigned int context, | |||
1295 | X509 *x, size_t chainidx) | |||
1296 | { | |||
1297 | unsigned int value; | |||
1298 | ||||
1299 | if (PACKET_remaining(pkt) != 1 || !PACKET_get_1(pkt, &value)) { | |||
1300 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1300, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1301 | return 0; | |||
1302 | } | |||
1303 | ||||
1304 | /* |value| should contains a valid max-fragment-length code. */ | |||
1305 | if (!IS_MAX_FRAGMENT_LENGTH_EXT_VALID(value)(((value) >= 1) && ((value) <= 4))) { | |||
1306 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1307, __func__), ossl_statem_fatal)((s), (47), (232), ((void *)0)) | |||
1307 | SSL_R_SSL3_EXT_INVALID_MAX_FRAGMENT_LENGTH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1307, __func__), ossl_statem_fatal)((s), (47), (232), ((void *)0)); | |||
1308 | return 0; | |||
1309 | } | |||
1310 | ||||
1311 | /* Must be the same value as client-configured one who was sent to server */ | |||
1312 | /*- | |||
1313 | * RFC 6066: if a client receives a maximum fragment length negotiation | |||
1314 | * response that differs from the length it requested, ... | |||
1315 | * It must abort with SSL_AD_ILLEGAL_PARAMETER alert | |||
1316 | */ | |||
1317 | if (value != s->ext.max_fragment_len_mode) { | |||
1318 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1319, __func__), ossl_statem_fatal)((s), (47), (232), ((void *)0)) | |||
1319 | SSL_R_SSL3_EXT_INVALID_MAX_FRAGMENT_LENGTH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1319, __func__), ossl_statem_fatal)((s), (47), (232), ((void *)0)); | |||
1320 | return 0; | |||
1321 | } | |||
1322 | ||||
1323 | /* | |||
1324 | * Maximum Fragment Length Negotiation succeeded. | |||
1325 | * The negotiated Maximum Fragment Length is binding now. | |||
1326 | */ | |||
1327 | s->session->ext.max_fragment_len_mode = value; | |||
1328 | ||||
1329 | return 1; | |||
1330 | } | |||
1331 | ||||
1332 | int tls_parse_stoc_server_name(SSL *s, PACKET *pkt, unsigned int context, | |||
1333 | X509 *x, size_t chainidx) | |||
1334 | { | |||
1335 | if (s->ext.hostname == NULL((void*)0)) { | |||
1336 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1336, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1337 | return 0; | |||
1338 | } | |||
1339 | ||||
1340 | if (PACKET_remaining(pkt) > 0) { | |||
1341 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1341, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1342 | return 0; | |||
1343 | } | |||
1344 | ||||
1345 | if (!s->hit) { | |||
1346 | if (s->session->ext.hostname != NULL((void*)0)) { | |||
1347 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1347, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1348 | return 0; | |||
1349 | } | |||
1350 | s->session->ext.hostname = OPENSSL_strdup(s->ext.hostname)CRYPTO_strdup(s->ext.hostname, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1350); | |||
1351 | if (s->session->ext.hostname == NULL((void*)0)) { | |||
1352 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1352, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1353 | return 0; | |||
1354 | } | |||
1355 | } | |||
1356 | ||||
1357 | return 1; | |||
1358 | } | |||
1359 | ||||
1360 | int tls_parse_stoc_ec_pt_formats(SSL *s, PACKET *pkt, unsigned int context, | |||
1361 | X509 *x, size_t chainidx) | |||
1362 | { | |||
1363 | size_t ecpointformats_len; | |||
1364 | PACKET ecptformatlist; | |||
1365 | ||||
1366 | if (!PACKET_as_length_prefixed_1(pkt, &ecptformatlist)) { | |||
1367 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1367, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1368 | return 0; | |||
1369 | } | |||
1370 | if (!s->hit) { | |||
1371 | ecpointformats_len = PACKET_remaining(&ecptformatlist); | |||
1372 | if (ecpointformats_len == 0) { | |||
1373 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_LENGTH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1373, __func__), ossl_statem_fatal)((s), (50), (271), ((void *)0)); | |||
1374 | return 0; | |||
1375 | } | |||
1376 | ||||
1377 | s->ext.peer_ecpointformats_len = 0; | |||
1378 | OPENSSL_free(s->ext.peer_ecpointformats)CRYPTO_free(s->ext.peer_ecpointformats, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1378); | |||
1379 | s->ext.peer_ecpointformats = OPENSSL_malloc(ecpointformats_len)CRYPTO_malloc(ecpointformats_len, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1379); | |||
1380 | if (s->ext.peer_ecpointformats == NULL((void*)0)) { | |||
1381 | s->ext.peer_ecpointformats_len = 0; | |||
1382 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1382, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1383 | return 0; | |||
1384 | } | |||
1385 | ||||
1386 | s->ext.peer_ecpointformats_len = ecpointformats_len; | |||
1387 | ||||
1388 | if (!PACKET_copy_bytes(&ecptformatlist, | |||
1389 | s->ext.peer_ecpointformats, | |||
1390 | ecpointformats_len)) { | |||
1391 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1391, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1392 | return 0; | |||
1393 | } | |||
1394 | } | |||
1395 | ||||
1396 | return 1; | |||
1397 | } | |||
1398 | ||||
1399 | int tls_parse_stoc_session_ticket(SSL *s, PACKET *pkt, unsigned int context, | |||
1400 | X509 *x, size_t chainidx) | |||
1401 | { | |||
1402 | if (s->ext.session_ticket_cb != NULL((void*)0) && | |||
1403 | !s->ext.session_ticket_cb(s, PACKET_data(pkt), | |||
1404 | PACKET_remaining(pkt), | |||
1405 | s->ext.session_ticket_cb_arg)) { | |||
1406 | SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1406, __func__), ossl_statem_fatal)((s), (40), (110), ((void *)0)); | |||
1407 | return 0; | |||
1408 | } | |||
1409 | ||||
1410 | if (!tls_use_ticket(s)) { | |||
1411 | SSLfatal(s, SSL_AD_UNSUPPORTED_EXTENSION, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1411, __func__), ossl_statem_fatal)((s), (110), (110), ((void *)0)); | |||
1412 | return 0; | |||
1413 | } | |||
1414 | if (PACKET_remaining(pkt) > 0) { | |||
1415 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1415, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1416 | return 0; | |||
1417 | } | |||
1418 | ||||
1419 | s->ext.ticket_expected = 1; | |||
1420 | ||||
1421 | return 1; | |||
1422 | } | |||
1423 | ||||
1424 | #ifndef OPENSSL_NO_OCSP | |||
1425 | int tls_parse_stoc_status_request(SSL *s, PACKET *pkt, unsigned int context, | |||
1426 | X509 *x, size_t chainidx) | |||
1427 | { | |||
1428 | if (context == SSL_EXT_TLS1_3_CERTIFICATE_REQUEST0x4000) { | |||
1429 | /* We ignore this if the server sends a CertificateRequest */ | |||
1430 | return 1; | |||
1431 | } | |||
1432 | ||||
1433 | /* | |||
1434 | * MUST only be sent if we've requested a status | |||
1435 | * request message. In TLS <= 1.2 it must also be empty. | |||
1436 | */ | |||
1437 | if (s->ext.status_type != TLSEXT_STATUSTYPE_ocsp1) { | |||
1438 | SSLfatal(s, SSL_AD_UNSUPPORTED_EXTENSION, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1438, __func__), ossl_statem_fatal)((s), (110), (110), ((void *)0)); | |||
1439 | return 0; | |||
1440 | } | |||
1441 | if (!SSL_IS_TLS13(s)(!(s->method->ssl3_enc->enc_flags & 0x8) && (s)->method->version >= 0x0304 && (s)->method ->version != 0x10000) && PACKET_remaining(pkt) > 0) { | |||
1442 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1442, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1443 | return 0; | |||
1444 | } | |||
1445 | ||||
1446 | if (SSL_IS_TLS13(s)(!(s->method->ssl3_enc->enc_flags & 0x8) && (s)->method->version >= 0x0304 && (s)->method ->version != 0x10000)) { | |||
1447 | /* We only know how to handle this if it's for the first Certificate in | |||
1448 | * the chain. We ignore any other responses. | |||
1449 | */ | |||
1450 | if (chainidx != 0) | |||
1451 | return 1; | |||
1452 | ||||
1453 | /* SSLfatal() already called */ | |||
1454 | return tls_process_cert_status_body(s, pkt); | |||
1455 | } | |||
1456 | ||||
1457 | /* Set flag to expect CertificateStatus message */ | |||
1458 | s->ext.status_expected = 1; | |||
1459 | ||||
1460 | return 1; | |||
1461 | } | |||
1462 | #endif | |||
1463 | ||||
1464 | ||||
1465 | #ifndef OPENSSL_NO_CT | |||
1466 | int tls_parse_stoc_sct(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1467 | size_t chainidx) | |||
1468 | { | |||
1469 | if (context == SSL_EXT_TLS1_3_CERTIFICATE_REQUEST0x4000) { | |||
1470 | /* We ignore this if the server sends it in a CertificateRequest */ | |||
1471 | return 1; | |||
1472 | } | |||
1473 | ||||
1474 | /* | |||
1475 | * Only take it if we asked for it - i.e if there is no CT validation | |||
1476 | * callback set, then a custom extension MAY be processing it, so we | |||
1477 | * need to let control continue to flow to that. | |||
1478 | */ | |||
1479 | if (s->ct_validation_callback != NULL((void*)0)) { | |||
1480 | size_t size = PACKET_remaining(pkt); | |||
1481 | ||||
1482 | /* Simply copy it off for later processing */ | |||
1483 | OPENSSL_free(s->ext.scts)CRYPTO_free(s->ext.scts, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1483); | |||
1484 | s->ext.scts = NULL((void*)0); | |||
1485 | ||||
1486 | s->ext.scts_len = (uint16_t)size; | |||
1487 | if (size > 0) { | |||
1488 | s->ext.scts = OPENSSL_malloc(size)CRYPTO_malloc(size, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1488); | |||
1489 | if (s->ext.scts == NULL((void*)0)) { | |||
1490 | s->ext.scts_len = 0; | |||
1491 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1491, __func__), ossl_statem_fatal)((s), (80), ((256|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1492 | return 0; | |||
1493 | } | |||
1494 | if (!PACKET_copy_bytes(pkt, s->ext.scts, size)) { | |||
1495 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1495, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1496 | return 0; | |||
1497 | } | |||
1498 | } | |||
1499 | } else { | |||
1500 | ENDPOINT role = (context & SSL_EXT_TLS1_2_SERVER_HELLO0x0100) != 0 | |||
1501 | ? ENDPOINT_CLIENT : ENDPOINT_BOTH; | |||
1502 | ||||
1503 | /* | |||
1504 | * If we didn't ask for it then there must be a custom extension, | |||
1505 | * otherwise this is unsolicited. | |||
1506 | */ | |||
1507 | if (custom_ext_find(&s->cert->custext, role, | |||
1508 | TLSEXT_TYPE_signed_certificate_timestamp18, | |||
1509 | NULL((void*)0)) == NULL((void*)0)) { | |||
1510 | SSLfatal(s, TLS1_AD_UNSUPPORTED_EXTENSION, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1510, __func__), ossl_statem_fatal)((s), (110), (110), ((void *)0)); | |||
1511 | return 0; | |||
1512 | } | |||
1513 | ||||
1514 | if (!custom_ext_parse(s, context, | |||
1515 | TLSEXT_TYPE_signed_certificate_timestamp18, | |||
1516 | PACKET_data(pkt), PACKET_remaining(pkt), | |||
1517 | x, chainidx)) { | |||
1518 | /* SSLfatal already called */ | |||
1519 | return 0; | |||
1520 | } | |||
1521 | } | |||
1522 | ||||
1523 | return 1; | |||
1524 | } | |||
1525 | #endif | |||
1526 | ||||
1527 | ||||
1528 | #ifndef OPENSSL_NO_NEXTPROTONEG | |||
1529 | /* | |||
1530 | * ssl_next_proto_validate validates a Next Protocol Negotiation block. No | |||
1531 | * elements of zero length are allowed and the set of elements must exactly | |||
1532 | * fill the length of the block. Returns 1 on success or 0 on failure. | |||
1533 | */ | |||
1534 | static int ssl_next_proto_validate(SSL *s, PACKET *pkt) | |||
1535 | { | |||
1536 | PACKET tmp_protocol; | |||
1537 | ||||
1538 | while (PACKET_remaining(pkt)) { | |||
1539 | if (!PACKET_get_length_prefixed_1(pkt, &tmp_protocol) | |||
1540 | || PACKET_remaining(&tmp_protocol) == 0) { | |||
1541 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1541, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1542 | return 0; | |||
1543 | } | |||
1544 | } | |||
1545 | ||||
1546 | return 1; | |||
1547 | } | |||
1548 | ||||
1549 | int tls_parse_stoc_npn(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1550 | size_t chainidx) | |||
1551 | { | |||
1552 | unsigned char *selected; | |||
1553 | unsigned char selected_len; | |||
1554 | PACKET tmppkt; | |||
1555 | ||||
1556 | /* Check if we are in a renegotiation. If so ignore this extension */ | |||
1557 | if (!SSL_IS_FIRST_HANDSHAKE(s)((s)->s3.tmp.finish_md_len == 0 || (s)->s3.tmp.peer_finish_md_len == 0)) | |||
1558 | return 1; | |||
1559 | ||||
1560 | /* We must have requested it. */ | |||
1561 | if (s->ctx->ext.npn_select_cb == NULL((void*)0)) { | |||
1562 | SSLfatal(s, SSL_AD_UNSUPPORTED_EXTENSION, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1562, __func__), ossl_statem_fatal)((s), (110), (110), ((void *)0)); | |||
1563 | return 0; | |||
1564 | } | |||
1565 | ||||
1566 | /* The data must be valid */ | |||
1567 | tmppkt = *pkt; | |||
1568 | if (!ssl_next_proto_validate(s, &tmppkt)) { | |||
1569 | /* SSLfatal() already called */ | |||
1570 | return 0; | |||
1571 | } | |||
1572 | if (s->ctx->ext.npn_select_cb(s, &selected, &selected_len, | |||
1573 | PACKET_data(pkt), | |||
1574 | PACKET_remaining(pkt), | |||
1575 | s->ctx->ext.npn_select_cb_arg) != | |||
1576 | SSL_TLSEXT_ERR_OK0) { | |||
1577 | SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1577, __func__), ossl_statem_fatal)((s), (40), (110), ((void *)0)); | |||
1578 | return 0; | |||
1579 | } | |||
1580 | ||||
1581 | /* | |||
1582 | * Could be non-NULL if server has sent multiple NPN extensions in | |||
1583 | * a single Serverhello | |||
1584 | */ | |||
1585 | OPENSSL_free(s->ext.npn)CRYPTO_free(s->ext.npn, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1585); | |||
1586 | s->ext.npn = OPENSSL_malloc(selected_len)CRYPTO_malloc(selected_len, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1586); | |||
1587 | if (s->ext.npn == NULL((void*)0)) { | |||
1588 | s->ext.npn_len = 0; | |||
1589 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1589, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1590 | return 0; | |||
1591 | } | |||
1592 | ||||
1593 | memcpy(s->ext.npn, selected, selected_len); | |||
1594 | s->ext.npn_len = selected_len; | |||
1595 | s->s3.npn_seen = 1; | |||
1596 | ||||
1597 | return 1; | |||
1598 | } | |||
1599 | #endif | |||
1600 | ||||
1601 | int tls_parse_stoc_alpn(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1602 | size_t chainidx) | |||
1603 | { | |||
1604 | size_t len; | |||
1605 | ||||
1606 | /* We must have requested it. */ | |||
1607 | if (!s->s3.alpn_sent) { | |||
1608 | SSLfatal(s, SSL_AD_UNSUPPORTED_EXTENSION, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1608, __func__), ossl_statem_fatal)((s), (110), (110), ((void *)0)); | |||
1609 | return 0; | |||
1610 | } | |||
1611 | /*- | |||
1612 | * The extension data consists of: | |||
1613 | * uint16 list_length | |||
1614 | * uint8 proto_length; | |||
1615 | * uint8 proto[proto_length]; | |||
1616 | */ | |||
1617 | if (!PACKET_get_net_2_len(pkt, &len) | |||
1618 | || PACKET_remaining(pkt) != len || !PACKET_get_1_len(pkt, &len) | |||
1619 | || PACKET_remaining(pkt) != len) { | |||
1620 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1620, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1621 | return 0; | |||
1622 | } | |||
1623 | OPENSSL_free(s->s3.alpn_selected)CRYPTO_free(s->s3.alpn_selected, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1623); | |||
1624 | s->s3.alpn_selected = OPENSSL_malloc(len)CRYPTO_malloc(len, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1624); | |||
1625 | if (s->s3.alpn_selected == NULL((void*)0)) { | |||
1626 | s->s3.alpn_selected_len = 0; | |||
1627 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1627, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1628 | return 0; | |||
1629 | } | |||
1630 | if (!PACKET_copy_bytes(pkt, s->s3.alpn_selected, len)) { | |||
1631 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1631, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1632 | return 0; | |||
1633 | } | |||
1634 | s->s3.alpn_selected_len = len; | |||
1635 | ||||
1636 | if (s->session->ext.alpn_selected == NULL((void*)0) | |||
1637 | || s->session->ext.alpn_selected_len != len | |||
1638 | || memcmp(s->session->ext.alpn_selected, s->s3.alpn_selected, len) | |||
1639 | != 0) { | |||
1640 | /* ALPN not consistent with the old session so cannot use early_data */ | |||
1641 | s->ext.early_data_ok = 0; | |||
1642 | } | |||
1643 | if (!s->hit) { | |||
1644 | /* | |||
1645 | * This is a new session and so alpn_selected should have been | |||
1646 | * initialised to NULL. We should update it with the selected ALPN. | |||
1647 | */ | |||
1648 | if (!ossl_assert(s->session->ext.alpn_selected == NULL)((s->session->ext.alpn_selected == ((void*)0)) != 0)) { | |||
1649 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1649, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1650 | return 0; | |||
1651 | } | |||
1652 | s->session->ext.alpn_selected = | |||
1653 | OPENSSL_memdup(s->s3.alpn_selected, s->s3.alpn_selected_len)CRYPTO_memdup((s->s3.alpn_selected), s->s3.alpn_selected_len , "../deps/openssl/openssl/ssl/statem/extensions_clnt.c", 1653 ); | |||
1654 | if (s->session->ext.alpn_selected == NULL((void*)0)) { | |||
1655 | s->session->ext.alpn_selected_len = 0; | |||
1656 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1656, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1657 | return 0; | |||
1658 | } | |||
1659 | s->session->ext.alpn_selected_len = s->s3.alpn_selected_len; | |||
1660 | } | |||
1661 | ||||
1662 | return 1; | |||
1663 | } | |||
1664 | ||||
1665 | #ifndef OPENSSL_NO_SRTP | |||
1666 | int tls_parse_stoc_use_srtp(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1667 | size_t chainidx) | |||
1668 | { | |||
1669 | unsigned int id, ct, mki; | |||
1670 | int i; | |||
1671 | STACK_OF(SRTP_PROTECTION_PROFILE)struct stack_st_SRTP_PROTECTION_PROFILE *clnt; | |||
1672 | SRTP_PROTECTION_PROFILE *prof; | |||
1673 | ||||
1674 | if (!PACKET_get_net_2(pkt, &ct) || ct != 2 | |||
1675 | || !PACKET_get_net_2(pkt, &id) | |||
1676 | || !PACKET_get_1(pkt, &mki) | |||
1677 | || PACKET_remaining(pkt) != 0) { | |||
1678 | SSLfatal(s, SSL_AD_DECODE_ERROR,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1679, __func__), ossl_statem_fatal)((s), (50), (353), ((void *)0)) | |||
1679 | SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1679, __func__), ossl_statem_fatal)((s), (50), (353), ((void *)0)); | |||
1680 | return 0; | |||
1681 | } | |||
1682 | ||||
1683 | if (mki != 0) { | |||
1684 | /* Must be no MKI, since we never offer one */ | |||
1685 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_SRTP_MKI_VALUE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1685, __func__), ossl_statem_fatal)((s), (47), (352), ((void *)0)); | |||
1686 | return 0; | |||
1687 | } | |||
1688 | ||||
1689 | /* Throw an error if the server gave us an unsolicited extension */ | |||
1690 | clnt = SSL_get_srtp_profiles(s); | |||
1691 | if (clnt == NULL((void*)0)) { | |||
1692 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_NO_SRTP_PROFILES)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1692, __func__), ossl_statem_fatal)((s), (50), (359), ((void *)0)); | |||
1693 | return 0; | |||
1694 | } | |||
1695 | ||||
1696 | /* | |||
1697 | * Check to see if the server gave us something we support (and | |||
1698 | * presumably offered) | |||
1699 | */ | |||
1700 | for (i = 0; i < sk_SRTP_PROTECTION_PROFILE_num(clnt)OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type (clnt)); i++) { | |||
1701 | prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i)((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type (clnt), (i))); | |||
1702 | ||||
1703 | if (prof->id == id) { | |||
1704 | s->srtp_profile = prof; | |||
1705 | return 1; | |||
1706 | } | |||
1707 | } | |||
1708 | ||||
1709 | SSLfatal(s, SSL_AD_DECODE_ERROR,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1710, __func__), ossl_statem_fatal)((s), (50), (353), ((void *)0)) | |||
1710 | SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1710, __func__), ossl_statem_fatal)((s), (50), (353), ((void *)0)); | |||
1711 | return 0; | |||
1712 | } | |||
1713 | #endif | |||
1714 | ||||
1715 | int tls_parse_stoc_etm(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1716 | size_t chainidx) | |||
1717 | { | |||
1718 | /* Ignore if inappropriate ciphersuite */ | |||
1719 | if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC((uint64_t)1 << (uint64_t)19)) | |||
1720 | && s->s3.tmp.new_cipher->algorithm_mac != SSL_AEAD0x00000040U | |||
1721 | && s->s3.tmp.new_cipher->algorithm_enc != SSL_RC40x00000004U | |||
1722 | && s->s3.tmp.new_cipher->algorithm_enc != SSL_eGOST2814789CNT0x00000400U | |||
1723 | && s->s3.tmp.new_cipher->algorithm_enc != SSL_eGOST2814789CNT120x00040000U | |||
1724 | && s->s3.tmp.new_cipher->algorithm_enc != SSL_MAGMA0x00400000U | |||
1725 | && s->s3.tmp.new_cipher->algorithm_enc != SSL_KUZNYECHIK0x00800000U) | |||
1726 | s->ext.use_etm = 1; | |||
1727 | ||||
1728 | return 1; | |||
1729 | } | |||
1730 | ||||
1731 | int tls_parse_stoc_ems(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1732 | size_t chainidx) | |||
1733 | { | |||
1734 | if (s->options & SSL_OP_NO_EXTENDED_MASTER_SECRET((uint64_t)1 << (uint64_t)0)) | |||
1735 | return 1; | |||
1736 | s->s3.flags |= TLS1_FLAGS_RECEIVED_EXTMS0x0200; | |||
1737 | if (!s->hit) | |||
1738 | s->session->flags |= SSL_SESS_FLAG_EXTMS0x1; | |||
1739 | ||||
1740 | return 1; | |||
1741 | } | |||
1742 | ||||
1743 | int tls_parse_stoc_supported_versions(SSL *s, PACKET *pkt, unsigned int context, | |||
1744 | X509 *x, size_t chainidx) | |||
1745 | { | |||
1746 | unsigned int version; | |||
1747 | ||||
1748 | if (!PACKET_get_net_2(pkt, &version) | |||
1749 | || PACKET_remaining(pkt) != 0) { | |||
1750 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1750, __func__), ossl_statem_fatal)((s), (50), (159), ((void *)0)); | |||
1751 | return 0; | |||
1752 | } | |||
1753 | ||||
1754 | /* | |||
1755 | * The only protocol version we support which is valid in this extension in | |||
1756 | * a ServerHello is TLSv1.3 therefore we shouldn't be getting anything else. | |||
1757 | */ | |||
1758 | if (version != TLS1_3_VERSION0x0304) { | |||
1759 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1760, __func__), ossl_statem_fatal)((s), (47), (116), ((void *)0)) | |||
1760 | SSL_R_BAD_PROTOCOL_VERSION_NUMBER)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1760, __func__), ossl_statem_fatal)((s), (47), (116), ((void *)0)); | |||
1761 | return 0; | |||
1762 | } | |||
1763 | ||||
1764 | /* We ignore this extension for HRRs except to sanity check it */ | |||
1765 | if (context == SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST0x0800) | |||
1766 | return 1; | |||
1767 | ||||
1768 | /* We just set it here. We validate it in ssl_choose_client_version */ | |||
1769 | s->version = version; | |||
1770 | ||||
1771 | return 1; | |||
1772 | } | |||
1773 | ||||
1774 | int tls_parse_stoc_key_share(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1775 | size_t chainidx) | |||
1776 | { | |||
1777 | #ifndef OPENSSL_NO_TLS1_3 | |||
1778 | unsigned int group_id; | |||
1779 | PACKET encoded_pt; | |||
1780 | EVP_PKEY *ckey = s->s3.tmp.pkey, *skey = NULL((void*)0); | |||
1781 | const TLS_GROUP_INFO *ginf = NULL((void*)0); | |||
1782 | ||||
1783 | /* Sanity check */ | |||
1784 | if (ckey == NULL((void*)0) || s->s3.peer_tmp != NULL((void*)0)) { | |||
1785 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1785, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1786 | return 0; | |||
1787 | } | |||
1788 | ||||
1789 | if (!PACKET_get_net_2(pkt, &group_id)) { | |||
1790 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1790, __func__), ossl_statem_fatal)((s), (50), (159), ((void *)0)); | |||
1791 | return 0; | |||
1792 | } | |||
1793 | ||||
1794 | if ((context & SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST0x0800) != 0) { | |||
1795 | const uint16_t *pgroups = NULL((void*)0); | |||
1796 | size_t i, num_groups; | |||
1797 | ||||
1798 | if (PACKET_remaining(pkt) != 0) { | |||
1799 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1799, __func__), ossl_statem_fatal)((s), (50), (159), ((void *)0)); | |||
1800 | return 0; | |||
1801 | } | |||
1802 | ||||
1803 | /* | |||
1804 | * It is an error if the HelloRetryRequest wants a key_share that we | |||
1805 | * already sent in the first ClientHello | |||
1806 | */ | |||
1807 | if (group_id == s->s3.group_id) { | |||
1808 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1808, __func__), ossl_statem_fatal)((s), (47), (108), ((void *)0)); | |||
1809 | return 0; | |||
1810 | } | |||
1811 | ||||
1812 | /* Validate the selected group is one we support */ | |||
1813 | tls1_get_supported_groups(s, &pgroups, &num_groups); | |||
1814 | for (i = 0; i < num_groups; i++) { | |||
1815 | if (group_id == pgroups[i]) | |||
1816 | break; | |||
1817 | } | |||
1818 | if (i >= num_groups | |||
1819 | || !tls_group_allowed(s, group_id, SSL_SECOP_CURVE_SUPPORTED(4 | (2 << 16)))) { | |||
1820 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1820, __func__), ossl_statem_fatal)((s), (47), (108), ((void *)0)); | |||
1821 | return 0; | |||
1822 | } | |||
1823 | ||||
1824 | s->s3.group_id = group_id; | |||
1825 | EVP_PKEY_free(s->s3.tmp.pkey); | |||
1826 | s->s3.tmp.pkey = NULL((void*)0); | |||
1827 | return 1; | |||
1828 | } | |||
1829 | ||||
1830 | if (group_id != s->s3.group_id) { | |||
1831 | /* | |||
1832 | * This isn't for the group that we sent in the original | |||
1833 | * key_share! | |||
1834 | */ | |||
1835 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1835, __func__), ossl_statem_fatal)((s), (47), (108), ((void *)0)); | |||
1836 | return 0; | |||
1837 | } | |||
1838 | /* Retain this group in the SSL_SESSION */ | |||
1839 | if (!s->hit) { | |||
1840 | s->session->kex_group = group_id; | |||
1841 | } else if (group_id != s->session->kex_group) { | |||
1842 | /* | |||
1843 | * If this is a resumption but changed what group was used, we need | |||
1844 | * to record the new group in the session, but the session is not | |||
1845 | * a new session and could be in use by other threads. So, make | |||
1846 | * a copy of the session to record the new information so that it's | |||
1847 | * useful for any sessions resumed from tickets issued on this | |||
1848 | * connection. | |||
1849 | */ | |||
1850 | SSL_SESSION *new_sess; | |||
1851 | ||||
1852 | if ((new_sess = ssl_session_dup(s->session, 0)) == NULL((void*)0)) { | |||
1853 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1853, __func__), ossl_statem_fatal)((s), (80), ((256|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
1854 | return 0; | |||
1855 | } | |||
1856 | SSL_SESSION_free(s->session); | |||
1857 | s->session = new_sess; | |||
1858 | s->session->kex_group = group_id; | |||
1859 | } | |||
1860 | ||||
1861 | if ((ginf = tls1_group_id_lookup(s->ctx, group_id)) == NULL((void*)0)) { | |||
1862 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1862, __func__), ossl_statem_fatal)((s), (47), (108), ((void *)0)); | |||
1863 | return 0; | |||
1864 | } | |||
1865 | ||||
1866 | if (!PACKET_as_length_prefixed_2(pkt, &encoded_pt) | |||
1867 | || PACKET_remaining(&encoded_pt) == 0) { | |||
1868 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1868, __func__), ossl_statem_fatal)((s), (50), (159), ((void *)0)); | |||
1869 | return 0; | |||
1870 | } | |||
1871 | ||||
1872 | if (!ginf->is_kem) { | |||
1873 | /* Regular KEX */ | |||
1874 | skey = EVP_PKEY_new(); | |||
1875 | if (skey == NULL((void*)0) || EVP_PKEY_copy_parameters(skey, ckey) <= 0) { | |||
1876 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_COPY_PARAMETERS_FAILED)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1876, __func__), ossl_statem_fatal)((s), (80), (296), ((void *)0)); | |||
1877 | EVP_PKEY_free(skey); | |||
1878 | return 0; | |||
1879 | } | |||
1880 | ||||
1881 | if (tls13_set_encoded_pub_key(skey, PACKET_data(&encoded_pt), | |||
1882 | PACKET_remaining(&encoded_pt)) <= 0) { | |||
1883 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_ECPOINT)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1883, __func__), ossl_statem_fatal)((s), (47), (306), ((void *)0)); | |||
1884 | EVP_PKEY_free(skey); | |||
1885 | return 0; | |||
1886 | } | |||
1887 | ||||
1888 | if (ssl_derive(s, ckey, skey, 1) == 0) { | |||
1889 | /* SSLfatal() already called */ | |||
1890 | EVP_PKEY_free(skey); | |||
1891 | return 0; | |||
1892 | } | |||
1893 | s->s3.peer_tmp = skey; | |||
1894 | } else { | |||
1895 | /* KEM Mode */ | |||
1896 | const unsigned char *ct = PACKET_data(&encoded_pt); | |||
1897 | size_t ctlen = PACKET_remaining(&encoded_pt); | |||
1898 | ||||
1899 | if (ssl_decapsulate(s, ckey, ct, ctlen, 1) == 0) { | |||
1900 | /* SSLfatal() already called */ | |||
1901 | return 0; | |||
1902 | } | |||
1903 | } | |||
1904 | s->s3.did_kex = 1; | |||
1905 | #endif | |||
1906 | ||||
1907 | return 1; | |||
1908 | } | |||
1909 | ||||
1910 | int tls_parse_stoc_cookie(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1911 | size_t chainidx) | |||
1912 | { | |||
1913 | PACKET cookie; | |||
1914 | ||||
1915 | if (!PACKET_as_length_prefixed_2(pkt, &cookie) | |||
1916 | || !PACKET_memdup(&cookie, &s->ext.tls13_cookie, | |||
1917 | &s->ext.tls13_cookie_len)) { | |||
1918 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1918, __func__), ossl_statem_fatal)((s), (50), (159), ((void *)0)); | |||
1919 | return 0; | |||
1920 | } | |||
1921 | ||||
1922 | return 1; | |||
1923 | } | |||
1924 | ||||
1925 | int tls_parse_stoc_early_data(SSL *s, PACKET *pkt, unsigned int context, | |||
1926 | X509 *x, size_t chainidx) | |||
1927 | { | |||
1928 | if (context == SSL_EXT_TLS1_3_NEW_SESSION_TICKET0x2000) { | |||
1929 | unsigned long max_early_data; | |||
1930 | ||||
1931 | if (!PACKET_get_net_4(pkt, &max_early_data) | |||
1932 | || PACKET_remaining(pkt) != 0) { | |||
1933 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_INVALID_MAX_EARLY_DATA)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1933, __func__), ossl_statem_fatal)((s), (50), (174), ((void *)0)); | |||
1934 | return 0; | |||
1935 | } | |||
1936 | ||||
1937 | #ifndef OPENSSL_NO_QUIC | |||
1938 | /* | |||
1939 | * QUIC server must send 0xFFFFFFFF or it's a PROTOCOL_VIOLATION | |||
1940 | * per RFC9001 S4.6.1 | |||
1941 | */ | |||
1942 | if (SSL_IS_QUIC(s)(s->quic_method != ((void*)0)) && max_early_data != 0xFFFFFFFF) { | |||
1943 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_INVALID_MAX_EARLY_DATA)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1943, __func__), ossl_statem_fatal)((s), (47), (174), ((void *)0)); | |||
1944 | return 0; | |||
1945 | } | |||
1946 | #endif | |||
1947 | ||||
1948 | s->session->ext.max_early_data = max_early_data; | |||
1949 | ||||
1950 | return 1; | |||
1951 | } | |||
1952 | ||||
1953 | if (PACKET_remaining(pkt) != 0) { | |||
1954 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1954, __func__), ossl_statem_fatal)((s), (50), (110), ((void *)0)); | |||
1955 | return 0; | |||
1956 | } | |||
1957 | ||||
1958 | if (!s->ext.early_data_ok | |||
1959 | || !s->hit) { | |||
1960 | /* | |||
1961 | * If we get here then we didn't send early data, or we didn't resume | |||
1962 | * using the first identity, or the SNI/ALPN is not consistent so the | |||
1963 | * server should not be accepting it. | |||
1964 | */ | |||
1965 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_EXTENSION)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1965, __func__), ossl_statem_fatal)((s), (47), (110), ((void *)0)); | |||
1966 | return 0; | |||
1967 | } | |||
1968 | ||||
1969 | s->ext.early_data = SSL_EARLY_DATA_ACCEPTED2; | |||
1970 | ||||
1971 | return 1; | |||
1972 | } | |||
1973 | ||||
1974 | int tls_parse_stoc_psk(SSL *s, PACKET *pkt, unsigned int context, X509 *x, | |||
1975 | size_t chainidx) | |||
1976 | { | |||
1977 | #ifndef OPENSSL_NO_TLS1_3 | |||
1978 | unsigned int identity; | |||
1979 | ||||
1980 | if (!PACKET_get_net_2(pkt, &identity) || PACKET_remaining(pkt) != 0) { | |||
1981 | SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1981, __func__), ossl_statem_fatal)((s), (50), (159), ((void *)0)); | |||
1982 | return 0; | |||
1983 | } | |||
1984 | ||||
1985 | if (identity >= (unsigned int)s->ext.tick_identity) { | |||
1986 | SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_PSK_IDENTITY)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 1986, __func__), ossl_statem_fatal)((s), (47), (114), ((void *)0)); | |||
1987 | return 0; | |||
1988 | } | |||
1989 | ||||
1990 | /* | |||
1991 | * Session resumption tickets are always sent before PSK tickets. If the | |||
1992 | * ticket index is 0 then it must be for a session resumption ticket if we | |||
1993 | * sent two tickets, or if we didn't send a PSK ticket. | |||
1994 | */ | |||
1995 | if (identity == 0 && (s->psksession == NULL((void*)0) || s->ext.tick_identity == 2)) { | |||
1996 | s->hit = 1; | |||
1997 | SSL_SESSION_free(s->psksession); | |||
1998 | s->psksession = NULL((void*)0); | |||
1999 | return 1; | |||
2000 | } | |||
2001 | ||||
2002 | if (s->psksession == NULL((void*)0)) { | |||
2003 | /* Should never happen */ | |||
2004 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 2004, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
2005 | return 0; | |||
2006 | } | |||
2007 | ||||
2008 | /* | |||
2009 | * If we used the external PSK for sending early_data then s->early_secret | |||
2010 | * is already set up, so don't overwrite it. Otherwise we copy the | |||
2011 | * early_secret across that we generated earlier. | |||
2012 | */ | |||
2013 | if ((s->early_data_state != SSL_EARLY_DATA_WRITE_RETRY | |||
2014 | && s->early_data_state != SSL_EARLY_DATA_FINISHED_WRITING) | |||
2015 | || s->session->ext.max_early_data > 0 | |||
2016 | || s->psksession->ext.max_early_data == 0) | |||
2017 | memcpy(s->early_secret, s->psksession->early_secret, EVP_MAX_MD_SIZE64); | |||
2018 | ||||
2019 | SSL_SESSION_free(s->session); | |||
2020 | s->session = s->psksession; | |||
2021 | s->psksession = NULL((void*)0); | |||
2022 | s->hit = 1; | |||
2023 | /* Early data is only allowed if we used the first ticket */ | |||
2024 | if (identity != 0) | |||
2025 | s->ext.early_data_ok = 0; | |||
2026 | #endif | |||
2027 | ||||
2028 | return 1; | |||
2029 | } | |||
2030 | #ifndef OPENSSL_NO_QUIC | |||
2031 | int tls_parse_stoc_quic_transport_params_draft(SSL *s, PACKET *pkt, | |||
2032 | unsigned int context, X509 *x, | |||
2033 | size_t chainidx) | |||
2034 | { | |||
2035 | OPENSSL_free(s->ext.peer_quic_transport_params_draft)CRYPTO_free(s->ext.peer_quic_transport_params_draft, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 2035); | |||
2036 | s->ext.peer_quic_transport_params_draft = NULL((void*)0); | |||
2037 | s->ext.peer_quic_transport_params_draft_len = 0; | |||
2038 | ||||
2039 | if (!PACKET_memdup(pkt, | |||
2040 | &s->ext.peer_quic_transport_params_draft, | |||
2041 | &s->ext.peer_quic_transport_params_draft_len)) { | |||
2042 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 2042, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
2043 | return 0; | |||
2044 | } | |||
2045 | return 1; | |||
2046 | } | |||
2047 | ||||
2048 | int tls_parse_stoc_quic_transport_params(SSL *s, PACKET *pkt, unsigned int context, | |||
2049 | X509 *x, size_t chainidx) | |||
2050 | { | |||
2051 | OPENSSL_free(s->ext.peer_quic_transport_params)CRYPTO_free(s->ext.peer_quic_transport_params, "../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 2051); | |||
2052 | s->ext.peer_quic_transport_params = NULL((void*)0); | |||
2053 | s->ext.peer_quic_transport_params_len = 0; | |||
2054 | ||||
2055 | if (!PACKET_memdup(pkt, | |||
2056 | &s->ext.peer_quic_transport_params, | |||
2057 | &s->ext.peer_quic_transport_params_len)) { | |||
2058 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/ssl/statem/extensions_clnt.c" , 2058, __func__), ossl_statem_fatal)((s), (80), ((259|((0x1 << 18L)|(0x2 << 18L)))), ((void*)0)); | |||
2059 | return 0; | |||
2060 | } | |||
2061 | return 1; | |||
2062 | } | |||
2063 | #endif |