blob: 67aa5d007821f51b75a0bbfa32de4b867a85e3c9 [file] [log] [blame]
Steven Valdez143e8b32016-07-11 13:19:03 -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
David Benjaminc11ea9422017-08-29 16:33:21 -040015// Per C99, various stdint.h macros are unavailable in C++ unless some macros
16// are defined. C++11 overruled this decision, but older Android NDKs still
17// require it.
David Benjamind304a2f2017-07-12 23:00:28 -040018#if !defined(__STDC_LIMIT_MACROS)
19#define __STDC_LIMIT_MACROS
20#endif
21
Steven Valdez143e8b32016-07-11 13:19:03 -040022#include <openssl/ssl.h>
23
24#include <assert.h>
25#include <string.h>
26
David Benjaminabbbee12016-10-31 19:20:42 -040027#include <openssl/aead.h>
Steven Valdez143e8b32016-07-11 13:19:03 -040028#include <openssl/bytestring.h>
29#include <openssl/digest.h>
30#include <openssl/err.h>
31#include <openssl/mem.h>
32#include <openssl/rand.h>
33#include <openssl/stack.h>
34
David Benjamin17cf2cb2016-12-13 01:07:13 -050035#include "../crypto/internal.h"
Steven Valdez143e8b32016-07-11 13:19:03 -040036#include "internal.h"
37
38
David Benjamin86e95b82017-07-18 16:34:25 -040039namespace bssl {
40
Steven Valdez143e8b32016-07-11 13:19:03 -040041enum server_hs_state_t {
David Benjamindaa05392017-02-02 23:33:21 -050042 state_select_parameters = 0,
David Benjamin707af292017-03-10 17:47:18 -050043 state_select_session,
Steven Valdez5440fe02016-07-18 12:40:30 -040044 state_send_hello_retry_request,
David Benjamin7934f082017-08-01 16:32:25 -040045 state_read_second_client_hello,
Steven Valdez143e8b32016-07-11 13:19:03 -040046 state_send_server_hello,
Steven Valdez143e8b32016-07-11 13:19:03 -040047 state_send_server_certificate_verify,
Steven Valdez143e8b32016-07-11 13:19:03 -040048 state_send_server_finished,
Steven Valdez2d850622017-01-11 11:34:52 -050049 state_read_second_client_flight,
50 state_process_end_of_early_data,
David Benjamin7934f082017-08-01 16:32:25 -040051 state_read_client_certificate,
52 state_read_client_certificate_verify,
53 state_read_channel_id,
54 state_read_client_finished,
Steven Valdez1e6f11a2016-07-27 11:10:52 -040055 state_send_new_session_ticket,
Steven Valdez143e8b32016-07-11 13:19:03 -040056 state_done,
57};
58
Steven Valdez5440fe02016-07-18 12:40:30 -040059static const uint8_t kZeroes[EVP_MAX_MD_SIZE] = {0};
60
David Benjamin046bc1f2017-08-31 15:06:42 -040061static int resolve_ecdhe_secret(SSL_HANDSHAKE *hs, bool *out_need_retry,
David Benjamin731058e2016-12-03 23:15:13 -050062 SSL_CLIENT_HELLO *client_hello) {
David Benjamin6e4fc332016-11-17 16:43:08 +090063 SSL *const ssl = hs->ssl;
David Benjamin046bc1f2017-08-31 15:06:42 -040064 *out_need_retry = false;
Steven Valdez5440fe02016-07-18 12:40:30 -040065
David Benjaminc11ea9422017-08-29 16:33:21 -040066 // We only support connections that include an ECDHE key exchange.
Steven Valdez5440fe02016-07-18 12:40:30 -040067 CBS key_share;
David Benjamin731058e2016-12-03 23:15:13 -050068 if (!ssl_client_hello_get_extension(client_hello, &key_share,
Steven Valdez7e5dd252018-01-22 15:20:31 -050069 TLSEXT_TYPE_key_share)) {
Steven Valdez5440fe02016-07-18 12:40:30 -040070 OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_KEY_SHARE);
David Benjamind1e3ce12017-10-06 18:31:15 -040071 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION);
David Benjamin6929f272016-11-16 19:10:08 +090072 return 0;
Steven Valdez5440fe02016-07-18 12:40:30 -040073 }
74
David Benjamin74795b32017-08-31 15:13:12 -040075 bool found_key_share;
David Benjamin499742c2017-07-22 12:45:38 -040076 Array<uint8_t> dhe_secret;
David Benjamin7e1f9842016-09-20 19:24:40 -040077 uint8_t alert = SSL_AD_DECODE_ERROR;
David Benjamin8baf9632016-11-17 17:11:16 +090078 if (!ssl_ext_key_share_parse_clienthello(hs, &found_key_share, &dhe_secret,
David Benjamin499742c2017-07-22 12:45:38 -040079 &alert, &key_share)) {
David Benjamind1e3ce12017-10-06 18:31:15 -040080 ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
Steven Valdez5440fe02016-07-18 12:40:30 -040081 return 0;
82 }
83
84 if (!found_key_share) {
David Benjamin046bc1f2017-08-31 15:06:42 -040085 *out_need_retry = true;
Steven Valdez5440fe02016-07-18 12:40:30 -040086 return 0;
87 }
88
David Benjamin499742c2017-07-22 12:45:38 -040089 return tls13_advance_key_schedule(hs, dhe_secret.data(), dhe_secret.size());
Steven Valdez5440fe02016-07-18 12:40:30 -040090}
91
Steven Valdez038da9b2017-07-10 12:57:25 -040092static int ssl_ext_supported_versions_add_serverhello(SSL_HANDSHAKE *hs,
93 CBB *out) {
94 CBB contents;
95 if (!CBB_add_u16(out, TLSEXT_TYPE_supported_versions) ||
96 !CBB_add_u16_length_prefixed(out, &contents) ||
97 !CBB_add_u16(&contents, hs->ssl->version) ||
98 !CBB_flush(out)) {
99 return 0;
100 }
101
102 return 1;
103}
104
David Benjamin34202b92016-11-16 19:07:53 +0900105static const SSL_CIPHER *choose_tls13_cipher(
David Benjamin731058e2016-12-03 23:15:13 -0500106 const SSL *ssl, const SSL_CLIENT_HELLO *client_hello) {
David Benjamin34202b92016-11-16 19:07:53 +0900107 if (client_hello->cipher_suites_len % 2 != 0) {
108 return NULL;
109 }
110
111 CBS cipher_suites;
112 CBS_init(&cipher_suites, client_hello->cipher_suites,
113 client_hello->cipher_suites_len);
114
115 const int aes_is_fine = EVP_has_aes_hardware();
David Benjamind1e3ce12017-10-06 18:31:15 -0400116 const uint16_t version = ssl_protocol_version(ssl);
David Benjamin34202b92016-11-16 19:07:53 +0900117
118 const SSL_CIPHER *best = NULL;
119 while (CBS_len(&cipher_suites) > 0) {
120 uint16_t cipher_suite;
121 if (!CBS_get_u16(&cipher_suites, &cipher_suite)) {
122 return NULL;
123 }
124
David Benjaminc11ea9422017-08-29 16:33:21 -0400125 // Limit to TLS 1.3 ciphers we know about.
David Benjamin34202b92016-11-16 19:07:53 +0900126 const SSL_CIPHER *candidate = SSL_get_cipher_by_value(cipher_suite);
David Benjaminf01f42a2016-11-16 19:05:33 +0900127 if (candidate == NULL ||
128 SSL_CIPHER_get_min_version(candidate) > version ||
129 SSL_CIPHER_get_max_version(candidate) < version) {
David Benjamin34202b92016-11-16 19:07:53 +0900130 continue;
131 }
132
David Benjaminc11ea9422017-08-29 16:33:21 -0400133 // TLS 1.3 removes legacy ciphers, so honor the client order, but prefer
134 // ChaCha20 if we do not have AES hardware.
David Benjamin34202b92016-11-16 19:07:53 +0900135 if (aes_is_fine) {
136 return candidate;
137 }
138
139 if (candidate->algorithm_enc == SSL_CHACHA20POLY1305) {
140 return candidate;
141 }
142
143 if (best == NULL) {
144 best = candidate;
145 }
146 }
147
148 return best;
149}
150
David Benjamin794cc592017-03-25 22:24:23 -0500151static int add_new_session_tickets(SSL_HANDSHAKE *hs) {
152 SSL *const ssl = hs->ssl;
David Benjaminc11ea9422017-08-29 16:33:21 -0400153 // TLS 1.3 recommends single-use tickets, so issue multiple tickets in case
154 // the client makes several connections before getting a renewal.
David Benjamin794cc592017-03-25 22:24:23 -0500155 static const int kNumTickets = 2;
156
David Benjaminc11ea9422017-08-29 16:33:21 -0400157 // Rebase the session timestamp so that it is measured from ticket
158 // issuance.
David Benjamin31b0c9b2017-07-20 14:49:15 -0400159 ssl_session_rebase_time(ssl, hs->new_session.get());
David Benjamin794cc592017-03-25 22:24:23 -0500160
161 for (int i = 0; i < kNumTickets; i++) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400162 UniquePtr<SSL_SESSION> session(
163 SSL_SESSION_dup(hs->new_session.get(), SSL_SESSION_INCLUDE_NONAUTH));
164 if (!session) {
David Benjamin1386aad2017-07-19 23:57:40 -0400165 return 0;
David Benjamin794cc592017-03-25 22:24:23 -0500166 }
David Benjamin794cc592017-03-25 22:24:23 -0500167
Steven Valdezcd8470f2017-10-11 12:29:36 -0400168 if (!RAND_bytes((uint8_t *)&session->ticket_age_add, 4)) {
169 return 0;
170 }
David Benjamina3a71e92018-06-29 13:24:45 -0400171 session->ticket_age_add_valid = true;
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700172 if (ssl->enable_early_data) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400173 session->ticket_max_early_data = kMaxEarlyDataAccepted;
Steven Valdezbe165a22017-10-10 11:45:01 -0400174 }
175
Steven Valdezcd8470f2017-10-11 12:29:36 -0400176 static_assert(kNumTickets < 256, "Too many tickets");
177 uint8_t nonce[] = {static_cast<uint8_t>(i)};
178
David Benjamin1386aad2017-07-19 23:57:40 -0400179 ScopedCBB cbb;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400180 CBB body, nonce_cbb, ticket, extensions;
David Benjamin1386aad2017-07-19 23:57:40 -0400181 if (!ssl->method->init_message(ssl, cbb.get(), &body,
David Benjamin794cc592017-03-25 22:24:23 -0500182 SSL3_MT_NEW_SESSION_TICKET) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400183 !CBB_add_u32(&body, session->timeout) ||
184 !CBB_add_u32(&body, session->ticket_age_add) ||
Steven Valdez7e5dd252018-01-22 15:20:31 -0500185 !CBB_add_u8_length_prefixed(&body, &nonce_cbb) ||
186 !CBB_add_bytes(&nonce_cbb, nonce, sizeof(nonce)) ||
David Benjamin794cc592017-03-25 22:24:23 -0500187 !CBB_add_u16_length_prefixed(&body, &ticket) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400188 !tls13_derive_session_psk(session.get(), nonce) ||
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700189 !ssl_encrypt_ticket(hs, &ticket, session.get()) ||
David Benjamin794cc592017-03-25 22:24:23 -0500190 !CBB_add_u16_length_prefixed(&body, &extensions)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400191 return 0;
David Benjamin794cc592017-03-25 22:24:23 -0500192 }
193
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700194 if (ssl->enable_early_data) {
David Benjamin794cc592017-03-25 22:24:23 -0500195 CBB early_data_info;
Steven Valdez7e5dd252018-01-22 15:20:31 -0500196 if (!CBB_add_u16(&extensions, TLSEXT_TYPE_early_data) ||
David Benjamin794cc592017-03-25 22:24:23 -0500197 !CBB_add_u16_length_prefixed(&extensions, &early_data_info) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400198 !CBB_add_u32(&early_data_info, session->ticket_max_early_data) ||
David Benjamin794cc592017-03-25 22:24:23 -0500199 !CBB_flush(&extensions)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400200 return 0;
David Benjamin794cc592017-03-25 22:24:23 -0500201 }
202 }
203
David Benjaminc11ea9422017-08-29 16:33:21 -0400204 // Add a fake extension. See draft-davidben-tls-grease-01.
David Benjamin794cc592017-03-25 22:24:23 -0500205 if (!CBB_add_u16(&extensions,
David Benjamina7bc9442018-01-18 10:08:53 -0500206 ssl_get_grease_value(hs, ssl_grease_ticket_extension)) ||
David Benjamin794cc592017-03-25 22:24:23 -0500207 !CBB_add_u16(&extensions, 0 /* empty */)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400208 return 0;
David Benjamin794cc592017-03-25 22:24:23 -0500209 }
210
David Benjamin1386aad2017-07-19 23:57:40 -0400211 if (!ssl_add_message_cbb(ssl, cbb.get())) {
212 return 0;
David Benjamin794cc592017-03-25 22:24:23 -0500213 }
214 }
215
216 return 1;
David Benjamin794cc592017-03-25 22:24:23 -0500217}
218
David Benjaminc3c88822016-11-14 10:32:04 +0900219static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400220 // At this point, most ClientHello extensions have already been processed by
221 // the common handshake logic. Resolve the remaining non-PSK parameters.
David Benjaminc3c88822016-11-14 10:32:04 +0900222 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400223 SSLMessage msg;
224 if (!ssl->method->get_message(ssl, &msg)) {
225 return ssl_hs_read_message;
226 }
David Benjamin731058e2016-12-03 23:15:13 -0500227 SSL_CLIENT_HELLO client_hello;
David Benjamin7934f082017-08-01 16:32:25 -0400228 if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
David Benjamin34202b92016-11-16 19:07:53 +0900229 OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400230 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
David Benjamin34202b92016-11-16 19:07:53 +0900231 return ssl_hs_error;
232 }
233
Steven Valdez520e1222017-06-13 12:45:25 -0400234 OPENSSL_memcpy(hs->session_id, client_hello.session_id,
235 client_hello.session_id_len);
236 hs->session_id_len = client_hello.session_id_len;
237
David Benjaminc11ea9422017-08-29 16:33:21 -0400238 // Negotiate the cipher suite.
David Benjamin45738dd2017-02-09 20:01:26 -0500239 hs->new_cipher = choose_tls13_cipher(ssl, &client_hello);
240 if (hs->new_cipher == NULL) {
David Benjaminf01f42a2016-11-16 19:05:33 +0900241 OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER);
David Benjamind1e3ce12017-10-06 18:31:15 -0400242 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
David Benjaminf01f42a2016-11-16 19:05:33 +0900243 return ssl_hs_error;
244 }
245
David Benjaminc11ea9422017-08-29 16:33:21 -0400246 // HTTP/2 negotiation depends on the cipher suite, so ALPN negotiation was
247 // deferred. Complete it now.
David Benjamin707af292017-03-10 17:47:18 -0500248 uint8_t alert = SSL_AD_DECODE_ERROR;
249 if (!ssl_negotiate_alpn(hs, &alert, &client_hello)) {
David Benjamind1e3ce12017-10-06 18:31:15 -0400250 ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
David Benjamin707af292017-03-10 17:47:18 -0500251 return ssl_hs_error;
252 }
253
David Benjaminc11ea9422017-08-29 16:33:21 -0400254 // The PRF hash is now known. Set up the key schedule and hash the
255 // ClientHello.
Steven Valdezcd8470f2017-10-11 12:29:36 -0400256 if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher)) {
257 return ssl_hs_error;
258 }
259
260 if (!ssl_hash_message(hs, msg)) {
Steven Valdez908ac192017-01-12 13:17:07 -0500261 return ssl_hs_error;
262 }
263
David Benjamin707af292017-03-10 17:47:18 -0500264 hs->tls13_state = state_select_session;
265 return ssl_hs_ok;
266}
Steven Valdez908ac192017-01-12 13:17:07 -0500267
David Benjamin707af292017-03-10 17:47:18 -0500268static enum ssl_ticket_aead_result_t select_session(
David Benjamin37af90f2017-07-29 01:42:16 -0400269 SSL_HANDSHAKE *hs, uint8_t *out_alert, UniquePtr<SSL_SESSION> *out_session,
David Benjamin7934f082017-08-01 16:32:25 -0400270 int32_t *out_ticket_age_skew, const SSLMessage &msg,
271 const SSL_CLIENT_HELLO *client_hello) {
David Benjamin707af292017-03-10 17:47:18 -0500272 SSL *const ssl = hs->ssl;
273 *out_session = NULL;
274
David Benjaminc11ea9422017-08-29 16:33:21 -0400275 // Decode the ticket if we agreed on a PSK key exchange mode.
David Benjamin707af292017-03-10 17:47:18 -0500276 CBS pre_shared_key;
277 if (!hs->accept_psk_mode ||
278 !ssl_client_hello_get_extension(client_hello, &pre_shared_key,
279 TLSEXT_TYPE_pre_shared_key)) {
280 return ssl_ticket_aead_ignore_ticket;
281 }
282
David Benjaminc11ea9422017-08-29 16:33:21 -0400283 // Verify that the pre_shared_key extension is the last extension in
284 // ClientHello.
David Benjamin707af292017-03-10 17:47:18 -0500285 if (CBS_data(&pre_shared_key) + CBS_len(&pre_shared_key) !=
286 client_hello->extensions + client_hello->extensions_len) {
287 OPENSSL_PUT_ERROR(SSL, SSL_R_PRE_SHARED_KEY_MUST_BE_LAST);
288 *out_alert = SSL_AD_ILLEGAL_PARAMETER;
289 return ssl_ticket_aead_error;
290 }
291
292 CBS ticket, binders;
293 uint32_t client_ticket_age;
294 if (!ssl_ext_pre_shared_key_parse_clienthello(hs, &ticket, &binders,
295 &client_ticket_age, out_alert,
296 &pre_shared_key)) {
297 return ssl_ticket_aead_error;
298 }
299
David Benjaminc11ea9422017-08-29 16:33:21 -0400300 // TLS 1.3 session tickets are renewed separately as part of the
301 // NewSessionTicket.
David Benjaminfd45ee72017-08-31 14:49:09 -0400302 bool unused_renew;
David Benjamin37af90f2017-07-29 01:42:16 -0400303 UniquePtr<SSL_SESSION> session;
David Benjamin707af292017-03-10 17:47:18 -0500304 enum ssl_ticket_aead_result_t ret =
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700305 ssl_process_ticket(hs, &session, &unused_renew, CBS_data(&ticket),
David Benjamin707af292017-03-10 17:47:18 -0500306 CBS_len(&ticket), NULL, 0);
307 switch (ret) {
308 case ssl_ticket_aead_success:
309 break;
310 case ssl_ticket_aead_error:
311 *out_alert = SSL_AD_INTERNAL_ERROR;
312 return ret;
313 default:
314 return ret;
315 }
316
David Benjamin37af90f2017-07-29 01:42:16 -0400317 if (!ssl_session_is_resumable(hs, session.get()) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400318 // Historically, some TLS 1.3 tickets were missing ticket_age_add.
David Benjamin707af292017-03-10 17:47:18 -0500319 !session->ticket_age_add_valid) {
David Benjamin707af292017-03-10 17:47:18 -0500320 return ssl_ticket_aead_ignore_ticket;
321 }
322
David Benjaminc11ea9422017-08-29 16:33:21 -0400323 // Recover the client ticket age and convert to seconds.
David Benjamin707af292017-03-10 17:47:18 -0500324 client_ticket_age -= session->ticket_age_add;
325 client_ticket_age /= 1000;
326
327 struct OPENSSL_timeval now;
328 ssl_get_current_time(ssl, &now);
329
David Benjaminc11ea9422017-08-29 16:33:21 -0400330 // Compute the server ticket age in seconds.
David Benjamin707af292017-03-10 17:47:18 -0500331 assert(now.tv_sec >= session->time);
332 uint64_t server_ticket_age = now.tv_sec - session->time;
333
David Benjaminc11ea9422017-08-29 16:33:21 -0400334 // To avoid overflowing |hs->ticket_age_skew|, we will not resume
335 // 68-year-old sessions.
David Benjamin707af292017-03-10 17:47:18 -0500336 if (server_ticket_age > INT32_MAX) {
David Benjamin707af292017-03-10 17:47:18 -0500337 return ssl_ticket_aead_ignore_ticket;
338 }
339
David Benjaminc11ea9422017-08-29 16:33:21 -0400340 // TODO(davidben,svaldez): Measure this value to decide on tolerance. For
341 // now, accept all values. https://crbug.com/boringssl/113.
David Benjamin707af292017-03-10 17:47:18 -0500342 *out_ticket_age_skew =
343 (int32_t)client_ticket_age - (int32_t)server_ticket_age;
344
David Benjaminc11ea9422017-08-29 16:33:21 -0400345 // Check the PSK binder.
David Benjamin7934f082017-08-01 16:32:25 -0400346 if (!tls13_verify_psk_binder(hs, session.get(), msg, &binders)) {
David Benjamin707af292017-03-10 17:47:18 -0500347 *out_alert = SSL_AD_DECRYPT_ERROR;
348 return ssl_ticket_aead_error;
349 }
350
David Benjamin37af90f2017-07-29 01:42:16 -0400351 *out_session = std::move(session);
David Benjamin707af292017-03-10 17:47:18 -0500352 return ssl_ticket_aead_success;
353}
354
355static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
356 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400357 SSLMessage msg;
358 if (!ssl->method->get_message(ssl, &msg)) {
359 return ssl_hs_read_message;
360 }
David Benjamin707af292017-03-10 17:47:18 -0500361 SSL_CLIENT_HELLO client_hello;
David Benjamin7934f082017-08-01 16:32:25 -0400362 if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
David Benjamin707af292017-03-10 17:47:18 -0500363 OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400364 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
David Benjamin707af292017-03-10 17:47:18 -0500365 return ssl_hs_error;
366 }
367
David Benjamin4eb95cc2016-11-16 17:08:23 +0900368 uint8_t alert = SSL_AD_DECODE_ERROR;
David Benjamin37af90f2017-07-29 01:42:16 -0400369 UniquePtr<SSL_SESSION> session;
David Benjamin7934f082017-08-01 16:32:25 -0400370 switch (select_session(hs, &alert, &session, &ssl->s3->ticket_age_skew, msg,
David Benjamin707af292017-03-10 17:47:18 -0500371 &client_hello)) {
372 case ssl_ticket_aead_ignore_ticket:
David Benjamin37af90f2017-07-29 01:42:16 -0400373 assert(!session);
David Benjamin707af292017-03-10 17:47:18 -0500374 if (!ssl_get_new_session(hs, 1 /* server */)) {
David Benjamind1e3ce12017-10-06 18:31:15 -0400375 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjaminf01f42a2016-11-16 19:05:33 +0900376 return ssl_hs_error;
377 }
David Benjamin707af292017-03-10 17:47:18 -0500378 break;
Steven Valdeza833c352016-11-01 13:39:36 -0400379
David Benjamin707af292017-03-10 17:47:18 -0500380 case ssl_ticket_aead_success:
David Benjaminc11ea9422017-08-29 16:33:21 -0400381 // Carry over authentication information from the previous handshake into
382 // a fresh session.
David Benjamin37af90f2017-07-29 01:42:16 -0400383 hs->new_session =
384 SSL_SESSION_dup(session.get(), SSL_SESSION_DUP_AUTH_ONLY);
Steven Valdez2d850622017-01-11 11:34:52 -0500385
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700386 if (ssl->enable_early_data &&
David Benjamin8e7bbba2017-10-13 17:18:35 -0400387 // Early data must be acceptable for this ticket.
Steven Valdez2d850622017-01-11 11:34:52 -0500388 session->ticket_max_early_data != 0 &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400389 // The client must have offered early data.
Steven Valdez2d850622017-01-11 11:34:52 -0500390 hs->early_data_offered &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400391 // Channel ID is incompatible with 0-RTT.
David Benjamin46853762018-07-03 14:01:26 -0400392 !ssl->s3->channel_id_valid &&
Nick Harper36fcc4c2017-09-21 15:02:22 -0700393 // If Token Binding is negotiated, reject 0-RTT.
David Benjamin9f0e7cb2018-04-12 15:36:30 -0400394 !ssl->s3->token_binding_negotiated &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400395 // Custom extensions is incompatible with 0-RTT.
Steven Valdezf4ecc842017-08-10 14:02:56 -0400396 hs->custom_extensions.received == 0 &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400397 // The negotiated ALPN must match the one in the ticket.
David Benjaminbfdd1a92018-06-29 16:26:38 -0400398 MakeConstSpan(ssl->s3->alpn_selected) == session->early_alpn) {
David Benjamin02e62562017-12-18 18:04:01 -0500399 ssl->s3->early_data_accepted = true;
Steven Valdez2d850622017-01-11 11:34:52 -0500400 }
401
David Benjamin707af292017-03-10 17:47:18 -0500402 if (hs->new_session == NULL) {
David Benjamind1e3ce12017-10-06 18:31:15 -0400403 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjamin707af292017-03-10 17:47:18 -0500404 return ssl_hs_error;
405 }
406
David Benjamin046bc1f2017-08-31 15:06:42 -0400407 ssl->s3->session_reused = true;
David Benjamin707af292017-03-10 17:47:18 -0500408
David Benjaminc11ea9422017-08-29 16:33:21 -0400409 // Resumption incorporates fresh key material, so refresh the timeout.
David Benjamin98472cb2018-05-02 16:05:36 -0400410 ssl_session_renew_timeout(ssl, hs->new_session.get(),
411 ssl->session_ctx->session_psk_dhe_timeout);
David Benjamin707af292017-03-10 17:47:18 -0500412 break;
413
414 case ssl_ticket_aead_error:
David Benjamind1e3ce12017-10-06 18:31:15 -0400415 ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
David Benjamin707af292017-03-10 17:47:18 -0500416 return ssl_hs_error;
417
418 case ssl_ticket_aead_retry:
419 hs->tls13_state = state_select_session;
420 return ssl_hs_pending_ticket;
421 }
422
David Benjaminc11ea9422017-08-29 16:33:21 -0400423 // Record connection properties in the new session.
David Benjamin707af292017-03-10 17:47:18 -0500424 hs->new_session->cipher = hs->new_cipher;
425
David Benjaminc11ea9422017-08-29 16:33:21 -0400426 // Store the initial negotiated ALPN in the session.
David Benjaminbfdd1a92018-06-29 16:26:38 -0400427 if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
428 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
429 return ssl_hs_error;
Steven Valdez27a9e6a2017-02-14 13:20:40 -0500430 }
431
David Benjamin707af292017-03-10 17:47:18 -0500432 if (ssl->ctx->dos_protection_cb != NULL &&
433 ssl->ctx->dos_protection_cb(&client_hello) == 0) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400434 // Connection rejected for DOS reasons.
David Benjamin707af292017-03-10 17:47:18 -0500435 OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400436 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjamin707af292017-03-10 17:47:18 -0500437 return ssl_hs_error;
438 }
439
Steven Valdezcd8470f2017-10-11 12:29:36 -0400440 size_t hash_len = EVP_MD_size(
441 ssl_get_handshake_digest(ssl_protocol_version(ssl), hs->new_cipher));
442
443 // Set up the key schedule and incorporate the PSK into the running secret.
David Benjamin8f820b42016-11-30 11:24:40 -0500444 if (ssl->s3->session_reused) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400445 if (!tls13_init_key_schedule(hs, hs->new_session->master_key,
David Benjamin45738dd2017-02-09 20:01:26 -0500446 hs->new_session->master_key_length)) {
David Benjamin8f820b42016-11-30 11:24:40 -0500447 return ssl_hs_error;
448 }
Steven Valdezcd8470f2017-10-11 12:29:36 -0400449 } else if (!tls13_init_key_schedule(hs, kZeroes, hash_len)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400450 return ssl_hs_error;
451 }
452
David Benjamin02e62562017-12-18 18:04:01 -0500453 if (ssl->s3->early_data_accepted) {
Steven Valdez2d850622017-01-11 11:34:52 -0500454 if (!tls13_derive_early_secrets(hs)) {
455 return ssl_hs_error;
456 }
457 } else if (hs->early_data_offered) {
David Benjamin046bc1f2017-08-31 15:06:42 -0400458 ssl->s3->skip_early_data = true;
Steven Valdez2d850622017-01-11 11:34:52 -0500459 }
460
David Benjaminc11ea9422017-08-29 16:33:21 -0400461 // Resolve ECDHE and incorporate it into the secret.
David Benjamin046bc1f2017-08-31 15:06:42 -0400462 bool need_retry;
David Benjamin6e4fc332016-11-17 16:43:08 +0900463 if (!resolve_ecdhe_secret(hs, &need_retry, &client_hello)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400464 if (need_retry) {
David Benjamin02e62562017-12-18 18:04:01 -0500465 ssl->s3->early_data_accepted = false;
David Benjamin046bc1f2017-08-31 15:06:42 -0400466 ssl->s3->skip_early_data = true;
David Benjamin8f94c312017-08-01 17:35:55 -0400467 ssl->method->next_message(ssl);
Steven Valdez7e5dd252018-01-22 15:20:31 -0500468 if (!hs->transcript.UpdateForHelloRetryRequest()) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400469 return ssl_hs_error;
470 }
David Benjamin3977f302016-12-11 13:30:41 -0500471 hs->tls13_state = state_send_hello_retry_request;
Steven Valdez5440fe02016-07-18 12:40:30 -0400472 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400473 }
Steven Valdez5440fe02016-07-18 12:40:30 -0400474 return ssl_hs_error;
475 }
Steven Valdez143e8b32016-07-11 13:19:03 -0400476
David Benjamin8f94c312017-08-01 17:35:55 -0400477 ssl->method->next_message(ssl);
David Benjamin3977f302016-12-11 13:30:41 -0500478 hs->tls13_state = state_send_server_hello;
Steven Valdez5440fe02016-07-18 12:40:30 -0400479 return ssl_hs_ok;
480}
Steven Valdez143e8b32016-07-11 13:19:03 -0400481
David Benjaminc3c88822016-11-14 10:32:04 +0900482static enum ssl_hs_wait_t do_send_hello_retry_request(SSL_HANDSHAKE *hs) {
483 SSL *const ssl = hs->ssl;
Steven Valdez964b2372017-11-07 17:09:52 -0500484
485
Steven Valdez7e5dd252018-01-22 15:20:31 -0500486 ScopedCBB cbb;
487 CBB body, session_id, extensions;
488 uint16_t group_id;
489 if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
490 !CBB_add_u16(&body, TLS1_2_VERSION) ||
491 !CBB_add_bytes(&body, kHelloRetryRequest, SSL3_RANDOM_SIZE) ||
492 !CBB_add_u8_length_prefixed(&body, &session_id) ||
493 !CBB_add_bytes(&session_id, hs->session_id, hs->session_id_len) ||
494 !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
495 !CBB_add_u8(&body, 0 /* no compression */) ||
496 !tls1_get_shared_group(hs, &group_id) ||
497 !CBB_add_u16_length_prefixed(&body, &extensions) ||
498 !CBB_add_u16(&extensions, TLSEXT_TYPE_supported_versions) ||
499 !CBB_add_u16(&extensions, 2 /* length */) ||
500 !CBB_add_u16(&extensions, ssl->version) ||
501 !CBB_add_u16(&extensions, TLSEXT_TYPE_key_share) ||
502 !CBB_add_u16(&extensions, 2 /* length */) ||
503 !CBB_add_u16(&extensions, group_id) ||
504 !ssl_add_message_cbb(ssl, cbb.get())) {
505 return ssl_hs_error;
506 }
Steven Valdez964b2372017-11-07 17:09:52 -0500507
Steven Valdez7e5dd252018-01-22 15:20:31 -0500508 if (!ssl->method->add_change_cipher_spec(ssl)) {
509 return ssl_hs_error;
Steven Valdez5440fe02016-07-18 12:40:30 -0400510 }
511
Steven Valdez964b2372017-11-07 17:09:52 -0500512 hs->sent_hello_retry_request = true;
David Benjamin7934f082017-08-01 16:32:25 -0400513 hs->tls13_state = state_read_second_client_hello;
514 return ssl_hs_flush;
Steven Valdez5440fe02016-07-18 12:40:30 -0400515}
516
David Benjamin7934f082017-08-01 16:32:25 -0400517static enum ssl_hs_wait_t do_read_second_client_hello(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900518 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400519 SSLMessage msg;
520 if (!ssl->method->get_message(ssl, &msg)) {
521 return ssl_hs_read_message;
522 }
523 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CLIENT_HELLO)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400524 return ssl_hs_error;
525 }
David Benjamin731058e2016-12-03 23:15:13 -0500526 SSL_CLIENT_HELLO client_hello;
David Benjamin7934f082017-08-01 16:32:25 -0400527 if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400528 OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400529 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
Steven Valdez5440fe02016-07-18 12:40:30 -0400530 return ssl_hs_error;
531 }
532
David Benjamin046bc1f2017-08-31 15:06:42 -0400533 bool need_retry;
David Benjamin6e4fc332016-11-17 16:43:08 +0900534 if (!resolve_ecdhe_secret(hs, &need_retry, &client_hello)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400535 if (need_retry) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400536 // Only send one HelloRetryRequest.
David Benjamind1e3ce12017-10-06 18:31:15 -0400537 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
Steven Valdez5440fe02016-07-18 12:40:30 -0400538 OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
Steven Valdez143e8b32016-07-11 13:19:03 -0400539 }
Steven Valdez5440fe02016-07-18 12:40:30 -0400540 return ssl_hs_error;
541 }
542
David Benjamin7934f082017-08-01 16:32:25 -0400543 if (!ssl_hash_message(hs, msg)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400544 return ssl_hs_error;
545 }
546
David Benjamin8f94c312017-08-01 17:35:55 -0400547 ssl->method->next_message(ssl);
David Benjamin3977f302016-12-11 13:30:41 -0500548 hs->tls13_state = state_send_server_hello;
Steven Valdez143e8b32016-07-11 13:19:03 -0400549 return ssl_hs_ok;
550}
551
David Benjaminc3c88822016-11-14 10:32:04 +0900552static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
553 SSL *const ssl = hs->ssl;
David Benjamin81b7bc32017-01-12 19:44:57 -0500554
David Benjaminc11ea9422017-08-29 16:33:21 -0400555 // Send a ServerHello.
David Benjamin1386aad2017-07-19 23:57:40 -0400556 ScopedCBB cbb;
557 CBB body, extensions, session_id;
558 if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500559 !CBB_add_u16(&body, TLS1_2_VERSION) ||
Steven Valdez143e8b32016-07-11 13:19:03 -0400560 !RAND_bytes(ssl->s3->server_random, sizeof(ssl->s3->server_random)) ||
561 !CBB_add_bytes(&body, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500562 !CBB_add_u8_length_prefixed(&body, &session_id) ||
563 !CBB_add_bytes(&session_id, hs->session_id, hs->session_id_len) ||
David Benjamin45738dd2017-02-09 20:01:26 -0500564 !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500565 !CBB_add_u8(&body, 0) ||
Steven Valdez143e8b32016-07-11 13:19:03 -0400566 !CBB_add_u16_length_prefixed(&body, &extensions) ||
David Benjamin8baf9632016-11-17 17:11:16 +0900567 !ssl_ext_pre_shared_key_add_serverhello(hs, &extensions) ||
Steven Valdez924a3522017-03-02 16:05:03 -0500568 !ssl_ext_key_share_add_serverhello(hs, &extensions) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500569 !ssl_ext_supported_versions_add_serverhello(hs, &extensions) ||
David Benjamin1386aad2017-07-19 23:57:40 -0400570 !ssl_add_message_cbb(ssl, cbb.get())) {
571 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400572 }
573
Steven Valdez7e5dd252018-01-22 15:20:31 -0500574 if (!hs->sent_hello_retry_request &&
David Benjamin666d16e2017-10-06 18:45:16 -0400575 !ssl->method->add_change_cipher_spec(ssl)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400576 return ssl_hs_error;
Steven Valdez520e1222017-06-13 12:45:25 -0400577 }
578
David Benjaminc11ea9422017-08-29 16:33:21 -0400579 // Derive and enable the handshake traffic secrets.
Steven Valdez4cb84942016-12-16 11:29:28 -0500580 if (!tls13_derive_handshake_secrets(hs) ||
Steven Valdez4cb84942016-12-16 11:29:28 -0500581 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->server_handshake_secret,
582 hs->hash_len)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400583 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400584 }
585
David Benjaminc11ea9422017-08-29 16:33:21 -0400586 // Send EncryptedExtensions.
David Benjamin1386aad2017-07-19 23:57:40 -0400587 if (!ssl->method->init_message(ssl, cbb.get(), &body,
Steven Valdez143e8b32016-07-11 13:19:03 -0400588 SSL3_MT_ENCRYPTED_EXTENSIONS) ||
David Benjamin8c880a22016-12-03 02:20:34 -0500589 !ssl_add_serverhello_tlsext(hs, &body) ||
David Benjamin1386aad2017-07-19 23:57:40 -0400590 !ssl_add_message_cbb(ssl, cbb.get())) {
591 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400592 }
593
David Benjaminc3648fa2017-07-01 10:50:56 -0400594 if (!ssl->s3->session_reused) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400595 // Determine whether to request a client certificate.
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700596 hs->cert_request = !!(hs->config->verify_mode & SSL_VERIFY_PEER);
David Benjaminc11ea9422017-08-29 16:33:21 -0400597 // Only request a certificate if Channel ID isn't negotiated.
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700598 if ((hs->config->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
David Benjamin46853762018-07-03 14:01:26 -0400599 ssl->s3->channel_id_valid) {
David Benjaminfd45ee72017-08-31 14:49:09 -0400600 hs->cert_request = false;
David Benjaminc3648fa2017-07-01 10:50:56 -0400601 }
Steven Valdez143e8b32016-07-11 13:19:03 -0400602 }
603
David Benjaminc11ea9422017-08-29 16:33:21 -0400604 // Send a CertificateRequest, if necessary.
David Benjamin81b7bc32017-01-12 19:44:57 -0500605 if (hs->cert_request) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500606 CBB cert_request_extensions, sigalg_contents, sigalgs_cbb;
607 if (!ssl->method->init_message(ssl, cbb.get(), &body,
608 SSL3_MT_CERTIFICATE_REQUEST) ||
609 !CBB_add_u8(&body, 0 /* no certificate_request_context. */) ||
610 !CBB_add_u16_length_prefixed(&body, &cert_request_extensions) ||
611 !CBB_add_u16(&cert_request_extensions,
612 TLSEXT_TYPE_signature_algorithms) ||
613 !CBB_add_u16_length_prefixed(&cert_request_extensions,
614 &sigalg_contents) ||
615 !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
David Benjamine28552d2018-04-08 13:59:25 -0400616 !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb,
617 false /* online signature */)) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500618 return ssl_hs_error;
619 }
620
David Benjamine28552d2018-04-08 13:59:25 -0400621 if (tls12_has_different_verify_sigalgs_for_certs(ssl)) {
622 if (!CBB_add_u16(&cert_request_extensions,
623 TLSEXT_TYPE_signature_algorithms_cert) ||
624 !CBB_add_u16_length_prefixed(&cert_request_extensions,
625 &sigalg_contents) ||
626 !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
627 !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb, true /* certs */)) {
628 return ssl_hs_error;
629 }
630 }
631
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700632 if (ssl_has_client_CAs(hs->config)) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500633 CBB ca_contents;
634 if (!CBB_add_u16(&cert_request_extensions,
635 TLSEXT_TYPE_certificate_authorities) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400636 !CBB_add_u16_length_prefixed(&cert_request_extensions,
Steven Valdez7e5dd252018-01-22 15:20:31 -0500637 &ca_contents) ||
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700638 !ssl_add_client_CA_list(hs, &ca_contents) ||
Steven Valdez7e5dd252018-01-22 15:20:31 -0500639 !CBB_flush(&cert_request_extensions)) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400640 return ssl_hs_error;
641 }
Steven Valdez7e5dd252018-01-22 15:20:31 -0500642 }
Steven Valdezcd8470f2017-10-11 12:29:36 -0400643
Steven Valdez7e5dd252018-01-22 15:20:31 -0500644 if (!ssl_add_message_cbb(ssl, cbb.get())) {
645 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400646 }
647 }
648
David Benjaminc11ea9422017-08-29 16:33:21 -0400649 // Send the server Certificate message, if necessary.
David Benjamin81b7bc32017-01-12 19:44:57 -0500650 if (!ssl->s3->session_reused) {
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700651 if (!ssl_has_certificate(hs->config)) {
David Benjamin81b7bc32017-01-12 19:44:57 -0500652 OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET);
David Benjamin1386aad2017-07-19 23:57:40 -0400653 return ssl_hs_error;
David Benjamin81b7bc32017-01-12 19:44:57 -0500654 }
655
David Benjamin0f24bed2017-01-12 19:46:50 -0500656 if (!tls13_add_certificate(hs)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400657 return ssl_hs_error;
David Benjamin81b7bc32017-01-12 19:44:57 -0500658 }
659
660 hs->tls13_state = state_send_server_certificate_verify;
661 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400662 }
663
David Benjamin81b7bc32017-01-12 19:44:57 -0500664 hs->tls13_state = state_send_server_finished;
David Benjamin25ac2512017-01-12 19:31:28 -0500665 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400666}
667
David Benjamin44148742017-06-17 13:20:59 -0400668static enum ssl_hs_wait_t do_send_server_certificate_verify(SSL_HANDSHAKE *hs) {
669 switch (tls13_add_certificate_verify(hs)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400670 case ssl_private_key_success:
David Benjamin3977f302016-12-11 13:30:41 -0500671 hs->tls13_state = state_send_server_finished;
David Benjamin25ac2512017-01-12 19:31:28 -0500672 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400673
674 case ssl_private_key_retry:
David Benjamin44148742017-06-17 13:20:59 -0400675 hs->tls13_state = state_send_server_certificate_verify;
Steven Valdez143e8b32016-07-11 13:19:03 -0400676 return ssl_hs_private_key_operation;
677
678 case ssl_private_key_failure:
679 return ssl_hs_error;
680 }
681
682 assert(0);
683 return ssl_hs_error;
684}
685
David Benjaminc3c88822016-11-14 10:32:04 +0900686static enum ssl_hs_wait_t do_send_server_finished(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900687 SSL *const ssl = hs->ssl;
David Benjamin0f24bed2017-01-12 19:46:50 -0500688 if (!tls13_add_finished(hs) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400689 // Update the secret to the master secret and derive traffic keys.
David Benjamin25ac2512017-01-12 19:31:28 -0500690 !tls13_advance_key_schedule(hs, kZeroes, hs->hash_len) ||
David Benjamin6e4fc332016-11-17 16:43:08 +0900691 !tls13_derive_application_secrets(hs) ||
Steven Valdeza833c352016-11-01 13:39:36 -0400692 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->server_traffic_secret_0,
693 hs->hash_len)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400694 return ssl_hs_error;
695 }
696
David Benjamin02e62562017-12-18 18:04:01 -0500697 if (ssl->s3->early_data_accepted) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400698 // If accepting 0-RTT, we send tickets half-RTT. This gets the tickets on
699 // the wire sooner and also avoids triggering a write on |SSL_read| when
700 // processing the client Finished. This requires computing the client
701 // Finished early. See draft-ietf-tls-tls13-18, section 4.5.1.
Steven Valdez7e5dd252018-01-22 15:20:31 -0500702 static const uint8_t kEndOfEarlyData[4] = {SSL3_MT_END_OF_EARLY_DATA, 0,
703 0, 0};
704 if (!hs->transcript.Update(kEndOfEarlyData)) {
705 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
706 return ssl_hs_error;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400707 }
708
David Benjamin794cc592017-03-25 22:24:23 -0500709 size_t finished_len;
710 if (!tls13_finished_mac(hs, hs->expected_client_finished, &finished_len,
711 0 /* client */)) {
712 return ssl_hs_error;
713 }
714
715 if (finished_len != hs->hash_len) {
716 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
717 return ssl_hs_error;
718 }
719
David Benjaminc11ea9422017-08-29 16:33:21 -0400720 // Feed the predicted Finished into the transcript. This allows us to derive
721 // the resumption secret early and send half-RTT tickets.
722 //
723 // TODO(davidben): This will need to be updated for DTLS 1.3.
David Benjamin794cc592017-03-25 22:24:23 -0500724 assert(!SSL_is_dtls(hs->ssl));
David Benjamind304a2f2017-07-12 23:00:28 -0400725 assert(hs->hash_len <= 0xff);
David Benjamin6dc8bf62017-07-19 16:38:21 -0400726 uint8_t header[4] = {SSL3_MT_FINISHED, 0, 0,
727 static_cast<uint8_t>(hs->hash_len)};
David Benjamin75a1f232017-10-11 17:19:19 -0400728 if (!hs->transcript.Update(header) ||
729 !hs->transcript.Update(
730 MakeConstSpan(hs->expected_client_finished, hs->hash_len)) ||
David Benjamin8f94c312017-08-01 17:35:55 -0400731 !tls13_derive_resumption_secret(hs) ||
732 !add_new_session_tickets(hs)) {
David Benjamin794cc592017-03-25 22:24:23 -0500733 return ssl_hs_error;
734 }
735 }
736
Steven Valdez2d850622017-01-11 11:34:52 -0500737 hs->tls13_state = state_read_second_client_flight;
738 return ssl_hs_flush;
739}
740
741static enum ssl_hs_wait_t do_read_second_client_flight(SSL_HANDSHAKE *hs) {
742 SSL *const ssl = hs->ssl;
David Benjamin02e62562017-12-18 18:04:01 -0500743 if (ssl->s3->early_data_accepted) {
Steven Valdez2d850622017-01-11 11:34:52 -0500744 if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->early_traffic_secret,
745 hs->hash_len)) {
746 return ssl_hs_error;
747 }
David Benjaminfd45ee72017-08-31 14:49:09 -0400748 hs->can_early_write = true;
749 hs->can_early_read = true;
750 hs->in_early_data = true;
Steven Valdez2d850622017-01-11 11:34:52 -0500751 }
Steven Valdez2d850622017-01-11 11:34:52 -0500752 hs->tls13_state = state_process_end_of_early_data;
David Benjamin02e62562017-12-18 18:04:01 -0500753 return ssl->s3->early_data_accepted ? ssl_hs_read_end_of_early_data
754 : ssl_hs_ok;
Steven Valdez2d850622017-01-11 11:34:52 -0500755}
756
757static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400758 SSL *const ssl = hs->ssl;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400759 if (hs->early_data_offered) {
760 // If early data was not accepted, the EndOfEarlyData and ChangeCipherSpec
761 // message will be in the discarded early data.
David Benjamin02e62562017-12-18 18:04:01 -0500762 if (hs->ssl->s3->early_data_accepted) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500763 SSLMessage msg;
764 if (!ssl->method->get_message(ssl, &msg)) {
765 return ssl_hs_read_message;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400766 }
Steven Valdez7e5dd252018-01-22 15:20:31 -0500767
768 if (!ssl_check_message_type(ssl, msg, SSL3_MT_END_OF_EARLY_DATA)) {
769 return ssl_hs_error;
770 }
771 if (CBS_len(&msg.body) != 0) {
772 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
773 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
774 return ssl_hs_error;
775 }
776 ssl->method->next_message(ssl);
Steven Valdezcd8470f2017-10-11 12:29:36 -0400777 }
Steven Valdez520e1222017-06-13 12:45:25 -0400778 }
Steven Valdez2d850622017-01-11 11:34:52 -0500779 if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->client_handshake_secret,
780 hs->hash_len)) {
781 return ssl_hs_error;
782 }
David Benjamin02e62562017-12-18 18:04:01 -0500783 hs->tls13_state = ssl->s3->early_data_accepted
784 ? state_read_client_finished
785 : state_read_client_certificate;
David Benjamin7934f082017-08-01 16:32:25 -0400786 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400787}
788
David Benjamin7934f082017-08-01 16:32:25 -0400789static enum ssl_hs_wait_t do_read_client_certificate(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900790 SSL *const ssl = hs->ssl;
791 if (!hs->cert_request) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400792 // OpenSSL returns X509_V_OK when no certificates are requested. This is
793 // classed by them as a bug, but it's assumed by at least NGINX.
David Benjamin45738dd2017-02-09 20:01:26 -0500794 hs->new_session->verify_result = X509_V_OK;
Adam Langley37646832016-08-01 16:16:46 -0700795
David Benjaminc11ea9422017-08-29 16:33:21 -0400796 // Skip this state.
David Benjamin7934f082017-08-01 16:32:25 -0400797 hs->tls13_state = state_read_channel_id;
Steven Valdez143e8b32016-07-11 13:19:03 -0400798 return ssl_hs_ok;
799 }
800
David Benjamin4087df92016-08-01 20:16:31 -0400801 const int allow_anonymous =
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700802 (hs->config->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) == 0;
David Benjamin7934f082017-08-01 16:32:25 -0400803 SSLMessage msg;
804 if (!ssl->method->get_message(ssl, &msg)) {
805 return ssl_hs_read_message;
806 }
807 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE) ||
808 !tls13_process_certificate(hs, msg, allow_anonymous) ||
809 !ssl_hash_message(hs, msg)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400810 return ssl_hs_error;
811 }
812
David Benjamin8f94c312017-08-01 17:35:55 -0400813 ssl->method->next_message(ssl);
David Benjamin7934f082017-08-01 16:32:25 -0400814 hs->tls13_state = state_read_client_certificate_verify;
815 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400816}
817
David Benjamin7934f082017-08-01 16:32:25 -0400818static enum ssl_hs_wait_t do_read_client_certificate_verify(
David Benjaminc3c88822016-11-14 10:32:04 +0900819 SSL_HANDSHAKE *hs) {
820 SSL *const ssl = hs->ssl;
David Benjaminbfdd1a92018-06-29 16:26:38 -0400821 if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400822 // Skip this state.
David Benjamin7934f082017-08-01 16:32:25 -0400823 hs->tls13_state = state_read_channel_id;
Steven Valdez143e8b32016-07-11 13:19:03 -0400824 return ssl_hs_ok;
825 }
826
David Benjamin7934f082017-08-01 16:32:25 -0400827 SSLMessage msg;
828 if (!ssl->method->get_message(ssl, &msg)) {
829 return ssl_hs_read_message;
830 }
831
David Benjamin3a1dd462017-07-11 16:13:10 -0400832 switch (ssl_verify_peer_cert(hs)) {
833 case ssl_verify_ok:
834 break;
835 case ssl_verify_invalid:
836 return ssl_hs_error;
837 case ssl_verify_retry:
David Benjamin7934f082017-08-01 16:32:25 -0400838 hs->tls13_state = state_read_client_certificate_verify;
David Benjamin3a1dd462017-07-11 16:13:10 -0400839 return ssl_hs_certificate_verify;
840 }
841
David Benjamin7934f082017-08-01 16:32:25 -0400842 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE_VERIFY) ||
843 !tls13_process_certificate_verify(hs, msg) ||
844 !ssl_hash_message(hs, msg)) {
David Benjamin6929f272016-11-16 19:10:08 +0900845 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400846 }
847
David Benjamin8f94c312017-08-01 17:35:55 -0400848 ssl->method->next_message(ssl);
David Benjamin7934f082017-08-01 16:32:25 -0400849 hs->tls13_state = state_read_channel_id;
850 return ssl_hs_ok;
Nick Harper60a85cb2016-09-23 16:25:11 -0700851}
852
David Benjamin7934f082017-08-01 16:32:25 -0400853static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) {
David Benjamin8f94c312017-08-01 17:35:55 -0400854 SSL *const ssl = hs->ssl;
David Benjamin46853762018-07-03 14:01:26 -0400855 if (!ssl->s3->channel_id_valid) {
David Benjamin7934f082017-08-01 16:32:25 -0400856 hs->tls13_state = state_read_client_finished;
Nick Harper60a85cb2016-09-23 16:25:11 -0700857 return ssl_hs_ok;
858 }
859
David Benjamin7934f082017-08-01 16:32:25 -0400860 SSLMessage msg;
861 if (!ssl->method->get_message(ssl, &msg)) {
862 return ssl_hs_read_message;
863 }
864 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CHANNEL_ID) ||
865 !tls1_verify_channel_id(hs, msg) ||
866 !ssl_hash_message(hs, msg)) {
Nick Harper60a85cb2016-09-23 16:25:11 -0700867 return ssl_hs_error;
868 }
869
David Benjamin8f94c312017-08-01 17:35:55 -0400870 ssl->method->next_message(ssl);
David Benjamin7934f082017-08-01 16:32:25 -0400871 hs->tls13_state = state_read_client_finished;
872 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400873}
874
David Benjamin7934f082017-08-01 16:32:25 -0400875static enum ssl_hs_wait_t do_read_client_finished(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900876 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400877 SSLMessage msg;
878 if (!ssl->method->get_message(ssl, &msg)) {
879 return ssl_hs_read_message;
880 }
881 if (!ssl_check_message_type(ssl, msg, SSL3_MT_FINISHED) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400882 // If early data was accepted, we've already computed the client Finished
883 // and derived the resumption secret.
David Benjamin02e62562017-12-18 18:04:01 -0500884 !tls13_process_finished(hs, msg, ssl->s3->early_data_accepted) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400885 // evp_aead_seal keys have already been switched.
Steven Valdeza833c352016-11-01 13:39:36 -0400886 !tls13_set_traffic_key(ssl, evp_aead_open, hs->client_traffic_secret_0,
David Benjamin794cc592017-03-25 22:24:23 -0500887 hs->hash_len)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400888 return ssl_hs_error;
889 }
890
David Benjamin02e62562017-12-18 18:04:01 -0500891 if (!ssl->s3->early_data_accepted) {
David Benjamin7934f082017-08-01 16:32:25 -0400892 if (!ssl_hash_message(hs, msg) ||
David Benjamin794cc592017-03-25 22:24:23 -0500893 !tls13_derive_resumption_secret(hs)) {
894 return ssl_hs_error;
895 }
896
David Benjaminc11ea9422017-08-29 16:33:21 -0400897 // We send post-handshake tickets as part of the handshake in 1-RTT.
David Benjamin794cc592017-03-25 22:24:23 -0500898 hs->tls13_state = state_send_new_session_ticket;
David Benjamin8f94c312017-08-01 17:35:55 -0400899 } else {
David Benjaminc11ea9422017-08-29 16:33:21 -0400900 // We already sent half-RTT tickets.
David Benjamin8f94c312017-08-01 17:35:55 -0400901 hs->tls13_state = state_done;
David Benjamin794cc592017-03-25 22:24:23 -0500902 }
903
David Benjamin8f94c312017-08-01 17:35:55 -0400904 ssl->method->next_message(ssl);
Steven Valdez143e8b32016-07-11 13:19:03 -0400905 return ssl_hs_ok;
906}
907
David Benjaminc3c88822016-11-14 10:32:04 +0900908static enum ssl_hs_wait_t do_send_new_session_ticket(SSL_HANDSHAKE *hs) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400909 // If the client doesn't accept resumption with PSK_DHE_KE, don't send a
910 // session ticket.
Steven Valdeza833c352016-11-01 13:39:36 -0400911 if (!hs->accept_psk_mode) {
David Benjamin3977f302016-12-11 13:30:41 -0500912 hs->tls13_state = state_done;
Steven Valdeza833c352016-11-01 13:39:36 -0400913 return ssl_hs_ok;
914 }
915
David Benjamin794cc592017-03-25 22:24:23 -0500916 if (!add_new_session_tickets(hs)) {
917 return ssl_hs_error;
Steven Valdez08b65f42016-12-07 15:29:45 -0500918 }
919
David Benjamin25ac2512017-01-12 19:31:28 -0500920 hs->tls13_state = state_done;
921 return ssl_hs_flush;
Steven Valdez1e6f11a2016-07-27 11:10:52 -0400922}
923
David Benjaminc3c88822016-11-14 10:32:04 +0900924enum ssl_hs_wait_t tls13_server_handshake(SSL_HANDSHAKE *hs) {
David Benjamin3977f302016-12-11 13:30:41 -0500925 while (hs->tls13_state != state_done) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400926 enum ssl_hs_wait_t ret = ssl_hs_error;
David Benjamind304a2f2017-07-12 23:00:28 -0400927 enum server_hs_state_t state =
928 static_cast<enum server_hs_state_t>(hs->tls13_state);
Steven Valdez143e8b32016-07-11 13:19:03 -0400929 switch (state) {
David Benjamin25fe85b2016-08-09 20:00:32 -0400930 case state_select_parameters:
David Benjaminc3c88822016-11-14 10:32:04 +0900931 ret = do_select_parameters(hs);
David Benjamin25fe85b2016-08-09 20:00:32 -0400932 break;
David Benjamin707af292017-03-10 17:47:18 -0500933 case state_select_session:
934 ret = do_select_session(hs);
935 break;
Steven Valdez5440fe02016-07-18 12:40:30 -0400936 case state_send_hello_retry_request:
David Benjaminc3c88822016-11-14 10:32:04 +0900937 ret = do_send_hello_retry_request(hs);
Steven Valdez5440fe02016-07-18 12:40:30 -0400938 break;
David Benjamin7934f082017-08-01 16:32:25 -0400939 case state_read_second_client_hello:
940 ret = do_read_second_client_hello(hs);
Steven Valdez5440fe02016-07-18 12:40:30 -0400941 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400942 case state_send_server_hello:
David Benjaminc3c88822016-11-14 10:32:04 +0900943 ret = do_send_server_hello(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400944 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400945 case state_send_server_certificate_verify:
David Benjamin44148742017-06-17 13:20:59 -0400946 ret = do_send_server_certificate_verify(hs);
Steven Valdez2d850622017-01-11 11:34:52 -0500947 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400948 case state_send_server_finished:
David Benjaminc3c88822016-11-14 10:32:04 +0900949 ret = do_send_server_finished(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400950 break;
Steven Valdez2d850622017-01-11 11:34:52 -0500951 case state_read_second_client_flight:
952 ret = do_read_second_client_flight(hs);
953 break;
954 case state_process_end_of_early_data:
955 ret = do_process_end_of_early_data(hs);
956 break;
David Benjamin7934f082017-08-01 16:32:25 -0400957 case state_read_client_certificate:
958 ret = do_read_client_certificate(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400959 break;
David Benjamin7934f082017-08-01 16:32:25 -0400960 case state_read_client_certificate_verify:
961 ret = do_read_client_certificate_verify(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400962 break;
David Benjamin7934f082017-08-01 16:32:25 -0400963 case state_read_channel_id:
964 ret = do_read_channel_id(hs);
Nick Harper60a85cb2016-09-23 16:25:11 -0700965 break;
David Benjamin7934f082017-08-01 16:32:25 -0400966 case state_read_client_finished:
967 ret = do_read_client_finished(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400968 break;
Steven Valdez1e6f11a2016-07-27 11:10:52 -0400969 case state_send_new_session_ticket:
David Benjaminc3c88822016-11-14 10:32:04 +0900970 ret = do_send_new_session_ticket(hs);
Steven Valdez1e6f11a2016-07-27 11:10:52 -0400971 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400972 case state_done:
973 ret = ssl_hs_ok;
974 break;
975 }
976
Steven Valdez4d71a9a2017-08-14 15:08:34 -0400977 if (hs->tls13_state != state) {
David Benjaminf60bcfb2017-08-18 15:23:44 -0400978 ssl_do_info_callback(hs->ssl, SSL_CB_ACCEPT_LOOP, 1);
979 }
980
Steven Valdez143e8b32016-07-11 13:19:03 -0400981 if (ret != ssl_hs_ok) {
982 return ret;
983 }
984 }
985
986 return ssl_hs_ok;
987}
David Benjamin86e95b82017-07-18 16:34:25 -0400988
David Benjaminf60bcfb2017-08-18 15:23:44 -0400989const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs) {
990 enum server_hs_state_t state =
991 static_cast<enum server_hs_state_t>(hs->tls13_state);
992 switch (state) {
993 case state_select_parameters:
994 return "TLS 1.3 server select_parameters";
995 case state_select_session:
996 return "TLS 1.3 server select_session";
997 case state_send_hello_retry_request:
998 return "TLS 1.3 server send_hello_retry_request";
999 case state_read_second_client_hello:
1000 return "TLS 1.3 server read_second_client_hello";
1001 case state_send_server_hello:
1002 return "TLS 1.3 server send_server_hello";
1003 case state_send_server_certificate_verify:
1004 return "TLS 1.3 server send_server_certificate_verify";
1005 case state_send_server_finished:
1006 return "TLS 1.3 server send_server_finished";
1007 case state_read_second_client_flight:
1008 return "TLS 1.3 server read_second_client_flight";
David Benjaminf60bcfb2017-08-18 15:23:44 -04001009 case state_process_end_of_early_data:
1010 return "TLS 1.3 server process_end_of_early_data";
1011 case state_read_client_certificate:
1012 return "TLS 1.3 server read_client_certificate";
1013 case state_read_client_certificate_verify:
1014 return "TLS 1.3 server read_client_certificate_verify";
1015 case state_read_channel_id:
1016 return "TLS 1.3 server read_channel_id";
1017 case state_read_client_finished:
1018 return "TLS 1.3 server read_client_finished";
1019 case state_send_new_session_ticket:
1020 return "TLS 1.3 server send_new_session_ticket";
1021 case state_done:
1022 return "TLS 1.3 server done";
1023 }
1024
1025 return "TLS 1.3 server unknown";
1026}
1027
David Benjamin86e95b82017-07-18 16:34:25 -04001028} // namespace bssl