tls13_server.cc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. /* 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. #include <openssl/ssl.h>
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <tuple>
  18. #include <openssl/aead.h>
  19. #include <openssl/bytestring.h>
  20. #include <openssl/digest.h>
  21. #include <openssl/err.h>
  22. #include <openssl/mem.h>
  23. #include <openssl/rand.h>
  24. #include <openssl/stack.h>
  25. #include "../crypto/internal.h"
  26. #include "internal.h"
  27. BSSL_NAMESPACE_BEGIN
  28. enum server_hs_state_t {
  29. state_select_parameters = 0,
  30. state_select_session,
  31. state_send_hello_retry_request,
  32. state_read_second_client_hello,
  33. state_send_server_hello,
  34. state_send_server_certificate_verify,
  35. state_send_server_finished,
  36. state_read_second_client_flight,
  37. state_process_end_of_early_data,
  38. state_read_client_certificate,
  39. state_read_client_certificate_verify,
  40. state_read_channel_id,
  41. state_read_client_finished,
  42. state_send_new_session_ticket,
  43. state_done,
  44. };
  45. static const uint8_t kZeroes[EVP_MAX_MD_SIZE] = {0};
  46. // Allow a minute of ticket age skew in either direction. This covers
  47. // transmission delays in ClientHello and NewSessionTicket, as well as
  48. // drift between client and server clock rate since the ticket was issued.
  49. // See RFC 8446, section 8.3.
  50. static const int32_t kMaxTicketAgeSkewSeconds = 60;
  51. static int resolve_ecdhe_secret(SSL_HANDSHAKE *hs, bool *out_need_retry,
  52. SSL_CLIENT_HELLO *client_hello) {
  53. SSL *const ssl = hs->ssl;
  54. *out_need_retry = false;
  55. // We only support connections that include an ECDHE key exchange.
  56. CBS key_share;
  57. if (!ssl_client_hello_get_extension(client_hello, &key_share,
  58. TLSEXT_TYPE_key_share)) {
  59. OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_KEY_SHARE);
  60. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION);
  61. return 0;
  62. }
  63. bool found_key_share;
  64. Array<uint8_t> dhe_secret;
  65. uint8_t alert = SSL_AD_DECODE_ERROR;
  66. if (!ssl_ext_key_share_parse_clienthello(hs, &found_key_share, &dhe_secret,
  67. &alert, &key_share)) {
  68. ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
  69. return 0;
  70. }
  71. if (!found_key_share) {
  72. *out_need_retry = true;
  73. return 0;
  74. }
  75. return tls13_advance_key_schedule(hs, dhe_secret);
  76. }
  77. static int ssl_ext_supported_versions_add_serverhello(SSL_HANDSHAKE *hs,
  78. CBB *out) {
  79. CBB contents;
  80. if (!CBB_add_u16(out, TLSEXT_TYPE_supported_versions) ||
  81. !CBB_add_u16_length_prefixed(out, &contents) ||
  82. !CBB_add_u16(&contents, hs->ssl->version) ||
  83. !CBB_flush(out)) {
  84. return 0;
  85. }
  86. return 1;
  87. }
  88. static const SSL_CIPHER *choose_tls13_cipher(
  89. const SSL *ssl, const SSL_CLIENT_HELLO *client_hello, uint16_t group_id) {
  90. CBS cipher_suites;
  91. CBS_init(&cipher_suites, client_hello->cipher_suites,
  92. client_hello->cipher_suites_len);
  93. const uint16_t version = ssl_protocol_version(ssl);
  94. return ssl_choose_tls13_cipher(cipher_suites, version, group_id);
  95. }
  96. static bool add_new_session_tickets(SSL_HANDSHAKE *hs, bool *out_sent_tickets) {
  97. SSL *const ssl = hs->ssl;
  98. if (// If the client doesn't accept resumption with PSK_DHE_KE, don't send a
  99. // session ticket.
  100. !hs->accept_psk_mode ||
  101. // We only implement stateless resumption in TLS 1.3, so skip sending
  102. // tickets if disabled.
  103. (SSL_get_options(ssl) & SSL_OP_NO_TICKET)) {
  104. *out_sent_tickets = false;
  105. return true;
  106. }
  107. // TLS 1.3 recommends single-use tickets, so issue multiple tickets in case
  108. // the client makes several connections before getting a renewal.
  109. static const int kNumTickets = 2;
  110. // Rebase the session timestamp so that it is measured from ticket
  111. // issuance.
  112. ssl_session_rebase_time(ssl, hs->new_session.get());
  113. for (int i = 0; i < kNumTickets; i++) {
  114. UniquePtr<SSL_SESSION> session(
  115. SSL_SESSION_dup(hs->new_session.get(), SSL_SESSION_INCLUDE_NONAUTH));
  116. if (!session) {
  117. return false;
  118. }
  119. if (!RAND_bytes((uint8_t *)&session->ticket_age_add, 4)) {
  120. return false;
  121. }
  122. session->ticket_age_add_valid = true;
  123. if (ssl->enable_early_data) {
  124. // QUIC does not use the max_early_data_size parameter and always sets it
  125. // to a fixed value. See draft-ietf-quic-tls-22, section 4.5.
  126. session->ticket_max_early_data =
  127. ssl->quic_method != nullptr ? 0xffffffff : kMaxEarlyDataAccepted;
  128. }
  129. static_assert(kNumTickets < 256, "Too many tickets");
  130. uint8_t nonce[] = {static_cast<uint8_t>(i)};
  131. ScopedCBB cbb;
  132. CBB body, nonce_cbb, ticket, extensions;
  133. if (!ssl->method->init_message(ssl, cbb.get(), &body,
  134. SSL3_MT_NEW_SESSION_TICKET) ||
  135. !CBB_add_u32(&body, session->timeout) ||
  136. !CBB_add_u32(&body, session->ticket_age_add) ||
  137. !CBB_add_u8_length_prefixed(&body, &nonce_cbb) ||
  138. !CBB_add_bytes(&nonce_cbb, nonce, sizeof(nonce)) ||
  139. !CBB_add_u16_length_prefixed(&body, &ticket) ||
  140. !tls13_derive_session_psk(session.get(), nonce) ||
  141. !ssl_encrypt_ticket(hs, &ticket, session.get()) ||
  142. !CBB_add_u16_length_prefixed(&body, &extensions)) {
  143. return false;
  144. }
  145. if (ssl->enable_early_data) {
  146. CBB early_data_info;
  147. if (!CBB_add_u16(&extensions, TLSEXT_TYPE_early_data) ||
  148. !CBB_add_u16_length_prefixed(&extensions, &early_data_info) ||
  149. !CBB_add_u32(&early_data_info, session->ticket_max_early_data) ||
  150. !CBB_flush(&extensions)) {
  151. return false;
  152. }
  153. }
  154. // Add a fake extension. See draft-davidben-tls-grease-01.
  155. if (!CBB_add_u16(&extensions,
  156. ssl_get_grease_value(hs, ssl_grease_ticket_extension)) ||
  157. !CBB_add_u16(&extensions, 0 /* empty */)) {
  158. return false;
  159. }
  160. if (!ssl_add_message_cbb(ssl, cbb.get())) {
  161. return false;
  162. }
  163. }
  164. *out_sent_tickets = true;
  165. return true;
  166. }
  167. static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
  168. // At this point, most ClientHello extensions have already been processed by
  169. // the common handshake logic. Resolve the remaining non-PSK parameters.
  170. SSL *const ssl = hs->ssl;
  171. SSLMessage msg;
  172. if (!ssl->method->get_message(ssl, &msg)) {
  173. return ssl_hs_read_message;
  174. }
  175. SSL_CLIENT_HELLO client_hello;
  176. if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
  177. OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
  178. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
  179. return ssl_hs_error;
  180. }
  181. OPENSSL_memcpy(hs->session_id, client_hello.session_id,
  182. client_hello.session_id_len);
  183. hs->session_id_len = client_hello.session_id_len;
  184. uint16_t group_id;
  185. if (!tls1_get_shared_group(hs, &group_id)) {
  186. OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_GROUP);
  187. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
  188. return ssl_hs_error;
  189. }
  190. // Negotiate the cipher suite.
  191. hs->new_cipher = choose_tls13_cipher(ssl, &client_hello, group_id);
  192. if (hs->new_cipher == NULL) {
  193. OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER);
  194. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
  195. return ssl_hs_error;
  196. }
  197. // HTTP/2 negotiation depends on the cipher suite, so ALPN negotiation was
  198. // deferred. Complete it now.
  199. uint8_t alert = SSL_AD_DECODE_ERROR;
  200. if (!ssl_negotiate_alpn(hs, &alert, &client_hello)) {
  201. ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
  202. return ssl_hs_error;
  203. }
  204. // The PRF hash is now known. Set up the key schedule and hash the
  205. // ClientHello.
  206. if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher)) {
  207. return ssl_hs_error;
  208. }
  209. hs->tls13_state = state_select_session;
  210. return ssl_hs_ok;
  211. }
  212. static enum ssl_ticket_aead_result_t select_session(
  213. SSL_HANDSHAKE *hs, uint8_t *out_alert, UniquePtr<SSL_SESSION> *out_session,
  214. int32_t *out_ticket_age_skew, bool *out_offered_ticket,
  215. const SSLMessage &msg, const SSL_CLIENT_HELLO *client_hello) {
  216. SSL *const ssl = hs->ssl;
  217. *out_session = nullptr;
  218. CBS pre_shared_key;
  219. *out_offered_ticket = ssl_client_hello_get_extension(
  220. client_hello, &pre_shared_key, TLSEXT_TYPE_pre_shared_key);
  221. if (!*out_offered_ticket) {
  222. return ssl_ticket_aead_ignore_ticket;
  223. }
  224. CBS ticket, binders;
  225. uint32_t client_ticket_age;
  226. if (!ssl_ext_pre_shared_key_parse_clienthello(
  227. hs, &ticket, &binders, &client_ticket_age, out_alert, client_hello,
  228. &pre_shared_key)) {
  229. return ssl_ticket_aead_error;
  230. }
  231. // If the peer did not offer psk_dhe, ignore the resumption.
  232. if (!hs->accept_psk_mode) {
  233. return ssl_ticket_aead_ignore_ticket;
  234. }
  235. // TLS 1.3 session tickets are renewed separately as part of the
  236. // NewSessionTicket.
  237. bool unused_renew;
  238. UniquePtr<SSL_SESSION> session;
  239. enum ssl_ticket_aead_result_t ret =
  240. ssl_process_ticket(hs, &session, &unused_renew, ticket, {});
  241. switch (ret) {
  242. case ssl_ticket_aead_success:
  243. break;
  244. case ssl_ticket_aead_error:
  245. *out_alert = SSL_AD_INTERNAL_ERROR;
  246. return ret;
  247. default:
  248. return ret;
  249. }
  250. if (!ssl_session_is_resumable(hs, session.get()) ||
  251. // Historically, some TLS 1.3 tickets were missing ticket_age_add.
  252. !session->ticket_age_add_valid) {
  253. return ssl_ticket_aead_ignore_ticket;
  254. }
  255. // Recover the client ticket age and convert to seconds.
  256. client_ticket_age -= session->ticket_age_add;
  257. client_ticket_age /= 1000;
  258. struct OPENSSL_timeval now;
  259. ssl_get_current_time(ssl, &now);
  260. // Compute the server ticket age in seconds.
  261. assert(now.tv_sec >= session->time);
  262. uint64_t server_ticket_age = now.tv_sec - session->time;
  263. // To avoid overflowing |hs->ticket_age_skew|, we will not resume
  264. // 68-year-old sessions.
  265. if (server_ticket_age > INT32_MAX) {
  266. return ssl_ticket_aead_ignore_ticket;
  267. }
  268. *out_ticket_age_skew = static_cast<int32_t>(client_ticket_age) -
  269. static_cast<int32_t>(server_ticket_age);
  270. // Check the PSK binder.
  271. if (!tls13_verify_psk_binder(hs, session.get(), msg, &binders)) {
  272. *out_alert = SSL_AD_DECRYPT_ERROR;
  273. return ssl_ticket_aead_error;
  274. }
  275. *out_session = std::move(session);
  276. return ssl_ticket_aead_success;
  277. }
  278. static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
  279. SSL *const ssl = hs->ssl;
  280. SSLMessage msg;
  281. if (!ssl->method->get_message(ssl, &msg)) {
  282. return ssl_hs_read_message;
  283. }
  284. SSL_CLIENT_HELLO client_hello;
  285. if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
  286. OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
  287. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
  288. return ssl_hs_error;
  289. }
  290. uint8_t alert = SSL_AD_DECODE_ERROR;
  291. UniquePtr<SSL_SESSION> session;
  292. bool offered_ticket = false;
  293. switch (select_session(hs, &alert, &session, &ssl->s3->ticket_age_skew,
  294. &offered_ticket, msg, &client_hello)) {
  295. case ssl_ticket_aead_ignore_ticket:
  296. assert(!session);
  297. if (!ssl->enable_early_data) {
  298. ssl->s3->early_data_reason = ssl_early_data_disabled;
  299. } else if (!offered_ticket) {
  300. ssl->s3->early_data_reason = ssl_early_data_no_session_offered;
  301. } else {
  302. ssl->s3->early_data_reason = ssl_early_data_session_not_resumed;
  303. }
  304. if (!ssl_get_new_session(hs, 1 /* server */)) {
  305. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
  306. return ssl_hs_error;
  307. }
  308. break;
  309. case ssl_ticket_aead_success:
  310. // Carry over authentication information from the previous handshake into
  311. // a fresh session.
  312. hs->new_session =
  313. SSL_SESSION_dup(session.get(), SSL_SESSION_DUP_AUTH_ONLY);
  314. if (hs->new_session == nullptr) {
  315. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
  316. return ssl_hs_error;
  317. }
  318. if (!ssl->enable_early_data) {
  319. ssl->s3->early_data_reason = ssl_early_data_disabled;
  320. } else if (session->ticket_max_early_data == 0) {
  321. ssl->s3->early_data_reason = ssl_early_data_unsupported_for_session;
  322. } else if (!hs->early_data_offered) {
  323. ssl->s3->early_data_reason = ssl_early_data_peer_declined;
  324. } else if (ssl->s3->channel_id_valid) {
  325. // Channel ID is incompatible with 0-RTT.
  326. ssl->s3->early_data_reason = ssl_early_data_channel_id;
  327. } else if (ssl->s3->token_binding_negotiated) {
  328. // Token Binding is incompatible with 0-RTT.
  329. ssl->s3->early_data_reason = ssl_early_data_token_binding;
  330. } else if (MakeConstSpan(ssl->s3->alpn_selected) != session->early_alpn) {
  331. // The negotiated ALPN must match the one in the ticket.
  332. ssl->s3->early_data_reason = ssl_early_data_alpn_mismatch;
  333. } else if (ssl->s3->ticket_age_skew < -kMaxTicketAgeSkewSeconds ||
  334. kMaxTicketAgeSkewSeconds < ssl->s3->ticket_age_skew) {
  335. ssl->s3->early_data_reason = ssl_early_data_ticket_age_skew;
  336. } else {
  337. ssl->s3->early_data_reason = ssl_early_data_accepted;
  338. ssl->s3->early_data_accepted = true;
  339. }
  340. ssl->s3->session_reused = true;
  341. // Resumption incorporates fresh key material, so refresh the timeout.
  342. ssl_session_renew_timeout(ssl, hs->new_session.get(),
  343. ssl->session_ctx->session_psk_dhe_timeout);
  344. break;
  345. case ssl_ticket_aead_error:
  346. ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
  347. return ssl_hs_error;
  348. case ssl_ticket_aead_retry:
  349. hs->tls13_state = state_select_session;
  350. return ssl_hs_pending_ticket;
  351. }
  352. // Record connection properties in the new session.
  353. hs->new_session->cipher = hs->new_cipher;
  354. // Store the initial negotiated ALPN in the session.
  355. if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
  356. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
  357. return ssl_hs_error;
  358. }
  359. if (ssl->ctx->dos_protection_cb != NULL &&
  360. ssl->ctx->dos_protection_cb(&client_hello) == 0) {
  361. // Connection rejected for DOS reasons.
  362. OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
  363. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
  364. return ssl_hs_error;
  365. }
  366. size_t hash_len = EVP_MD_size(
  367. ssl_get_handshake_digest(ssl_protocol_version(ssl), hs->new_cipher));
  368. // Set up the key schedule and incorporate the PSK into the running secret.
  369. if (ssl->s3->session_reused) {
  370. if (!tls13_init_key_schedule(
  371. hs, MakeConstSpan(hs->new_session->master_key,
  372. hs->new_session->master_key_length))) {
  373. return ssl_hs_error;
  374. }
  375. } else if (!tls13_init_key_schedule(hs, MakeConstSpan(kZeroes, hash_len))) {
  376. return ssl_hs_error;
  377. }
  378. if (!ssl_hash_message(hs, msg)) {
  379. return ssl_hs_error;
  380. }
  381. if (ssl->s3->early_data_accepted) {
  382. if (!tls13_derive_early_secret(hs)) {
  383. return ssl_hs_error;
  384. }
  385. } else if (hs->early_data_offered) {
  386. ssl->s3->skip_early_data = true;
  387. }
  388. // Resolve ECDHE and incorporate it into the secret.
  389. bool need_retry;
  390. if (!resolve_ecdhe_secret(hs, &need_retry, &client_hello)) {
  391. if (need_retry) {
  392. if (ssl->s3->early_data_accepted) {
  393. ssl->s3->early_data_reason = ssl_early_data_hello_retry_request;
  394. ssl->s3->early_data_accepted = false;
  395. }
  396. ssl->s3->skip_early_data = true;
  397. ssl->method->next_message(ssl);
  398. if (!hs->transcript.UpdateForHelloRetryRequest()) {
  399. return ssl_hs_error;
  400. }
  401. hs->tls13_state = state_send_hello_retry_request;
  402. return ssl_hs_ok;
  403. }
  404. return ssl_hs_error;
  405. }
  406. // Note we defer releasing the early traffic secret to QUIC until after ECDHE
  407. // is resolved. The early traffic secret should be derived before the key
  408. // schedule incorporates ECDHE, but doing so may reject 0-RTT. To avoid
  409. // confusing the caller, we split derivation and releasing the secret to QUIC.
  410. if (ssl->s3->early_data_accepted &&
  411. !tls13_set_early_secret_for_quic(hs)) {
  412. return ssl_hs_error;
  413. }
  414. ssl->method->next_message(ssl);
  415. hs->tls13_state = state_send_server_hello;
  416. return ssl_hs_ok;
  417. }
  418. static enum ssl_hs_wait_t do_send_hello_retry_request(SSL_HANDSHAKE *hs) {
  419. SSL *const ssl = hs->ssl;
  420. ScopedCBB cbb;
  421. CBB body, session_id, extensions;
  422. uint16_t group_id;
  423. if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
  424. !CBB_add_u16(&body, TLS1_2_VERSION) ||
  425. !CBB_add_bytes(&body, kHelloRetryRequest, SSL3_RANDOM_SIZE) ||
  426. !CBB_add_u8_length_prefixed(&body, &session_id) ||
  427. !CBB_add_bytes(&session_id, hs->session_id, hs->session_id_len) ||
  428. !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
  429. !CBB_add_u8(&body, 0 /* no compression */) ||
  430. !tls1_get_shared_group(hs, &group_id) ||
  431. !CBB_add_u16_length_prefixed(&body, &extensions) ||
  432. !CBB_add_u16(&extensions, TLSEXT_TYPE_supported_versions) ||
  433. !CBB_add_u16(&extensions, 2 /* length */) ||
  434. !CBB_add_u16(&extensions, ssl->version) ||
  435. !CBB_add_u16(&extensions, TLSEXT_TYPE_key_share) ||
  436. !CBB_add_u16(&extensions, 2 /* length */) ||
  437. !CBB_add_u16(&extensions, group_id) ||
  438. !ssl_add_message_cbb(ssl, cbb.get())) {
  439. return ssl_hs_error;
  440. }
  441. if (!ssl->method->add_change_cipher_spec(ssl)) {
  442. return ssl_hs_error;
  443. }
  444. hs->sent_hello_retry_request = true;
  445. hs->tls13_state = state_read_second_client_hello;
  446. return ssl_hs_flush;
  447. }
  448. static enum ssl_hs_wait_t do_read_second_client_hello(SSL_HANDSHAKE *hs) {
  449. SSL *const ssl = hs->ssl;
  450. SSLMessage msg;
  451. if (!ssl->method->get_message(ssl, &msg)) {
  452. return ssl_hs_read_message;
  453. }
  454. if (!ssl_check_message_type(ssl, msg, SSL3_MT_CLIENT_HELLO)) {
  455. return ssl_hs_error;
  456. }
  457. SSL_CLIENT_HELLO client_hello;
  458. if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
  459. OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED);
  460. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
  461. return ssl_hs_error;
  462. }
  463. // We perform all our negotiation based on the first ClientHello (for
  464. // consistency with what |select_certificate_cb| observed), which is in the
  465. // transcript, so we can ignore most of this second one.
  466. //
  467. // We do, however, check the second PSK binder. This covers the client key
  468. // share, in case we ever send half-RTT data (we currently do not). It is also
  469. // a tricky computation, so we enforce the peer handled it correctly.
  470. if (ssl->s3->session_reused) {
  471. CBS pre_shared_key;
  472. if (!ssl_client_hello_get_extension(&client_hello, &pre_shared_key,
  473. TLSEXT_TYPE_pre_shared_key)) {
  474. OPENSSL_PUT_ERROR(SSL, SSL_R_INCONSISTENT_CLIENT_HELLO);
  475. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
  476. return ssl_hs_error;
  477. }
  478. CBS ticket, binders;
  479. uint32_t client_ticket_age;
  480. uint8_t alert = SSL_AD_DECODE_ERROR;
  481. if (!ssl_ext_pre_shared_key_parse_clienthello(
  482. hs, &ticket, &binders, &client_ticket_age, &alert, &client_hello,
  483. &pre_shared_key)) {
  484. ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
  485. return ssl_hs_error;
  486. }
  487. // Note it is important that we do not obtain a new |SSL_SESSION| from
  488. // |ticket|. We have already selected parameters based on the first
  489. // ClientHello (in the transcript) and must not switch partway through.
  490. if (!tls13_verify_psk_binder(hs, hs->new_session.get(), msg, &binders)) {
  491. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
  492. return ssl_hs_error;
  493. }
  494. }
  495. bool need_retry;
  496. if (!resolve_ecdhe_secret(hs, &need_retry, &client_hello)) {
  497. if (need_retry) {
  498. // Only send one HelloRetryRequest.
  499. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
  500. OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
  501. }
  502. return ssl_hs_error;
  503. }
  504. if (!ssl_hash_message(hs, msg)) {
  505. return ssl_hs_error;
  506. }
  507. ssl->method->next_message(ssl);
  508. hs->tls13_state = state_send_server_hello;
  509. return ssl_hs_ok;
  510. }
  511. static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
  512. SSL *const ssl = hs->ssl;
  513. // Send a ServerHello.
  514. ScopedCBB cbb;
  515. CBB body, extensions, session_id;
  516. if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
  517. !CBB_add_u16(&body, TLS1_2_VERSION) ||
  518. !RAND_bytes(ssl->s3->server_random, sizeof(ssl->s3->server_random)) ||
  519. !CBB_add_bytes(&body, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
  520. !CBB_add_u8_length_prefixed(&body, &session_id) ||
  521. !CBB_add_bytes(&session_id, hs->session_id, hs->session_id_len) ||
  522. !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
  523. !CBB_add_u8(&body, 0) ||
  524. !CBB_add_u16_length_prefixed(&body, &extensions) ||
  525. !ssl_ext_pre_shared_key_add_serverhello(hs, &extensions) ||
  526. !ssl_ext_key_share_add_serverhello(hs, &extensions) ||
  527. !ssl_ext_supported_versions_add_serverhello(hs, &extensions) ||
  528. !ssl_add_message_cbb(ssl, cbb.get())) {
  529. return ssl_hs_error;
  530. }
  531. if (!hs->sent_hello_retry_request &&
  532. !ssl->method->add_change_cipher_spec(ssl)) {
  533. return ssl_hs_error;
  534. }
  535. // Derive and enable the handshake traffic secrets.
  536. if (!tls13_derive_handshake_secrets(hs) ||
  537. !tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal,
  538. hs->server_handshake_secret())) {
  539. return ssl_hs_error;
  540. }
  541. // Send EncryptedExtensions.
  542. if (!ssl->method->init_message(ssl, cbb.get(), &body,
  543. SSL3_MT_ENCRYPTED_EXTENSIONS) ||
  544. !ssl_add_serverhello_tlsext(hs, &body) ||
  545. !ssl_add_message_cbb(ssl, cbb.get())) {
  546. return ssl_hs_error;
  547. }
  548. if (!ssl->s3->session_reused) {
  549. // Determine whether to request a client certificate.
  550. hs->cert_request = !!(hs->config->verify_mode & SSL_VERIFY_PEER);
  551. // Only request a certificate if Channel ID isn't negotiated.
  552. if ((hs->config->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
  553. ssl->s3->channel_id_valid) {
  554. hs->cert_request = false;
  555. }
  556. }
  557. // Send a CertificateRequest, if necessary.
  558. if (hs->cert_request) {
  559. CBB cert_request_extensions, sigalg_contents, sigalgs_cbb;
  560. if (!ssl->method->init_message(ssl, cbb.get(), &body,
  561. SSL3_MT_CERTIFICATE_REQUEST) ||
  562. !CBB_add_u8(&body, 0 /* no certificate_request_context. */) ||
  563. !CBB_add_u16_length_prefixed(&body, &cert_request_extensions) ||
  564. !CBB_add_u16(&cert_request_extensions,
  565. TLSEXT_TYPE_signature_algorithms) ||
  566. !CBB_add_u16_length_prefixed(&cert_request_extensions,
  567. &sigalg_contents) ||
  568. !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
  569. !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb,
  570. false /* online signature */)) {
  571. return ssl_hs_error;
  572. }
  573. if (tls12_has_different_verify_sigalgs_for_certs(ssl)) {
  574. if (!CBB_add_u16(&cert_request_extensions,
  575. TLSEXT_TYPE_signature_algorithms_cert) ||
  576. !CBB_add_u16_length_prefixed(&cert_request_extensions,
  577. &sigalg_contents) ||
  578. !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) ||
  579. !tls12_add_verify_sigalgs(ssl, &sigalgs_cbb, true /* certs */)) {
  580. return ssl_hs_error;
  581. }
  582. }
  583. if (ssl_has_client_CAs(hs->config)) {
  584. CBB ca_contents;
  585. if (!CBB_add_u16(&cert_request_extensions,
  586. TLSEXT_TYPE_certificate_authorities) ||
  587. !CBB_add_u16_length_prefixed(&cert_request_extensions,
  588. &ca_contents) ||
  589. !ssl_add_client_CA_list(hs, &ca_contents) ||
  590. !CBB_flush(&cert_request_extensions)) {
  591. return ssl_hs_error;
  592. }
  593. }
  594. if (!ssl_add_message_cbb(ssl, cbb.get())) {
  595. return ssl_hs_error;
  596. }
  597. }
  598. // Send the server Certificate message, if necessary.
  599. if (!ssl->s3->session_reused) {
  600. if (!ssl_has_certificate(hs)) {
  601. OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET);
  602. return ssl_hs_error;
  603. }
  604. if (!tls13_add_certificate(hs)) {
  605. return ssl_hs_error;
  606. }
  607. hs->tls13_state = state_send_server_certificate_verify;
  608. return ssl_hs_ok;
  609. }
  610. hs->tls13_state = state_send_server_finished;
  611. return ssl_hs_ok;
  612. }
  613. static enum ssl_hs_wait_t do_send_server_certificate_verify(SSL_HANDSHAKE *hs) {
  614. switch (tls13_add_certificate_verify(hs)) {
  615. case ssl_private_key_success:
  616. hs->tls13_state = state_send_server_finished;
  617. return ssl_hs_ok;
  618. case ssl_private_key_retry:
  619. hs->tls13_state = state_send_server_certificate_verify;
  620. return ssl_hs_private_key_operation;
  621. case ssl_private_key_failure:
  622. return ssl_hs_error;
  623. }
  624. assert(0);
  625. return ssl_hs_error;
  626. }
  627. static enum ssl_hs_wait_t do_send_server_finished(SSL_HANDSHAKE *hs) {
  628. SSL *const ssl = hs->ssl;
  629. if (!tls13_add_finished(hs) ||
  630. // Update the secret to the master secret and derive traffic keys.
  631. !tls13_advance_key_schedule(
  632. hs, MakeConstSpan(kZeroes, hs->transcript.DigestLen())) ||
  633. !tls13_derive_application_secrets(hs) ||
  634. !tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_seal,
  635. hs->server_traffic_secret_0())) {
  636. return ssl_hs_error;
  637. }
  638. if (ssl->s3->early_data_accepted) {
  639. // If accepting 0-RTT, we send tickets half-RTT. This gets the tickets on
  640. // the wire sooner and also avoids triggering a write on |SSL_read| when
  641. // processing the client Finished. This requires computing the client
  642. // Finished early. See RFC 8446, section 4.6.1.
  643. static const uint8_t kEndOfEarlyData[4] = {SSL3_MT_END_OF_EARLY_DATA, 0,
  644. 0, 0};
  645. if (ssl->quic_method == nullptr &&
  646. !hs->transcript.Update(kEndOfEarlyData)) {
  647. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  648. return ssl_hs_error;
  649. }
  650. size_t finished_len;
  651. if (!tls13_finished_mac(hs, hs->expected_client_finished().data(),
  652. &finished_len, false /* client */)) {
  653. return ssl_hs_error;
  654. }
  655. if (finished_len != hs->expected_client_finished().size()) {
  656. OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
  657. return ssl_hs_error;
  658. }
  659. // Feed the predicted Finished into the transcript. This allows us to derive
  660. // the resumption secret early and send half-RTT tickets.
  661. //
  662. // TODO(davidben): This will need to be updated for DTLS 1.3.
  663. assert(!SSL_is_dtls(hs->ssl));
  664. assert(hs->expected_client_finished().size() <= 0xff);
  665. uint8_t header[4] = {
  666. SSL3_MT_FINISHED, 0, 0,
  667. static_cast<uint8_t>(hs->expected_client_finished().size())};
  668. bool unused_sent_tickets;
  669. if (!hs->transcript.Update(header) ||
  670. !hs->transcript.Update(hs->expected_client_finished()) ||
  671. !tls13_derive_resumption_secret(hs) ||
  672. !add_new_session_tickets(hs, &unused_sent_tickets)) {
  673. return ssl_hs_error;
  674. }
  675. }
  676. hs->tls13_state = state_read_second_client_flight;
  677. return ssl_hs_flush;
  678. }
  679. static enum ssl_hs_wait_t do_read_second_client_flight(SSL_HANDSHAKE *hs) {
  680. SSL *const ssl = hs->ssl;
  681. if (ssl->s3->early_data_accepted) {
  682. // QUIC never receives handshake messages under 0-RTT keys.
  683. if (ssl->quic_method == nullptr &&
  684. !tls13_set_traffic_key(ssl, ssl_encryption_early_data, evp_aead_open,
  685. hs->early_traffic_secret())) {
  686. return ssl_hs_error;
  687. }
  688. hs->can_early_write = true;
  689. hs->can_early_read = true;
  690. hs->in_early_data = true;
  691. }
  692. // QUIC doesn't use an EndOfEarlyData message (draft-ietf-quic-tls-22,
  693. // section 8.3), so we switch to client_handshake_secret before the early
  694. // return.
  695. if (ssl->quic_method != nullptr) {
  696. if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open,
  697. hs->client_handshake_secret())) {
  698. return ssl_hs_error;
  699. }
  700. hs->tls13_state = state_read_client_certificate;
  701. return ssl->s3->early_data_accepted ? ssl_hs_early_return : ssl_hs_ok;
  702. }
  703. hs->tls13_state = state_process_end_of_early_data;
  704. return ssl->s3->early_data_accepted ? ssl_hs_read_end_of_early_data
  705. : ssl_hs_ok;
  706. }
  707. static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) {
  708. SSL *const ssl = hs->ssl;
  709. // If early data was not accepted, the EndOfEarlyData will be in the discarded
  710. // early data.
  711. if (hs->ssl->s3->early_data_accepted) {
  712. SSLMessage msg;
  713. if (!ssl->method->get_message(ssl, &msg)) {
  714. return ssl_hs_read_message;
  715. }
  716. if (!ssl_check_message_type(ssl, msg, SSL3_MT_END_OF_EARLY_DATA)) {
  717. return ssl_hs_error;
  718. }
  719. if (CBS_len(&msg.body) != 0) {
  720. ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
  721. OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
  722. return ssl_hs_error;
  723. }
  724. ssl->method->next_message(ssl);
  725. }
  726. if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open,
  727. hs->client_handshake_secret())) {
  728. return ssl_hs_error;
  729. }
  730. hs->tls13_state = state_read_client_certificate;
  731. return ssl_hs_ok;
  732. }
  733. static enum ssl_hs_wait_t do_read_client_certificate(SSL_HANDSHAKE *hs) {
  734. SSL *const ssl = hs->ssl;
  735. if (!hs->cert_request) {
  736. if (!ssl->s3->session_reused) {
  737. // OpenSSL returns X509_V_OK when no certificates are requested. This is
  738. // classed by them as a bug, but it's assumed by at least NGINX. (Only do
  739. // this in full handshakes as resumptions should carry over the previous
  740. // |verify_result|, though this is a no-op because servers do not
  741. // implement the client's odd soft-fail mode.)
  742. hs->new_session->verify_result = X509_V_OK;
  743. }
  744. // Skip this state.
  745. hs->tls13_state = state_read_channel_id;
  746. return ssl_hs_ok;
  747. }
  748. const bool allow_anonymous =
  749. (hs->config->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) == 0;
  750. SSLMessage msg;
  751. if (!ssl->method->get_message(ssl, &msg)) {
  752. return ssl_hs_read_message;
  753. }
  754. if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE) ||
  755. !tls13_process_certificate(hs, msg, allow_anonymous) ||
  756. !ssl_hash_message(hs, msg)) {
  757. return ssl_hs_error;
  758. }
  759. ssl->method->next_message(ssl);
  760. hs->tls13_state = state_read_client_certificate_verify;
  761. return ssl_hs_ok;
  762. }
  763. static enum ssl_hs_wait_t do_read_client_certificate_verify(
  764. SSL_HANDSHAKE *hs) {
  765. SSL *const ssl = hs->ssl;
  766. if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0) {
  767. // Skip this state.
  768. hs->tls13_state = state_read_channel_id;
  769. return ssl_hs_ok;
  770. }
  771. SSLMessage msg;
  772. if (!ssl->method->get_message(ssl, &msg)) {
  773. return ssl_hs_read_message;
  774. }
  775. switch (ssl_verify_peer_cert(hs)) {
  776. case ssl_verify_ok:
  777. break;
  778. case ssl_verify_invalid:
  779. return ssl_hs_error;
  780. case ssl_verify_retry:
  781. hs->tls13_state = state_read_client_certificate_verify;
  782. return ssl_hs_certificate_verify;
  783. }
  784. if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE_VERIFY) ||
  785. !tls13_process_certificate_verify(hs, msg) ||
  786. !ssl_hash_message(hs, msg)) {
  787. return ssl_hs_error;
  788. }
  789. ssl->method->next_message(ssl);
  790. hs->tls13_state = state_read_channel_id;
  791. return ssl_hs_ok;
  792. }
  793. static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) {
  794. SSL *const ssl = hs->ssl;
  795. if (!ssl->s3->channel_id_valid) {
  796. hs->tls13_state = state_read_client_finished;
  797. return ssl_hs_ok;
  798. }
  799. SSLMessage msg;
  800. if (!ssl->method->get_message(ssl, &msg)) {
  801. return ssl_hs_read_message;
  802. }
  803. if (!ssl_check_message_type(ssl, msg, SSL3_MT_CHANNEL_ID) ||
  804. !tls1_verify_channel_id(hs, msg) ||
  805. !ssl_hash_message(hs, msg)) {
  806. return ssl_hs_error;
  807. }
  808. ssl->method->next_message(ssl);
  809. hs->tls13_state = state_read_client_finished;
  810. return ssl_hs_ok;
  811. }
  812. static enum ssl_hs_wait_t do_read_client_finished(SSL_HANDSHAKE *hs) {
  813. SSL *const ssl = hs->ssl;
  814. SSLMessage msg;
  815. if (!ssl->method->get_message(ssl, &msg)) {
  816. return ssl_hs_read_message;
  817. }
  818. if (!ssl_check_message_type(ssl, msg, SSL3_MT_FINISHED) ||
  819. // If early data was accepted, we've already computed the client Finished
  820. // and derived the resumption secret.
  821. !tls13_process_finished(hs, msg, ssl->s3->early_data_accepted) ||
  822. // evp_aead_seal keys have already been switched.
  823. !tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_open,
  824. hs->client_traffic_secret_0())) {
  825. return ssl_hs_error;
  826. }
  827. if (!ssl->s3->early_data_accepted) {
  828. if (!ssl_hash_message(hs, msg) ||
  829. !tls13_derive_resumption_secret(hs)) {
  830. return ssl_hs_error;
  831. }
  832. // We send post-handshake tickets as part of the handshake in 1-RTT.
  833. hs->tls13_state = state_send_new_session_ticket;
  834. } else {
  835. // We already sent half-RTT tickets.
  836. hs->tls13_state = state_done;
  837. }
  838. ssl->method->next_message(ssl);
  839. return ssl_hs_ok;
  840. }
  841. static enum ssl_hs_wait_t do_send_new_session_ticket(SSL_HANDSHAKE *hs) {
  842. bool sent_tickets;
  843. if (!add_new_session_tickets(hs, &sent_tickets)) {
  844. return ssl_hs_error;
  845. }
  846. hs->tls13_state = state_done;
  847. // In TLS 1.3, the NewSessionTicket isn't flushed until the server performs a
  848. // write, to prevent a non-reading client from causing the server to hang in
  849. // the case of a small server write buffer. Consumers which don't write data
  850. // to the client will need to do a zero-byte write if they wish to flush the
  851. // tickets.
  852. if (hs->ssl->ctx->quic_method != nullptr && sent_tickets) {
  853. return ssl_hs_flush;
  854. }
  855. return ssl_hs_ok;
  856. }
  857. enum ssl_hs_wait_t tls13_server_handshake(SSL_HANDSHAKE *hs) {
  858. while (hs->tls13_state != state_done) {
  859. enum ssl_hs_wait_t ret = ssl_hs_error;
  860. enum server_hs_state_t state =
  861. static_cast<enum server_hs_state_t>(hs->tls13_state);
  862. switch (state) {
  863. case state_select_parameters:
  864. ret = do_select_parameters(hs);
  865. break;
  866. case state_select_session:
  867. ret = do_select_session(hs);
  868. break;
  869. case state_send_hello_retry_request:
  870. ret = do_send_hello_retry_request(hs);
  871. break;
  872. case state_read_second_client_hello:
  873. ret = do_read_second_client_hello(hs);
  874. break;
  875. case state_send_server_hello:
  876. ret = do_send_server_hello(hs);
  877. break;
  878. case state_send_server_certificate_verify:
  879. ret = do_send_server_certificate_verify(hs);
  880. break;
  881. case state_send_server_finished:
  882. ret = do_send_server_finished(hs);
  883. break;
  884. case state_read_second_client_flight:
  885. ret = do_read_second_client_flight(hs);
  886. break;
  887. case state_process_end_of_early_data:
  888. ret = do_process_end_of_early_data(hs);
  889. break;
  890. case state_read_client_certificate:
  891. ret = do_read_client_certificate(hs);
  892. break;
  893. case state_read_client_certificate_verify:
  894. ret = do_read_client_certificate_verify(hs);
  895. break;
  896. case state_read_channel_id:
  897. ret = do_read_channel_id(hs);
  898. break;
  899. case state_read_client_finished:
  900. ret = do_read_client_finished(hs);
  901. break;
  902. case state_send_new_session_ticket:
  903. ret = do_send_new_session_ticket(hs);
  904. break;
  905. case state_done:
  906. ret = ssl_hs_ok;
  907. break;
  908. }
  909. if (hs->tls13_state != state) {
  910. ssl_do_info_callback(hs->ssl, SSL_CB_ACCEPT_LOOP, 1);
  911. }
  912. if (ret != ssl_hs_ok) {
  913. return ret;
  914. }
  915. }
  916. return ssl_hs_ok;
  917. }
  918. const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs) {
  919. enum server_hs_state_t state =
  920. static_cast<enum server_hs_state_t>(hs->tls13_state);
  921. switch (state) {
  922. case state_select_parameters:
  923. return "TLS 1.3 server select_parameters";
  924. case state_select_session:
  925. return "TLS 1.3 server select_session";
  926. case state_send_hello_retry_request:
  927. return "TLS 1.3 server send_hello_retry_request";
  928. case state_read_second_client_hello:
  929. return "TLS 1.3 server read_second_client_hello";
  930. case state_send_server_hello:
  931. return "TLS 1.3 server send_server_hello";
  932. case state_send_server_certificate_verify:
  933. return "TLS 1.3 server send_server_certificate_verify";
  934. case state_send_server_finished:
  935. return "TLS 1.3 server send_server_finished";
  936. case state_read_second_client_flight:
  937. return "TLS 1.3 server read_second_client_flight";
  938. case state_process_end_of_early_data:
  939. return "TLS 1.3 server process_end_of_early_data";
  940. case state_read_client_certificate:
  941. return "TLS 1.3 server read_client_certificate";
  942. case state_read_client_certificate_verify:
  943. return "TLS 1.3 server read_client_certificate_verify";
  944. case state_read_channel_id:
  945. return "TLS 1.3 server read_channel_id";
  946. case state_read_client_finished:
  947. return "TLS 1.3 server read_client_finished";
  948. case state_send_new_session_ticket:
  949. return "TLS 1.3 server send_new_session_ticket";
  950. case state_done:
  951. return "TLS 1.3 server done";
  952. }
  953. return "TLS 1.3 server unknown";
  954. }
  955. BSSL_NAMESPACE_END