David Benjamin | 33d1049 | 2025-02-03 17:00:03 -0500 | [diff] [blame] | 1 | // Copyright 2016 The BoringSSL Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 14 | |
| 15 | #include <openssl/ssl.h> |
| 16 | |
| 17 | #include <assert.h> |
| 18 | #include <string.h> |
| 19 | |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 20 | #include <algorithm> |
Adam Langley | 4bfab5d | 2019-01-23 13:52:17 -0800 | [diff] [blame] | 21 | #include <tuple> |
| 22 | |
David Benjamin | abbbee1 | 2016-10-31 19:20:42 -0400 | [diff] [blame] | 23 | #include <openssl/aead.h> |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 24 | #include <openssl/bytestring.h> |
| 25 | #include <openssl/digest.h> |
| 26 | #include <openssl/err.h> |
David Benjamin | 070a6c3 | 2021-05-05 15:39:27 -0400 | [diff] [blame] | 27 | #include <openssl/hpke.h> |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 28 | #include <openssl/mem.h> |
| 29 | #include <openssl/rand.h> |
| 30 | #include <openssl/stack.h> |
| 31 | |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 32 | #include "../crypto/internal.h" |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 33 | #include "internal.h" |
| 34 | |
| 35 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 36 | BSSL_NAMESPACE_BEGIN |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 37 | |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 38 | static const uint8_t kZeroes[EVP_MAX_MD_SIZE] = {0}; |
| 39 | |
David Benjamin | 6433a91 | 2019-05-04 14:17:08 -0500 | [diff] [blame] | 40 | // Allow a minute of ticket age skew in either direction. This covers |
| 41 | // transmission delays in ClientHello and NewSessionTicket, as well as |
| 42 | // drift between client and server clock rate since the ticket was issued. |
| 43 | // See RFC 8446, section 8.3. |
| 44 | static const int32_t kMaxTicketAgeSkewSeconds = 60; |
| 45 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 46 | static bool resolve_pake_secret(SSL_HANDSHAKE *hs) { |
| 47 | uint8_t verifier_share[spake2plus::kShareSize]; |
| 48 | uint8_t verifier_confirm[spake2plus::kConfirmSize]; |
| 49 | uint8_t shared_secret[spake2plus::kSecretSize]; |
| 50 | if (!hs->pake_verifier->ProcessProverShare(verifier_share, verifier_confirm, |
| 51 | shared_secret, |
| 52 | hs->pake_share->pake_message)) { |
| 53 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 54 | ssl_send_alert(hs->ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | bssl::ScopedCBB cbb; |
| 59 | if (!CBB_init(cbb.get(), sizeof(verifier_share) + sizeof(verifier_confirm)) || |
| 60 | !CBB_add_bytes(cbb.get(), verifier_share, sizeof(verifier_share)) || |
| 61 | !CBB_add_bytes(cbb.get(), verifier_confirm, sizeof(verifier_confirm)) || |
| 62 | !CBBFinishArray(cbb.get(), &hs->pake_share_bytes)) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | return tls13_advance_key_schedule( |
| 67 | hs, MakeConstSpan(shared_secret, sizeof(shared_secret))); |
| 68 | } |
| 69 | |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 70 | static bool resolve_ecdhe_secret(SSL_HANDSHAKE *hs, |
| 71 | const SSL_CLIENT_HELLO *client_hello) { |
David Benjamin | 6e4fc33 | 2016-11-17 16:43:08 +0900 | [diff] [blame] | 72 | SSL *const ssl = hs->ssl; |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 73 | const uint16_t group_id = hs->new_session->group_id; |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 74 | |
David Benjamin | 74795b3 | 2017-08-31 15:13:12 -0400 | [diff] [blame] | 75 | bool found_key_share; |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 76 | Span<const uint8_t> peer_key; |
David Benjamin | 7e1f984 | 2016-09-20 19:24:40 -0400 | [diff] [blame] | 77 | uint8_t alert = SSL_AD_DECODE_ERROR; |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 78 | if (!ssl_ext_key_share_parse_clienthello(hs, &found_key_share, &peer_key, |
| 79 | &alert, client_hello)) { |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 80 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 81 | return false; |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (!found_key_share) { |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 85 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 86 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE); |
| 87 | return false; |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 88 | } |
| 89 | |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 90 | Array<uint8_t> secret; |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 91 | SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); |
| 92 | if (hints && !hs->hints_requested && hints->key_share_group_id == group_id && |
| 93 | !hints->key_share_secret.empty()) { |
David Benjamin | 08b1f38 | 2023-02-28 17:22:23 -0500 | [diff] [blame] | 94 | // Copy the key_share secret from hints. |
| 95 | if (!hs->key_share_ciphertext.CopyFrom(hints->key_share_ciphertext) || |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 96 | !secret.CopyFrom(hints->key_share_secret)) { |
| 97 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 98 | return false; |
| 99 | } |
| 100 | } else { |
David Benjamin | 08b1f38 | 2023-02-28 17:22:23 -0500 | [diff] [blame] | 101 | ScopedCBB ciphertext; |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 102 | UniquePtr<SSLKeyShare> key_share = SSLKeyShare::Create(group_id); |
| 103 | if (!key_share || // |
David Benjamin | 08b1f38 | 2023-02-28 17:22:23 -0500 | [diff] [blame] | 104 | !CBB_init(ciphertext.get(), 32) || |
| 105 | !key_share->Encap(ciphertext.get(), &secret, &alert, peer_key) || |
| 106 | !CBBFinishArray(ciphertext.get(), &hs->key_share_ciphertext)) { |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 107 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 108 | return false; |
| 109 | } |
| 110 | if (hints && hs->hints_requested) { |
| 111 | hints->key_share_group_id = group_id; |
David Benjamin | 08b1f38 | 2023-02-28 17:22:23 -0500 | [diff] [blame] | 112 | if (!hints->key_share_ciphertext.CopyFrom(hs->key_share_ciphertext) || |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 113 | !hints->key_share_secret.CopyFrom(secret)) { |
| 114 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 115 | return false; |
| 116 | } |
| 117 | } |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | return tls13_advance_key_schedule(hs, secret); |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Steven Valdez | 038da9b | 2017-07-10 12:57:25 -0400 | [diff] [blame] | 123 | static int ssl_ext_supported_versions_add_serverhello(SSL_HANDSHAKE *hs, |
| 124 | CBB *out) { |
| 125 | CBB contents; |
Bob Beck | 61725ea | 2024-11-13 17:50:07 +0000 | [diff] [blame] | 126 | if (!CBB_add_u16(out, TLSEXT_TYPE_supported_versions) || // |
| 127 | !CBB_add_u16_length_prefixed(out, &contents) || // |
| 128 | !CBB_add_u16(&contents, hs->ssl->s3->version) || // |
Steven Valdez | 038da9b | 2017-07-10 12:57:25 -0400 | [diff] [blame] | 129 | !CBB_flush(out)) { |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | return 1; |
| 134 | } |
| 135 | |
David Benjamin | 34202b9 | 2016-11-16 19:07:53 +0900 | [diff] [blame] | 136 | static const SSL_CIPHER *choose_tls13_cipher( |
David Benjamin | 860db9e | 2024-03-02 22:53:13 -0500 | [diff] [blame] | 137 | const SSL *ssl, const SSL_CLIENT_HELLO *client_hello) { |
David Benjamin | 34202b9 | 2016-11-16 19:07:53 +0900 | [diff] [blame] | 138 | CBS cipher_suites; |
| 139 | CBS_init(&cipher_suites, client_hello->cipher_suites, |
| 140 | client_hello->cipher_suites_len); |
| 141 | |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 142 | const uint16_t version = ssl_protocol_version(ssl); |
David Benjamin | 34202b9 | 2016-11-16 19:07:53 +0900 | [diff] [blame] | 143 | |
David Benjamin | 860db9e | 2024-03-02 22:53:13 -0500 | [diff] [blame] | 144 | return ssl_choose_tls13_cipher(cipher_suites, |
| 145 | ssl->config->aes_hw_override |
| 146 | ? ssl->config->aes_hw_override_value |
| 147 | : EVP_has_aes_hardware(), |
Adam Langley | ca3146c | 2024-12-17 17:31:33 -0800 | [diff] [blame] | 148 | version, ssl->config->compliance_policy); |
David Benjamin | 34202b9 | 2016-11-16 19:07:53 +0900 | [diff] [blame] | 149 | } |
| 150 | |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 151 | static bool add_new_session_tickets(SSL_HANDSHAKE *hs, bool *out_sent_tickets) { |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 152 | SSL *const ssl = hs->ssl; |
Bob Beck | 61725ea | 2024-11-13 17:50:07 +0000 | [diff] [blame] | 153 | if ( // If the client doesn't accept resumption with PSK_DHE_KE, don't send a |
| 154 | // session ticket. |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 155 | !hs->accept_psk_mode || |
| 156 | // We only implement stateless resumption in TLS 1.3, so skip sending |
| 157 | // tickets if disabled. |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 158 | (SSL_get_options(ssl) & SSL_OP_NO_TICKET) || |
| 159 | // Don't send tickets for PAKE connections. We don't support resumption |
| 160 | // with PAKEs. |
| 161 | hs->pake_verifier != nullptr) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 162 | *out_sent_tickets = false; |
| 163 | return true; |
| 164 | } |
| 165 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 166 | // Rebase the session timestamp so that it is measured from ticket |
| 167 | // issuance. |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 168 | ssl_session_rebase_time(ssl, hs->new_session.get()); |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 169 | |
David Benjamin | 3f180b8 | 2022-05-09 17:45:18 -0400 | [diff] [blame] | 170 | assert(ssl->session_ctx->num_tickets <= kMaxTickets); |
David Benjamin | c59bf8b | 2024-11-12 12:02:09 -0500 | [diff] [blame] | 171 | bool sent_tickets = false; |
David Benjamin | 3f180b8 | 2022-05-09 17:45:18 -0400 | [diff] [blame] | 172 | for (size_t i = 0; i < ssl->session_ctx->num_tickets; i++) { |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 173 | UniquePtr<SSL_SESSION> session( |
| 174 | SSL_SESSION_dup(hs->new_session.get(), SSL_SESSION_INCLUDE_NONAUTH)); |
| 175 | if (!session) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 176 | return false; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 177 | } |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 178 | |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 179 | if (!RAND_bytes((uint8_t *)&session->ticket_age_add, 4)) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 180 | return false; |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 181 | } |
David Benjamin | a3a71e9 | 2018-06-29 13:24:45 -0400 | [diff] [blame] | 182 | session->ticket_age_add_valid = true; |
David Benjamin | 873ff5c | 2024-11-27 00:38:03 -0500 | [diff] [blame] | 183 | // TODO(crbug.com/381113363): Remove the SSL_is_dtls check once we support |
Nick Harper | 2dc95ee | 2024-10-29 23:42:56 +0000 | [diff] [blame] | 184 | // 0-RTT for DTLS 1.3. |
Nick Harper | 8519432 | 2020-05-20 16:59:29 -0700 | [diff] [blame] | 185 | bool enable_early_data = |
| 186 | ssl->enable_early_data && |
David Benjamin | 7ad6554 | 2024-11-20 15:01:01 -0500 | [diff] [blame] | 187 | (!SSL_is_quic(ssl) || !ssl->config->quic_early_data_context.empty()) && |
Nick Harper | 2dc95ee | 2024-10-29 23:42:56 +0000 | [diff] [blame] | 188 | !SSL_is_dtls(ssl); |
Nick Harper | 8519432 | 2020-05-20 16:59:29 -0700 | [diff] [blame] | 189 | if (enable_early_data) { |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 190 | // QUIC does not use the max_early_data_size parameter and always sets it |
David Benjamin | a1d3bfb | 2021-06-01 12:12:44 -0400 | [diff] [blame] | 191 | // to a fixed value. See RFC 9001, section 4.6.1. |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 192 | session->ticket_max_early_data = |
David Benjamin | 7ad6554 | 2024-11-20 15:01:01 -0500 | [diff] [blame] | 193 | SSL_is_quic(ssl) ? 0xffffffff : kMaxEarlyDataAccepted; |
Steven Valdez | be165a2 | 2017-10-10 11:45:01 -0400 | [diff] [blame] | 194 | } |
David Benjamin | 899b557 | 2025-03-04 11:08:40 -0500 | [diff] [blame] | 195 | session->is_resumable_across_names = ssl->resumption_across_names_enabled; |
Steven Valdez | be165a2 | 2017-10-10 11:45:01 -0400 | [diff] [blame] | 196 | |
David Benjamin | 3f180b8 | 2022-05-09 17:45:18 -0400 | [diff] [blame] | 197 | static_assert(kMaxTickets < 256, "Too many tickets"); |
| 198 | assert(i < 256); |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 199 | uint8_t nonce[] = {static_cast<uint8_t>(i)}; |
| 200 | |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 201 | ScopedCBB cbb; |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 202 | CBB body, nonce_cbb, ticket, extensions; |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 203 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 204 | SSL3_MT_NEW_SESSION_TICKET) || |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 205 | !CBB_add_u32(&body, session->timeout) || |
| 206 | !CBB_add_u32(&body, session->ticket_age_add) || |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 207 | !CBB_add_u8_length_prefixed(&body, &nonce_cbb) || |
| 208 | !CBB_add_bytes(&nonce_cbb, nonce, sizeof(nonce)) || |
Nick Harper | f9e0c6c | 2024-08-02 23:19:44 +0000 | [diff] [blame] | 209 | !tls13_derive_session_psk(session.get(), nonce, SSL_is_dtls(ssl)) || |
David Benjamin | c59bf8b | 2024-11-12 12:02:09 -0500 | [diff] [blame] | 210 | !CBB_add_u16_length_prefixed(&body, &ticket) || |
| 211 | !ssl_encrypt_ticket(hs, &ticket, session.get())) { |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | if (CBB_len(&ticket) == 0) { |
| 216 | // The caller decided not to encrypt a ticket. Skip the message. |
| 217 | continue; |
| 218 | } |
| 219 | |
| 220 | if (!CBB_add_u16_length_prefixed(&body, &extensions)) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 221 | return false; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 222 | } |
| 223 | |
Nick Harper | 8519432 | 2020-05-20 16:59:29 -0700 | [diff] [blame] | 224 | if (enable_early_data) { |
David Benjamin | a93beba | 2019-10-15 16:58:21 -0400 | [diff] [blame] | 225 | CBB early_data; |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 226 | if (!CBB_add_u16(&extensions, TLSEXT_TYPE_early_data) || |
David Benjamin | a93beba | 2019-10-15 16:58:21 -0400 | [diff] [blame] | 227 | !CBB_add_u16_length_prefixed(&extensions, &early_data) || |
| 228 | !CBB_add_u32(&early_data, session->ticket_max_early_data) || |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 229 | !CBB_flush(&extensions)) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 230 | return false; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
David Benjamin | 899b557 | 2025-03-04 11:08:40 -0500 | [diff] [blame] | 234 | SSLFlags flags = 0; |
| 235 | if (session->is_resumable_across_names) { |
| 236 | flags |= kSSLFlagResumptionAcrossNames; |
| 237 | } |
| 238 | if (!ssl_add_flags_extension(&extensions, flags)) { |
| 239 | return false; |
| 240 | } |
| 241 | |
David Benjamin | 3675eb3 | 2021-05-18 14:01:07 -0400 | [diff] [blame] | 242 | // Add a fake extension. See RFC 8701. |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 243 | if (!CBB_add_u16(&extensions, |
David Benjamin | a7bc944 | 2018-01-18 10:08:53 -0500 | [diff] [blame] | 244 | ssl_get_grease_value(hs, ssl_grease_ticket_extension)) || |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 245 | !CBB_add_u16(&extensions, 0 /* empty */)) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 246 | return false; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 247 | } |
| 248 | |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 249 | if (!ssl_add_message_cbb(ssl, cbb.get())) { |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 250 | return false; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 251 | } |
David Benjamin | c59bf8b | 2024-11-12 12:02:09 -0500 | [diff] [blame] | 252 | sent_tickets = true; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 253 | } |
| 254 | |
David Benjamin | c59bf8b | 2024-11-12 12:02:09 -0500 | [diff] [blame] | 255 | *out_sent_tickets = sent_tickets; |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 256 | return true; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 257 | } |
| 258 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 259 | static bool check_signature_credential(SSL_HANDSHAKE *hs, |
| 260 | const SSL_CREDENTIAL *cred, |
| 261 | uint16_t *out_sigalg) { |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 262 | switch (cred->type) { |
| 263 | case SSLCredentialType::kX509: |
| 264 | break; |
| 265 | case SSLCredentialType::kDelegated: |
| 266 | // Check that the peer supports the signature over the delegated |
| 267 | // credential. |
| 268 | if (std::find(hs->peer_sigalgs.begin(), hs->peer_sigalgs.end(), |
| 269 | cred->dc_algorithm) == hs->peer_sigalgs.end()) { |
| 270 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS); |
| 271 | return false; |
| 272 | } |
| 273 | break; |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 274 | default: |
| 275 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CERTIFICATE_TYPE); |
| 276 | return false; |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 279 | // If we reach here then the credential requires a signature. If |cred| is a |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 280 | // delegated credential, this also checks that the peer supports delegated |
| 281 | // credentials and matched |dc_cert_verify_algorithm|. |
Bob Beck | c8fafe8 | 2024-09-24 21:54:25 +0000 | [diff] [blame] | 282 | if (!tls1_choose_signature_algorithm(hs, cred, out_sigalg)) { |
| 283 | return false; |
| 284 | } |
| 285 | // Use this credential if it either matches a requested issuer, |
| 286 | // or does not require issuer matching. |
| 287 | return ssl_credential_matches_requested_issuers(hs, cred); |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 290 | static bool check_pake_credential(SSL_HANDSHAKE *hs, |
| 291 | const SSL_CREDENTIAL *cred) { |
| 292 | assert(cred->type == SSLCredentialType::kSPAKE2PlusV1Server); |
| 293 | // Look for a client PAKE share that matches |cred|. |
| 294 | if (hs->pake_share == nullptr || |
| 295 | hs->pake_share->named_pake != SSL_PAKE_SPAKE2PLUSV1 || |
| 296 | hs->pake_share->client_identity != Span(cred->client_identity) || |
| 297 | hs->pake_share->server_identity != Span(cred->server_identity)) { |
| 298 | OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_PAKE_MISMATCH); |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | return true; |
| 303 | } |
| 304 | |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 305 | static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 306 | // At this point, most ClientHello extensions have already been processed by |
| 307 | // the common handshake logic. Resolve the remaining non-PSK parameters. |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 308 | SSL *const ssl = hs->ssl; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 309 | SSLMessage msg; |
David Benjamin | 731058e | 2016-12-03 23:15:13 -0500 | [diff] [blame] | 310 | SSL_CLIENT_HELLO client_hello; |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 311 | if (!hs->GetClientHello(&msg, &client_hello)) { |
David Benjamin | 34202b9 | 2016-11-16 19:07:53 +0900 | [diff] [blame] | 312 | return ssl_hs_error; |
| 313 | } |
| 314 | |
David Benjamin | 7ad6554 | 2024-11-20 15:01:01 -0500 | [diff] [blame] | 315 | if (SSL_is_quic(ssl) && client_hello.session_id_len > 0) { |
Nick Harper | cac9392 | 2020-05-07 13:53:23 -0700 | [diff] [blame] | 316 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_COMPATIBILITY_MODE); |
| 317 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 318 | return ssl_hs_error; |
| 319 | } |
Nick Harper | cee4fe2 | 2024-07-29 20:01:29 +0000 | [diff] [blame] | 320 | // DTLS 1.3 disables compatibility mode, and even if the client advertised a |
| 321 | // session ID (for resumption in DTLS 1.2), the server "MUST NOT echo the |
| 322 | // 'legacy_session_id' value from the client" (RFC 9147, section 5) as it |
| 323 | // would in a TLS 1.3 handshake. |
| 324 | if (!SSL_is_dtls(ssl)) { |
David Benjamin | 87d0c17 | 2024-09-20 16:45:42 -0400 | [diff] [blame] | 325 | hs->session_id.CopyFrom( |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 326 | Span(client_hello.session_id, client_hello.session_id_len)); |
Nick Harper | cee4fe2 | 2024-07-29 20:01:29 +0000 | [diff] [blame] | 327 | } |
Steven Valdez | 520e122 | 2017-06-13 12:45:25 -0400 | [diff] [blame] | 328 | |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 329 | Array<SSL_CREDENTIAL *> creds; |
David Benjamin | a3de8ea | 2025-02-17 18:27:07 -0500 | [diff] [blame] | 330 | if (!ssl_get_full_credential_list(hs, &creds)) { |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 331 | return ssl_hs_error; |
| 332 | } |
| 333 | if (creds.empty()) { |
| 334 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET); |
| 335 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 336 | return ssl_hs_error; |
| 337 | } |
| 338 | |
| 339 | // Select the credential to use. |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 340 | for (SSL_CREDENTIAL *cred : creds) { |
| 341 | ERR_clear_error(); |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 342 | if (cred->type == SSLCredentialType::kSPAKE2PlusV1Server) { |
| 343 | if (check_pake_credential(hs, cred)) { |
| 344 | hs->credential = UpRef(cred); |
| 345 | hs->pake_verifier = MakeUnique<spake2plus::Verifier>(); |
| 346 | if (hs->pake_verifier == nullptr || |
| 347 | !hs->pake_verifier->Init(cred->pake_context, cred->client_identity, |
| 348 | cred->server_identity, |
| 349 | cred->password_verifier_w0, |
| 350 | cred->registration_record)) { |
| 351 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 352 | return ssl_hs_error; |
| 353 | } |
| 354 | break; |
| 355 | } |
| 356 | } else { |
| 357 | uint16_t sigalg; |
| 358 | if (check_signature_credential(hs, cred, &sigalg)) { |
| 359 | hs->credential = UpRef(cred); |
| 360 | hs->signature_algorithm = sigalg; |
| 361 | break; |
| 362 | } |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | if (hs->credential == nullptr) { |
| 366 | // The error from the last attempt is in the error queue. |
David Benjamin | f44677c | 2025-01-27 16:11:49 -0500 | [diff] [blame] | 367 | assert(ERR_peek_error() != 0); |
David Benjamin | 91a3f26 | 2024-02-10 11:08:08 -0500 | [diff] [blame] | 368 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 369 | return ssl_hs_error; |
| 370 | } |
| 371 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 372 | // Negotiate the cipher suite. |
David Benjamin | 860db9e | 2024-03-02 22:53:13 -0500 | [diff] [blame] | 373 | hs->new_cipher = choose_tls13_cipher(ssl, &client_hello); |
David Benjamin | 45738dd | 2017-02-09 20:01:26 -0500 | [diff] [blame] | 374 | if (hs->new_cipher == NULL) { |
David Benjamin | f01f42a | 2016-11-16 19:05:33 +0900 | [diff] [blame] | 375 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER); |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 376 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
David Benjamin | f01f42a | 2016-11-16 19:05:33 +0900 | [diff] [blame] | 377 | return ssl_hs_error; |
| 378 | } |
| 379 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 380 | // HTTP/2 negotiation depends on the cipher suite, so ALPN negotiation was |
| 381 | // deferred. Complete it now. |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 382 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 383 | if (!ssl_negotiate_alpn(hs, &alert, &client_hello)) { |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 384 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 385 | return ssl_hs_error; |
| 386 | } |
| 387 | |
David Benjamin | d55f450 | 2021-08-11 13:19:19 -0400 | [diff] [blame] | 388 | // The PRF hash is now known. |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 389 | if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher)) { |
| 390 | return ssl_hs_error; |
| 391 | } |
| 392 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 393 | hs->tls13_state = state13_select_session; |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 394 | return ssl_hs_ok; |
| 395 | } |
Steven Valdez | 908ac19 | 2017-01-12 13:17:07 -0500 | [diff] [blame] | 396 | |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 397 | static enum ssl_ticket_aead_result_t select_session( |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 398 | SSL_HANDSHAKE *hs, uint8_t *out_alert, UniquePtr<SSL_SESSION> *out_session, |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 399 | int32_t *out_ticket_age_skew, bool *out_offered_ticket, |
| 400 | const SSLMessage &msg, const SSL_CLIENT_HELLO *client_hello) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 401 | SSL *const ssl = hs->ssl; |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 402 | *out_session = nullptr; |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 403 | |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 404 | CBS pre_shared_key; |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 405 | *out_offered_ticket = ssl_client_hello_get_extension( |
| 406 | client_hello, &pre_shared_key, TLSEXT_TYPE_pre_shared_key); |
| 407 | if (!*out_offered_ticket) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 408 | return ssl_ticket_aead_ignore_ticket; |
| 409 | } |
| 410 | |
David Benjamin | 8648c53 | 2021-08-19 18:02:37 -0400 | [diff] [blame] | 411 | // Per RFC 8446, section 4.2.9, servers MUST abort the handshake if the client |
David Benjamin | 3af6226 | 2021-03-30 13:37:53 -0400 | [diff] [blame] | 412 | // sends pre_shared_key without psk_key_exchange_modes. |
| 413 | CBS unused; |
| 414 | if (!ssl_client_hello_get_extension(client_hello, &unused, |
| 415 | TLSEXT_TYPE_psk_key_exchange_modes)) { |
| 416 | *out_alert = SSL_AD_MISSING_EXTENSION; |
| 417 | OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_EXTENSION); |
| 418 | return ssl_ticket_aead_error; |
| 419 | } |
| 420 | |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 421 | CBS ticket, binders; |
| 422 | uint32_t client_ticket_age; |
David Benjamin | 9806ae0 | 2019-08-16 15:32:03 -0400 | [diff] [blame] | 423 | if (!ssl_ext_pre_shared_key_parse_clienthello( |
| 424 | hs, &ticket, &binders, &client_ticket_age, out_alert, client_hello, |
| 425 | &pre_shared_key)) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 426 | return ssl_ticket_aead_error; |
| 427 | } |
| 428 | |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 429 | // If the peer did not offer psk_dhe, ignore the resumption. |
| 430 | if (!hs->accept_psk_mode) { |
| 431 | return ssl_ticket_aead_ignore_ticket; |
| 432 | } |
| 433 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 434 | // We do not currently support resumption with PAKEs. |
| 435 | if (hs->credential != nullptr && |
| 436 | hs->credential->type == SSLCredentialType::kSPAKE2PlusV1Server) { |
| 437 | return ssl_ticket_aead_ignore_ticket; |
| 438 | } |
| 439 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 440 | // TLS 1.3 session tickets are renewed separately as part of the |
| 441 | // NewSessionTicket. |
David Benjamin | fd45ee7 | 2017-08-31 14:49:09 -0400 | [diff] [blame] | 442 | bool unused_renew; |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 443 | UniquePtr<SSL_SESSION> session; |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 444 | enum ssl_ticket_aead_result_t ret = |
David Benjamin | 2865567 | 2018-07-18 23:23:25 -0400 | [diff] [blame] | 445 | ssl_process_ticket(hs, &session, &unused_renew, ticket, {}); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 446 | switch (ret) { |
| 447 | case ssl_ticket_aead_success: |
| 448 | break; |
| 449 | case ssl_ticket_aead_error: |
| 450 | *out_alert = SSL_AD_INTERNAL_ERROR; |
| 451 | return ret; |
| 452 | default: |
| 453 | return ret; |
| 454 | } |
| 455 | |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 456 | if (!ssl_session_is_resumable(hs, session.get()) || |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 457 | // Historically, some TLS 1.3 tickets were missing ticket_age_add. |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 458 | !session->ticket_age_add_valid) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 459 | return ssl_ticket_aead_ignore_ticket; |
| 460 | } |
| 461 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 462 | // Recover the client ticket age and convert to seconds. |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 463 | client_ticket_age -= session->ticket_age_add; |
| 464 | client_ticket_age /= 1000; |
| 465 | |
David Benjamin | a5d14be | 2024-11-03 14:31:16 +0000 | [diff] [blame] | 466 | OPENSSL_timeval now = ssl_ctx_get_current_time(ssl->ctx.get()); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 467 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 468 | // Compute the server ticket age in seconds. |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 469 | assert(now.tv_sec >= session->time); |
| 470 | uint64_t server_ticket_age = now.tv_sec - session->time; |
| 471 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 472 | // To avoid overflowing |hs->ticket_age_skew|, we will not resume |
| 473 | // 68-year-old sessions. |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 474 | if (server_ticket_age > INT32_MAX) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 475 | return ssl_ticket_aead_ignore_ticket; |
| 476 | } |
| 477 | |
David Benjamin | 8c98bac | 2019-08-15 20:40:01 -0400 | [diff] [blame] | 478 | *out_ticket_age_skew = static_cast<int32_t>(client_ticket_age) - |
| 479 | static_cast<int32_t>(server_ticket_age); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 480 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 481 | // Check the PSK binder. |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 482 | if (!tls13_verify_psk_binder(hs, session.get(), msg, &binders)) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 483 | *out_alert = SSL_AD_DECRYPT_ERROR; |
| 484 | return ssl_ticket_aead_error; |
| 485 | } |
| 486 | |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 487 | *out_session = std::move(session); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 488 | return ssl_ticket_aead_success; |
| 489 | } |
| 490 | |
Nick Harper | 7c52299 | 2020-04-30 14:15:49 -0700 | [diff] [blame] | 491 | static bool quic_ticket_compatible(const SSL_SESSION *session, |
| 492 | const SSL_CONFIG *config) { |
| 493 | if (!session->is_quic) { |
| 494 | return true; |
| 495 | } |
Nick Harper | 8519432 | 2020-05-20 16:59:29 -0700 | [diff] [blame] | 496 | |
| 497 | if (session->quic_early_data_context.empty() || |
| 498 | config->quic_early_data_context.size() != |
| 499 | session->quic_early_data_context.size() || |
| 500 | CRYPTO_memcmp(config->quic_early_data_context.data(), |
| 501 | session->quic_early_data_context.data(), |
| 502 | session->quic_early_data_context.size()) != 0) { |
Nick Harper | 7c52299 | 2020-04-30 14:15:49 -0700 | [diff] [blame] | 503 | return false; |
| 504 | } |
| 505 | return true; |
| 506 | } |
| 507 | |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 508 | static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) { |
| 509 | SSL *const ssl = hs->ssl; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 510 | SSLMessage msg; |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 511 | SSL_CLIENT_HELLO client_hello; |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 512 | if (!hs->GetClientHello(&msg, &client_hello)) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 513 | return ssl_hs_error; |
| 514 | } |
| 515 | |
David Benjamin | 4eb95cc | 2016-11-16 17:08:23 +0900 | [diff] [blame] | 516 | uint8_t alert = SSL_AD_DECODE_ERROR; |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 517 | UniquePtr<SSL_SESSION> session; |
David Benjamin | 6477012 | 2019-05-04 11:00:04 -0500 | [diff] [blame] | 518 | bool offered_ticket = false; |
| 519 | switch (select_session(hs, &alert, &session, &ssl->s3->ticket_age_skew, |
| 520 | &offered_ticket, msg, &client_hello)) { |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 521 | case ssl_ticket_aead_ignore_ticket: |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 522 | assert(!session); |
David Benjamin | 962b375 | 2021-05-10 15:17:18 -0400 | [diff] [blame] | 523 | if (!ssl_get_new_session(hs)) { |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 524 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
David Benjamin | f01f42a | 2016-11-16 19:05:33 +0900 | [diff] [blame] | 525 | return ssl_hs_error; |
| 526 | } |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 527 | break; |
Steven Valdez | a833c35 | 2016-11-01 13:39:36 -0400 | [diff] [blame] | 528 | |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 529 | case ssl_ticket_aead_success: |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 530 | // Carry over authentication information from the previous handshake into |
| 531 | // a fresh session. |
David Benjamin | 37af90f | 2017-07-29 01:42:16 -0400 | [diff] [blame] | 532 | hs->new_session = |
| 533 | SSL_SESSION_dup(session.get(), SSL_SESSION_DUP_AUTH_ONLY); |
David Benjamin | 6433a91 | 2019-05-04 14:17:08 -0500 | [diff] [blame] | 534 | if (hs->new_session == nullptr) { |
| 535 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 536 | return ssl_hs_error; |
| 537 | } |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 538 | |
David Benjamin | 046bc1f | 2017-08-31 15:06:42 -0400 | [diff] [blame] | 539 | ssl->s3->session_reused = true; |
David Benjamin | 9b2cdb7 | 2021-04-01 23:21:53 -0400 | [diff] [blame] | 540 | hs->can_release_private_key = true; |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 541 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 542 | // Resumption incorporates fresh key material, so refresh the timeout. |
David Benjamin | 98472cb | 2018-05-02 16:05:36 -0400 | [diff] [blame] | 543 | ssl_session_renew_timeout(ssl, hs->new_session.get(), |
| 544 | ssl->session_ctx->session_psk_dhe_timeout); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 545 | break; |
| 546 | |
| 547 | case ssl_ticket_aead_error: |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 548 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 549 | return ssl_hs_error; |
| 550 | |
| 551 | case ssl_ticket_aead_retry: |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 552 | hs->tls13_state = state13_select_session; |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 553 | return ssl_hs_pending_ticket; |
| 554 | } |
| 555 | |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 556 | // Negotiate ALPS now, after ALPN is negotiated and |hs->new_session| is |
| 557 | // initialized. |
| 558 | if (!ssl_negotiate_alps(hs, &alert, &client_hello)) { |
| 559 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 560 | return ssl_hs_error; |
| 561 | } |
| 562 | |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 563 | // Record connection properties in the new session. |
| 564 | hs->new_session->cipher = hs->new_cipher; |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 565 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 566 | // If using key shares, resolve the supported group and determine if we need |
| 567 | // HelloRetryRequest. |
| 568 | bool need_hrr = false; |
| 569 | if (hs->pake_verifier == nullptr) { |
| 570 | if (!tls1_get_shared_group(hs, &hs->new_session->group_id)) { |
| 571 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_GROUP); |
| 572 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 573 | return ssl_hs_error; |
| 574 | } |
| 575 | bool found_key_share; |
| 576 | if (!ssl_ext_key_share_parse_clienthello(hs, &found_key_share, |
| 577 | /*out_key_share=*/nullptr, &alert, |
| 578 | &client_hello)) { |
| 579 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 580 | return ssl_hs_error; |
| 581 | } |
| 582 | need_hrr = !found_key_share; |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 583 | } |
| 584 | |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 585 | // Determine if we're negotiating 0-RTT. |
| 586 | if (!ssl->enable_early_data) { |
| 587 | ssl->s3->early_data_reason = ssl_early_data_disabled; |
| 588 | } else if (!offered_ticket) { |
| 589 | ssl->s3->early_data_reason = ssl_early_data_no_session_offered; |
| 590 | } else if (!session) { |
| 591 | ssl->s3->early_data_reason = ssl_early_data_session_not_resumed; |
| 592 | } else if (session->ticket_max_early_data == 0) { |
| 593 | ssl->s3->early_data_reason = ssl_early_data_unsupported_for_session; |
| 594 | } else if (!hs->early_data_offered) { |
| 595 | ssl->s3->early_data_reason = ssl_early_data_peer_declined; |
David Benjamin | 8acec00 | 2021-05-19 13:03:34 -0400 | [diff] [blame] | 596 | } else if (hs->channel_id_negotiated) { |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 597 | // Channel ID is incompatible with 0-RTT. |
| 598 | ssl->s3->early_data_reason = ssl_early_data_channel_id; |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 599 | } else if (Span(ssl->s3->alpn_selected) != session->early_alpn) { |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 600 | // The negotiated ALPN must match the one in the ticket. |
| 601 | ssl->s3->early_data_reason = ssl_early_data_alpn_mismatch; |
| 602 | } else if (hs->new_session->has_application_settings != |
| 603 | session->has_application_settings || |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 604 | Span(hs->new_session->local_application_settings) != |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 605 | session->local_application_settings) { |
| 606 | ssl->s3->early_data_reason = ssl_early_data_alps_mismatch; |
| 607 | } else if (ssl->s3->ticket_age_skew < -kMaxTicketAgeSkewSeconds || |
| 608 | kMaxTicketAgeSkewSeconds < ssl->s3->ticket_age_skew) { |
| 609 | ssl->s3->early_data_reason = ssl_early_data_ticket_age_skew; |
| 610 | } else if (!quic_ticket_compatible(session.get(), hs->config)) { |
| 611 | ssl->s3->early_data_reason = ssl_early_data_quic_parameter_mismatch; |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 612 | } else if (need_hrr) { |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 613 | ssl->s3->early_data_reason = ssl_early_data_hello_retry_request; |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 614 | } else { |
| 615 | // |ssl_session_is_resumable| forbids cross-cipher resumptions even if the |
| 616 | // PRF hashes match. |
| 617 | assert(hs->new_cipher == session->cipher); |
| 618 | |
| 619 | ssl->s3->early_data_reason = ssl_early_data_accepted; |
| 620 | ssl->s3->early_data_accepted = true; |
| 621 | } |
| 622 | |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 623 | // Store the ALPN and ALPS values in the session for 0-RTT. Note the peer |
| 624 | // applications settings are not generally known until client |
| 625 | // EncryptedExtensions. |
David Benjamin | bfdd1a9 | 2018-06-29 16:26:38 -0400 | [diff] [blame] | 626 | if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) { |
| 627 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 628 | return ssl_hs_error; |
Steven Valdez | 27a9e6a | 2017-02-14 13:20:40 -0500 | [diff] [blame] | 629 | } |
| 630 | |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 631 | // The peer applications settings are usually received later, in |
| 632 | // EncryptedExtensions. But, in 0-RTT handshakes, we carry over the |
| 633 | // values from |session|. Do this now, before |session| is discarded. |
| 634 | if (ssl->s3->early_data_accepted && |
| 635 | hs->new_session->has_application_settings && |
| 636 | !hs->new_session->peer_application_settings.CopyFrom( |
| 637 | session->peer_application_settings)) { |
| 638 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 639 | return ssl_hs_error; |
| 640 | } |
| 641 | |
Nick Harper | 5e08695 | 2020-09-30 13:59:14 -0700 | [diff] [blame] | 642 | // Copy the QUIC early data context to the session. |
David Benjamin | 7ad6554 | 2024-11-20 15:01:01 -0500 | [diff] [blame] | 643 | if (ssl->enable_early_data && SSL_is_quic(ssl)) { |
Nick Harper | 5e08695 | 2020-09-30 13:59:14 -0700 | [diff] [blame] | 644 | if (!hs->new_session->quic_early_data_context.CopyFrom( |
| 645 | hs->config->quic_early_data_context)) { |
| 646 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 647 | return ssl_hs_error; |
| 648 | } |
| 649 | } |
| 650 | |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 651 | if (ssl->ctx->dos_protection_cb != NULL && |
| 652 | ssl->ctx->dos_protection_cb(&client_hello) == 0) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 653 | // Connection rejected for DOS reasons. |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 654 | OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED); |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 655 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 656 | return ssl_hs_error; |
| 657 | } |
| 658 | |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 659 | size_t hash_len = EVP_MD_size( |
| 660 | ssl_get_handshake_digest(ssl_protocol_version(ssl), hs->new_cipher)); |
| 661 | |
| 662 | // Set up the key schedule and incorporate the PSK into the running secret. |
David Benjamin | 87d0c17 | 2024-09-20 16:45:42 -0400 | [diff] [blame] | 663 | if (!tls13_init_key_schedule(hs, ssl->s3->session_reused |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 664 | ? Span(hs->new_session->secret) |
| 665 | : Span(kZeroes, hash_len)) || |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 666 | !ssl_hash_message(hs, msg)) { |
David Benjamin | 9806ae0 | 2019-08-16 15:32:03 -0400 | [diff] [blame] | 667 | return ssl_hs_error; |
| 668 | } |
| 669 | |
David Benjamin | 02e6256 | 2017-12-18 18:04:01 -0500 | [diff] [blame] | 670 | if (ssl->s3->early_data_accepted) { |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 671 | if (!tls13_derive_early_secret(hs)) { |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 672 | return ssl_hs_error; |
| 673 | } |
| 674 | } else if (hs->early_data_offered) { |
David Benjamin | 046bc1f | 2017-08-31 15:06:42 -0400 | [diff] [blame] | 675 | ssl->s3->skip_early_data = true; |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 676 | } |
| 677 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 678 | if (need_hrr) { |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 679 | ssl->method->next_message(ssl); |
| 680 | if (!hs->transcript.UpdateForHelloRetryRequest()) { |
| 681 | return ssl_hs_error; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 682 | } |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 683 | hs->tls13_state = state13_send_hello_retry_request; |
| 684 | return ssl_hs_ok; |
| 685 | } |
| 686 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 687 | if (hs->pake_verifier) { |
| 688 | assert(!ssl->s3->session_reused); |
| 689 | // Revealing the PAKE share (notably confirmV) allows the client to confirm |
| 690 | // one PAKE guess, so we must deduct from the brute force limit. |
| 691 | if (!hs->credential->ClaimPAKEAttempt()) { |
| 692 | OPENSSL_PUT_ERROR(SSL, SSL_R_PAKE_EXHAUSTED); |
| 693 | ssl_send_alert(hs->ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 694 | return ssl_hs_error; |
| 695 | } |
| 696 | if (!resolve_pake_secret(hs)) { |
| 697 | return ssl_hs_error; |
| 698 | } |
| 699 | } else { |
| 700 | if (!resolve_ecdhe_secret(hs, &client_hello)) { |
| 701 | return ssl_hs_error; |
| 702 | } |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 703 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 704 | |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 705 | ssl->method->next_message(ssl); |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 706 | hs->ech_client_hello_buf.Reset(); |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 707 | hs->tls13_state = state13_send_server_hello; |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 708 | return ssl_hs_ok; |
| 709 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 710 | |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 711 | static enum ssl_hs_wait_t do_send_hello_retry_request(SSL_HANDSHAKE *hs) { |
| 712 | SSL *const ssl = hs->ssl; |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 713 | if (hs->hints_requested) { |
| 714 | return ssl_hs_hints_ready; |
| 715 | } |
Steven Valdez | 964b237 | 2017-11-07 17:09:52 -0500 | [diff] [blame] | 716 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 717 | // Although a server could HelloRetryRequest with PAKEs to request a cookie, |
| 718 | // we never do so. |
| 719 | assert(hs->pake_verifier == nullptr); |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 720 | ScopedCBB cbb; |
| 721 | CBB body, session_id, extensions; |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 722 | if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) || |
David Benjamin | 294ab97 | 2025-02-19 17:04:07 -0500 | [diff] [blame] | 723 | !CBB_add_u16(&body, |
| 724 | SSL_is_dtls(ssl) ? DTLS1_2_VERSION : TLS1_2_VERSION) || |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 725 | !CBB_add_bytes(&body, kHelloRetryRequest, SSL3_RANDOM_SIZE) || |
| 726 | !CBB_add_u8_length_prefixed(&body, &session_id) || |
David Benjamin | 87d0c17 | 2024-09-20 16:45:42 -0400 | [diff] [blame] | 727 | !CBB_add_bytes(&session_id, hs->session_id.data(), |
| 728 | hs->session_id.size()) || |
David Benjamin | 3743aaf | 2020-09-21 13:55:16 -0400 | [diff] [blame] | 729 | !CBB_add_u16(&body, SSL_CIPHER_get_protocol_id(hs->new_cipher)) || |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 730 | !CBB_add_u8(&body, 0 /* no compression */) || |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 731 | !CBB_add_u16_length_prefixed(&body, &extensions) || |
| 732 | !CBB_add_u16(&extensions, TLSEXT_TYPE_supported_versions) || |
| 733 | !CBB_add_u16(&extensions, 2 /* length */) || |
David Benjamin | 83824d2 | 2024-09-22 13:35:09 -0400 | [diff] [blame] | 734 | !CBB_add_u16(&extensions, ssl->s3->version) || |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 735 | !CBB_add_u16(&extensions, TLSEXT_TYPE_key_share) || |
| 736 | !CBB_add_u16(&extensions, 2 /* length */) || |
David Benjamin | 860db9e | 2024-03-02 22:53:13 -0500 | [diff] [blame] | 737 | !CBB_add_u16(&extensions, hs->new_session->group_id)) { |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 738 | return ssl_hs_error; |
| 739 | } |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 740 | if (hs->ech_is_inner) { |
| 741 | // Fill a placeholder for the ECH confirmation value. |
| 742 | if (!CBB_add_u16(&extensions, TLSEXT_TYPE_encrypted_client_hello) || |
| 743 | !CBB_add_u16(&extensions, ECH_CONFIRMATION_SIGNAL_LEN) || |
| 744 | !CBB_add_zeros(&extensions, ECH_CONFIRMATION_SIGNAL_LEN)) { |
| 745 | return ssl_hs_error; |
| 746 | } |
| 747 | } |
| 748 | Array<uint8_t> hrr; |
| 749 | if (!ssl->method->finish_message(ssl, cbb.get(), &hrr)) { |
| 750 | return ssl_hs_error; |
| 751 | } |
| 752 | if (hs->ech_is_inner) { |
| 753 | // Now that the message is encoded, fill in the whole value. |
| 754 | size_t offset = hrr.size() - ECH_CONFIRMATION_SIGNAL_LEN; |
| 755 | if (!ssl_ech_accept_confirmation( |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 756 | hs, Span(hrr).last(ECH_CONFIRMATION_SIGNAL_LEN), |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 757 | ssl->s3->client_random, hs->transcript, /*is_hrr=*/true, hrr, |
| 758 | offset)) { |
| 759 | return ssl_hs_error; |
| 760 | } |
| 761 | } |
Steven Valdez | 964b237 | 2017-11-07 17:09:52 -0500 | [diff] [blame] | 762 | |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 763 | if (!ssl->method->add_message(ssl, std::move(hrr)) || |
| 764 | !ssl->method->add_change_cipher_spec(ssl)) { |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 765 | return ssl_hs_error; |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 766 | } |
| 767 | |
Kris Kwiatkowski | b11902a | 2019-08-24 11:01:04 +0100 | [diff] [blame] | 768 | ssl->s3->used_hello_retry_request = true; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 769 | hs->tls13_state = state13_read_second_client_hello; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 770 | return ssl_hs_flush; |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 771 | } |
| 772 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 773 | static enum ssl_hs_wait_t do_read_second_client_hello(SSL_HANDSHAKE *hs) { |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 774 | SSL *const ssl = hs->ssl; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 775 | SSLMessage msg; |
| 776 | if (!ssl->method->get_message(ssl, &msg)) { |
| 777 | return ssl_hs_read_message; |
| 778 | } |
| 779 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CLIENT_HELLO)) { |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 780 | return ssl_hs_error; |
| 781 | } |
David Benjamin | 731058e | 2016-12-03 23:15:13 -0500 | [diff] [blame] | 782 | SSL_CLIENT_HELLO client_hello; |
David Benjamin | 9439870 | 2025-02-11 13:47:02 -0500 | [diff] [blame] | 783 | if (!SSL_parse_client_hello(ssl, &client_hello, CBS_data(&msg.body), |
| 784 | CBS_len(&msg.body))) { |
David Benjamin | d1e3ce1 | 2017-10-06 18:31:15 -0400 | [diff] [blame] | 785 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 786 | return ssl_hs_error; |
| 787 | } |
| 788 | |
David Benjamin | ba423c9 | 2021-06-15 16:26:58 -0400 | [diff] [blame] | 789 | if (ssl->s3->ech_status == ssl_ech_accepted) { |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 790 | // If we previously accepted the ClientHelloInner, the second ClientHello |
| 791 | // must contain an outer encrypted_client_hello extension. |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 792 | CBS ech_body; |
| 793 | if (!ssl_client_hello_get_extension(&client_hello, &ech_body, |
| 794 | TLSEXT_TYPE_encrypted_client_hello)) { |
| 795 | OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_EXTENSION); |
| 796 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION); |
| 797 | return ssl_hs_error; |
| 798 | } |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 799 | uint16_t kdf_id, aead_id; |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 800 | uint8_t type, config_id; |
Steven Valdez | 94a63a5 | 2021-04-29 10:52:42 -0400 | [diff] [blame] | 801 | CBS enc, payload; |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 802 | if (!CBS_get_u8(&ech_body, &type) || // |
| 803 | type != ECH_CLIENT_OUTER || // |
| 804 | !CBS_get_u16(&ech_body, &kdf_id) || // |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 805 | !CBS_get_u16(&ech_body, &aead_id) || |
Steven Valdez | 94a63a5 | 2021-04-29 10:52:42 -0400 | [diff] [blame] | 806 | !CBS_get_u8(&ech_body, &config_id) || |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 807 | !CBS_get_u16_length_prefixed(&ech_body, &enc) || |
| 808 | !CBS_get_u16_length_prefixed(&ech_body, &payload) || |
| 809 | CBS_len(&ech_body) != 0) { |
| 810 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 811 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 812 | return ssl_hs_error; |
| 813 | } |
| 814 | |
David Benjamin | f39c81d | 2021-05-03 18:39:46 -0400 | [diff] [blame] | 815 | if (kdf_id != EVP_HPKE_KDF_id(EVP_HPKE_CTX_kdf(hs->ech_hpke_ctx.get())) || |
| 816 | aead_id != |
| 817 | EVP_HPKE_AEAD_id(EVP_HPKE_CTX_aead(hs->ech_hpke_ctx.get())) || |
| 818 | config_id != hs->ech_config_id || CBS_len(&enc) > 0) { |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 819 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 820 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 821 | return ssl_hs_error; |
| 822 | } |
| 823 | |
| 824 | // Decrypt the payload with the HPKE context from the first ClientHello. |
David Benjamin | 44425dd | 2022-01-27 12:22:42 -0500 | [diff] [blame] | 825 | uint8_t alert = SSL_AD_DECODE_ERROR; |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 826 | bool unused; |
David Benjamin | 44425dd | 2022-01-27 12:22:42 -0500 | [diff] [blame] | 827 | if (!ssl_client_hello_decrypt(hs, &alert, &unused, |
| 828 | &hs->ech_client_hello_buf, &client_hello, |
| 829 | payload)) { |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 830 | // Decryption failure is fatal in the second ClientHello. |
| 831 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED); |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 832 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 833 | return ssl_hs_error; |
| 834 | } |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 835 | |
| 836 | // Reparse |client_hello| from the buffer owned by |hs|. |
| 837 | if (!hs->GetClientHello(&msg, &client_hello)) { |
| 838 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 839 | return ssl_hs_error; |
| 840 | } |
| 841 | } |
| 842 | |
David Benjamin | 9806ae0 | 2019-08-16 15:32:03 -0400 | [diff] [blame] | 843 | // We perform all our negotiation based on the first ClientHello (for |
| 844 | // consistency with what |select_certificate_cb| observed), which is in the |
| 845 | // transcript, so we can ignore most of this second one. |
| 846 | // |
| 847 | // We do, however, check the second PSK binder. This covers the client key |
| 848 | // share, in case we ever send half-RTT data (we currently do not). It is also |
| 849 | // a tricky computation, so we enforce the peer handled it correctly. |
| 850 | if (ssl->s3->session_reused) { |
| 851 | CBS pre_shared_key; |
| 852 | if (!ssl_client_hello_get_extension(&client_hello, &pre_shared_key, |
| 853 | TLSEXT_TYPE_pre_shared_key)) { |
| 854 | OPENSSL_PUT_ERROR(SSL, SSL_R_INCONSISTENT_CLIENT_HELLO); |
| 855 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 856 | return ssl_hs_error; |
| 857 | } |
| 858 | |
| 859 | CBS ticket, binders; |
| 860 | uint32_t client_ticket_age; |
| 861 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 862 | if (!ssl_ext_pre_shared_key_parse_clienthello( |
| 863 | hs, &ticket, &binders, &client_ticket_age, &alert, &client_hello, |
| 864 | &pre_shared_key)) { |
| 865 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 866 | return ssl_hs_error; |
| 867 | } |
| 868 | |
| 869 | // Note it is important that we do not obtain a new |SSL_SESSION| from |
| 870 | // |ticket|. We have already selected parameters based on the first |
| 871 | // ClientHello (in the transcript) and must not switch partway through. |
| 872 | if (!tls13_verify_psk_binder(hs, hs->new_session.get(), msg, &binders)) { |
| 873 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR); |
| 874 | return ssl_hs_error; |
| 875 | } |
| 876 | } |
| 877 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 878 | // Although a server could HelloRetryRequest with PAKEs to request a cookie, |
| 879 | // we never do so. |
| 880 | assert(hs->pake_verifier == nullptr); |
David Benjamin | 3b8c5ec | 2021-04-12 17:43:23 -0400 | [diff] [blame] | 881 | if (!resolve_ecdhe_secret(hs, &client_hello)) { |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 882 | return ssl_hs_error; |
| 883 | } |
| 884 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 885 | if (!ssl_hash_message(hs, msg)) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 886 | return ssl_hs_error; |
| 887 | } |
| 888 | |
David Benjamin | f9cc26f | 2020-02-09 16:49:31 -0500 | [diff] [blame] | 889 | // ClientHello should be the end of the flight. |
| 890 | if (ssl->method->has_unprocessed_handshake_data(ssl)) { |
| 891 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE); |
| 892 | OPENSSL_PUT_ERROR(SSL, SSL_R_EXCESS_HANDSHAKE_DATA); |
| 893 | return ssl_hs_error; |
| 894 | } |
| 895 | |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 896 | ssl->method->next_message(ssl); |
Daniel McArdle | 00e434d | 2021-02-18 11:47:18 -0500 | [diff] [blame] | 897 | hs->ech_client_hello_buf.Reset(); |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 898 | hs->tls13_state = state13_send_server_hello; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 899 | return ssl_hs_ok; |
| 900 | } |
| 901 | |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 902 | static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) { |
| 903 | SSL *const ssl = hs->ssl; |
David Benjamin | 81b7bc3 | 2017-01-12 19:44:57 -0500 | [diff] [blame] | 904 | |
Dan McArdle | c295935 | 2020-10-29 14:31:31 -0400 | [diff] [blame] | 905 | Span<uint8_t> random(ssl->s3->server_random); |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 906 | |
| 907 | SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); |
| 908 | if (hints && !hs->hints_requested && |
David Benjamin | 4a6c8fd | 2022-07-21 14:05:41 -0700 | [diff] [blame] | 909 | hints->server_random_tls13.size() == random.size()) { |
| 910 | OPENSSL_memcpy(random.data(), hints->server_random_tls13.data(), |
| 911 | random.size()); |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 912 | } else { |
| 913 | RAND_bytes(random.data(), random.size()); |
| 914 | if (hints && hs->hints_requested && |
David Benjamin | 4a6c8fd | 2022-07-21 14:05:41 -0700 | [diff] [blame] | 915 | !hints->server_random_tls13.CopyFrom(random)) { |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 916 | return ssl_hs_error; |
| 917 | } |
| 918 | } |
Dan McArdle | c295935 | 2020-10-29 14:31:31 -0400 | [diff] [blame] | 919 | |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 920 | Array<uint8_t> server_hello; |
| 921 | ScopedCBB cbb; |
| 922 | CBB body, extensions, session_id; |
| 923 | if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) || |
David Benjamin | 294ab97 | 2025-02-19 17:04:07 -0500 | [diff] [blame] | 924 | !CBB_add_u16(&body, |
| 925 | SSL_is_dtls(ssl) ? DTLS1_2_VERSION : TLS1_2_VERSION) || |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 926 | !CBB_add_bytes(&body, ssl->s3->server_random, |
| 927 | sizeof(ssl->s3->server_random)) || |
| 928 | !CBB_add_u8_length_prefixed(&body, &session_id) || |
David Benjamin | 87d0c17 | 2024-09-20 16:45:42 -0400 | [diff] [blame] | 929 | !CBB_add_bytes(&session_id, hs->session_id.data(), |
| 930 | hs->session_id.size()) || |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 931 | !CBB_add_u16(&body, SSL_CIPHER_get_protocol_id(hs->new_cipher)) || |
| 932 | !CBB_add_u8(&body, 0) || |
| 933 | !CBB_add_u16_length_prefixed(&body, &extensions) || |
| 934 | !ssl_ext_pre_shared_key_add_serverhello(hs, &extensions) || |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 935 | !ssl_ext_pake_add_serverhello(hs, &extensions) || |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 936 | !ssl_ext_key_share_add_serverhello(hs, &extensions) || |
| 937 | !ssl_ext_supported_versions_add_serverhello(hs, &extensions) || |
| 938 | !ssl->method->finish_message(ssl, cbb.get(), &server_hello)) { |
| 939 | return ssl_hs_error; |
Dan McArdle | c295935 | 2020-10-29 14:31:31 -0400 | [diff] [blame] | 940 | } |
| 941 | |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 942 | assert(ssl->s3->ech_status != ssl_ech_accepted || hs->ech_is_inner); |
| 943 | if (hs->ech_is_inner) { |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 944 | // Fill in the ECH confirmation signal. |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 945 | const size_t offset = ssl_ech_confirmation_signal_hello_offset(ssl); |
David Benjamin | 006f20a | 2021-06-22 23:00:49 -0400 | [diff] [blame] | 946 | Span<uint8_t> random_suffix = random.last(ECH_CONFIRMATION_SIGNAL_LEN); |
David Benjamin | 18b6836 | 2021-06-18 23:13:46 -0400 | [diff] [blame] | 947 | if (!ssl_ech_accept_confirmation(hs, random_suffix, ssl->s3->client_random, |
| 948 | hs->transcript, |
| 949 | /*is_hrr=*/false, server_hello, offset)) { |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 950 | return ssl_hs_error; |
| 951 | } |
| 952 | |
| 953 | // Update |server_hello|. |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 954 | Span<uint8_t> server_hello_out = |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 955 | Span(server_hello).subspan(offset, ECH_CONFIRMATION_SIGNAL_LEN); |
David Benjamin | 83a4993 | 2021-05-20 15:57:09 -0400 | [diff] [blame] | 956 | OPENSSL_memcpy(server_hello_out.data(), random_suffix.data(), |
| 957 | ECH_CONFIRMATION_SIGNAL_LEN); |
| 958 | } |
| 959 | |
| 960 | if (!ssl->method->add_message(ssl, std::move(server_hello))) { |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 961 | return ssl_hs_error; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 962 | } |
| 963 | |
David Benjamin | 08b1f38 | 2023-02-28 17:22:23 -0500 | [diff] [blame] | 964 | hs->key_share_ciphertext.Reset(); // No longer needed. |
Kris Kwiatkowski | b11902a | 2019-08-24 11:01:04 +0100 | [diff] [blame] | 965 | if (!ssl->s3->used_hello_retry_request && |
David Benjamin | 666d16e | 2017-10-06 18:45:16 -0400 | [diff] [blame] | 966 | !ssl->method->add_change_cipher_spec(ssl)) { |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 967 | return ssl_hs_error; |
Steven Valdez | 520e122 | 2017-06-13 12:45:25 -0400 | [diff] [blame] | 968 | } |
| 969 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 970 | // Derive and enable the handshake traffic secrets. |
Steven Valdez | 4cb8494 | 2016-12-16 11:29:28 -0500 | [diff] [blame] | 971 | if (!tls13_derive_handshake_secrets(hs) || |
David Benjamin | e530ea3 | 2019-08-16 19:28:00 -0400 | [diff] [blame] | 972 | !tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal, |
David Benjamin | 754d4c9 | 2020-02-11 16:27:21 -0500 | [diff] [blame] | 973 | hs->new_session.get(), |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 974 | hs->server_handshake_secret)) { |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 975 | return ssl_hs_error; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 976 | } |
| 977 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 978 | // Send EncryptedExtensions. |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 979 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 980 | SSL3_MT_ENCRYPTED_EXTENSIONS) || |
David Benjamin | 8c880a2 | 2016-12-03 02:20:34 -0500 | [diff] [blame] | 981 | !ssl_add_serverhello_tlsext(hs, &body) || |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 982 | !ssl_add_message_cbb(ssl, cbb.get())) { |
| 983 | return ssl_hs_error; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 986 | if (!ssl->s3->session_reused && !hs->pake_verifier) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 987 | // Determine whether to request a client certificate. |
Matthew Braithwaite | b7bc80a | 2018-04-13 15:51:30 -0700 | [diff] [blame] | 988 | hs->cert_request = !!(hs->config->verify_mode & SSL_VERIFY_PEER); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 989 | } |
| 990 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 991 | // Send a CertificateRequest, if necessary. |
David Benjamin | 81b7bc3 | 2017-01-12 19:44:57 -0500 | [diff] [blame] | 992 | if (hs->cert_request) { |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 993 | CBB cert_request_extensions, sigalg_contents, sigalgs_cbb; |
| 994 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
| 995 | SSL3_MT_CERTIFICATE_REQUEST) || |
| 996 | !CBB_add_u8(&body, 0 /* no certificate_request_context. */) || |
| 997 | !CBB_add_u16_length_prefixed(&body, &cert_request_extensions) || |
| 998 | !CBB_add_u16(&cert_request_extensions, |
| 999 | TLSEXT_TYPE_signature_algorithms) || |
| 1000 | !CBB_add_u16_length_prefixed(&cert_request_extensions, |
| 1001 | &sigalg_contents) || |
| 1002 | !CBB_add_u16_length_prefixed(&sigalg_contents, &sigalgs_cbb) || |
David Benjamin | ebad508 | 2020-02-03 19:32:19 -0500 | [diff] [blame] | 1003 | !tls12_add_verify_sigalgs(hs, &sigalgs_cbb)) { |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1004 | return ssl_hs_error; |
| 1005 | } |
| 1006 | |
Matthew Braithwaite | b7bc80a | 2018-04-13 15:51:30 -0700 | [diff] [blame] | 1007 | if (ssl_has_client_CAs(hs->config)) { |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1008 | CBB ca_contents; |
| 1009 | if (!CBB_add_u16(&cert_request_extensions, |
| 1010 | TLSEXT_TYPE_certificate_authorities) || |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 1011 | !CBB_add_u16_length_prefixed(&cert_request_extensions, |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1012 | &ca_contents) || |
Matthew Braithwaite | b7bc80a | 2018-04-13 15:51:30 -0700 | [diff] [blame] | 1013 | !ssl_add_client_CA_list(hs, &ca_contents) || |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1014 | !CBB_flush(&cert_request_extensions)) { |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 1015 | return ssl_hs_error; |
| 1016 | } |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1017 | } |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 1018 | |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1019 | if (!ssl_add_message_cbb(ssl, cbb.get())) { |
| 1020 | return ssl_hs_error; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1024 | // Send the server Certificate message, if necessary. |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 1025 | if (!ssl->s3->session_reused && !hs->pake_verifier) { |
David Benjamin | 0f24bed | 2017-01-12 19:46:50 -0500 | [diff] [blame] | 1026 | if (!tls13_add_certificate(hs)) { |
David Benjamin | 1386aad | 2017-07-19 23:57:40 -0400 | [diff] [blame] | 1027 | return ssl_hs_error; |
David Benjamin | 81b7bc3 | 2017-01-12 19:44:57 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1030 | hs->tls13_state = state13_send_server_certificate_verify; |
David Benjamin | 81b7bc3 | 2017-01-12 19:44:57 -0500 | [diff] [blame] | 1031 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1034 | hs->tls13_state = state13_send_server_finished; |
David Benjamin | 25ac251 | 2017-01-12 19:31:28 -0500 | [diff] [blame] | 1035 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
David Benjamin | 4414874 | 2017-06-17 13:20:59 -0400 | [diff] [blame] | 1038 | static enum ssl_hs_wait_t do_send_server_certificate_verify(SSL_HANDSHAKE *hs) { |
| 1039 | switch (tls13_add_certificate_verify(hs)) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1040 | case ssl_private_key_success: |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1041 | hs->tls13_state = state13_send_server_finished; |
David Benjamin | 25ac251 | 2017-01-12 19:31:28 -0500 | [diff] [blame] | 1042 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1043 | |
| 1044 | case ssl_private_key_retry: |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1045 | hs->tls13_state = state13_send_server_certificate_verify; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1046 | return ssl_hs_private_key_operation; |
| 1047 | |
| 1048 | case ssl_private_key_failure: |
| 1049 | return ssl_hs_error; |
| 1050 | } |
| 1051 | |
| 1052 | assert(0); |
| 1053 | return ssl_hs_error; |
| 1054 | } |
| 1055 | |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1056 | static enum ssl_hs_wait_t do_send_server_finished(SSL_HANDSHAKE *hs) { |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1057 | SSL *const ssl = hs->ssl; |
David Benjamin | b571e77 | 2021-03-25 19:42:16 -0400 | [diff] [blame] | 1058 | if (hs->hints_requested) { |
| 1059 | return ssl_hs_hints_ready; |
| 1060 | } |
| 1061 | |
David Benjamin | 9b2cdb7 | 2021-04-01 23:21:53 -0400 | [diff] [blame] | 1062 | hs->can_release_private_key = true; |
David Benjamin | 0f24bed | 2017-01-12 19:46:50 -0500 | [diff] [blame] | 1063 | if (!tls13_add_finished(hs) || |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1064 | // Update the secret to the master secret and derive traffic keys. |
David Benjamin | f609950 | 2025-01-11 00:38:56 -0500 | [diff] [blame] | 1065 | !tls13_advance_key_schedule(hs, |
| 1066 | Span(kZeroes, hs->transcript.DigestLen())) || |
David Benjamin | 6e4fc33 | 2016-11-17 16:43:08 +0900 | [diff] [blame] | 1067 | !tls13_derive_application_secrets(hs) || |
David Benjamin | e530ea3 | 2019-08-16 19:28:00 -0400 | [diff] [blame] | 1068 | !tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_seal, |
David Benjamin | 754d4c9 | 2020-02-11 16:27:21 -0500 | [diff] [blame] | 1069 | hs->new_session.get(), |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1070 | hs->server_traffic_secret_0)) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1071 | return ssl_hs_error; |
| 1072 | } |
| 1073 | |
Matthew Braithwaite | 093a823 | 2020-01-28 14:06:55 -0800 | [diff] [blame] | 1074 | hs->tls13_state = state13_send_half_rtt_ticket; |
David Benjamin | 0c30649 | 2020-02-09 16:28:52 -0500 | [diff] [blame] | 1075 | return hs->handback ? ssl_hs_handback : ssl_hs_ok; |
Matthew Braithwaite | 093a823 | 2020-01-28 14:06:55 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | static enum ssl_hs_wait_t do_send_half_rtt_ticket(SSL_HANDSHAKE *hs) { |
| 1079 | SSL *const ssl = hs->ssl; |
| 1080 | |
David Benjamin | 02e6256 | 2017-12-18 18:04:01 -0500 | [diff] [blame] | 1081 | if (ssl->s3->early_data_accepted) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1082 | // If accepting 0-RTT, we send tickets half-RTT. This gets the tickets on |
| 1083 | // the wire sooner and also avoids triggering a write on |SSL_read| when |
| 1084 | // processing the client Finished. This requires computing the client |
David Benjamin | a130ce0 | 2018-08-14 22:26:39 -0500 | [diff] [blame] | 1085 | // Finished early. See RFC 8446, section 4.6.1. |
Bob Beck | 61725ea | 2024-11-13 17:50:07 +0000 | [diff] [blame] | 1086 | static const uint8_t kEndOfEarlyData[4] = {SSL3_MT_END_OF_EARLY_DATA, 0, 0, |
| 1087 | 0}; |
David Benjamin | 7ad6554 | 2024-11-20 15:01:01 -0500 | [diff] [blame] | 1088 | if (!SSL_is_quic(ssl) && !hs->transcript.Update(kEndOfEarlyData)) { |
Steven Valdez | 7e5dd25 | 2018-01-22 15:20:31 -0500 | [diff] [blame] | 1089 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1090 | return ssl_hs_error; |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 1091 | } |
| 1092 | |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1093 | size_t finished_len; |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1094 | hs->expected_client_finished.Resize(hs->transcript.DigestLen()); |
| 1095 | if (!tls13_finished_mac(hs, hs->expected_client_finished.data(), |
David Benjamin | e530ea3 | 2019-08-16 19:28:00 -0400 | [diff] [blame] | 1096 | &finished_len, false /* client */)) { |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1097 | return ssl_hs_error; |
| 1098 | } |
| 1099 | |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1100 | if (finished_len != hs->expected_client_finished.size()) { |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1101 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1102 | return ssl_hs_error; |
| 1103 | } |
| 1104 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1105 | // Feed the predicted Finished into the transcript. This allows us to derive |
| 1106 | // the resumption secret early and send half-RTT tickets. |
David Benjamin | d252906 | 2024-10-22 17:53:35 -0400 | [diff] [blame] | 1107 | // |
David Benjamin | 873ff5c | 2024-11-27 00:38:03 -0500 | [diff] [blame] | 1108 | // TODO(crbug.com/381113363): Don't use half-RTT tickets with DTLS 1.3. |
| 1109 | // TODO(crbug.com/376939532): Perhaps don't use half-RTT tickets at all. |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1110 | assert(!SSL_is_dtls(hs->ssl)); |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1111 | assert(hs->expected_client_finished.size() <= 0xff); |
David Benjamin | e530ea3 | 2019-08-16 19:28:00 -0400 | [diff] [blame] | 1112 | uint8_t header[4] = { |
| 1113 | SSL3_MT_FINISHED, 0, 0, |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1114 | static_cast<uint8_t>(hs->expected_client_finished.size())}; |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 1115 | bool unused_sent_tickets; |
David Benjamin | 75a1f23 | 2017-10-11 17:19:19 -0400 | [diff] [blame] | 1116 | if (!hs->transcript.Update(header) || |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1117 | !hs->transcript.Update(hs->expected_client_finished) || |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1118 | !tls13_derive_resumption_secret(hs) || |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 1119 | !add_new_session_tickets(hs, &unused_sent_tickets)) { |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1120 | return ssl_hs_error; |
| 1121 | } |
| 1122 | } |
| 1123 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1124 | hs->tls13_state = state13_read_second_client_flight; |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1125 | return ssl_hs_flush; |
| 1126 | } |
| 1127 | |
David Benjamin | 8237469 | 2024-09-05 17:04:04 -0400 | [diff] [blame] | 1128 | static bool uses_end_of_early_data(const SSL *ssl) { |
| 1129 | // DTLS and QUIC omit the EndOfEarlyData message. See RFC 9001, section 8.3, |
| 1130 | // and RFC 9147, section 5.6. |
David Benjamin | 7ad6554 | 2024-11-20 15:01:01 -0500 | [diff] [blame] | 1131 | return !SSL_is_quic(ssl) && !SSL_is_dtls(ssl); |
David Benjamin | 8237469 | 2024-09-05 17:04:04 -0400 | [diff] [blame] | 1132 | } |
| 1133 | |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1134 | static enum ssl_hs_wait_t do_read_second_client_flight(SSL_HANDSHAKE *hs) { |
| 1135 | SSL *const ssl = hs->ssl; |
David Benjamin | 02e6256 | 2017-12-18 18:04:01 -0500 | [diff] [blame] | 1136 | if (ssl->s3->early_data_accepted) { |
David Benjamin | 1e85905 | 2020-02-09 16:04:58 -0500 | [diff] [blame] | 1137 | if (!tls13_set_traffic_key(ssl, ssl_encryption_early_data, evp_aead_open, |
David Benjamin | 754d4c9 | 2020-02-11 16:27:21 -0500 | [diff] [blame] | 1138 | hs->new_session.get(), |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1139 | hs->early_traffic_secret)) { |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1140 | return ssl_hs_error; |
| 1141 | } |
David Benjamin | fd45ee7 | 2017-08-31 14:49:09 -0400 | [diff] [blame] | 1142 | hs->can_early_write = true; |
| 1143 | hs->can_early_read = true; |
| 1144 | hs->in_early_data = true; |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1145 | } |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 1146 | |
David Benjamin | 8237469 | 2024-09-05 17:04:04 -0400 | [diff] [blame] | 1147 | // If the EndOfEarlyData message is not used, switch to |
| 1148 | // client_handshake_secret before the early return. |
| 1149 | if (!uses_end_of_early_data(ssl)) { |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 1150 | if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open, |
David Benjamin | 754d4c9 | 2020-02-11 16:27:21 -0500 | [diff] [blame] | 1151 | hs->new_session.get(), |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1152 | hs->client_handshake_secret)) { |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 1153 | return ssl_hs_error; |
| 1154 | } |
David Benjamin | 71ed9d7 | 2021-01-12 18:18:46 -0500 | [diff] [blame] | 1155 | hs->tls13_state = state13_process_end_of_early_data; |
David Benjamin | d634357 | 2019-08-15 17:29:02 -0400 | [diff] [blame] | 1156 | return ssl->s3->early_data_accepted ? ssl_hs_early_return : ssl_hs_ok; |
| 1157 | } |
| 1158 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1159 | hs->tls13_state = state13_process_end_of_early_data; |
David Benjamin | 02e6256 | 2017-12-18 18:04:01 -0500 | [diff] [blame] | 1160 | return ssl->s3->early_data_accepted ? ssl_hs_read_end_of_early_data |
| 1161 | : ssl_hs_ok; |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) { |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 1165 | SSL *const ssl = hs->ssl; |
David Benjamin | 71ed9d7 | 2021-01-12 18:18:46 -0500 | [diff] [blame] | 1166 | // In protocols that use EndOfEarlyData, we must consume the extra message and |
| 1167 | // switch to client_handshake_secret after the early return. |
David Benjamin | 8237469 | 2024-09-05 17:04:04 -0400 | [diff] [blame] | 1168 | if (uses_end_of_early_data(ssl)) { |
David Benjamin | 71ed9d7 | 2021-01-12 18:18:46 -0500 | [diff] [blame] | 1169 | // If early data was not accepted, the EndOfEarlyData will be in the |
| 1170 | // discarded early data. |
| 1171 | if (hs->ssl->s3->early_data_accepted) { |
| 1172 | SSLMessage msg; |
| 1173 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1174 | return ssl_hs_read_message; |
| 1175 | } |
| 1176 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_END_OF_EARLY_DATA)) { |
| 1177 | return ssl_hs_error; |
| 1178 | } |
| 1179 | if (CBS_len(&msg.body) != 0) { |
| 1180 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1181 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1182 | return ssl_hs_error; |
| 1183 | } |
| 1184 | ssl->method->next_message(ssl); |
Steven Valdez | cd8470f | 2017-10-11 12:29:36 -0400 | [diff] [blame] | 1185 | } |
David Benjamin | 71ed9d7 | 2021-01-12 18:18:46 -0500 | [diff] [blame] | 1186 | if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open, |
| 1187 | hs->new_session.get(), |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1188 | hs->client_handshake_secret)) { |
David Benjamin | f350351 | 2019-08-20 15:55:24 -0400 | [diff] [blame] | 1189 | return ssl_hs_error; |
| 1190 | } |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1191 | } |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1192 | hs->tls13_state = state13_read_client_encrypted_extensions; |
| 1193 | return ssl_hs_ok; |
| 1194 | } |
| 1195 | |
| 1196 | static enum ssl_hs_wait_t do_read_client_encrypted_extensions( |
| 1197 | SSL_HANDSHAKE *hs) { |
| 1198 | SSL *const ssl = hs->ssl; |
| 1199 | // For now, only one extension uses client EncryptedExtensions. This function |
| 1200 | // may be generalized if others use it in the future. |
| 1201 | if (hs->new_session->has_application_settings && |
| 1202 | !ssl->s3->early_data_accepted) { |
| 1203 | SSLMessage msg; |
| 1204 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1205 | return ssl_hs_read_message; |
| 1206 | } |
| 1207 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_ENCRYPTED_EXTENSIONS)) { |
| 1208 | return ssl_hs_error; |
| 1209 | } |
| 1210 | |
| 1211 | CBS body = msg.body, extensions; |
| 1212 | if (!CBS_get_u16_length_prefixed(&body, &extensions) || |
| 1213 | CBS_len(&body) != 0) { |
| 1214 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1215 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1216 | return ssl_hs_error; |
| 1217 | } |
| 1218 | |
Victor Tan | 558960d | 2023-06-23 15:04:33 +0000 | [diff] [blame] | 1219 | uint16_t extension_type = TLSEXT_TYPE_application_settings_old; |
| 1220 | if (hs->config->alps_use_new_codepoint) { |
| 1221 | extension_type = TLSEXT_TYPE_application_settings; |
| 1222 | } |
| 1223 | SSLExtension application_settings(extension_type); |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1224 | uint8_t alert = SSL_AD_DECODE_ERROR; |
David Benjamin | a75027b | 2021-07-20 15:07:22 -0400 | [diff] [blame] | 1225 | if (!ssl_parse_extensions(&extensions, &alert, {&application_settings}, |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1226 | /*ignore_unknown=*/false)) { |
| 1227 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 1228 | return ssl_hs_error; |
| 1229 | } |
| 1230 | |
David Benjamin | a75027b | 2021-07-20 15:07:22 -0400 | [diff] [blame] | 1231 | if (!application_settings.present) { |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1232 | OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_EXTENSION); |
| 1233 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION); |
| 1234 | return ssl_hs_error; |
| 1235 | } |
| 1236 | |
| 1237 | // Note that, if 0-RTT was accepted, these values will already have been |
| 1238 | // initialized earlier. |
| 1239 | if (!hs->new_session->peer_application_settings.CopyFrom( |
David Benjamin | a75027b | 2021-07-20 15:07:22 -0400 | [diff] [blame] | 1240 | application_settings.data) || |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1241 | !ssl_hash_message(hs, msg)) { |
| 1242 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 1243 | return ssl_hs_error; |
| 1244 | } |
| 1245 | |
| 1246 | ssl->method->next_message(ssl); |
| 1247 | } |
| 1248 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1249 | hs->tls13_state = state13_read_client_certificate; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1250 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1251 | } |
| 1252 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1253 | static enum ssl_hs_wait_t do_read_client_certificate(SSL_HANDSHAKE *hs) { |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1254 | SSL *const ssl = hs->ssl; |
| 1255 | if (!hs->cert_request) { |
David Benjamin | f350351 | 2019-08-20 15:55:24 -0400 | [diff] [blame] | 1256 | if (!ssl->s3->session_reused) { |
| 1257 | // OpenSSL returns X509_V_OK when no certificates are requested. This is |
| 1258 | // classed by them as a bug, but it's assumed by at least NGINX. (Only do |
| 1259 | // this in full handshakes as resumptions should carry over the previous |
| 1260 | // |verify_result|, though this is a no-op because servers do not |
| 1261 | // implement the client's odd soft-fail mode.) |
| 1262 | hs->new_session->verify_result = X509_V_OK; |
| 1263 | } |
Adam Langley | 3764683 | 2016-08-01 16:16:46 -0700 | [diff] [blame] | 1264 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1265 | // Skip this state. |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1266 | hs->tls13_state = state13_read_channel_id; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1267 | return ssl_hs_ok; |
| 1268 | } |
| 1269 | |
David Benjamin | 12f5878 | 2018-08-28 17:06:31 -0500 | [diff] [blame] | 1270 | const bool allow_anonymous = |
Matthew Braithwaite | b7bc80a | 2018-04-13 15:51:30 -0700 | [diff] [blame] | 1271 | (hs->config->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) == 0; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1272 | SSLMessage msg; |
| 1273 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1274 | return ssl_hs_read_message; |
| 1275 | } |
| 1276 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE) || |
| 1277 | !tls13_process_certificate(hs, msg, allow_anonymous) || |
| 1278 | !ssl_hash_message(hs, msg)) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1279 | return ssl_hs_error; |
| 1280 | } |
| 1281 | |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1282 | ssl->method->next_message(ssl); |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1283 | hs->tls13_state = state13_read_client_certificate_verify; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1284 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1287 | static enum ssl_hs_wait_t do_read_client_certificate_verify(SSL_HANDSHAKE *hs) { |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1288 | SSL *const ssl = hs->ssl; |
David Benjamin | bfdd1a9 | 2018-06-29 16:26:38 -0400 | [diff] [blame] | 1289 | if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1290 | // Skip this state. |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1291 | hs->tls13_state = state13_read_channel_id; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1292 | return ssl_hs_ok; |
| 1293 | } |
| 1294 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1295 | SSLMessage msg; |
| 1296 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1297 | return ssl_hs_read_message; |
| 1298 | } |
| 1299 | |
David Benjamin | 3a1dd46 | 2017-07-11 16:13:10 -0400 | [diff] [blame] | 1300 | switch (ssl_verify_peer_cert(hs)) { |
| 1301 | case ssl_verify_ok: |
| 1302 | break; |
| 1303 | case ssl_verify_invalid: |
| 1304 | return ssl_hs_error; |
| 1305 | case ssl_verify_retry: |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1306 | hs->tls13_state = state13_read_client_certificate_verify; |
David Benjamin | 3a1dd46 | 2017-07-11 16:13:10 -0400 | [diff] [blame] | 1307 | return ssl_hs_certificate_verify; |
| 1308 | } |
| 1309 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1310 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE_VERIFY) || |
| 1311 | !tls13_process_certificate_verify(hs, msg) || |
| 1312 | !ssl_hash_message(hs, msg)) { |
David Benjamin | 6929f27 | 2016-11-16 19:10:08 +0900 | [diff] [blame] | 1313 | return ssl_hs_error; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1316 | ssl->method->next_message(ssl); |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1317 | hs->tls13_state = state13_read_channel_id; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1318 | return ssl_hs_ok; |
Nick Harper | 60a85cb | 2016-09-23 16:25:11 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1321 | static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) { |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1322 | SSL *const ssl = hs->ssl; |
David Benjamin | 8acec00 | 2021-05-19 13:03:34 -0400 | [diff] [blame] | 1323 | if (!hs->channel_id_negotiated) { |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1324 | hs->tls13_state = state13_read_client_finished; |
Nick Harper | 60a85cb | 2016-09-23 16:25:11 -0700 | [diff] [blame] | 1325 | return ssl_hs_ok; |
| 1326 | } |
| 1327 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1328 | SSLMessage msg; |
| 1329 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1330 | return ssl_hs_read_message; |
| 1331 | } |
Bob Beck | 61725ea | 2024-11-13 17:50:07 +0000 | [diff] [blame] | 1332 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CHANNEL_ID) || // |
| 1333 | !tls1_verify_channel_id(hs, msg) || // |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1334 | !ssl_hash_message(hs, msg)) { |
Nick Harper | 60a85cb | 2016-09-23 16:25:11 -0700 | [diff] [blame] | 1335 | return ssl_hs_error; |
| 1336 | } |
| 1337 | |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1338 | ssl->method->next_message(ssl); |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1339 | hs->tls13_state = state13_read_client_finished; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1340 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1343 | static enum ssl_hs_wait_t do_read_client_finished(SSL_HANDSHAKE *hs) { |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1344 | SSL *const ssl = hs->ssl; |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1345 | SSLMessage msg; |
| 1346 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1347 | return ssl_hs_read_message; |
| 1348 | } |
| 1349 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_FINISHED) || |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1350 | // If early data was accepted, we've already computed the client Finished |
| 1351 | // and derived the resumption secret. |
David Benjamin | 02e6256 | 2017-12-18 18:04:01 -0500 | [diff] [blame] | 1352 | !tls13_process_finished(hs, msg, ssl->s3->early_data_accepted) || |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1353 | // evp_aead_seal keys have already been switched. |
David Benjamin | e530ea3 | 2019-08-16 19:28:00 -0400 | [diff] [blame] | 1354 | !tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_open, |
David Benjamin | 754d4c9 | 2020-02-11 16:27:21 -0500 | [diff] [blame] | 1355 | hs->new_session.get(), |
David Benjamin | 0f55aa8 | 2024-10-08 22:09:51 -0400 | [diff] [blame] | 1356 | hs->client_traffic_secret_0)) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1357 | return ssl_hs_error; |
| 1358 | } |
| 1359 | |
David Benjamin | 02e6256 | 2017-12-18 18:04:01 -0500 | [diff] [blame] | 1360 | if (!ssl->s3->early_data_accepted) { |
Bob Beck | 61725ea | 2024-11-13 17:50:07 +0000 | [diff] [blame] | 1361 | if (!ssl_hash_message(hs, msg) || // |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1362 | !tls13_derive_resumption_secret(hs)) { |
| 1363 | return ssl_hs_error; |
| 1364 | } |
| 1365 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1366 | // We send post-handshake tickets as part of the handshake in 1-RTT. |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1367 | hs->tls13_state = state13_send_new_session_ticket; |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1368 | } else { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1369 | // We already sent half-RTT tickets. |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1370 | hs->tls13_state = state13_done; |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1371 | } |
| 1372 | |
Chris Wood | 2b19cd3 | 2024-10-23 10:41:55 -0400 | [diff] [blame] | 1373 | if (hs->credential != nullptr && |
| 1374 | hs->credential->type == SSLCredentialType::kSPAKE2PlusV1Server) { |
| 1375 | // The client has now confirmed that it does know the correct password, so |
| 1376 | // this connection no longer counts towards the brute force limit. |
| 1377 | hs->credential->RestorePAKEAttempt(); |
| 1378 | } |
| 1379 | |
David Benjamin | 8f94c31 | 2017-08-01 17:35:55 -0400 | [diff] [blame] | 1380 | ssl->method->next_message(ssl); |
David Benjamin | 484c334 | 2024-11-22 00:38:38 -0500 | [diff] [blame] | 1381 | if (SSL_is_dtls(ssl)) { |
| 1382 | ssl->method->schedule_ack(ssl); |
| 1383 | return ssl_hs_flush; |
| 1384 | } |
| 1385 | return ssl_hs_ok; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1386 | } |
| 1387 | |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1388 | static enum ssl_hs_wait_t do_send_new_session_ticket(SSL_HANDSHAKE *hs) { |
David Benjamin | 484c334 | 2024-11-22 00:38:38 -0500 | [diff] [blame] | 1389 | SSL *const ssl = hs->ssl; |
David Benjamin | 0cbb1af | 2018-07-17 21:26:05 -0400 | [diff] [blame] | 1390 | bool sent_tickets; |
| 1391 | if (!add_new_session_tickets(hs, &sent_tickets)) { |
David Benjamin | 794cc59 | 2017-03-25 22:24:23 -0500 | [diff] [blame] | 1392 | return ssl_hs_error; |
Steven Valdez | 08b65f4 | 2016-12-07 15:29:45 -0500 | [diff] [blame] | 1393 | } |
| 1394 | |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1395 | hs->tls13_state = state13_done; |
David Benjamin | 484c334 | 2024-11-22 00:38:38 -0500 | [diff] [blame] | 1396 | // In QUIC and DTLS, we can flush the ticket to the transport immediately. In |
| 1397 | // TLS over TCP-like transports, we defer until the server performs a write. |
| 1398 | // This prevents a non-reading client from causing the server to hang in the |
| 1399 | // case of a small server write buffer. Consumers which don't write data to |
| 1400 | // the client will need to do a zero-byte write if they wish to flush the |
| 1401 | // tickets. |
| 1402 | bool should_flush = sent_tickets && (SSL_is_dtls(ssl) || SSL_is_quic(ssl)); |
| 1403 | return should_flush ? ssl_hs_flush : ssl_hs_ok; |
Steven Valdez | 1e6f11a | 2016-07-27 11:10:52 -0400 | [diff] [blame] | 1404 | } |
| 1405 | |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1406 | enum ssl_hs_wait_t tls13_server_handshake(SSL_HANDSHAKE *hs) { |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1407 | while (hs->tls13_state != state13_done) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1408 | enum ssl_hs_wait_t ret = ssl_hs_error; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1409 | enum tls13_server_hs_state_t state = |
| 1410 | static_cast<enum tls13_server_hs_state_t>(hs->tls13_state); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1411 | switch (state) { |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1412 | case state13_select_parameters: |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1413 | ret = do_select_parameters(hs); |
David Benjamin | 25fe85b | 2016-08-09 20:00:32 -0400 | [diff] [blame] | 1414 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1415 | case state13_select_session: |
David Benjamin | 707af29 | 2017-03-10 17:47:18 -0500 | [diff] [blame] | 1416 | ret = do_select_session(hs); |
| 1417 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1418 | case state13_send_hello_retry_request: |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1419 | ret = do_send_hello_retry_request(hs); |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 1420 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1421 | case state13_read_second_client_hello: |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1422 | ret = do_read_second_client_hello(hs); |
Steven Valdez | 5440fe0 | 2016-07-18 12:40:30 -0400 | [diff] [blame] | 1423 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1424 | case state13_send_server_hello: |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1425 | ret = do_send_server_hello(hs); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1426 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1427 | case state13_send_server_certificate_verify: |
David Benjamin | 4414874 | 2017-06-17 13:20:59 -0400 | [diff] [blame] | 1428 | ret = do_send_server_certificate_verify(hs); |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1429 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1430 | case state13_send_server_finished: |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1431 | ret = do_send_server_finished(hs); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1432 | break; |
Matthew Braithwaite | 093a823 | 2020-01-28 14:06:55 -0800 | [diff] [blame] | 1433 | case state13_send_half_rtt_ticket: |
| 1434 | ret = do_send_half_rtt_ticket(hs); |
| 1435 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1436 | case state13_read_second_client_flight: |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1437 | ret = do_read_second_client_flight(hs); |
| 1438 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1439 | case state13_process_end_of_early_data: |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 1440 | ret = do_process_end_of_early_data(hs); |
| 1441 | break; |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1442 | case state13_read_client_encrypted_extensions: |
| 1443 | ret = do_read_client_encrypted_extensions(hs); |
| 1444 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1445 | case state13_read_client_certificate: |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1446 | ret = do_read_client_certificate(hs); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1447 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1448 | case state13_read_client_certificate_verify: |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1449 | ret = do_read_client_certificate_verify(hs); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1450 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1451 | case state13_read_channel_id: |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1452 | ret = do_read_channel_id(hs); |
Nick Harper | 60a85cb | 2016-09-23 16:25:11 -0700 | [diff] [blame] | 1453 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1454 | case state13_read_client_finished: |
David Benjamin | 7934f08 | 2017-08-01 16:32:25 -0400 | [diff] [blame] | 1455 | ret = do_read_client_finished(hs); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1456 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1457 | case state13_send_new_session_ticket: |
David Benjamin | c3c8882 | 2016-11-14 10:32:04 +0900 | [diff] [blame] | 1458 | ret = do_send_new_session_ticket(hs); |
Steven Valdez | 1e6f11a | 2016-07-27 11:10:52 -0400 | [diff] [blame] | 1459 | break; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1460 | case state13_done: |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1461 | ret = ssl_hs_ok; |
| 1462 | break; |
| 1463 | } |
| 1464 | |
Steven Valdez | 4d71a9a | 2017-08-14 15:08:34 -0400 | [diff] [blame] | 1465 | if (hs->tls13_state != state) { |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1466 | ssl_do_info_callback(hs->ssl, SSL_CB_ACCEPT_LOOP, 1); |
| 1467 | } |
| 1468 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1469 | if (ret != ssl_hs_ok) { |
| 1470 | return ret; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | return ssl_hs_ok; |
| 1475 | } |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1476 | |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1477 | const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs) { |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1478 | enum tls13_server_hs_state_t state = |
| 1479 | static_cast<enum tls13_server_hs_state_t>(hs->tls13_state); |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1480 | switch (state) { |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1481 | case state13_select_parameters: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1482 | return "TLS 1.3 server select_parameters"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1483 | case state13_select_session: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1484 | return "TLS 1.3 server select_session"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1485 | case state13_send_hello_retry_request: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1486 | return "TLS 1.3 server send_hello_retry_request"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1487 | case state13_read_second_client_hello: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1488 | return "TLS 1.3 server read_second_client_hello"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1489 | case state13_send_server_hello: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1490 | return "TLS 1.3 server send_server_hello"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1491 | case state13_send_server_certificate_verify: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1492 | return "TLS 1.3 server send_server_certificate_verify"; |
Matthew Braithwaite | 093a823 | 2020-01-28 14:06:55 -0800 | [diff] [blame] | 1493 | case state13_send_half_rtt_ticket: |
| 1494 | return "TLS 1.3 server send_half_rtt_ticket"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1495 | case state13_send_server_finished: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1496 | return "TLS 1.3 server send_server_finished"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1497 | case state13_read_second_client_flight: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1498 | return "TLS 1.3 server read_second_client_flight"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1499 | case state13_process_end_of_early_data: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1500 | return "TLS 1.3 server process_end_of_early_data"; |
Steven Valdez | 51607f1 | 2020-08-05 10:46:05 -0400 | [diff] [blame] | 1501 | case state13_read_client_encrypted_extensions: |
| 1502 | return "TLS 1.3 server read_client_encrypted_extensions"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1503 | case state13_read_client_certificate: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1504 | return "TLS 1.3 server read_client_certificate"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1505 | case state13_read_client_certificate_verify: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1506 | return "TLS 1.3 server read_client_certificate_verify"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1507 | case state13_read_channel_id: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1508 | return "TLS 1.3 server read_channel_id"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1509 | case state13_read_client_finished: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1510 | return "TLS 1.3 server read_client_finished"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1511 | case state13_send_new_session_ticket: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1512 | return "TLS 1.3 server send_new_session_ticket"; |
Matthew Braithwaite | 08e1fe0 | 2019-11-26 17:49:04 -0800 | [diff] [blame] | 1513 | case state13_done: |
David Benjamin | f60bcfb | 2017-08-18 15:23:44 -0400 | [diff] [blame] | 1514 | return "TLS 1.3 server done"; |
| 1515 | } |
| 1516 | |
| 1517 | return "TLS 1.3 server unknown"; |
| 1518 | } |
| 1519 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 1520 | BSSL_NAMESPACE_END |