blob: a3940b640f4b4013ca98952dfa4efdbee62d7075 [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 Benjamin0cbb1af2018-07-17 21:26:05 -0400151static bool add_new_session_tickets(SSL_HANDSHAKE *hs, bool *out_sent_tickets) {
David Benjamin794cc592017-03-25 22:24:23 -0500152 SSL *const ssl = hs->ssl;
David Benjamin0cbb1af2018-07-17 21:26:05 -0400153 if (// If the client doesn't accept resumption with PSK_DHE_KE, don't send a
154 // session ticket.
155 !hs->accept_psk_mode ||
156 // We only implement stateless resumption in TLS 1.3, so skip sending
157 // tickets if disabled.
158 (SSL_get_options(ssl) & SSL_OP_NO_TICKET)) {
159 *out_sent_tickets = false;
160 return true;
161 }
162
David Benjaminc11ea9422017-08-29 16:33:21 -0400163 // TLS 1.3 recommends single-use tickets, so issue multiple tickets in case
164 // the client makes several connections before getting a renewal.
David Benjamin794cc592017-03-25 22:24:23 -0500165 static const int kNumTickets = 2;
166
David Benjaminc11ea9422017-08-29 16:33:21 -0400167 // Rebase the session timestamp so that it is measured from ticket
168 // issuance.
David Benjamin31b0c9b2017-07-20 14:49:15 -0400169 ssl_session_rebase_time(ssl, hs->new_session.get());
David Benjamin794cc592017-03-25 22:24:23 -0500170
171 for (int i = 0; i < kNumTickets; i++) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400172 UniquePtr<SSL_SESSION> session(
173 SSL_SESSION_dup(hs->new_session.get(), SSL_SESSION_INCLUDE_NONAUTH));
174 if (!session) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400175 return false;
David Benjamin794cc592017-03-25 22:24:23 -0500176 }
David Benjamin794cc592017-03-25 22:24:23 -0500177
Steven Valdezcd8470f2017-10-11 12:29:36 -0400178 if (!RAND_bytes((uint8_t *)&session->ticket_age_add, 4)) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400179 return false;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400180 }
David Benjamina3a71e92018-06-29 13:24:45 -0400181 session->ticket_age_add_valid = true;
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700182 if (ssl->enable_early_data) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400183 session->ticket_max_early_data = kMaxEarlyDataAccepted;
Steven Valdezbe165a22017-10-10 11:45:01 -0400184 }
185
Steven Valdezcd8470f2017-10-11 12:29:36 -0400186 static_assert(kNumTickets < 256, "Too many tickets");
187 uint8_t nonce[] = {static_cast<uint8_t>(i)};
188
David Benjamin1386aad2017-07-19 23:57:40 -0400189 ScopedCBB cbb;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400190 CBB body, nonce_cbb, ticket, extensions;
David Benjamin1386aad2017-07-19 23:57:40 -0400191 if (!ssl->method->init_message(ssl, cbb.get(), &body,
David Benjamin794cc592017-03-25 22:24:23 -0500192 SSL3_MT_NEW_SESSION_TICKET) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400193 !CBB_add_u32(&body, session->timeout) ||
194 !CBB_add_u32(&body, session->ticket_age_add) ||
Steven Valdez7e5dd252018-01-22 15:20:31 -0500195 !CBB_add_u8_length_prefixed(&body, &nonce_cbb) ||
196 !CBB_add_bytes(&nonce_cbb, nonce, sizeof(nonce)) ||
David Benjamin794cc592017-03-25 22:24:23 -0500197 !CBB_add_u16_length_prefixed(&body, &ticket) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400198 !tls13_derive_session_psk(session.get(), nonce) ||
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700199 !ssl_encrypt_ticket(hs, &ticket, session.get()) ||
David Benjamin794cc592017-03-25 22:24:23 -0500200 !CBB_add_u16_length_prefixed(&body, &extensions)) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400201 return false;
David Benjamin794cc592017-03-25 22:24:23 -0500202 }
203
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700204 if (ssl->enable_early_data) {
David Benjamin794cc592017-03-25 22:24:23 -0500205 CBB early_data_info;
Steven Valdez7e5dd252018-01-22 15:20:31 -0500206 if (!CBB_add_u16(&extensions, TLSEXT_TYPE_early_data) ||
David Benjamin794cc592017-03-25 22:24:23 -0500207 !CBB_add_u16_length_prefixed(&extensions, &early_data_info) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400208 !CBB_add_u32(&early_data_info, session->ticket_max_early_data) ||
David Benjamin794cc592017-03-25 22:24:23 -0500209 !CBB_flush(&extensions)) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400210 return false;
David Benjamin794cc592017-03-25 22:24:23 -0500211 }
212 }
213
David Benjaminc11ea9422017-08-29 16:33:21 -0400214 // Add a fake extension. See draft-davidben-tls-grease-01.
David Benjamin794cc592017-03-25 22:24:23 -0500215 if (!CBB_add_u16(&extensions,
David Benjamina7bc9442018-01-18 10:08:53 -0500216 ssl_get_grease_value(hs, ssl_grease_ticket_extension)) ||
David Benjamin794cc592017-03-25 22:24:23 -0500217 !CBB_add_u16(&extensions, 0 /* empty */)) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400218 return false;
David Benjamin794cc592017-03-25 22:24:23 -0500219 }
220
David Benjamin1386aad2017-07-19 23:57:40 -0400221 if (!ssl_add_message_cbb(ssl, cbb.get())) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400222 return false;
David Benjamin794cc592017-03-25 22:24:23 -0500223 }
224 }
225
David Benjamin0cbb1af2018-07-17 21:26:05 -0400226 *out_sent_tickets = true;
227 return true;
David Benjamin794cc592017-03-25 22:24:23 -0500228}
229
David Benjaminc3c88822016-11-14 10:32:04 +0900230static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400231 // At this point, most ClientHello extensions have already been processed by
232 // the common handshake logic. Resolve the remaining non-PSK parameters.
David Benjaminc3c88822016-11-14 10:32:04 +0900233 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400234 SSLMessage msg;
235 if (!ssl->method->get_message(ssl, &msg)) {
236 return ssl_hs_read_message;
237 }
David Benjamin731058e2016-12-03 23:15:13 -0500238 SSL_CLIENT_HELLO client_hello;
David Benjamin7934f082017-08-01 16:32:25 -0400239 if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
David Benjamin34202b92016-11-16 19:07:53 +0900240 OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400241 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
David Benjamin34202b92016-11-16 19:07:53 +0900242 return ssl_hs_error;
243 }
244
Steven Valdez520e1222017-06-13 12:45:25 -0400245 OPENSSL_memcpy(hs->session_id, client_hello.session_id,
246 client_hello.session_id_len);
247 hs->session_id_len = client_hello.session_id_len;
248
David Benjaminc11ea9422017-08-29 16:33:21 -0400249 // Negotiate the cipher suite.
David Benjamin45738dd2017-02-09 20:01:26 -0500250 hs->new_cipher = choose_tls13_cipher(ssl, &client_hello);
251 if (hs->new_cipher == NULL) {
David Benjaminf01f42a2016-11-16 19:05:33 +0900252 OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER);
David Benjamind1e3ce12017-10-06 18:31:15 -0400253 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
David Benjaminf01f42a2016-11-16 19:05:33 +0900254 return ssl_hs_error;
255 }
256
David Benjaminc11ea9422017-08-29 16:33:21 -0400257 // HTTP/2 negotiation depends on the cipher suite, so ALPN negotiation was
258 // deferred. Complete it now.
David Benjamin707af292017-03-10 17:47:18 -0500259 uint8_t alert = SSL_AD_DECODE_ERROR;
260 if (!ssl_negotiate_alpn(hs, &alert, &client_hello)) {
David Benjamind1e3ce12017-10-06 18:31:15 -0400261 ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
David Benjamin707af292017-03-10 17:47:18 -0500262 return ssl_hs_error;
263 }
264
David Benjaminc11ea9422017-08-29 16:33:21 -0400265 // The PRF hash is now known. Set up the key schedule and hash the
266 // ClientHello.
Steven Valdezcd8470f2017-10-11 12:29:36 -0400267 if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher)) {
268 return ssl_hs_error;
269 }
270
271 if (!ssl_hash_message(hs, msg)) {
Steven Valdez908ac192017-01-12 13:17:07 -0500272 return ssl_hs_error;
273 }
274
David Benjamin707af292017-03-10 17:47:18 -0500275 hs->tls13_state = state_select_session;
276 return ssl_hs_ok;
277}
Steven Valdez908ac192017-01-12 13:17:07 -0500278
David Benjamin707af292017-03-10 17:47:18 -0500279static enum ssl_ticket_aead_result_t select_session(
David Benjamin37af90f2017-07-29 01:42:16 -0400280 SSL_HANDSHAKE *hs, uint8_t *out_alert, UniquePtr<SSL_SESSION> *out_session,
David Benjamin7934f082017-08-01 16:32:25 -0400281 int32_t *out_ticket_age_skew, const SSLMessage &msg,
282 const SSL_CLIENT_HELLO *client_hello) {
David Benjamin707af292017-03-10 17:47:18 -0500283 SSL *const ssl = hs->ssl;
284 *out_session = NULL;
285
David Benjaminc11ea9422017-08-29 16:33:21 -0400286 // Decode the ticket if we agreed on a PSK key exchange mode.
David Benjamin707af292017-03-10 17:47:18 -0500287 CBS pre_shared_key;
288 if (!hs->accept_psk_mode ||
289 !ssl_client_hello_get_extension(client_hello, &pre_shared_key,
290 TLSEXT_TYPE_pre_shared_key)) {
291 return ssl_ticket_aead_ignore_ticket;
292 }
293
David Benjaminc11ea9422017-08-29 16:33:21 -0400294 // Verify that the pre_shared_key extension is the last extension in
295 // ClientHello.
David Benjamin707af292017-03-10 17:47:18 -0500296 if (CBS_data(&pre_shared_key) + CBS_len(&pre_shared_key) !=
297 client_hello->extensions + client_hello->extensions_len) {
298 OPENSSL_PUT_ERROR(SSL, SSL_R_PRE_SHARED_KEY_MUST_BE_LAST);
299 *out_alert = SSL_AD_ILLEGAL_PARAMETER;
300 return ssl_ticket_aead_error;
301 }
302
303 CBS ticket, binders;
304 uint32_t client_ticket_age;
305 if (!ssl_ext_pre_shared_key_parse_clienthello(hs, &ticket, &binders,
306 &client_ticket_age, out_alert,
307 &pre_shared_key)) {
308 return ssl_ticket_aead_error;
309 }
310
David Benjaminc11ea9422017-08-29 16:33:21 -0400311 // TLS 1.3 session tickets are renewed separately as part of the
312 // NewSessionTicket.
David Benjaminfd45ee72017-08-31 14:49:09 -0400313 bool unused_renew;
David Benjamin37af90f2017-07-29 01:42:16 -0400314 UniquePtr<SSL_SESSION> session;
David Benjamin707af292017-03-10 17:47:18 -0500315 enum ssl_ticket_aead_result_t ret =
David Benjamin28655672018-07-18 23:23:25 -0400316 ssl_process_ticket(hs, &session, &unused_renew, ticket, {});
David Benjamin707af292017-03-10 17:47:18 -0500317 switch (ret) {
318 case ssl_ticket_aead_success:
319 break;
320 case ssl_ticket_aead_error:
321 *out_alert = SSL_AD_INTERNAL_ERROR;
322 return ret;
323 default:
324 return ret;
325 }
326
David Benjamin37af90f2017-07-29 01:42:16 -0400327 if (!ssl_session_is_resumable(hs, session.get()) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400328 // Historically, some TLS 1.3 tickets were missing ticket_age_add.
David Benjamin707af292017-03-10 17:47:18 -0500329 !session->ticket_age_add_valid) {
David Benjamin707af292017-03-10 17:47:18 -0500330 return ssl_ticket_aead_ignore_ticket;
331 }
332
David Benjaminc11ea9422017-08-29 16:33:21 -0400333 // Recover the client ticket age and convert to seconds.
David Benjamin707af292017-03-10 17:47:18 -0500334 client_ticket_age -= session->ticket_age_add;
335 client_ticket_age /= 1000;
336
337 struct OPENSSL_timeval now;
338 ssl_get_current_time(ssl, &now);
339
David Benjaminc11ea9422017-08-29 16:33:21 -0400340 // Compute the server ticket age in seconds.
David Benjamin707af292017-03-10 17:47:18 -0500341 assert(now.tv_sec >= session->time);
342 uint64_t server_ticket_age = now.tv_sec - session->time;
343
David Benjaminc11ea9422017-08-29 16:33:21 -0400344 // To avoid overflowing |hs->ticket_age_skew|, we will not resume
345 // 68-year-old sessions.
David Benjamin707af292017-03-10 17:47:18 -0500346 if (server_ticket_age > INT32_MAX) {
David Benjamin707af292017-03-10 17:47:18 -0500347 return ssl_ticket_aead_ignore_ticket;
348 }
349
David Benjaminc11ea9422017-08-29 16:33:21 -0400350 // TODO(davidben,svaldez): Measure this value to decide on tolerance. For
351 // now, accept all values. https://crbug.com/boringssl/113.
David Benjamin707af292017-03-10 17:47:18 -0500352 *out_ticket_age_skew =
353 (int32_t)client_ticket_age - (int32_t)server_ticket_age;
354
David Benjaminc11ea9422017-08-29 16:33:21 -0400355 // Check the PSK binder.
David Benjamin7934f082017-08-01 16:32:25 -0400356 if (!tls13_verify_psk_binder(hs, session.get(), msg, &binders)) {
David Benjamin707af292017-03-10 17:47:18 -0500357 *out_alert = SSL_AD_DECRYPT_ERROR;
358 return ssl_ticket_aead_error;
359 }
360
David Benjamin37af90f2017-07-29 01:42:16 -0400361 *out_session = std::move(session);
David Benjamin707af292017-03-10 17:47:18 -0500362 return ssl_ticket_aead_success;
363}
364
365static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
366 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400367 SSLMessage msg;
368 if (!ssl->method->get_message(ssl, &msg)) {
369 return ssl_hs_read_message;
370 }
David Benjamin707af292017-03-10 17:47:18 -0500371 SSL_CLIENT_HELLO client_hello;
David Benjamin7934f082017-08-01 16:32:25 -0400372 if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
David Benjamin707af292017-03-10 17:47:18 -0500373 OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400374 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
David Benjamin707af292017-03-10 17:47:18 -0500375 return ssl_hs_error;
376 }
377
David Benjamin4eb95cc2016-11-16 17:08:23 +0900378 uint8_t alert = SSL_AD_DECODE_ERROR;
David Benjamin37af90f2017-07-29 01:42:16 -0400379 UniquePtr<SSL_SESSION> session;
David Benjamin7934f082017-08-01 16:32:25 -0400380 switch (select_session(hs, &alert, &session, &ssl->s3->ticket_age_skew, msg,
David Benjamin707af292017-03-10 17:47:18 -0500381 &client_hello)) {
382 case ssl_ticket_aead_ignore_ticket:
David Benjamin37af90f2017-07-29 01:42:16 -0400383 assert(!session);
David Benjamin707af292017-03-10 17:47:18 -0500384 if (!ssl_get_new_session(hs, 1 /* server */)) {
David Benjamind1e3ce12017-10-06 18:31:15 -0400385 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjaminf01f42a2016-11-16 19:05:33 +0900386 return ssl_hs_error;
387 }
David Benjamin707af292017-03-10 17:47:18 -0500388 break;
Steven Valdeza833c352016-11-01 13:39:36 -0400389
David Benjamin707af292017-03-10 17:47:18 -0500390 case ssl_ticket_aead_success:
David Benjaminc11ea9422017-08-29 16:33:21 -0400391 // Carry over authentication information from the previous handshake into
392 // a fresh session.
David Benjamin37af90f2017-07-29 01:42:16 -0400393 hs->new_session =
394 SSL_SESSION_dup(session.get(), SSL_SESSION_DUP_AUTH_ONLY);
Steven Valdez2d850622017-01-11 11:34:52 -0500395
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700396 if (ssl->enable_early_data &&
David Benjamin8e7bbba2017-10-13 17:18:35 -0400397 // Early data must be acceptable for this ticket.
Steven Valdez2d850622017-01-11 11:34:52 -0500398 session->ticket_max_early_data != 0 &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400399 // The client must have offered early data.
Steven Valdez2d850622017-01-11 11:34:52 -0500400 hs->early_data_offered &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400401 // Channel ID is incompatible with 0-RTT.
David Benjamin46853762018-07-03 14:01:26 -0400402 !ssl->s3->channel_id_valid &&
Nick Harper36fcc4c2017-09-21 15:02:22 -0700403 // If Token Binding is negotiated, reject 0-RTT.
David Benjamin9f0e7cb2018-04-12 15:36:30 -0400404 !ssl->s3->token_binding_negotiated &&
David Benjaminc11ea9422017-08-29 16:33:21 -0400405 // The negotiated ALPN must match the one in the ticket.
David Benjaminbfdd1a92018-06-29 16:26:38 -0400406 MakeConstSpan(ssl->s3->alpn_selected) == session->early_alpn) {
David Benjamin02e62562017-12-18 18:04:01 -0500407 ssl->s3->early_data_accepted = true;
Steven Valdez2d850622017-01-11 11:34:52 -0500408 }
409
David Benjamin707af292017-03-10 17:47:18 -0500410 if (hs->new_session == NULL) {
David Benjamind1e3ce12017-10-06 18:31:15 -0400411 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjamin707af292017-03-10 17:47:18 -0500412 return ssl_hs_error;
413 }
414
David Benjamin046bc1f2017-08-31 15:06:42 -0400415 ssl->s3->session_reused = true;
David Benjamin707af292017-03-10 17:47:18 -0500416
David Benjaminc11ea9422017-08-29 16:33:21 -0400417 // Resumption incorporates fresh key material, so refresh the timeout.
David Benjamin98472cb2018-05-02 16:05:36 -0400418 ssl_session_renew_timeout(ssl, hs->new_session.get(),
419 ssl->session_ctx->session_psk_dhe_timeout);
David Benjamin707af292017-03-10 17:47:18 -0500420 break;
421
422 case ssl_ticket_aead_error:
David Benjamind1e3ce12017-10-06 18:31:15 -0400423 ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
David Benjamin707af292017-03-10 17:47:18 -0500424 return ssl_hs_error;
425
426 case ssl_ticket_aead_retry:
427 hs->tls13_state = state_select_session;
428 return ssl_hs_pending_ticket;
429 }
430
David Benjaminc11ea9422017-08-29 16:33:21 -0400431 // Record connection properties in the new session.
David Benjamin707af292017-03-10 17:47:18 -0500432 hs->new_session->cipher = hs->new_cipher;
433
David Benjaminc11ea9422017-08-29 16:33:21 -0400434 // Store the initial negotiated ALPN in the session.
David Benjaminbfdd1a92018-06-29 16:26:38 -0400435 if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
436 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
437 return ssl_hs_error;
Steven Valdez27a9e6a2017-02-14 13:20:40 -0500438 }
439
David Benjamin707af292017-03-10 17:47:18 -0500440 if (ssl->ctx->dos_protection_cb != NULL &&
441 ssl->ctx->dos_protection_cb(&client_hello) == 0) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400442 // Connection rejected for DOS reasons.
David Benjamin707af292017-03-10 17:47:18 -0500443 OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400444 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
David Benjamin707af292017-03-10 17:47:18 -0500445 return ssl_hs_error;
446 }
447
Steven Valdezcd8470f2017-10-11 12:29:36 -0400448 size_t hash_len = EVP_MD_size(
449 ssl_get_handshake_digest(ssl_protocol_version(ssl), hs->new_cipher));
450
451 // Set up the key schedule and incorporate the PSK into the running secret.
David Benjamin8f820b42016-11-30 11:24:40 -0500452 if (ssl->s3->session_reused) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400453 if (!tls13_init_key_schedule(hs, hs->new_session->master_key,
David Benjamin45738dd2017-02-09 20:01:26 -0500454 hs->new_session->master_key_length)) {
David Benjamin8f820b42016-11-30 11:24:40 -0500455 return ssl_hs_error;
456 }
Steven Valdezcd8470f2017-10-11 12:29:36 -0400457 } else if (!tls13_init_key_schedule(hs, kZeroes, hash_len)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400458 return ssl_hs_error;
459 }
460
David Benjamin02e62562017-12-18 18:04:01 -0500461 if (ssl->s3->early_data_accepted) {
Steven Valdez2d850622017-01-11 11:34:52 -0500462 if (!tls13_derive_early_secrets(hs)) {
463 return ssl_hs_error;
464 }
465 } else if (hs->early_data_offered) {
David Benjamin046bc1f2017-08-31 15:06:42 -0400466 ssl->s3->skip_early_data = true;
Steven Valdez2d850622017-01-11 11:34:52 -0500467 }
468
David Benjaminc11ea9422017-08-29 16:33:21 -0400469 // Resolve ECDHE and incorporate it into the secret.
David Benjamin046bc1f2017-08-31 15:06:42 -0400470 bool need_retry;
David Benjamin6e4fc332016-11-17 16:43:08 +0900471 if (!resolve_ecdhe_secret(hs, &need_retry, &client_hello)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400472 if (need_retry) {
David Benjamin02e62562017-12-18 18:04:01 -0500473 ssl->s3->early_data_accepted = false;
David Benjamin046bc1f2017-08-31 15:06:42 -0400474 ssl->s3->skip_early_data = true;
David Benjamin8f94c312017-08-01 17:35:55 -0400475 ssl->method->next_message(ssl);
Steven Valdez7e5dd252018-01-22 15:20:31 -0500476 if (!hs->transcript.UpdateForHelloRetryRequest()) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400477 return ssl_hs_error;
478 }
David Benjamin3977f302016-12-11 13:30:41 -0500479 hs->tls13_state = state_send_hello_retry_request;
Steven Valdez5440fe02016-07-18 12:40:30 -0400480 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400481 }
Steven Valdez5440fe02016-07-18 12:40:30 -0400482 return ssl_hs_error;
483 }
Steven Valdez143e8b32016-07-11 13:19:03 -0400484
David Benjamin8f94c312017-08-01 17:35:55 -0400485 ssl->method->next_message(ssl);
David Benjamin3977f302016-12-11 13:30:41 -0500486 hs->tls13_state = state_send_server_hello;
Steven Valdez5440fe02016-07-18 12:40:30 -0400487 return ssl_hs_ok;
488}
Steven Valdez143e8b32016-07-11 13:19:03 -0400489
David Benjaminc3c88822016-11-14 10:32:04 +0900490static enum ssl_hs_wait_t do_send_hello_retry_request(SSL_HANDSHAKE *hs) {
491 SSL *const ssl = hs->ssl;
Steven Valdez964b2372017-11-07 17:09:52 -0500492
493
Steven Valdez7e5dd252018-01-22 15:20:31 -0500494 ScopedCBB cbb;
495 CBB body, session_id, extensions;
496 uint16_t group_id;
497 if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
498 !CBB_add_u16(&body, TLS1_2_VERSION) ||
499 !CBB_add_bytes(&body, kHelloRetryRequest, SSL3_RANDOM_SIZE) ||
500 !CBB_add_u8_length_prefixed(&body, &session_id) ||
501 !CBB_add_bytes(&session_id, hs->session_id, hs->session_id_len) ||
502 !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
503 !CBB_add_u8(&body, 0 /* no compression */) ||
504 !tls1_get_shared_group(hs, &group_id) ||
505 !CBB_add_u16_length_prefixed(&body, &extensions) ||
506 !CBB_add_u16(&extensions, TLSEXT_TYPE_supported_versions) ||
507 !CBB_add_u16(&extensions, 2 /* length */) ||
508 !CBB_add_u16(&extensions, ssl->version) ||
509 !CBB_add_u16(&extensions, TLSEXT_TYPE_key_share) ||
510 !CBB_add_u16(&extensions, 2 /* length */) ||
511 !CBB_add_u16(&extensions, group_id) ||
512 !ssl_add_message_cbb(ssl, cbb.get())) {
513 return ssl_hs_error;
514 }
Steven Valdez964b2372017-11-07 17:09:52 -0500515
Steven Valdez7e5dd252018-01-22 15:20:31 -0500516 if (!ssl->method->add_change_cipher_spec(ssl)) {
517 return ssl_hs_error;
Steven Valdez5440fe02016-07-18 12:40:30 -0400518 }
519
Steven Valdez964b2372017-11-07 17:09:52 -0500520 hs->sent_hello_retry_request = true;
David Benjamin7934f082017-08-01 16:32:25 -0400521 hs->tls13_state = state_read_second_client_hello;
522 return ssl_hs_flush;
Steven Valdez5440fe02016-07-18 12:40:30 -0400523}
524
David Benjamin7934f082017-08-01 16:32:25 -0400525static enum ssl_hs_wait_t do_read_second_client_hello(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900526 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400527 SSLMessage msg;
528 if (!ssl->method->get_message(ssl, &msg)) {
529 return ssl_hs_read_message;
530 }
531 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CLIENT_HELLO)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400532 return ssl_hs_error;
533 }
David Benjamin731058e2016-12-03 23:15:13 -0500534 SSL_CLIENT_HELLO client_hello;
David Benjamin7934f082017-08-01 16:32:25 -0400535 if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400536 OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
David Benjamind1e3ce12017-10-06 18:31:15 -0400537 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
Steven Valdez5440fe02016-07-18 12:40:30 -0400538 return ssl_hs_error;
539 }
540
David Benjamin046bc1f2017-08-31 15:06:42 -0400541 bool need_retry;
David Benjamin6e4fc332016-11-17 16:43:08 +0900542 if (!resolve_ecdhe_secret(hs, &need_retry, &client_hello)) {
Steven Valdez5440fe02016-07-18 12:40:30 -0400543 if (need_retry) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400544 // Only send one HelloRetryRequest.
David Benjamind1e3ce12017-10-06 18:31:15 -0400545 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
Steven Valdez5440fe02016-07-18 12:40:30 -0400546 OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
Steven Valdez143e8b32016-07-11 13:19:03 -0400547 }
Steven Valdez5440fe02016-07-18 12:40:30 -0400548 return ssl_hs_error;
549 }
550
David Benjamin7934f082017-08-01 16:32:25 -0400551 if (!ssl_hash_message(hs, msg)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400552 return ssl_hs_error;
553 }
554
David Benjamin8f94c312017-08-01 17:35:55 -0400555 ssl->method->next_message(ssl);
David Benjamin3977f302016-12-11 13:30:41 -0500556 hs->tls13_state = state_send_server_hello;
Steven Valdez143e8b32016-07-11 13:19:03 -0400557 return ssl_hs_ok;
558}
559
David Benjaminc3c88822016-11-14 10:32:04 +0900560static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
561 SSL *const ssl = hs->ssl;
David Benjamin81b7bc32017-01-12 19:44:57 -0500562
David Benjaminc11ea9422017-08-29 16:33:21 -0400563 // Send a ServerHello.
David Benjamin1386aad2017-07-19 23:57:40 -0400564 ScopedCBB cbb;
565 CBB body, extensions, session_id;
566 if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500567 !CBB_add_u16(&body, TLS1_2_VERSION) ||
Steven Valdez143e8b32016-07-11 13:19:03 -0400568 !RAND_bytes(ssl->s3->server_random, sizeof(ssl->s3->server_random)) ||
569 !CBB_add_bytes(&body, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500570 !CBB_add_u8_length_prefixed(&body, &session_id) ||
571 !CBB_add_bytes(&session_id, hs->session_id, hs->session_id_len) ||
David Benjamin45738dd2017-02-09 20:01:26 -0500572 !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500573 !CBB_add_u8(&body, 0) ||
Steven Valdez143e8b32016-07-11 13:19:03 -0400574 !CBB_add_u16_length_prefixed(&body, &extensions) ||
David Benjamin8baf9632016-11-17 17:11:16 +0900575 !ssl_ext_pre_shared_key_add_serverhello(hs, &extensions) ||
Steven Valdez924a3522017-03-02 16:05:03 -0500576 !ssl_ext_key_share_add_serverhello(hs, &extensions) ||
Steven Valdez64cc1212017-12-04 11:15:37 -0500577 !ssl_ext_supported_versions_add_serverhello(hs, &extensions) ||
David Benjamin1386aad2017-07-19 23:57:40 -0400578 !ssl_add_message_cbb(ssl, cbb.get())) {
579 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400580 }
581
Steven Valdez7e5dd252018-01-22 15:20:31 -0500582 if (!hs->sent_hello_retry_request &&
David Benjamin666d16e2017-10-06 18:45:16 -0400583 !ssl->method->add_change_cipher_spec(ssl)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400584 return ssl_hs_error;
Steven Valdez520e1222017-06-13 12:45:25 -0400585 }
586
David Benjaminc11ea9422017-08-29 16:33:21 -0400587 // Derive and enable the handshake traffic secrets.
Steven Valdez4cb84942016-12-16 11:29:28 -0500588 if (!tls13_derive_handshake_secrets(hs) ||
Steven Valdez4cb84942016-12-16 11:29:28 -0500589 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->server_handshake_secret,
590 hs->hash_len)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400591 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400592 }
593
David Benjaminc11ea9422017-08-29 16:33:21 -0400594 // Send EncryptedExtensions.
David Benjamin1386aad2017-07-19 23:57:40 -0400595 if (!ssl->method->init_message(ssl, cbb.get(), &body,
Steven Valdez143e8b32016-07-11 13:19:03 -0400596 SSL3_MT_ENCRYPTED_EXTENSIONS) ||
David Benjamin8c880a22016-12-03 02:20:34 -0500597 !ssl_add_serverhello_tlsext(hs, &body) ||
David Benjamin1386aad2017-07-19 23:57:40 -0400598 !ssl_add_message_cbb(ssl, cbb.get())) {
599 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400600 }
601
David Benjaminc3648fa2017-07-01 10:50:56 -0400602 if (!ssl->s3->session_reused) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400603 // Determine whether to request a client certificate.
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700604 hs->cert_request = !!(hs->config->verify_mode & SSL_VERIFY_PEER);
David Benjaminc11ea9422017-08-29 16:33:21 -0400605 // Only request a certificate if Channel ID isn't negotiated.
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700606 if ((hs->config->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
David Benjamin46853762018-07-03 14:01:26 -0400607 ssl->s3->channel_id_valid) {
David Benjaminfd45ee72017-08-31 14:49:09 -0400608 hs->cert_request = false;
David Benjaminc3648fa2017-07-01 10:50:56 -0400609 }
Steven Valdez143e8b32016-07-11 13:19:03 -0400610 }
611
David Benjaminc11ea9422017-08-29 16:33:21 -0400612 // Send a CertificateRequest, if necessary.
David Benjamin81b7bc32017-01-12 19:44:57 -0500613 if (hs->cert_request) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500614 CBB cert_request_extensions, sigalg_contents, sigalgs_cbb;
615 if (!ssl->method->init_message(ssl, cbb.get(), &body,
616 SSL3_MT_CERTIFICATE_REQUEST) ||
617 !CBB_add_u8(&body, 0 /* no certificate_request_context. */) ||
618 !CBB_add_u16_length_prefixed(&body, &cert_request_extensions) ||
619 !CBB_add_u16(&cert_request_extensions,
620 TLSEXT_TYPE_signature_algorithms) ||
621 !CBB_add_u16_length_prefixed(&cert_request_extensions,
622 &sigalg_contents) ||
623 !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
David Benjamine28552d2018-04-08 13:59:25 -0400624 !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb,
625 false /* online signature */)) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500626 return ssl_hs_error;
627 }
628
David Benjamine28552d2018-04-08 13:59:25 -0400629 if (tls12_has_different_verify_sigalgs_for_certs(ssl)) {
630 if (!CBB_add_u16(&cert_request_extensions,
631 TLSEXT_TYPE_signature_algorithms_cert) ||
632 !CBB_add_u16_length_prefixed(&cert_request_extensions,
633 &sigalg_contents) ||
634 !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
635 !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb, true /* certs */)) {
636 return ssl_hs_error;
637 }
638 }
639
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700640 if (ssl_has_client_CAs(hs->config)) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500641 CBB ca_contents;
642 if (!CBB_add_u16(&cert_request_extensions,
643 TLSEXT_TYPE_certificate_authorities) ||
Steven Valdezcd8470f2017-10-11 12:29:36 -0400644 !CBB_add_u16_length_prefixed(&cert_request_extensions,
Steven Valdez7e5dd252018-01-22 15:20:31 -0500645 &ca_contents) ||
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700646 !ssl_add_client_CA_list(hs, &ca_contents) ||
Steven Valdez7e5dd252018-01-22 15:20:31 -0500647 !CBB_flush(&cert_request_extensions)) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400648 return ssl_hs_error;
649 }
Steven Valdez7e5dd252018-01-22 15:20:31 -0500650 }
Steven Valdezcd8470f2017-10-11 12:29:36 -0400651
Steven Valdez7e5dd252018-01-22 15:20:31 -0500652 if (!ssl_add_message_cbb(ssl, cbb.get())) {
653 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400654 }
655 }
656
David Benjaminc11ea9422017-08-29 16:33:21 -0400657 // Send the server Certificate message, if necessary.
David Benjamin81b7bc32017-01-12 19:44:57 -0500658 if (!ssl->s3->session_reused) {
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700659 if (!ssl_has_certificate(hs->config)) {
David Benjamin81b7bc32017-01-12 19:44:57 -0500660 OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET);
David Benjamin1386aad2017-07-19 23:57:40 -0400661 return ssl_hs_error;
David Benjamin81b7bc32017-01-12 19:44:57 -0500662 }
663
David Benjamin0f24bed2017-01-12 19:46:50 -0500664 if (!tls13_add_certificate(hs)) {
David Benjamin1386aad2017-07-19 23:57:40 -0400665 return ssl_hs_error;
David Benjamin81b7bc32017-01-12 19:44:57 -0500666 }
667
668 hs->tls13_state = state_send_server_certificate_verify;
669 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400670 }
671
David Benjamin81b7bc32017-01-12 19:44:57 -0500672 hs->tls13_state = state_send_server_finished;
David Benjamin25ac2512017-01-12 19:31:28 -0500673 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400674}
675
David Benjamin44148742017-06-17 13:20:59 -0400676static enum ssl_hs_wait_t do_send_server_certificate_verify(SSL_HANDSHAKE *hs) {
677 switch (tls13_add_certificate_verify(hs)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400678 case ssl_private_key_success:
David Benjamin3977f302016-12-11 13:30:41 -0500679 hs->tls13_state = state_send_server_finished;
David Benjamin25ac2512017-01-12 19:31:28 -0500680 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400681
682 case ssl_private_key_retry:
David Benjamin44148742017-06-17 13:20:59 -0400683 hs->tls13_state = state_send_server_certificate_verify;
Steven Valdez143e8b32016-07-11 13:19:03 -0400684 return ssl_hs_private_key_operation;
685
686 case ssl_private_key_failure:
687 return ssl_hs_error;
688 }
689
690 assert(0);
691 return ssl_hs_error;
692}
693
David Benjaminc3c88822016-11-14 10:32:04 +0900694static enum ssl_hs_wait_t do_send_server_finished(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900695 SSL *const ssl = hs->ssl;
David Benjamin0f24bed2017-01-12 19:46:50 -0500696 if (!tls13_add_finished(hs) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400697 // Update the secret to the master secret and derive traffic keys.
David Benjamin25ac2512017-01-12 19:31:28 -0500698 !tls13_advance_key_schedule(hs, kZeroes, hs->hash_len) ||
David Benjamin6e4fc332016-11-17 16:43:08 +0900699 !tls13_derive_application_secrets(hs) ||
Steven Valdeza833c352016-11-01 13:39:36 -0400700 !tls13_set_traffic_key(ssl, evp_aead_seal, hs->server_traffic_secret_0,
701 hs->hash_len)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400702 return ssl_hs_error;
703 }
704
David Benjamin02e62562017-12-18 18:04:01 -0500705 if (ssl->s3->early_data_accepted) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400706 // If accepting 0-RTT, we send tickets half-RTT. This gets the tickets on
707 // the wire sooner and also avoids triggering a write on |SSL_read| when
708 // processing the client Finished. This requires computing the client
709 // Finished early. See draft-ietf-tls-tls13-18, section 4.5.1.
Steven Valdez7e5dd252018-01-22 15:20:31 -0500710 static const uint8_t kEndOfEarlyData[4] = {SSL3_MT_END_OF_EARLY_DATA, 0,
711 0, 0};
712 if (!hs->transcript.Update(kEndOfEarlyData)) {
713 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
714 return ssl_hs_error;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400715 }
716
David Benjamin794cc592017-03-25 22:24:23 -0500717 size_t finished_len;
718 if (!tls13_finished_mac(hs, hs->expected_client_finished, &finished_len,
719 0 /* client */)) {
720 return ssl_hs_error;
721 }
722
723 if (finished_len != hs->hash_len) {
724 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
725 return ssl_hs_error;
726 }
727
David Benjaminc11ea9422017-08-29 16:33:21 -0400728 // Feed the predicted Finished into the transcript. This allows us to derive
729 // the resumption secret early and send half-RTT tickets.
730 //
731 // TODO(davidben): This will need to be updated for DTLS 1.3.
David Benjamin794cc592017-03-25 22:24:23 -0500732 assert(!SSL_is_dtls(hs->ssl));
David Benjamind304a2f2017-07-12 23:00:28 -0400733 assert(hs->hash_len <= 0xff);
David Benjamin6dc8bf62017-07-19 16:38:21 -0400734 uint8_t header[4] = {SSL3_MT_FINISHED, 0, 0,
735 static_cast<uint8_t>(hs->hash_len)};
David Benjamin0cbb1af2018-07-17 21:26:05 -0400736 bool unused_sent_tickets;
David Benjamin75a1f232017-10-11 17:19:19 -0400737 if (!hs->transcript.Update(header) ||
738 !hs->transcript.Update(
739 MakeConstSpan(hs->expected_client_finished, hs->hash_len)) ||
David Benjamin8f94c312017-08-01 17:35:55 -0400740 !tls13_derive_resumption_secret(hs) ||
David Benjamin0cbb1af2018-07-17 21:26:05 -0400741 !add_new_session_tickets(hs, &unused_sent_tickets)) {
David Benjamin794cc592017-03-25 22:24:23 -0500742 return ssl_hs_error;
743 }
744 }
745
Steven Valdez2d850622017-01-11 11:34:52 -0500746 hs->tls13_state = state_read_second_client_flight;
747 return ssl_hs_flush;
748}
749
750static enum ssl_hs_wait_t do_read_second_client_flight(SSL_HANDSHAKE *hs) {
751 SSL *const ssl = hs->ssl;
David Benjamin02e62562017-12-18 18:04:01 -0500752 if (ssl->s3->early_data_accepted) {
Steven Valdez2d850622017-01-11 11:34:52 -0500753 if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->early_traffic_secret,
754 hs->hash_len)) {
755 return ssl_hs_error;
756 }
David Benjaminfd45ee72017-08-31 14:49:09 -0400757 hs->can_early_write = true;
758 hs->can_early_read = true;
759 hs->in_early_data = true;
Steven Valdez2d850622017-01-11 11:34:52 -0500760 }
Steven Valdez2d850622017-01-11 11:34:52 -0500761 hs->tls13_state = state_process_end_of_early_data;
David Benjamin02e62562017-12-18 18:04:01 -0500762 return ssl->s3->early_data_accepted ? ssl_hs_read_end_of_early_data
763 : ssl_hs_ok;
Steven Valdez2d850622017-01-11 11:34:52 -0500764}
765
766static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) {
Steven Valdezcd8470f2017-10-11 12:29:36 -0400767 SSL *const ssl = hs->ssl;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400768 if (hs->early_data_offered) {
769 // If early data was not accepted, the EndOfEarlyData and ChangeCipherSpec
770 // message will be in the discarded early data.
David Benjamin02e62562017-12-18 18:04:01 -0500771 if (hs->ssl->s3->early_data_accepted) {
Steven Valdez7e5dd252018-01-22 15:20:31 -0500772 SSLMessage msg;
773 if (!ssl->method->get_message(ssl, &msg)) {
774 return ssl_hs_read_message;
Steven Valdezcd8470f2017-10-11 12:29:36 -0400775 }
Steven Valdez7e5dd252018-01-22 15:20:31 -0500776
777 if (!ssl_check_message_type(ssl, msg, SSL3_MT_END_OF_EARLY_DATA)) {
778 return ssl_hs_error;
779 }
780 if (CBS_len(&msg.body) != 0) {
781 ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
782 OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
783 return ssl_hs_error;
784 }
785 ssl->method->next_message(ssl);
Steven Valdezcd8470f2017-10-11 12:29:36 -0400786 }
Steven Valdez520e1222017-06-13 12:45:25 -0400787 }
Steven Valdez2d850622017-01-11 11:34:52 -0500788 if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->client_handshake_secret,
789 hs->hash_len)) {
790 return ssl_hs_error;
791 }
David Benjamin02e62562017-12-18 18:04:01 -0500792 hs->tls13_state = ssl->s3->early_data_accepted
793 ? state_read_client_finished
794 : state_read_client_certificate;
David Benjamin7934f082017-08-01 16:32:25 -0400795 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400796}
797
David Benjamin7934f082017-08-01 16:32:25 -0400798static enum ssl_hs_wait_t do_read_client_certificate(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900799 SSL *const ssl = hs->ssl;
800 if (!hs->cert_request) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400801 // OpenSSL returns X509_V_OK when no certificates are requested. This is
802 // classed by them as a bug, but it's assumed by at least NGINX.
David Benjamin45738dd2017-02-09 20:01:26 -0500803 hs->new_session->verify_result = X509_V_OK;
Adam Langley37646832016-08-01 16:16:46 -0700804
David Benjaminc11ea9422017-08-29 16:33:21 -0400805 // Skip this state.
David Benjamin7934f082017-08-01 16:32:25 -0400806 hs->tls13_state = state_read_channel_id;
Steven Valdez143e8b32016-07-11 13:19:03 -0400807 return ssl_hs_ok;
808 }
809
David Benjamin4087df92016-08-01 20:16:31 -0400810 const int allow_anonymous =
Matthew Braithwaiteb7bc80a2018-04-13 15:51:30 -0700811 (hs->config->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) == 0;
David Benjamin7934f082017-08-01 16:32:25 -0400812 SSLMessage msg;
813 if (!ssl->method->get_message(ssl, &msg)) {
814 return ssl_hs_read_message;
815 }
816 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE) ||
817 !tls13_process_certificate(hs, msg, allow_anonymous) ||
818 !ssl_hash_message(hs, msg)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400819 return ssl_hs_error;
820 }
821
David Benjamin8f94c312017-08-01 17:35:55 -0400822 ssl->method->next_message(ssl);
David Benjamin7934f082017-08-01 16:32:25 -0400823 hs->tls13_state = state_read_client_certificate_verify;
824 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400825}
826
David Benjamin7934f082017-08-01 16:32:25 -0400827static enum ssl_hs_wait_t do_read_client_certificate_verify(
David Benjaminc3c88822016-11-14 10:32:04 +0900828 SSL_HANDSHAKE *hs) {
829 SSL *const ssl = hs->ssl;
David Benjaminbfdd1a92018-06-29 16:26:38 -0400830 if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0) {
David Benjaminc11ea9422017-08-29 16:33:21 -0400831 // Skip this state.
David Benjamin7934f082017-08-01 16:32:25 -0400832 hs->tls13_state = state_read_channel_id;
Steven Valdez143e8b32016-07-11 13:19:03 -0400833 return ssl_hs_ok;
834 }
835
David Benjamin7934f082017-08-01 16:32:25 -0400836 SSLMessage msg;
837 if (!ssl->method->get_message(ssl, &msg)) {
838 return ssl_hs_read_message;
839 }
840
David Benjamin3a1dd462017-07-11 16:13:10 -0400841 switch (ssl_verify_peer_cert(hs)) {
842 case ssl_verify_ok:
843 break;
844 case ssl_verify_invalid:
845 return ssl_hs_error;
846 case ssl_verify_retry:
David Benjamin7934f082017-08-01 16:32:25 -0400847 hs->tls13_state = state_read_client_certificate_verify;
David Benjamin3a1dd462017-07-11 16:13:10 -0400848 return ssl_hs_certificate_verify;
849 }
850
David Benjamin7934f082017-08-01 16:32:25 -0400851 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE_VERIFY) ||
852 !tls13_process_certificate_verify(hs, msg) ||
853 !ssl_hash_message(hs, msg)) {
David Benjamin6929f272016-11-16 19:10:08 +0900854 return ssl_hs_error;
Steven Valdez143e8b32016-07-11 13:19:03 -0400855 }
856
David Benjamin8f94c312017-08-01 17:35:55 -0400857 ssl->method->next_message(ssl);
David Benjamin7934f082017-08-01 16:32:25 -0400858 hs->tls13_state = state_read_channel_id;
859 return ssl_hs_ok;
Nick Harper60a85cb2016-09-23 16:25:11 -0700860}
861
David Benjamin7934f082017-08-01 16:32:25 -0400862static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) {
David Benjamin8f94c312017-08-01 17:35:55 -0400863 SSL *const ssl = hs->ssl;
David Benjamin46853762018-07-03 14:01:26 -0400864 if (!ssl->s3->channel_id_valid) {
David Benjamin7934f082017-08-01 16:32:25 -0400865 hs->tls13_state = state_read_client_finished;
Nick Harper60a85cb2016-09-23 16:25:11 -0700866 return ssl_hs_ok;
867 }
868
David Benjamin7934f082017-08-01 16:32:25 -0400869 SSLMessage msg;
870 if (!ssl->method->get_message(ssl, &msg)) {
871 return ssl_hs_read_message;
872 }
873 if (!ssl_check_message_type(ssl, msg, SSL3_MT_CHANNEL_ID) ||
874 !tls1_verify_channel_id(hs, msg) ||
875 !ssl_hash_message(hs, msg)) {
Nick Harper60a85cb2016-09-23 16:25:11 -0700876 return ssl_hs_error;
877 }
878
David Benjamin8f94c312017-08-01 17:35:55 -0400879 ssl->method->next_message(ssl);
David Benjamin7934f082017-08-01 16:32:25 -0400880 hs->tls13_state = state_read_client_finished;
881 return ssl_hs_ok;
Steven Valdez143e8b32016-07-11 13:19:03 -0400882}
883
David Benjamin7934f082017-08-01 16:32:25 -0400884static enum ssl_hs_wait_t do_read_client_finished(SSL_HANDSHAKE *hs) {
David Benjaminc3c88822016-11-14 10:32:04 +0900885 SSL *const ssl = hs->ssl;
David Benjamin7934f082017-08-01 16:32:25 -0400886 SSLMessage msg;
887 if (!ssl->method->get_message(ssl, &msg)) {
888 return ssl_hs_read_message;
889 }
890 if (!ssl_check_message_type(ssl, msg, SSL3_MT_FINISHED) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400891 // If early data was accepted, we've already computed the client Finished
892 // and derived the resumption secret.
David Benjamin02e62562017-12-18 18:04:01 -0500893 !tls13_process_finished(hs, msg, ssl->s3->early_data_accepted) ||
David Benjaminc11ea9422017-08-29 16:33:21 -0400894 // evp_aead_seal keys have already been switched.
Steven Valdeza833c352016-11-01 13:39:36 -0400895 !tls13_set_traffic_key(ssl, evp_aead_open, hs->client_traffic_secret_0,
David Benjamin794cc592017-03-25 22:24:23 -0500896 hs->hash_len)) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400897 return ssl_hs_error;
898 }
899
David Benjamin02e62562017-12-18 18:04:01 -0500900 if (!ssl->s3->early_data_accepted) {
David Benjamin7934f082017-08-01 16:32:25 -0400901 if (!ssl_hash_message(hs, msg) ||
David Benjamin794cc592017-03-25 22:24:23 -0500902 !tls13_derive_resumption_secret(hs)) {
903 return ssl_hs_error;
904 }
905
David Benjaminc11ea9422017-08-29 16:33:21 -0400906 // We send post-handshake tickets as part of the handshake in 1-RTT.
David Benjamin794cc592017-03-25 22:24:23 -0500907 hs->tls13_state = state_send_new_session_ticket;
David Benjamin8f94c312017-08-01 17:35:55 -0400908 } else {
David Benjaminc11ea9422017-08-29 16:33:21 -0400909 // We already sent half-RTT tickets.
David Benjamin8f94c312017-08-01 17:35:55 -0400910 hs->tls13_state = state_done;
David Benjamin794cc592017-03-25 22:24:23 -0500911 }
912
David Benjamin8f94c312017-08-01 17:35:55 -0400913 ssl->method->next_message(ssl);
Steven Valdez143e8b32016-07-11 13:19:03 -0400914 return ssl_hs_ok;
915}
916
David Benjaminc3c88822016-11-14 10:32:04 +0900917static enum ssl_hs_wait_t do_send_new_session_ticket(SSL_HANDSHAKE *hs) {
David Benjamin0cbb1af2018-07-17 21:26:05 -0400918 bool sent_tickets;
919 if (!add_new_session_tickets(hs, &sent_tickets)) {
David Benjamin794cc592017-03-25 22:24:23 -0500920 return ssl_hs_error;
Steven Valdez08b65f42016-12-07 15:29:45 -0500921 }
922
David Benjamin25ac2512017-01-12 19:31:28 -0500923 hs->tls13_state = state_done;
David Benjamin0cbb1af2018-07-17 21:26:05 -0400924 return sent_tickets ? ssl_hs_flush : ssl_hs_ok;
Steven Valdez1e6f11a2016-07-27 11:10:52 -0400925}
926
David Benjaminc3c88822016-11-14 10:32:04 +0900927enum ssl_hs_wait_t tls13_server_handshake(SSL_HANDSHAKE *hs) {
David Benjamin3977f302016-12-11 13:30:41 -0500928 while (hs->tls13_state != state_done) {
Steven Valdez143e8b32016-07-11 13:19:03 -0400929 enum ssl_hs_wait_t ret = ssl_hs_error;
David Benjamind304a2f2017-07-12 23:00:28 -0400930 enum server_hs_state_t state =
931 static_cast<enum server_hs_state_t>(hs->tls13_state);
Steven Valdez143e8b32016-07-11 13:19:03 -0400932 switch (state) {
David Benjamin25fe85b2016-08-09 20:00:32 -0400933 case state_select_parameters:
David Benjaminc3c88822016-11-14 10:32:04 +0900934 ret = do_select_parameters(hs);
David Benjamin25fe85b2016-08-09 20:00:32 -0400935 break;
David Benjamin707af292017-03-10 17:47:18 -0500936 case state_select_session:
937 ret = do_select_session(hs);
938 break;
Steven Valdez5440fe02016-07-18 12:40:30 -0400939 case state_send_hello_retry_request:
David Benjaminc3c88822016-11-14 10:32:04 +0900940 ret = do_send_hello_retry_request(hs);
Steven Valdez5440fe02016-07-18 12:40:30 -0400941 break;
David Benjamin7934f082017-08-01 16:32:25 -0400942 case state_read_second_client_hello:
943 ret = do_read_second_client_hello(hs);
Steven Valdez5440fe02016-07-18 12:40:30 -0400944 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400945 case state_send_server_hello:
David Benjaminc3c88822016-11-14 10:32:04 +0900946 ret = do_send_server_hello(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400947 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400948 case state_send_server_certificate_verify:
David Benjamin44148742017-06-17 13:20:59 -0400949 ret = do_send_server_certificate_verify(hs);
Steven Valdez2d850622017-01-11 11:34:52 -0500950 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400951 case state_send_server_finished:
David Benjaminc3c88822016-11-14 10:32:04 +0900952 ret = do_send_server_finished(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400953 break;
Steven Valdez2d850622017-01-11 11:34:52 -0500954 case state_read_second_client_flight:
955 ret = do_read_second_client_flight(hs);
956 break;
957 case state_process_end_of_early_data:
958 ret = do_process_end_of_early_data(hs);
959 break;
David Benjamin7934f082017-08-01 16:32:25 -0400960 case state_read_client_certificate:
961 ret = do_read_client_certificate(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400962 break;
David Benjamin7934f082017-08-01 16:32:25 -0400963 case state_read_client_certificate_verify:
964 ret = do_read_client_certificate_verify(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400965 break;
David Benjamin7934f082017-08-01 16:32:25 -0400966 case state_read_channel_id:
967 ret = do_read_channel_id(hs);
Nick Harper60a85cb2016-09-23 16:25:11 -0700968 break;
David Benjamin7934f082017-08-01 16:32:25 -0400969 case state_read_client_finished:
970 ret = do_read_client_finished(hs);
Steven Valdez143e8b32016-07-11 13:19:03 -0400971 break;
Steven Valdez1e6f11a2016-07-27 11:10:52 -0400972 case state_send_new_session_ticket:
David Benjaminc3c88822016-11-14 10:32:04 +0900973 ret = do_send_new_session_ticket(hs);
Steven Valdez1e6f11a2016-07-27 11:10:52 -0400974 break;
Steven Valdez143e8b32016-07-11 13:19:03 -0400975 case state_done:
976 ret = ssl_hs_ok;
977 break;
978 }
979
Steven Valdez4d71a9a2017-08-14 15:08:34 -0400980 if (hs->tls13_state != state) {
David Benjaminf60bcfb2017-08-18 15:23:44 -0400981 ssl_do_info_callback(hs->ssl, SSL_CB_ACCEPT_LOOP, 1);
982 }
983
Steven Valdez143e8b32016-07-11 13:19:03 -0400984 if (ret != ssl_hs_ok) {
985 return ret;
986 }
987 }
988
989 return ssl_hs_ok;
990}
David Benjamin86e95b82017-07-18 16:34:25 -0400991
David Benjaminf60bcfb2017-08-18 15:23:44 -0400992const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs) {
993 enum server_hs_state_t state =
994 static_cast<enum server_hs_state_t>(hs->tls13_state);
995 switch (state) {
996 case state_select_parameters:
997 return "TLS 1.3 server select_parameters";
998 case state_select_session:
999 return "TLS 1.3 server select_session";
1000 case state_send_hello_retry_request:
1001 return "TLS 1.3 server send_hello_retry_request";
1002 case state_read_second_client_hello:
1003 return "TLS 1.3 server read_second_client_hello";
1004 case state_send_server_hello:
1005 return "TLS 1.3 server send_server_hello";
1006 case state_send_server_certificate_verify:
1007 return "TLS 1.3 server send_server_certificate_verify";
1008 case state_send_server_finished:
1009 return "TLS 1.3 server send_server_finished";
1010 case state_read_second_client_flight:
1011 return "TLS 1.3 server read_second_client_flight";
David Benjaminf60bcfb2017-08-18 15:23:44 -04001012 case state_process_end_of_early_data:
1013 return "TLS 1.3 server process_end_of_early_data";
1014 case state_read_client_certificate:
1015 return "TLS 1.3 server read_client_certificate";
1016 case state_read_client_certificate_verify:
1017 return "TLS 1.3 server read_client_certificate_verify";
1018 case state_read_channel_id:
1019 return "TLS 1.3 server read_channel_id";
1020 case state_read_client_finished:
1021 return "TLS 1.3 server read_client_finished";
1022 case state_send_new_session_ticket:
1023 return "TLS 1.3 server send_new_session_ticket";
1024 case state_done:
1025 return "TLS 1.3 server done";
1026 }
1027
1028 return "TLS 1.3 server unknown";
1029}
1030
David Benjamin86e95b82017-07-18 16:34:25 -04001031} // namespace bssl