blob: 6de51e5b02709f5e6d24a5635b6764c81dc6f250 [file] [log] [blame]
David Benjaminc895d6b2016-08-11 13:26:41 -04001/* Copyright (c) 2016, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#include <openssl/ssl.h>
16
17#include <assert.h>
Robert Sloan4d1ac502017-02-06 08:36:14 -080018#include <limits.h>
David Benjaminc895d6b2016-08-11 13:26:41 -040019#include <string.h>
20
21#include <openssl/bytestring.h>
22#include <openssl/digest.h>
23#include <openssl/err.h>
24#include <openssl/mem.h>
25#include <openssl/stack.h>
David Benjaminc895d6b2016-08-11 13:26:41 -040026
Steven Valdez909b19f2016-11-21 15:35:44 -050027#include "../crypto/internal.h"
David Benjaminc895d6b2016-08-11 13:26:41 -040028#include "internal.h"
29
30
31enum client_hs_state_t {
32 state_process_hello_retry_request = 0,
33 state_send_second_client_hello,
David Benjaminc895d6b2016-08-11 13:26:41 -040034 state_process_server_hello,
35 state_process_encrypted_extensions,
36 state_process_certificate_request,
37 state_process_server_certificate,
38 state_process_server_certificate_verify,
39 state_process_server_finished,
Robert Sloan6d0d00e2017-03-27 07:13:07 -070040 state_send_end_of_early_data,
David Benjaminc895d6b2016-08-11 13:26:41 -040041 state_send_client_certificate,
42 state_send_client_certificate_verify,
43 state_complete_client_certificate_verify,
Robert Sloan4d1ac502017-02-06 08:36:14 -080044 state_complete_second_flight,
David Benjaminc895d6b2016-08-11 13:26:41 -040045 state_done,
46};
47
David Benjamin1b249672016-12-06 18:25:50 -050048static const uint8_t kZeroes[EVP_MAX_MD_SIZE] = {0};
49
50static enum ssl_hs_wait_t do_process_hello_retry_request(SSL_HANDSHAKE *hs) {
51 SSL *const ssl = hs->ssl;
David Benjaminc895d6b2016-08-11 13:26:41 -040052 if (ssl->s3->tmp.message_type != SSL3_MT_HELLO_RETRY_REQUEST) {
Steven Valdeze7531f02016-12-14 13:29:57 -050053 hs->tls13_state = state_process_server_hello;
David Benjaminc895d6b2016-08-11 13:26:41 -040054 return ssl_hs_ok;
55 }
56
57 CBS cbs, extensions;
David Benjamin95add822016-10-19 01:09:12 -040058 uint16_t server_wire_version;
David Benjaminc895d6b2016-08-11 13:26:41 -040059 CBS_init(&cbs, ssl->init_msg, ssl->init_num);
60 if (!CBS_get_u16(&cbs, &server_wire_version) ||
David Benjaminc895d6b2016-08-11 13:26:41 -040061 !CBS_get_u16_length_prefixed(&cbs, &extensions) ||
David Benjamin95add822016-10-19 01:09:12 -040062 /* HelloRetryRequest may not be empty. */
63 CBS_len(&extensions) == 0 ||
David Benjaminc895d6b2016-08-11 13:26:41 -040064 CBS_len(&cbs) != 0) {
David Benjamin95add822016-10-19 01:09:12 -040065 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
David Benjaminc895d6b2016-08-11 13:26:41 -040066 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
67 return ssl_hs_error;
68 }
69
Steven Valdez909b19f2016-11-21 15:35:44 -050070 int have_cookie, have_key_share;
71 CBS cookie, key_share;
72 const SSL_EXTENSION_TYPE ext_types[] = {
73 {TLSEXT_TYPE_key_share, &have_key_share, &key_share},
74 {TLSEXT_TYPE_cookie, &have_cookie, &cookie},
75 };
76
Robert Sloan5d625782017-02-13 09:55:39 -080077 uint8_t alert = SSL_AD_DECODE_ERROR;
Steven Valdez909b19f2016-11-21 15:35:44 -050078 if (!ssl_parse_extensions(&extensions, &alert, ext_types,
Robert Sloan69939df2017-01-09 10:53:07 -080079 OPENSSL_ARRAY_SIZE(ext_types),
80 0 /* reject unknown */)) {
Steven Valdez909b19f2016-11-21 15:35:44 -050081 ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
82 return ssl_hs_error;
83 }
84
85 if (have_cookie) {
86 CBS cookie_value;
87 if (!CBS_get_u16_length_prefixed(&cookie, &cookie_value) ||
88 CBS_len(&cookie_value) == 0 ||
89 CBS_len(&cookie) != 0) {
David Benjamin95add822016-10-19 01:09:12 -040090 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
91 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
92 return ssl_hs_error;
93 }
David Benjaminc895d6b2016-08-11 13:26:41 -040094
Steven Valdez909b19f2016-11-21 15:35:44 -050095 if (!CBS_stow(&cookie_value, &hs->cookie, &hs->cookie_len)) {
96 return ssl_hs_error;
David Benjaminc895d6b2016-08-11 13:26:41 -040097 }
98 }
99
Steven Valdez909b19f2016-11-21 15:35:44 -0500100 if (have_key_share) {
101 uint16_t group_id;
102 if (!CBS_get_u16(&key_share, &group_id) || CBS_len(&key_share) != 0) {
103 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
104 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
105 return ssl_hs_error;
106 }
107
108 /* The group must be supported. */
109 const uint16_t *groups;
110 size_t groups_len;
111 tls1_get_grouplist(ssl, &groups, &groups_len);
112 int found = 0;
113 for (size_t i = 0; i < groups_len; i++) {
114 if (groups[i] == group_id) {
115 found = 1;
116 break;
117 }
118 }
119
120 if (!found) {
121 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
122 OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
123 return ssl_hs_error;
124 }
125
126 /* Check that the HelloRetryRequest does not request the key share that
127 * was provided in the initial ClientHello. */
128 if (SSL_ECDH_CTX_get_id(&hs->ecdh_ctx) == group_id) {
129 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
130 OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
131 return ssl_hs_error;
132 }
133
134 SSL_ECDH_CTX_cleanup(&hs->ecdh_ctx);
135 hs->retry_group = group_id;
136 }
137
Robert Sloan5d625782017-02-13 09:55:39 -0800138 if (!ssl_hash_current_message(hs)) {
Robert Sloan4d1ac502017-02-06 08:36:14 -0800139 return ssl_hs_error;
140 }
141
David Benjamin95add822016-10-19 01:09:12 -0400142 hs->received_hello_retry_request = 1;
Steven Valdeze7531f02016-12-14 13:29:57 -0500143 hs->tls13_state = state_send_second_client_hello;
David Benjaminc895d6b2016-08-11 13:26:41 -0400144 return ssl_hs_ok;
145}
146
David Benjamin1b249672016-12-06 18:25:50 -0500147static enum ssl_hs_wait_t do_send_second_client_hello(SSL_HANDSHAKE *hs) {
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700148 SSL *const ssl = hs->ssl;
149 /* TODO(svaldez): Ensure that we set can_early_write to false since 0-RTT is
150 * rejected if we receive a HelloRetryRequest. */
151 if (!ssl->method->set_write_state(ssl, NULL) ||
152 !ssl_write_client_hello(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400153 return ssl_hs_error;
154 }
155
Steven Valdeze7531f02016-12-14 13:29:57 -0500156 hs->tls13_state = state_process_server_hello;
David Benjaminc895d6b2016-08-11 13:26:41 -0400157 return ssl_hs_flush_and_read_message;
158}
159
David Benjamin1b249672016-12-06 18:25:50 -0500160static enum ssl_hs_wait_t do_process_server_hello(SSL_HANDSHAKE *hs) {
161 SSL *const ssl = hs->ssl;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800162 if (!ssl_check_message_type(ssl, SSL3_MT_SERVER_HELLO)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400163 return ssl_hs_error;
164 }
165
166 CBS cbs, server_random, extensions;
167 uint16_t server_wire_version;
168 uint16_t cipher_suite;
169 CBS_init(&cbs, ssl->init_msg, ssl->init_num);
170 if (!CBS_get_u16(&cbs, &server_wire_version) ||
171 !CBS_get_bytes(&cbs, &server_random, SSL3_RANDOM_SIZE) ||
172 !CBS_get_u16(&cbs, &cipher_suite) ||
173 !CBS_get_u16_length_prefixed(&cbs, &extensions) ||
174 CBS_len(&cbs) != 0) {
175 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
176 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
177 return ssl_hs_error;
178 }
179
180 if (server_wire_version != ssl->version) {
181 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
182 OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_VERSION_NUMBER);
183 return ssl_hs_error;
184 }
185
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400186 assert(ssl->s3->have_version);
Robert Sloan69939df2017-01-09 10:53:07 -0800187 OPENSSL_memcpy(ssl->s3->server_random, CBS_data(&server_random),
188 SSL3_RANDOM_SIZE);
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400189
190 const SSL_CIPHER *cipher = SSL_get_cipher_by_value(cipher_suite);
191 if (cipher == NULL) {
192 OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CIPHER_RETURNED);
193 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
194 return ssl_hs_error;
195 }
196
Steven Valdez909b19f2016-11-21 15:35:44 -0500197 /* Check if the cipher is a TLS 1.3 cipher. */
198 if (SSL_CIPHER_get_min_version(cipher) > ssl3_protocol_version(ssl) ||
199 SSL_CIPHER_get_max_version(cipher) < ssl3_protocol_version(ssl)) {
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400200 OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
201 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
202 return ssl_hs_error;
203 }
204
David Benjaminc895d6b2016-08-11 13:26:41 -0400205 /* Parse out the extensions. */
Robert Sloan7d422bc2017-03-06 10:04:29 -0800206 int have_key_share = 0, have_pre_shared_key = 0;
207 CBS key_share, pre_shared_key;
Steven Valdez909b19f2016-11-21 15:35:44 -0500208 const SSL_EXTENSION_TYPE ext_types[] = {
209 {TLSEXT_TYPE_key_share, &have_key_share, &key_share},
210 {TLSEXT_TYPE_pre_shared_key, &have_pre_shared_key, &pre_shared_key},
211 };
David Benjaminc895d6b2016-08-11 13:26:41 -0400212
Robert Sloan5d625782017-02-13 09:55:39 -0800213 uint8_t alert = SSL_AD_DECODE_ERROR;
Steven Valdez909b19f2016-11-21 15:35:44 -0500214 if (!ssl_parse_extensions(&extensions, &alert, ext_types,
Robert Sloan69939df2017-01-09 10:53:07 -0800215 OPENSSL_ARRAY_SIZE(ext_types),
216 0 /* reject unknown */)) {
Steven Valdez909b19f2016-11-21 15:35:44 -0500217 ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
218 return ssl_hs_error;
David Benjaminc895d6b2016-08-11 13:26:41 -0400219 }
220
Steven Valdez909b19f2016-11-21 15:35:44 -0500221 alert = SSL_AD_DECODE_ERROR;
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400222 if (have_pre_shared_key) {
223 if (ssl->session == NULL) {
224 OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION);
225 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNSUPPORTED_EXTENSION);
226 return ssl_hs_error;
227 }
228
David Benjamin1b249672016-12-06 18:25:50 -0500229 if (!ssl_ext_pre_shared_key_parse_serverhello(hs, &alert,
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400230 &pre_shared_key)) {
231 ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
232 return ssl_hs_error;
233 }
234
235 if (ssl->session->ssl_version != ssl->version) {
236 OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
237 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
238 return ssl_hs_error;
239 }
240
Steven Valdez909b19f2016-11-21 15:35:44 -0500241 if (ssl->session->cipher->algorithm_prf != cipher->algorithm_prf) {
242 OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_PRF_HASH_MISMATCH);
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400243 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
244 return ssl_hs_error;
245 }
246
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400247 if (!ssl_session_is_context_valid(ssl, ssl->session)) {
248 /* This is actually a client application bug. */
249 OPENSSL_PUT_ERROR(SSL,
250 SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
251 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
252 return ssl_hs_error;
253 }
254
255 ssl->s3->session_reused = 1;
256 /* Only authentication information carries over in TLS 1.3. */
Robert Sloana94fe052017-02-21 08:49:28 -0800257 hs->new_session = SSL_SESSION_dup(ssl->session, SSL_SESSION_DUP_AUTH_ONLY);
258 if (hs->new_session == NULL) {
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400259 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
260 return ssl_hs_error;
261 }
Robert Sloan4d1ac502017-02-06 08:36:14 -0800262
263 /* Resumption incorporates fresh key material, so refresh the timeout. */
Robert Sloana94fe052017-02-21 08:49:28 -0800264 ssl_session_renew_timeout(ssl, hs->new_session,
Robert Sloan1c9db532017-03-13 08:03:59 -0700265 ssl->session_ctx->session_psk_dhe_timeout);
David Benjamin1b249672016-12-06 18:25:50 -0500266 } else if (!ssl_get_new_session(hs, 0)) {
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400267 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjaminc895d6b2016-08-11 13:26:41 -0400268 return ssl_hs_error;
269 }
270
Robert Sloana94fe052017-02-21 08:49:28 -0800271 hs->new_session->cipher = cipher;
272 hs->new_cipher = cipher;
273
David Benjaminc895d6b2016-08-11 13:26:41 -0400274 /* The PRF hash is now known. Set up the key schedule. */
David Benjamin1b249672016-12-06 18:25:50 -0500275 if (!tls13_init_key_schedule(hs)) {
276 return ssl_hs_error;
David Benjaminc895d6b2016-08-11 13:26:41 -0400277 }
278
David Benjamin1b249672016-12-06 18:25:50 -0500279 /* Incorporate the PSK into the running secret. */
280 if (ssl->s3->session_reused) {
Robert Sloana94fe052017-02-21 08:49:28 -0800281 if (!tls13_advance_key_schedule(hs, hs->new_session->master_key,
282 hs->new_session->master_key_length)) {
David Benjamin1b249672016-12-06 18:25:50 -0500283 return ssl_hs_error;
284 }
Robert Sloan5d625782017-02-13 09:55:39 -0800285 } else if (!tls13_advance_key_schedule(hs, kZeroes, hs->hash_len)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400286 return ssl_hs_error;
287 }
288
Steven Valdeze7531f02016-12-14 13:29:57 -0500289 if (!have_key_share) {
290 /* We do not support psk_ke and thus always require a key share. */
291 OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_KEY_SHARE);
292 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION);
293 return ssl_hs_error;
294 }
295
David Benjaminc895d6b2016-08-11 13:26:41 -0400296 /* Resolve ECDHE and incorporate it into the secret. */
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400297 uint8_t *dhe_secret;
298 size_t dhe_secret_len;
Robert Sloan5d625782017-02-13 09:55:39 -0800299 alert = SSL_AD_DECODE_ERROR;
David Benjamin1b249672016-12-06 18:25:50 -0500300 if (!ssl_ext_key_share_parse_serverhello(hs, &dhe_secret, &dhe_secret_len,
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400301 &alert, &key_share)) {
302 ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
303 return ssl_hs_error;
304 }
David Benjaminc895d6b2016-08-11 13:26:41 -0400305
David Benjamin1b249672016-12-06 18:25:50 -0500306 if (!tls13_advance_key_schedule(hs, dhe_secret, dhe_secret_len)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400307 OPENSSL_free(dhe_secret);
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400308 return ssl_hs_error;
309 }
310 OPENSSL_free(dhe_secret);
311
Robert Sloan5d625782017-02-13 09:55:39 -0800312 if (!ssl_hash_current_message(hs) ||
Robert Sloan4d1ac502017-02-06 08:36:14 -0800313 !tls13_derive_handshake_secrets(hs) ||
Robert Sloan69939df2017-01-09 10:53:07 -0800314 !tls13_set_traffic_key(ssl, evp_aead_open, hs->server_handshake_secret,
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700315 hs->hash_len)) {
316 return ssl_hs_error;
317 }
318
319 /* If not sending early data, set client traffic keys now so that alerts are
320 * encrypted. */
321 if (!hs->early_data_offered &&
Robert Sloan69939df2017-01-09 10:53:07 -0800322 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->client_handshake_secret,
323 hs->hash_len)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400324 return ssl_hs_error;
325 }
326
Steven Valdeze7531f02016-12-14 13:29:57 -0500327 hs->tls13_state = state_process_encrypted_extensions;
David Benjaminc895d6b2016-08-11 13:26:41 -0400328 return ssl_hs_read_message;
329}
330
David Benjamin1b249672016-12-06 18:25:50 -0500331static enum ssl_hs_wait_t do_process_encrypted_extensions(SSL_HANDSHAKE *hs) {
332 SSL *const ssl = hs->ssl;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800333 if (!ssl_check_message_type(ssl, SSL3_MT_ENCRYPTED_EXTENSIONS)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400334 return ssl_hs_error;
335 }
336
337 CBS cbs;
338 CBS_init(&cbs, ssl->init_msg, ssl->init_num);
David Benjamin1b249672016-12-06 18:25:50 -0500339 if (!ssl_parse_serverhello_tlsext(hs, &cbs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400340 OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
341 return ssl_hs_error;
342 }
343 if (CBS_len(&cbs) != 0) {
344 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
345 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
346 return ssl_hs_error;
347 }
348
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700349 /* Store the negotiated ALPN in the session. */
350 if (ssl->s3->alpn_selected != NULL) {
351 hs->new_session->early_alpn =
352 BUF_memdup(ssl->s3->alpn_selected, ssl->s3->alpn_selected_len);
353 if (hs->new_session->early_alpn == NULL) {
354 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
355 return ssl_hs_error;
356 }
357 hs->new_session->early_alpn_len = ssl->s3->alpn_selected_len;
358 }
359
360 if (ssl->early_data_accepted) {
361 if (ssl->session->cipher != hs->new_session->cipher ||
362 ssl->session->early_alpn_len != ssl->s3->alpn_selected_len ||
363 OPENSSL_memcmp(ssl->session->early_alpn, ssl->s3->alpn_selected,
364 ssl->s3->alpn_selected_len) != 0) {
365 OPENSSL_PUT_ERROR(SSL, SSL_R_ALPN_MISMATCH_ON_EARLY_DATA);
366 return ssl_hs_error;
367 }
368 if (ssl->s3->tlsext_channel_id_valid) {
369 OPENSSL_PUT_ERROR(SSL, SSL_R_CHANNEL_ID_ON_EARLY_DATA);
370 return ssl_hs_error;
371 }
372 }
373
374 /* Release offered session now that it is no longer needed. */
375 if (ssl->s3->session_reused) {
376 ssl_set_session(ssl, NULL);
377 }
378
Robert Sloan5d625782017-02-13 09:55:39 -0800379 if (!ssl_hash_current_message(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400380 return ssl_hs_error;
381 }
382
Steven Valdeze7531f02016-12-14 13:29:57 -0500383 hs->tls13_state = state_process_certificate_request;
David Benjaminc895d6b2016-08-11 13:26:41 -0400384 return ssl_hs_read_message;
385}
386
David Benjamin1b249672016-12-06 18:25:50 -0500387static enum ssl_hs_wait_t do_process_certificate_request(SSL_HANDSHAKE *hs) {
388 SSL *const ssl = hs->ssl;
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400389 /* CertificateRequest may only be sent in non-resumption handshakes. */
390 if (ssl->s3->session_reused) {
Steven Valdeze7531f02016-12-14 13:29:57 -0500391 hs->tls13_state = state_process_server_finished;
David Benjaminc895d6b2016-08-11 13:26:41 -0400392 return ssl_hs_ok;
393 }
394
395 /* CertificateRequest is optional. */
396 if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
Steven Valdeze7531f02016-12-14 13:29:57 -0500397 hs->tls13_state = state_process_server_certificate;
David Benjaminc895d6b2016-08-11 13:26:41 -0400398 return ssl_hs_ok;
399 }
400
401 CBS cbs, context, supported_signature_algorithms;
402 CBS_init(&cbs, ssl->init_msg, ssl->init_num);
403 if (!CBS_get_u8_length_prefixed(&cbs, &context) ||
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400404 /* The request context is always empty during the handshake. */
405 CBS_len(&context) != 0 ||
David Benjaminc895d6b2016-08-11 13:26:41 -0400406 !CBS_get_u16_length_prefixed(&cbs, &supported_signature_algorithms) ||
407 CBS_len(&supported_signature_algorithms) == 0 ||
David Benjamin1b249672016-12-06 18:25:50 -0500408 !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400409 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
410 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
411 return ssl_hs_error;
412 }
413
Robert Sloan5d625782017-02-13 09:55:39 -0800414 uint8_t alert = SSL_AD_DECODE_ERROR;
Robert Sloan7d422bc2017-03-06 10:04:29 -0800415 STACK_OF(CRYPTO_BUFFER) *ca_names =
416 ssl_parse_client_CA_list(ssl, &alert, &cbs);
417 if (ca_names == NULL) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400418 ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
419 return ssl_hs_error;
420 }
421
422 /* Ignore extensions. */
423 CBS extensions;
424 if (!CBS_get_u16_length_prefixed(&cbs, &extensions) ||
425 CBS_len(&cbs) != 0) {
426 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
Robert Sloan7d422bc2017-03-06 10:04:29 -0800427 sk_CRYPTO_BUFFER_pop_free(ca_names, CRYPTO_BUFFER_free);
David Benjaminc895d6b2016-08-11 13:26:41 -0400428 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
429 return ssl_hs_error;
430 }
431
David Benjamin1b249672016-12-06 18:25:50 -0500432 hs->cert_request = 1;
Robert Sloan7d422bc2017-03-06 10:04:29 -0800433 sk_CRYPTO_BUFFER_pop_free(hs->ca_names, CRYPTO_BUFFER_free);
434 hs->ca_names = ca_names;
435 ssl->ctx->x509_method->hs_flush_cached_ca_names(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400436
Robert Sloan5d625782017-02-13 09:55:39 -0800437 if (!ssl_hash_current_message(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400438 return ssl_hs_error;
439 }
440
Steven Valdeze7531f02016-12-14 13:29:57 -0500441 hs->tls13_state = state_process_server_certificate;
David Benjaminc895d6b2016-08-11 13:26:41 -0400442 return ssl_hs_read_message;
443}
444
David Benjamin1b249672016-12-06 18:25:50 -0500445static enum ssl_hs_wait_t do_process_server_certificate(SSL_HANDSHAKE *hs) {
446 SSL *const ssl = hs->ssl;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800447 if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE) ||
Steven Valdeze7531f02016-12-14 13:29:57 -0500448 !tls13_process_certificate(hs, 0 /* certificate required */) ||
Robert Sloan5d625782017-02-13 09:55:39 -0800449 !ssl_hash_current_message(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400450 return ssl_hs_error;
451 }
452
Steven Valdeze7531f02016-12-14 13:29:57 -0500453 hs->tls13_state = state_process_server_certificate_verify;
David Benjaminc895d6b2016-08-11 13:26:41 -0400454 return ssl_hs_read_message;
455}
456
457static enum ssl_hs_wait_t do_process_server_certificate_verify(
David Benjamin1b249672016-12-06 18:25:50 -0500458 SSL_HANDSHAKE *hs) {
459 SSL *const ssl = hs->ssl;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800460 if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE_VERIFY) ||
Steven Valdeze7531f02016-12-14 13:29:57 -0500461 !tls13_process_certificate_verify(hs) ||
Robert Sloan5d625782017-02-13 09:55:39 -0800462 !ssl_hash_current_message(hs)) {
Steven Valdez909b19f2016-11-21 15:35:44 -0500463 return ssl_hs_error;
David Benjaminc895d6b2016-08-11 13:26:41 -0400464 }
465
Steven Valdeze7531f02016-12-14 13:29:57 -0500466 hs->tls13_state = state_process_server_finished;
David Benjaminc895d6b2016-08-11 13:26:41 -0400467 return ssl_hs_read_message;
468}
469
David Benjamin1b249672016-12-06 18:25:50 -0500470static enum ssl_hs_wait_t do_process_server_finished(SSL_HANDSHAKE *hs) {
471 SSL *const ssl = hs->ssl;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800472 if (!ssl_check_message_type(ssl, SSL3_MT_FINISHED) ||
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700473 !tls13_process_finished(hs, 0 /* don't use saved value */) ||
Robert Sloan5d625782017-02-13 09:55:39 -0800474 !ssl_hash_current_message(hs) ||
David Benjaminc895d6b2016-08-11 13:26:41 -0400475 /* Update the secret to the master secret and derive traffic keys. */
David Benjamin1b249672016-12-06 18:25:50 -0500476 !tls13_advance_key_schedule(hs, kZeroes, hs->hash_len) ||
477 !tls13_derive_application_secrets(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400478 return ssl_hs_error;
479 }
480
481 ssl->method->received_flight(ssl);
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700482 hs->tls13_state = state_send_end_of_early_data;
483 return ssl_hs_ok;
484}
485
486static enum ssl_hs_wait_t do_send_end_of_early_data(SSL_HANDSHAKE *hs) {
487 SSL *const ssl = hs->ssl;
488 /* TODO(svaldez): Stop sending early data. */
489 if (ssl->early_data_accepted &&
490 !ssl->method->add_alert(ssl, SSL3_AL_WARNING,
491 TLS1_AD_END_OF_EARLY_DATA)) {
492 return ssl_hs_error;
493 }
494
495 if (hs->early_data_offered &&
496 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->client_handshake_secret,
497 hs->hash_len)) {
498 return ssl_hs_error;
499 }
500
Steven Valdeze7531f02016-12-14 13:29:57 -0500501 hs->tls13_state = state_send_client_certificate;
David Benjaminc895d6b2016-08-11 13:26:41 -0400502 return ssl_hs_ok;
503}
504
Steven Valdeze7531f02016-12-14 13:29:57 -0500505static enum ssl_hs_wait_t do_send_client_certificate(SSL_HANDSHAKE *hs) {
David Benjamin1b249672016-12-06 18:25:50 -0500506 SSL *const ssl = hs->ssl;
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700507
David Benjaminc895d6b2016-08-11 13:26:41 -0400508 /* The peer didn't request a certificate. */
David Benjamin1b249672016-12-06 18:25:50 -0500509 if (!hs->cert_request) {
Robert Sloan4d1ac502017-02-06 08:36:14 -0800510 hs->tls13_state = state_complete_second_flight;
David Benjaminc895d6b2016-08-11 13:26:41 -0400511 return ssl_hs_ok;
512 }
513
514 /* Call cert_cb to update the certificate. */
515 if (ssl->cert->cert_cb != NULL) {
516 int rv = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
517 if (rv == 0) {
518 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
519 OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
520 return ssl_hs_error;
521 }
522 if (rv < 0) {
Steven Valdeze7531f02016-12-14 13:29:57 -0500523 hs->tls13_state = state_send_client_certificate;
David Benjaminc895d6b2016-08-11 13:26:41 -0400524 return ssl_hs_x509_lookup;
525 }
526 }
527
Robert Sloan572a4e22017-04-17 10:52:19 -0700528 if (!ssl_on_certificate_selected(hs) ||
Robert Sloan4d1ac502017-02-06 08:36:14 -0800529 !tls13_add_certificate(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400530 return ssl_hs_error;
531 }
532
Steven Valdeze7531f02016-12-14 13:29:57 -0500533 hs->tls13_state = state_send_client_certificate_verify;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800534 return ssl_hs_ok;
David Benjaminc895d6b2016-08-11 13:26:41 -0400535}
536
David Benjamin1b249672016-12-06 18:25:50 -0500537static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs,
David Benjaminc895d6b2016-08-11 13:26:41 -0400538 int is_first_run) {
David Benjamin1b249672016-12-06 18:25:50 -0500539 SSL *const ssl = hs->ssl;
David Benjaminc895d6b2016-08-11 13:26:41 -0400540 /* Don't send CertificateVerify if there is no certificate. */
541 if (!ssl_has_certificate(ssl)) {
Robert Sloan4d1ac502017-02-06 08:36:14 -0800542 hs->tls13_state = state_complete_second_flight;
David Benjaminc895d6b2016-08-11 13:26:41 -0400543 return ssl_hs_ok;
544 }
545
Robert Sloan4d1ac502017-02-06 08:36:14 -0800546 switch (tls13_add_certificate_verify(hs, is_first_run)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400547 case ssl_private_key_success:
Robert Sloan4d1ac502017-02-06 08:36:14 -0800548 hs->tls13_state = state_complete_second_flight;
549 return ssl_hs_ok;
David Benjaminc895d6b2016-08-11 13:26:41 -0400550
551 case ssl_private_key_retry:
Steven Valdeze7531f02016-12-14 13:29:57 -0500552 hs->tls13_state = state_complete_client_certificate_verify;
David Benjaminc895d6b2016-08-11 13:26:41 -0400553 return ssl_hs_private_key_operation;
554
555 case ssl_private_key_failure:
556 return ssl_hs_error;
557 }
558
559 assert(0);
560 return ssl_hs_error;
561}
562
Robert Sloan4d1ac502017-02-06 08:36:14 -0800563static enum ssl_hs_wait_t do_complete_second_flight(SSL_HANDSHAKE *hs) {
David Benjamin1b249672016-12-06 18:25:50 -0500564 SSL *const ssl = hs->ssl;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800565
566 /* Send a Channel ID assertion if necessary. */
567 if (ssl->s3->tlsext_channel_id_valid) {
568 if (!ssl_do_channel_id_callback(ssl)) {
569 hs->tls13_state = state_complete_second_flight;
570 return ssl_hs_error;
571 }
572
573 if (ssl->tlsext_channel_id_private == NULL) {
574 return ssl_hs_channel_id_lookup;
575 }
576
577 CBB cbb, body;
578 if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CHANNEL_ID) ||
Robert Sloan5d625782017-02-13 09:55:39 -0800579 !tls1_write_channel_id(hs, &body) ||
Robert Sloan4d1ac502017-02-06 08:36:14 -0800580 !ssl_add_message_cbb(ssl, &cbb)) {
581 CBB_cleanup(&cbb);
582 return ssl_hs_error;
583 }
Steven Valdez909b19f2016-11-21 15:35:44 -0500584 }
585
Robert Sloan4d1ac502017-02-06 08:36:14 -0800586 /* Send a Finished message. */
587 if (!tls13_add_finished(hs)) {
Steven Valdez909b19f2016-11-21 15:35:44 -0500588 return ssl_hs_error;
589 }
590
Robert Sloan4d1ac502017-02-06 08:36:14 -0800591 /* Derive the final keys and enable them. */
Steven Valdez909b19f2016-11-21 15:35:44 -0500592 if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->server_traffic_secret_0,
593 hs->hash_len) ||
594 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->client_traffic_secret_0,
595 hs->hash_len) ||
David Benjamin1b249672016-12-06 18:25:50 -0500596 !tls13_derive_resumption_secret(hs)) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400597 return ssl_hs_error;
598 }
599
Steven Valdeze7531f02016-12-14 13:29:57 -0500600 hs->tls13_state = state_done;
David Benjaminc895d6b2016-08-11 13:26:41 -0400601 return ssl_hs_flush;
602}
603
David Benjamin1b249672016-12-06 18:25:50 -0500604enum ssl_hs_wait_t tls13_client_handshake(SSL_HANDSHAKE *hs) {
Steven Valdeze7531f02016-12-14 13:29:57 -0500605 while (hs->tls13_state != state_done) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400606 enum ssl_hs_wait_t ret = ssl_hs_error;
Steven Valdeze7531f02016-12-14 13:29:57 -0500607 enum client_hs_state_t state = hs->tls13_state;
David Benjaminc895d6b2016-08-11 13:26:41 -0400608 switch (state) {
609 case state_process_hello_retry_request:
David Benjamin1b249672016-12-06 18:25:50 -0500610 ret = do_process_hello_retry_request(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400611 break;
612 case state_send_second_client_hello:
David Benjamin1b249672016-12-06 18:25:50 -0500613 ret = do_send_second_client_hello(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400614 break;
David Benjaminc895d6b2016-08-11 13:26:41 -0400615 case state_process_server_hello:
David Benjamin1b249672016-12-06 18:25:50 -0500616 ret = do_process_server_hello(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400617 break;
618 case state_process_encrypted_extensions:
David Benjamin1b249672016-12-06 18:25:50 -0500619 ret = do_process_encrypted_extensions(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400620 break;
621 case state_process_certificate_request:
David Benjamin1b249672016-12-06 18:25:50 -0500622 ret = do_process_certificate_request(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400623 break;
624 case state_process_server_certificate:
David Benjamin1b249672016-12-06 18:25:50 -0500625 ret = do_process_server_certificate(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400626 break;
627 case state_process_server_certificate_verify:
David Benjamin1b249672016-12-06 18:25:50 -0500628 ret = do_process_server_certificate_verify(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400629 break;
630 case state_process_server_finished:
David Benjamin1b249672016-12-06 18:25:50 -0500631 ret = do_process_server_finished(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400632 break;
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700633 case state_send_end_of_early_data:
634 ret = do_send_end_of_early_data(hs);
635 break;
David Benjaminc895d6b2016-08-11 13:26:41 -0400636 case state_send_client_certificate:
David Benjamin1b249672016-12-06 18:25:50 -0500637 ret = do_send_client_certificate(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400638 break;
639 case state_send_client_certificate_verify:
David Benjamin1b249672016-12-06 18:25:50 -0500640 ret = do_send_client_certificate_verify(hs, 1 /* first run */);
Steven Valdez909b19f2016-11-21 15:35:44 -0500641 break;
David Benjaminc895d6b2016-08-11 13:26:41 -0400642 case state_complete_client_certificate_verify:
David Benjamin1b249672016-12-06 18:25:50 -0500643 ret = do_send_client_certificate_verify(hs, 0 /* complete */);
Steven Valdez909b19f2016-11-21 15:35:44 -0500644 break;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800645 case state_complete_second_flight:
646 ret = do_complete_second_flight(hs);
David Benjaminc895d6b2016-08-11 13:26:41 -0400647 break;
648 case state_done:
649 ret = ssl_hs_ok;
650 break;
651 }
652
653 if (ret != ssl_hs_ok) {
654 return ret;
655 }
656 }
657
658 return ssl_hs_ok;
659}
660
661int tls13_process_new_session_ticket(SSL *ssl) {
Robert Sloan69939df2017-01-09 10:53:07 -0800662 int ret = 0;
Robert Sloan5d625782017-02-13 09:55:39 -0800663 SSL_SESSION *session = SSL_SESSION_dup(ssl->s3->established_session,
664 SSL_SESSION_INCLUDE_NONAUTH);
David Benjaminc895d6b2016-08-11 13:26:41 -0400665 if (session == NULL) {
666 return 0;
667 }
668
Robert Sloan4d1ac502017-02-06 08:36:14 -0800669 ssl_session_rebase_time(ssl, session);
Steven Valdez909b19f2016-11-21 15:35:44 -0500670
Robert Sloan4d1ac502017-02-06 08:36:14 -0800671 uint32_t server_timeout;
Steven Valdez909b19f2016-11-21 15:35:44 -0500672 CBS cbs, ticket, extensions;
David Benjaminc895d6b2016-08-11 13:26:41 -0400673 CBS_init(&cbs, ssl->init_msg, ssl->init_num);
Robert Sloan4d1ac502017-02-06 08:36:14 -0800674 if (!CBS_get_u32(&cbs, &server_timeout) ||
Steven Valdez909b19f2016-11-21 15:35:44 -0500675 !CBS_get_u32(&cbs, &session->ticket_age_add) ||
David Benjaminc895d6b2016-08-11 13:26:41 -0400676 !CBS_get_u16_length_prefixed(&cbs, &ticket) ||
677 !CBS_stow(&ticket, &session->tlsext_tick, &session->tlsext_ticklen) ||
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400678 !CBS_get_u16_length_prefixed(&cbs, &extensions) ||
David Benjaminc895d6b2016-08-11 13:26:41 -0400679 CBS_len(&cbs) != 0) {
David Benjaminc895d6b2016-08-11 13:26:41 -0400680 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
681 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
Robert Sloan69939df2017-01-09 10:53:07 -0800682 goto err;
683 }
684
Robert Sloan4d1ac502017-02-06 08:36:14 -0800685 /* Cap the renewable lifetime by the server advertised value. This avoids
Robert Sloan7d422bc2017-03-06 10:04:29 -0800686 * wasting bandwidth on 0-RTT when we know the server will reject it. */
687 if (session->timeout > server_timeout) {
688 session->timeout = server_timeout;
Robert Sloan4d1ac502017-02-06 08:36:14 -0800689 }
690
Robert Sloan69939df2017-01-09 10:53:07 -0800691 /* Parse out the extensions. */
692 int have_early_data_info = 0;
693 CBS early_data_info;
694 const SSL_EXTENSION_TYPE ext_types[] = {
695 {TLSEXT_TYPE_ticket_early_data_info, &have_early_data_info,
696 &early_data_info},
697 };
698
Robert Sloan5d625782017-02-13 09:55:39 -0800699 uint8_t alert = SSL_AD_DECODE_ERROR;
Robert Sloan69939df2017-01-09 10:53:07 -0800700 if (!ssl_parse_extensions(&extensions, &alert, ext_types,
701 OPENSSL_ARRAY_SIZE(ext_types),
702 1 /* ignore unknown */)) {
703 ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
704 goto err;
705 }
706
Robert Sloan572a4e22017-04-17 10:52:19 -0700707 if (have_early_data_info && ssl->cert->enable_early_data) {
Robert Sloan69939df2017-01-09 10:53:07 -0800708 if (!CBS_get_u32(&early_data_info, &session->ticket_max_early_data) ||
709 CBS_len(&early_data_info) != 0) {
710 ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
711 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
712 goto err;
713 }
David Benjaminc895d6b2016-08-11 13:26:41 -0400714 }
715
Steven Valdez909b19f2016-11-21 15:35:44 -0500716 session->ticket_age_add_valid = 1;
David Benjaminc895d6b2016-08-11 13:26:41 -0400717 session->not_resumable = 0;
718
Steven Valdez909b19f2016-11-21 15:35:44 -0500719 if (ssl->ctx->new_session_cb != NULL &&
David Benjaminc895d6b2016-08-11 13:26:41 -0400720 ssl->ctx->new_session_cb(ssl, session)) {
721 /* |new_session_cb|'s return value signals that it took ownership. */
Robert Sloan69939df2017-01-09 10:53:07 -0800722 session = NULL;
David Benjaminc895d6b2016-08-11 13:26:41 -0400723 }
724
Robert Sloan69939df2017-01-09 10:53:07 -0800725 ret = 1;
726
727err:
David Benjaminc895d6b2016-08-11 13:26:41 -0400728 SSL_SESSION_free(session);
Robert Sloan69939df2017-01-09 10:53:07 -0800729 return ret;
David Benjaminc895d6b2016-08-11 13:26:41 -0400730}
David Benjamin7c0d06c2016-08-11 13:26:41 -0400731
David Benjamin1b249672016-12-06 18:25:50 -0500732void ssl_clear_tls13_state(SSL_HANDSHAKE *hs) {
733 SSL_ECDH_CTX_cleanup(&hs->ecdh_ctx);
David Benjamin7c0d06c2016-08-11 13:26:41 -0400734
David Benjamin1b249672016-12-06 18:25:50 -0500735 OPENSSL_free(hs->key_share_bytes);
736 hs->key_share_bytes = NULL;
737 hs->key_share_bytes_len = 0;
David Benjamin7c0d06c2016-08-11 13:26:41 -0400738}