| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 |
| 17 | #include <openssl/ssl.h> |
| 18 |
| 19 | #include <assert.h> |
| 20 | #include <string.h> |
| 21 |
| 22 | #include <openssl/bn.h> |
| 23 | #include <openssl/bytestring.h> |
| 24 | #include <openssl/cipher.h> |
| 25 | #include <openssl/curve25519.h> |
| 26 | #include <openssl/digest.h> |
| 27 | #include <openssl/ec.h> |
| 28 | #include <openssl/ecdsa.h> |
| 29 | #include <openssl/err.h> |
| 30 | #include <openssl/evp.h> |
| 31 | #include <openssl/hmac.h> |
| 32 | #include <openssl/md5.h> |
| 33 | #include <openssl/mem.h> |
| 34 | #include <openssl/nid.h> |
| 35 | #include <openssl/rand.h> |
| 36 | #include <openssl/x509.h> |
| 37 |
| 38 | #include "../crypto/internal.h" |
| 39 | #include "internal.h" |
| 40 |
| 41 |
| 42 | BSSL_NAMESPACE_BEGIN |
| 43 |
| 44 | bool ssl_client_cipher_list_contains_cipher( |
| 45 | const SSL_CLIENT_HELLO *client_hello, uint16_t id) { |
| 46 | CBS cipher_suites; |
| 47 | CBS_init(&cipher_suites, client_hello->cipher_suites, |
| 48 | client_hello->cipher_suites_len); |
| 49 |
| 50 | while (CBS_len(&cipher_suites) > 0) { |
| 51 | uint16_t got_id; |
| 52 | if (!CBS_get_u16(&cipher_suites, &got_id)) { |
| 53 | return false; |
| 54 | } |
| 55 |
| 56 | if (got_id == id) { |
| 57 | return true; |
| 58 | } |
| 59 | } |
| 60 |
| 61 | return false; |
| 62 | } |
| 63 |
| 64 | static bool negotiate_version(SSL_HANDSHAKE *hs, uint8_t *out_alert, |
| 65 | const SSL_CLIENT_HELLO *client_hello) { |
| 66 | SSL *const ssl = hs->ssl; |
| 67 | assert(ssl->s3->version == 0); |
| 68 | CBS supported_versions, versions; |
| 69 | if (ssl_client_hello_get_extension(client_hello, &supported_versions, |
| 70 | TLSEXT_TYPE_supported_versions)) { |
| 71 | if (!CBS_get_u8_length_prefixed(&supported_versions, &versions) || // |
| 72 | CBS_len(&supported_versions) != 0 || // |
| 73 | CBS_len(&versions) == 0) { |
| 74 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 75 | *out_alert = SSL_AD_DECODE_ERROR; |
| 76 | return false; |
| 77 | } |
| 78 | } else { |
| 79 | // Convert the ClientHello version to an equivalent supported_versions |
| 80 | // extension. |
| 81 | static const uint8_t kTLSVersions[] = { |
| 82 | 0x03, 0x03, // TLS 1.2 |
| 83 | 0x03, 0x02, // TLS 1.1 |
| 84 | 0x03, 0x01, // TLS 1 |
| 85 | }; |
| 86 |
| 87 | static const uint8_t kDTLSVersions[] = { |
| 88 | 0xfe, 0xfd, // DTLS 1.2 |
| 89 | 0xfe, 0xff, // DTLS 1.0 |
| 90 | }; |
| 91 |
| 92 | size_t versions_len = 0; |
| 93 | if (SSL_is_dtls(ssl)) { |
| 94 | if (client_hello->version <= DTLS1_2_VERSION) { |
| 95 | versions_len = 4; |
| 96 | } else if (client_hello->version <= DTLS1_VERSION) { |
| 97 | versions_len = 2; |
| 98 | } |
| 99 | versions = Span(kDTLSVersions).last(versions_len); |
| 100 | } else { |
| 101 | if (client_hello->version >= TLS1_2_VERSION) { |
| 102 | versions_len = 6; |
| 103 | } else if (client_hello->version >= TLS1_1_VERSION) { |
| 104 | versions_len = 4; |
| 105 | } else if (client_hello->version >= TLS1_VERSION) { |
| 106 | versions_len = 2; |
| 107 | } |
| 108 | versions = Span(kTLSVersions).last(versions_len); |
| 109 | } |
| 110 | } |
| 111 |
| 112 | if (!ssl_negotiate_version(hs, out_alert, &ssl->s3->version, &versions)) { |
| 113 | return false; |
| 114 | } |
| 115 |
| 116 | // Handle FALLBACK_SCSV. |
| 117 | if (ssl_client_cipher_list_contains_cipher(client_hello, |
| 118 | SSL3_CK_FALLBACK_SCSV & 0xffff) && |
| 119 | ssl_protocol_version(ssl) < hs->max_version) { |
| 120 | OPENSSL_PUT_ERROR(SSL, SSL_R_INAPPROPRIATE_FALLBACK); |
| 121 | *out_alert = SSL3_AD_INAPPROPRIATE_FALLBACK; |
| 122 | return false; |
| 123 | } |
| 124 |
| 125 | return true; |
| 126 | } |
| 127 |
| 128 | static UniquePtr<STACK_OF(SSL_CIPHER)> ssl_parse_client_cipher_list( |
| 129 | const SSL_CLIENT_HELLO *client_hello) { |
| 130 | CBS cipher_suites; |
| 131 | CBS_init(&cipher_suites, client_hello->cipher_suites, |
| 132 | client_hello->cipher_suites_len); |
| 133 |
| 134 | UniquePtr<STACK_OF(SSL_CIPHER)> sk(sk_SSL_CIPHER_new_null()); |
| 135 | if (!sk) { |
| 136 | return nullptr; |
| 137 | } |
| 138 |
| 139 | while (CBS_len(&cipher_suites) > 0) { |
| 140 | uint16_t cipher_suite; |
| 141 |
| 142 | if (!CBS_get_u16(&cipher_suites, &cipher_suite)) { |
| 143 | OPENSSL_PUT_ERROR(SSL, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); |
| 144 | return nullptr; |
| 145 | } |
| 146 |
| 147 | const SSL_CIPHER *c = SSL_get_cipher_by_value(cipher_suite); |
| 148 | if (c != NULL && !sk_SSL_CIPHER_push(sk.get(), c)) { |
| 149 | return nullptr; |
| 150 | } |
| 151 | } |
| 152 |
| 153 | return sk; |
| 154 | } |
| 155 |
| 156 | static const SSL_CIPHER *choose_cipher(SSL_HANDSHAKE *hs, |
| 157 | const STACK_OF(SSL_CIPHER) *client_pref, |
| 158 | uint32_t mask_k, uint32_t mask_a) { |
| 159 | SSL *const ssl = hs->ssl; |
| 160 | const STACK_OF(SSL_CIPHER) *prio, *allow; |
| 161 | // in_group_flags will either be NULL, or will point to an array of bytes |
| 162 | // which indicate equal-preference groups in the |prio| stack. See the |
| 163 | // comment about |in_group_flags| in the |SSLCipherPreferenceList| |
| 164 | // struct. |
| 165 | const bool *in_group_flags; |
| 166 | // group_min contains the minimal index so far found in a group, or -1 if no |
| 167 | // such value exists yet. |
| 168 | int group_min = -1; |
| 169 |
| 170 | const SSLCipherPreferenceList *server_pref = |
| 171 | hs->config->cipher_list ? hs->config->cipher_list.get() |
| 172 | : ssl->ctx->cipher_list.get(); |
| 173 | if (ssl->options & SSL_OP_CIPHER_SERVER_PREFERENCE) { |
| 174 | prio = server_pref->ciphers.get(); |
| 175 | in_group_flags = server_pref->in_group_flags; |
| 176 | allow = client_pref; |
| 177 | } else { |
| 178 | prio = client_pref; |
| 179 | in_group_flags = NULL; |
| 180 | allow = server_pref->ciphers.get(); |
| 181 | } |
| 182 |
| 183 | for (size_t i = 0; i < sk_SSL_CIPHER_num(prio); i++) { |
| 184 | const SSL_CIPHER *c = sk_SSL_CIPHER_value(prio, i); |
| 185 |
| 186 | size_t cipher_index; |
| 187 | if ( // Check if the cipher is supported for the current version. |
| 188 | SSL_CIPHER_get_min_version(c) <= ssl_protocol_version(ssl) && // |
| 189 | ssl_protocol_version(ssl) <= SSL_CIPHER_get_max_version(c) && // |
| 190 | // Check the cipher is supported for the server configuration. |
| 191 | (c->algorithm_mkey & mask_k) && // |
| 192 | (c->algorithm_auth & mask_a) && // |
| 193 | // Check the cipher is in the |allow| list. |
| 194 | sk_SSL_CIPHER_find(allow, &cipher_index, c)) { |
| 195 | if (in_group_flags != NULL && in_group_flags[i]) { |
| 196 | // This element of |prio| is in a group. Update the minimum index found |
| 197 | // so far and continue looking. |
| 198 | if (group_min == -1 || (size_t)group_min > cipher_index) { |
| 199 | group_min = cipher_index; |
| 200 | } |
| 201 | } else { |
| 202 | if (group_min != -1 && (size_t)group_min < cipher_index) { |
| 203 | cipher_index = group_min; |
| 204 | } |
| 205 | return sk_SSL_CIPHER_value(allow, cipher_index); |
| 206 | } |
| 207 | } |
| 208 |
| 209 | if (in_group_flags != NULL && !in_group_flags[i] && group_min != -1) { |
| 210 | // We are about to leave a group, but we found a match in it, so that's |
| 211 | // our answer. |
| 212 | return sk_SSL_CIPHER_value(allow, group_min); |
| 213 | } |
| 214 | } |
| 215 |
| 216 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER); |
| 217 | return nullptr; |
| 218 | } |
| 219 |
| 220 | struct TLS12ServerParams { |
| 221 | bool ok() const { return cipher != nullptr; } |
| 222 |
| 223 | const SSL_CIPHER *cipher = nullptr; |
| 224 | uint16_t signature_algorithm = 0; |
| 225 | }; |
| 226 |
| 227 | static TLS12ServerParams choose_params(SSL_HANDSHAKE *hs, |
| 228 | const SSL_CREDENTIAL *cred, |
| 229 | const STACK_OF(SSL_CIPHER) *client_pref, |
| 230 | bool has_ecdhe_group) { |
| 231 | // Determine the usable cipher suites. |
| 232 | uint32_t mask_k = 0, mask_a = 0; |
| 233 | if (has_ecdhe_group) { |
| 234 | mask_k |= SSL_kECDHE; |
| 235 | } |
| 236 | if (hs->config->psk_server_callback != nullptr) { |
| 237 | mask_k |= SSL_kPSK; |
| 238 | mask_a |= SSL_aPSK; |
| 239 | } |
| 240 | uint16_t sigalg = 0; |
| 241 | if (cred != nullptr && cred->type == SSLCredentialType::kX509) { |
| 242 | bool sign_ok = tls1_choose_signature_algorithm(hs, cred, &sigalg); |
| 243 | ERR_clear_error(); |
| 244 |
| 245 | // ECDSA keys must additionally be checked against the peer's supported |
| 246 | // curve list. |
| 247 | int key_type = EVP_PKEY_id(cred->pubkey.get()); |
| 248 | if (key_type == EVP_PKEY_EC) { |
| 249 | EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(cred->pubkey.get()); |
| 250 | uint16_t group_id; |
| 251 | if (!ssl_nid_to_group_id( |
| 252 | &group_id, EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key))) || |
| 253 | std::find(hs->peer_supported_group_list.begin(), |
| 254 | hs->peer_supported_group_list.end(), |
| 255 | group_id) == hs->peer_supported_group_list.end()) { |
| 256 | sign_ok = false; |
| 257 |
| 258 | // If this would make us unable to pick any cipher, return an error. |
| 259 | // This is not strictly necessary, but it gives us a more specific |
| 260 | // error to help the caller diagnose issues. |
| 261 | if (mask_a == 0) { |
| 262 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE); |
| 263 | return TLS12ServerParams(); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 |
| 268 | mask_a |= ssl_cipher_auth_mask_for_key(cred->pubkey.get(), sign_ok); |
| 269 | if (key_type == EVP_PKEY_RSA) { |
| 270 | mask_k |= SSL_kRSA; |
| 271 | } |
| 272 | } |
| 273 |
| 274 | TLS12ServerParams params; |
| 275 | params.cipher = choose_cipher(hs, client_pref, mask_k, mask_a); |
| 276 | if (params.cipher == nullptr || |
| 277 | (cred != nullptr && |
| 278 | !ssl_credential_matches_requested_issuers(hs, cred))) { |
| 279 | return TLS12ServerParams(); |
| 280 | } |
| 281 | // Only report the selected signature algorithm if it will be used. |
| 282 | if (ssl_cipher_requires_server_key_exchange(params.cipher) && |
| 283 | ssl_cipher_uses_certificate_auth(params.cipher)) { |
| 284 | params.signature_algorithm = sigalg; |
| 285 | } |
| 286 | return params; |
| 287 | } |
| 288 |
| 289 | static enum ssl_hs_wait_t do_start_accept(SSL_HANDSHAKE *hs) { |
| 290 | ssl_do_info_callback(hs->ssl, SSL_CB_HANDSHAKE_START, 1); |
| 291 | hs->state = state12_read_client_hello; |
| 292 | return ssl_hs_ok; |
| 293 | } |
| 294 |
| 295 | // is_probably_jdk11_with_tls13 returns whether |client_hello| was probably sent |
| 296 | // from a JDK 11 client with both TLS 1.3 and a prior version enabled. |
| 297 | static bool is_probably_jdk11_with_tls13(const SSL_CLIENT_HELLO *client_hello) { |
| 298 | // JDK 11 ClientHellos contain a number of unusual properties which should |
| 299 | // limit false positives. |
| 300 |
| 301 | // JDK 11 does not support ChaCha20-Poly1305. This is unusual: many modern |
| 302 | // clients implement ChaCha20-Poly1305. |
| 303 | if (ssl_client_cipher_list_contains_cipher( |
| 304 | client_hello, TLS1_3_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { |
| 305 | return false; |
| 306 | } |
| 307 |
| 308 | // JDK 11 always sends extensions in a particular order. |
| 309 | constexpr uint16_t kMaxFragmentLength = 0x0001; |
| 310 | constexpr uint16_t kStatusRequestV2 = 0x0011; |
| 311 | static constexpr struct { |
| 312 | uint16_t id; |
| 313 | bool required; |
| 314 | } kJavaExtensions[] = { |
| 315 | {TLSEXT_TYPE_server_name, false}, |
| 316 | {kMaxFragmentLength, false}, |
| 317 | {TLSEXT_TYPE_status_request, false}, |
| 318 | {TLSEXT_TYPE_supported_groups, true}, |
| 319 | {TLSEXT_TYPE_ec_point_formats, false}, |
| 320 | {TLSEXT_TYPE_signature_algorithms, true}, |
| 321 | // Java always sends signature_algorithms_cert. |
| 322 | {TLSEXT_TYPE_signature_algorithms_cert, true}, |
| 323 | {TLSEXT_TYPE_application_layer_protocol_negotiation, false}, |
| 324 | {kStatusRequestV2, false}, |
| 325 | {TLSEXT_TYPE_extended_master_secret, false}, |
| 326 | {TLSEXT_TYPE_supported_versions, true}, |
| 327 | {TLSEXT_TYPE_cookie, false}, |
| 328 | {TLSEXT_TYPE_psk_key_exchange_modes, true}, |
| 329 | {TLSEXT_TYPE_key_share, true}, |
| 330 | {TLSEXT_TYPE_renegotiate, false}, |
| 331 | {TLSEXT_TYPE_pre_shared_key, false}, |
| 332 | }; |
| 333 | Span<const uint8_t> sigalgs, sigalgs_cert; |
| 334 | bool has_status_request = false, has_status_request_v2 = false; |
| 335 | CBS extensions, supported_groups; |
| 336 | CBS_init(&extensions, client_hello->extensions, client_hello->extensions_len); |
| 337 | for (const auto &java_extension : kJavaExtensions) { |
| 338 | CBS copy = extensions; |
| 339 | uint16_t id; |
| 340 | if (CBS_get_u16(©, &id) && id == java_extension.id) { |
| 341 | // The next extension is the one we expected. |
| 342 | extensions = copy; |
| 343 | CBS body; |
| 344 | if (!CBS_get_u16_length_prefixed(&extensions, &body)) { |
| 345 | return false; |
| 346 | } |
| 347 | switch (id) { |
| 348 | case TLSEXT_TYPE_status_request: |
| 349 | has_status_request = true; |
| 350 | break; |
| 351 | case kStatusRequestV2: |
| 352 | has_status_request_v2 = true; |
| 353 | break; |
| 354 | case TLSEXT_TYPE_signature_algorithms: |
| 355 | sigalgs = body; |
| 356 | break; |
| 357 | case TLSEXT_TYPE_signature_algorithms_cert: |
| 358 | sigalgs_cert = body; |
| 359 | break; |
| 360 | case TLSEXT_TYPE_supported_groups: |
| 361 | supported_groups = body; |
| 362 | break; |
| 363 | } |
| 364 | } else if (java_extension.required) { |
| 365 | return false; |
| 366 | } |
| 367 | } |
| 368 | if (CBS_len(&extensions) != 0) { |
| 369 | return false; |
| 370 | } |
| 371 |
| 372 | // JDK 11 never advertises X25519. It is not offered by default, and |
| 373 | // -Djdk.tls.namedGroups=x25519 does not work. This is unusual: many modern |
| 374 | // clients implement X25519. |
| 375 | while (CBS_len(&supported_groups) > 0) { |
| 376 | uint16_t group; |
| 377 | if (!CBS_get_u16(&supported_groups, &group) || // |
| 378 | group == SSL_GROUP_X25519) { |
| 379 | return false; |
| 380 | } |
| 381 | } |
| 382 |
| 383 | if ( // JDK 11 always sends the same contents in signature_algorithms and |
| 384 | // signature_algorithms_cert. This is unusual: |
| 385 | // signature_algorithms_cert, if omitted, is treated as if it were |
| 386 | // signature_algorithms. |
| 387 | sigalgs != sigalgs_cert || |
| 388 | // When TLS 1.2 or below is enabled, JDK 11 sends status_request_v2 iff it |
| 389 | // sends status_request. This is unusual: status_request_v2 is not widely |
| 390 | // implemented. |
| 391 | has_status_request != has_status_request_v2) { |
| 392 | return false; |
| 393 | } |
| 394 |
| 395 | return true; |
| 396 | } |
| 397 |
| 398 | static bool decrypt_ech(SSL_HANDSHAKE *hs, uint8_t *out_alert, |
| 399 | const SSL_CLIENT_HELLO *client_hello) { |
| 400 | SSL *const ssl = hs->ssl; |
| 401 | CBS body; |
| 402 | if (!ssl_client_hello_get_extension(client_hello, &body, |
| 403 | TLSEXT_TYPE_encrypted_client_hello)) { |
| 404 | return true; |
| 405 | } |
| 406 | uint8_t type; |
| 407 | if (!CBS_get_u8(&body, &type)) { |
| 408 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 409 | *out_alert = SSL_AD_DECODE_ERROR; |
| 410 | return false; |
| 411 | } |
| 412 | if (type != ECH_CLIENT_OUTER) { |
| 413 | return true; |
| 414 | } |
| 415 | // This is a ClientHelloOuter ECH extension. Attempt to decrypt it. |
| 416 | uint8_t config_id; |
| 417 | uint16_t kdf_id, aead_id; |
| 418 | CBS enc, payload; |
| 419 | if (!CBS_get_u16(&body, &kdf_id) || // |
| 420 | !CBS_get_u16(&body, &aead_id) || // |
| 421 | !CBS_get_u8(&body, &config_id) || |
| 422 | !CBS_get_u16_length_prefixed(&body, &enc) || |
| 423 | !CBS_get_u16_length_prefixed(&body, &payload) || // |
| 424 | CBS_len(&body) != 0) { |
| 425 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 426 | *out_alert = SSL_AD_DECODE_ERROR; |
| 427 | return false; |
| 428 | } |
| 429 |
| 430 | { |
| 431 | MutexReadLock lock(&ssl->ctx->lock); |
| 432 | hs->ech_keys = UpRef(ssl->ctx->ech_keys); |
| 433 | } |
| 434 |
| 435 | if (!hs->ech_keys) { |
| 436 | ssl->s3->ech_status = ssl_ech_rejected; |
| 437 | return true; |
| 438 | } |
| 439 |
| 440 | for (const auto &config : hs->ech_keys->configs) { |
| 441 | hs->ech_hpke_ctx.Reset(); |
| 442 | if (config_id != config->ech_config().config_id || |
| 443 | !config->SetupContext(hs->ech_hpke_ctx.get(), kdf_id, aead_id, enc)) { |
| 444 | // Ignore the error and try another ECHConfig. |
| 445 | ERR_clear_error(); |
| 446 | continue; |
| 447 | } |
| 448 | bool is_decrypt_error; |
| 449 | if (!ssl_client_hello_decrypt(hs, out_alert, &is_decrypt_error, |
| 450 | &hs->ech_client_hello_buf, client_hello, |
| 451 | payload)) { |
| 452 | if (is_decrypt_error) { |
| 453 | // Ignore the error and try another ECHConfig. |
| 454 | ERR_clear_error(); |
| 455 | // The |out_alert| calling convention currently relies on a default of |
| 456 | // |SSL_AD_DECODE_ERROR|. https://crbug.com/boringssl/373 tracks |
| 457 | // switching to sum types, which avoids this. |
| 458 | *out_alert = SSL_AD_DECODE_ERROR; |
| 459 | continue; |
| 460 | } |
| 461 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED); |
| 462 | return false; |
| 463 | } |
| 464 | hs->ech_config_id = config_id; |
| 465 | ssl->s3->ech_status = ssl_ech_accepted; |
| 466 | return true; |
| 467 | } |
| 468 |
| 469 | // If we did not accept ECH, proceed with the ClientHelloOuter. Note this |
| 470 | // could be key mismatch or ECH GREASE, so we must complete the handshake |
| 471 | // as usual, except EncryptedExtensions will contain retry configs. |
| 472 | ssl->s3->ech_status = ssl_ech_rejected; |
| 473 | return true; |
| 474 | } |
| 475 |
| 476 | static bool extract_sni(SSL_HANDSHAKE *hs, uint8_t *out_alert, |
| 477 | const SSL_CLIENT_HELLO *client_hello) { |
| 478 | SSL *const ssl = hs->ssl; |
| 479 | CBS sni; |
| 480 | if (!ssl_client_hello_get_extension(client_hello, &sni, |
| 481 | TLSEXT_TYPE_server_name)) { |
| 482 | // No SNI extension to parse. |
| 483 | // |
| 484 | // Clear state in case we previously extracted SNI from ClientHelloOuter. |
| 485 | ssl->s3->hostname.reset(); |
| 486 | return true; |
| 487 | } |
| 488 |
| 489 | CBS server_name_list, host_name; |
| 490 | uint8_t name_type; |
| 491 | if (!CBS_get_u16_length_prefixed(&sni, &server_name_list) || // |
| 492 | !CBS_get_u8(&server_name_list, &name_type) || // |
| 493 | // Although the server_name extension was intended to be extensible to |
| 494 | // new name types and multiple names, OpenSSL 1.0.x had a bug which meant |
| 495 | // different name types will cause an error. Further, RFC 4366 originally |
| 496 | // defined syntax inextensibly. RFC 6066 corrected this mistake, but |
| 497 | // adding new name types is no longer feasible. |
| 498 | // |
| 499 | // Act as if the extensibility does not exist to simplify parsing. |
| 500 | !CBS_get_u16_length_prefixed(&server_name_list, &host_name) || // |
| 501 | CBS_len(&server_name_list) != 0 || // |
| 502 | CBS_len(&sni) != 0) { |
| 503 | *out_alert = SSL_AD_DECODE_ERROR; |
| 504 | return false; |
| 505 | } |
| 506 |
| 507 | if (name_type != TLSEXT_NAMETYPE_host_name || // |
| 508 | CBS_len(&host_name) == 0 || // |
| 509 | CBS_len(&host_name) > TLSEXT_MAXLEN_host_name || // |
| 510 | CBS_contains_zero_byte(&host_name)) { |
| 511 | *out_alert = SSL_AD_UNRECOGNIZED_NAME; |
| 512 | return false; |
| 513 | } |
| 514 |
| 515 | // Copy the hostname as a string. |
| 516 | char *raw = nullptr; |
| 517 | if (!CBS_strdup(&host_name, &raw)) { |
| 518 | *out_alert = SSL_AD_INTERNAL_ERROR; |
| 519 | return false; |
| 520 | } |
| 521 | ssl->s3->hostname.reset(raw); |
| 522 | return true; |
| 523 | } |
| 524 |
| 525 | static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) { |
| 526 | SSL *const ssl = hs->ssl; |
| 527 |
| 528 | SSLMessage msg; |
| 529 | if (!ssl->method->get_message(ssl, &msg)) { |
| 530 | return ssl_hs_read_message; |
| 531 | } |
| 532 |
| 533 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CLIENT_HELLO)) { |
| 534 | return ssl_hs_error; |
| 535 | } |
| 536 |
| 537 | SSL_CLIENT_HELLO client_hello; |
| 538 | if (!SSL_parse_client_hello(ssl, &client_hello, CBS_data(&msg.body), |
| 539 | CBS_len(&msg.body))) { |
| 540 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 541 | return ssl_hs_error; |
| 542 | } |
| 543 |
| 544 | // ClientHello should be the end of the flight. We check this early to cover |
| 545 | // all protocol versions. |
| 546 | if (ssl->method->has_unprocessed_handshake_data(ssl)) { |
| 547 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE); |
| 548 | OPENSSL_PUT_ERROR(SSL, SSL_R_EXCESS_HANDSHAKE_DATA); |
| 549 | return ssl_hs_error; |
| 550 | } |
| 551 |
| 552 | if (hs->config->handoff) { |
| 553 | return ssl_hs_handoff; |
| 554 | } |
| 555 |
| 556 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 557 | // We check for rejection status in case we've rewound the state machine after |
| 558 | // determining `ClientHelloInner` is invalid. |
| 559 | if (ssl->s3->ech_status != ssl_ech_rejected && |
| 560 | !decrypt_ech(hs, &alert, &client_hello)) { |
| 561 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 562 | return ssl_hs_error; |
| 563 | } |
| 564 |
| 565 | // ECH may have changed which ClientHello we process. Update |msg| and |
| 566 | // |client_hello| in case. |
| 567 | if (!hs->GetClientHello(&msg, &client_hello)) { |
| 568 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 569 | return ssl_hs_error; |
| 570 | } |
| 571 |
| 572 | if (!extract_sni(hs, &alert, &client_hello)) { |
| 573 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 574 | return ssl_hs_error; |
| 575 | } |
| 576 |
| 577 | hs->state = state12_read_client_hello_after_ech; |
| 578 | return ssl_hs_ok; |
| 579 | } |
| 580 |
| 581 | static enum ssl_hs_wait_t do_read_client_hello_after_ech(SSL_HANDSHAKE *hs) { |
| 582 | SSL *const ssl = hs->ssl; |
| 583 |
| 584 | SSLMessage msg_unused; |
| 585 | SSL_CLIENT_HELLO client_hello; |
| 586 | if (!hs->GetClientHello(&msg_unused, &client_hello)) { |
| 587 | return ssl_hs_error; |
| 588 | } |
| 589 |
| 590 | // Run the early callback. |
| 591 | if (ssl->ctx->select_certificate_cb != NULL) { |
| 592 | switch (ssl->ctx->select_certificate_cb(&client_hello)) { |
| 593 | case ssl_select_cert_retry: |
| 594 | return ssl_hs_certificate_selection_pending; |
| 595 |
| 596 | case ssl_select_cert_disable_ech: |
| 597 | hs->ech_client_hello_buf.Reset(); |
| 598 | hs->ech_keys = nullptr; |
| 599 | hs->state = state12_read_client_hello; |
| 600 | ssl->s3->ech_status = ssl_ech_rejected; |
| 601 | return ssl_hs_ok; |
| 602 |
| 603 | case ssl_select_cert_error: |
| 604 | // Connection rejected. |
| 605 | OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED); |
| 606 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 607 | return ssl_hs_error; |
| 608 |
| 609 | default: |
| 610 | /* fallthrough */; |
| 611 | } |
| 612 | } |
| 613 |
| 614 | // Freeze the version range after the early callback. |
| 615 | if (!ssl_get_version_range(hs, &hs->min_version, &hs->max_version)) { |
| 616 | return ssl_hs_error; |
| 617 | } |
| 618 |
| 619 | if (hs->config->jdk11_workaround && |
| 620 | is_probably_jdk11_with_tls13(&client_hello)) { |
| 621 | hs->apply_jdk11_workaround = true; |
| 622 | } |
| 623 |
| 624 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 625 | if (!negotiate_version(hs, &alert, &client_hello)) { |
| 626 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 627 | return ssl_hs_error; |
| 628 | } |
| 629 |
| 630 | hs->client_version = client_hello.version; |
| 631 | if (client_hello.random_len != SSL3_RANDOM_SIZE) { |
| 632 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 633 | return ssl_hs_error; |
| 634 | } |
| 635 | OPENSSL_memcpy(ssl->s3->client_random, client_hello.random, |
| 636 | client_hello.random_len); |
| 637 |
| 638 | // Only null compression is supported. TLS 1.3 further requires the peer |
| 639 | // advertise no other compression. |
| 640 | if (OPENSSL_memchr(client_hello.compression_methods, 0, |
| 641 | client_hello.compression_methods_len) == NULL || |
| 642 | (ssl_protocol_version(ssl) >= TLS1_3_VERSION && |
| 643 | client_hello.compression_methods_len != 1)) { |
| 644 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMPRESSION_LIST); |
| 645 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 646 | return ssl_hs_error; |
| 647 | } |
| 648 |
| 649 | // TLS extensions. |
| 650 | if (!ssl_parse_clienthello_tlsext(hs, &client_hello)) { |
| 651 | OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT); |
| 652 | return ssl_hs_error; |
| 653 | } |
| 654 |
| 655 | hs->state = state12_cert_callback; |
| 656 | return ssl_hs_ok; |
| 657 | } |
| 658 |
| 659 | static enum ssl_hs_wait_t do_cert_callback(SSL_HANDSHAKE *hs) { |
| 660 | SSL *const ssl = hs->ssl; |
| 661 |
| 662 | // Call |cert_cb| to update server certificates if required. |
| 663 | if (hs->config->cert->cert_cb != NULL) { |
| 664 | int rv = hs->config->cert->cert_cb(ssl, hs->config->cert->cert_cb_arg); |
| 665 | if (rv == 0) { |
| 666 | OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR); |
| 667 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 668 | return ssl_hs_error; |
| 669 | } |
| 670 | if (rv < 0) { |
| 671 | return ssl_hs_x509_lookup; |
| 672 | } |
| 673 | } |
| 674 |
| 675 | if (hs->ocsp_stapling_requested && |
| 676 | ssl->ctx->legacy_ocsp_callback != nullptr) { |
| 677 | switch (ssl->ctx->legacy_ocsp_callback( |
| 678 | ssl, ssl->ctx->legacy_ocsp_callback_arg)) { |
| 679 | case SSL_TLSEXT_ERR_OK: |
| 680 | break; |
| 681 | case SSL_TLSEXT_ERR_NOACK: |
| 682 | hs->ocsp_stapling_requested = false; |
| 683 | break; |
| 684 | default: |
| 685 | OPENSSL_PUT_ERROR(SSL, SSL_R_OCSP_CB_ERROR); |
| 686 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 687 | return ssl_hs_error; |
| 688 | } |
| 689 | } |
| 690 |
| 691 | if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) { |
| 692 | // Jump to the TLS 1.3 state machine. |
| 693 | hs->state = state12_tls13; |
| 694 | return ssl_hs_ok; |
| 695 | } |
| 696 |
| 697 | // It should not be possible to negotiate TLS 1.2 with ECH. The |
| 698 | // ClientHelloInner decoding function rejects ClientHellos which offer TLS 1.2 |
| 699 | // or below. |
| 700 | assert(ssl->s3->ech_status != ssl_ech_accepted); |
| 701 |
| 702 | ssl->s3->early_data_reason = ssl_early_data_protocol_version; |
| 703 |
| 704 | hs->state = state12_select_parameters; |
| 705 | return ssl_hs_ok; |
| 706 | } |
| 707 |
| 708 | static enum ssl_hs_wait_t do_tls13(SSL_HANDSHAKE *hs) { |
| 709 | enum ssl_hs_wait_t wait = tls13_server_handshake(hs); |
| 710 | if (wait == ssl_hs_ok) { |
| 711 | hs->state = state12_finish_server_handshake; |
| 712 | return ssl_hs_ok; |
| 713 | } |
| 714 |
| 715 | return wait; |
| 716 | } |
| 717 |
| 718 | static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) { |
| 719 | SSL *const ssl = hs->ssl; |
| 720 | SSLMessage msg; |
| 721 | SSL_CLIENT_HELLO client_hello; |
| 722 | if (!hs->GetClientHello(&msg, &client_hello)) { |
| 723 | return ssl_hs_error; |
| 724 | } |
| 725 |
| 726 | // Determine the ECDHE group to use, if we are to use ECDHE. |
| 727 | uint16_t group_id = 0; |
| 728 | bool has_ecdhe_group = tls1_get_shared_group(hs, &group_id); |
| 729 |
| 730 | // Select the credential and cipher suite. This must be done after |cert_cb| |
| 731 | // runs, so the final credential list is known. |
| 732 | // |
| 733 | // TODO(davidben): In the course of picking these, we also pick the ECDHE |
| 734 | // group and signature algorithm. It would be tidier if we saved that decision |
| 735 | // and avoided redoing it later. |
| 736 | UniquePtr<STACK_OF(SSL_CIPHER)> client_pref = |
| 737 | ssl_parse_client_cipher_list(&client_hello); |
| 738 | if (client_pref == nullptr) { |
| 739 | return ssl_hs_error; |
| 740 | } |
| 741 | Array<SSL_CREDENTIAL *> creds; |
| 742 | if (!ssl_get_full_credential_list(hs, &creds)) { |
| 743 | return ssl_hs_error; |
| 744 | } |
| 745 | TLS12ServerParams params; |
| 746 | if (creds.empty()) { |
| 747 | // The caller may have configured no credentials, but set a PSK callback. |
| 748 | params = |
| 749 | choose_params(hs, /*cred=*/nullptr, client_pref.get(), has_ecdhe_group); |
| 750 | } else { |
| 751 | // Select the first credential which works. |
| 752 | for (SSL_CREDENTIAL *cred : creds) { |
| 753 | ERR_clear_error(); |
| 754 | params = choose_params(hs, cred, client_pref.get(), has_ecdhe_group); |
| 755 | if (params.ok()) { |
| 756 | hs->credential = UpRef(cred); |
| 757 | break; |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | if (!params.ok()) { |
| 762 | // The error from the last attempt is in the error queue. |
| 763 | assert(ERR_peek_error() != 0); |
| 764 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 765 | return ssl_hs_error; |
| 766 | } |
| 767 | hs->new_cipher = params.cipher; |
| 768 | hs->signature_algorithm = params.signature_algorithm; |
| 769 |
| 770 | // |SSL_parse_client_hello| checks that |client_hello.session_id| is not too |
| 771 | // large. |
| 772 | hs->session_id.CopyFrom( |
| 773 | Span(client_hello.session_id, client_hello.session_id_len)); |
| 774 |
| 775 | // Determine whether we are doing session resumption. |
| 776 | UniquePtr<SSL_SESSION> session; |
| 777 | bool tickets_supported = false, renew_ticket = false; |
| 778 | enum ssl_hs_wait_t wait = ssl_get_prev_session( |
| 779 | hs, &session, &tickets_supported, &renew_ticket, &client_hello); |
| 780 | if (wait != ssl_hs_ok) { |
| 781 | return wait; |
| 782 | } |
| 783 |
| 784 | if (session) { |
| 785 | if (session->extended_master_secret && !hs->extended_master_secret) { |
| 786 | // A ClientHello without EMS that attempts to resume a session with EMS |
| 787 | // is fatal to the connection. |
| 788 | OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION); |
| 789 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 790 | return ssl_hs_error; |
| 791 | } |
| 792 |
| 793 | if (!ssl_session_is_resumable(hs, session.get()) || |
| 794 | // If the client offers the EMS extension, but the previous session |
| 795 | // didn't use it, then negotiate a new session. |
| 796 | hs->extended_master_secret != session->extended_master_secret) { |
| 797 | session.reset(); |
| 798 | } |
| 799 | } |
| 800 |
| 801 | if (session) { |
| 802 | // Use the old session. |
| 803 | hs->ticket_expected = renew_ticket; |
| 804 | ssl->session = std::move(session); |
| 805 | ssl->s3->session_reused = true; |
| 806 | hs->can_release_private_key = true; |
| 807 | } else { |
| 808 | hs->ticket_expected = tickets_supported; |
| 809 | ssl_set_session(ssl, nullptr); |
| 810 | if (!ssl_get_new_session(hs)) { |
| 811 | return ssl_hs_error; |
| 812 | } |
| 813 |
| 814 | // Assign a session ID if not using session tickets. |
| 815 | if (!hs->ticket_expected && |
| 816 | (ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) { |
| 817 | hs->new_session->session_id.ResizeForOverwrite( |
| 818 | SSL3_SSL_SESSION_ID_LENGTH); |
| 819 | RAND_bytes(hs->new_session->session_id.data(), |
| 820 | hs->new_session->session_id.size()); |
| 821 | } |
| 822 | } |
| 823 |
| 824 | if (ssl->ctx->dos_protection_cb != NULL && |
| 825 | ssl->ctx->dos_protection_cb(&client_hello) == 0) { |
| 826 | // Connection rejected for DOS reasons. |
| 827 | OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED); |
| 828 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 829 | return ssl_hs_error; |
| 830 | } |
| 831 |
| 832 | if (ssl->session == NULL) { |
| 833 | hs->new_session->cipher = hs->new_cipher; |
| 834 | if (hs->new_session->cipher->algorithm_mkey & SSL_kECDHE) { |
| 835 | assert(has_ecdhe_group); |
| 836 | hs->new_session->group_id = group_id; |
| 837 | } |
| 838 |
| 839 | // Determine whether to request a client certificate. CertificateRequest may |
| 840 | // only be sent in certificate-based ciphers. |
| 841 | hs->cert_request = (hs->config->verify_mode & SSL_VERIFY_PEER) && |
| 842 | ssl_cipher_uses_certificate_auth(hs->new_cipher); |
| 843 | if (!hs->cert_request) { |
| 844 | // OpenSSL returns X509_V_OK when no certificates are requested. This is |
| 845 | // classed by them as a bug, but it's assumed by at least NGINX. |
| 846 | hs->new_session->verify_result = X509_V_OK; |
| 847 | } |
| 848 | } |
| 849 |
| 850 | // HTTP/2 negotiation depends on the cipher suite, so ALPN negotiation was |
| 851 | // deferred. Complete it now. |
| 852 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 853 | if (!ssl_negotiate_alpn(hs, &alert, &client_hello)) { |
| 854 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 855 | return ssl_hs_error; |
| 856 | } |
| 857 |
| 858 | // Now that all parameters are known, initialize the handshake hash and hash |
| 859 | // the ClientHello. |
| 860 | if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher)) { |
| 861 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 862 | return ssl_hs_error; |
| 863 | } |
| 864 |
| 865 | // Handback includes the whole handshake transcript, so we cannot free the |
| 866 | // transcript buffer in the handback case. |
| 867 | if (!hs->cert_request && !hs->handback) { |
| 868 | hs->transcript.FreeBuffer(); |
| 869 | } |
| 870 |
| 871 | if (!ssl_hash_message(hs, msg)) { |
| 872 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 873 | return ssl_hs_error; |
| 874 | } |
| 875 |
| 876 | ssl->method->next_message(ssl); |
| 877 |
| 878 | hs->state = state12_send_server_hello; |
| 879 | return ssl_hs_ok; |
| 880 | } |
| 881 |
| 882 | static void copy_suffix(Span<uint8_t> out, Span<const uint8_t> in) { |
| 883 | out = out.last(in.size()); |
| 884 | OPENSSL_memcpy(out.data(), in.data(), in.size()); |
| 885 | } |
| 886 |
| 887 | static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) { |
| 888 | SSL *const ssl = hs->ssl; |
| 889 |
| 890 | // We only accept ChannelIDs on connections with ECDHE in order to avoid a |
| 891 | // known attack while we fix ChannelID itself. |
| 892 | if (hs->channel_id_negotiated && |
| 893 | (hs->new_cipher->algorithm_mkey & SSL_kECDHE) == 0) { |
| 894 | hs->channel_id_negotiated = false; |
| 895 | } |
| 896 |
| 897 | // If this is a resumption and the original handshake didn't support |
| 898 | // ChannelID then we didn't record the original handshake hashes in the |
| 899 | // session and so cannot resume with ChannelIDs. |
| 900 | if (ssl->session != nullptr && |
| 901 | ssl->session->original_handshake_hash.empty()) { |
| 902 | hs->channel_id_negotiated = false; |
| 903 | } |
| 904 |
| 905 | SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); |
| 906 | if (hints && !hs->hints_requested && |
| 907 | hints->server_random_tls12.size() == SSL3_RANDOM_SIZE) { |
| 908 | OPENSSL_memcpy(ssl->s3->server_random, hints->server_random_tls12.data(), |
| 909 | SSL3_RANDOM_SIZE); |
| 910 | } else { |
| 911 | OPENSSL_timeval now = ssl_ctx_get_current_time(ssl->ctx.get()); |
| 912 | CRYPTO_store_u32_be(ssl->s3->server_random, |
| 913 | static_cast<uint32_t>(now.tv_sec)); |
| 914 | if (!RAND_bytes(ssl->s3->server_random + 4, SSL3_RANDOM_SIZE - 4)) { |
| 915 | return ssl_hs_error; |
| 916 | } |
| 917 | if (hints && hs->hints_requested && |
| 918 | !hints->server_random_tls12.CopyFrom(ssl->s3->server_random)) { |
| 919 | return ssl_hs_error; |
| 920 | } |
| 921 | } |
| 922 |
| 923 | // Implement the TLS 1.3 anti-downgrade feature. |
| 924 | if (hs->max_version >= TLS1_3_VERSION) { |
| 925 | if (ssl_protocol_version(ssl) == TLS1_2_VERSION) { |
| 926 | if (hs->apply_jdk11_workaround) { |
| 927 | // JDK 11 implements the TLS 1.3 downgrade signal, so we cannot send it |
| 928 | // here. However, the signal is only effective if all TLS 1.2 |
| 929 | // ServerHellos produced by the server are marked. Thus we send a |
| 930 | // different non-standard signal for the time being, until JDK 11.0.2 is |
| 931 | // released and clients have updated. |
| 932 | copy_suffix(ssl->s3->server_random, kJDK11DowngradeRandom); |
| 933 | } else { |
| 934 | copy_suffix(ssl->s3->server_random, kTLS13DowngradeRandom); |
| 935 | } |
| 936 | } else { |
| 937 | copy_suffix(ssl->s3->server_random, kTLS12DowngradeRandom); |
| 938 | } |
| 939 | } |
| 940 |
| 941 | Span<const uint8_t> session_id; |
| 942 | if (ssl->session != nullptr) { |
| 943 | // Echo the session ID from the ClientHello to indicate resumption. |
| 944 | session_id = hs->session_id; |
| 945 | } else { |
| 946 | session_id = hs->new_session->session_id; |
| 947 | } |
| 948 |
| 949 | ScopedCBB cbb; |
| 950 | CBB body, session_id_bytes; |
| 951 | if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) || |
| 952 | !CBB_add_u16(&body, ssl->s3->version) || |
| 953 | !CBB_add_bytes(&body, ssl->s3->server_random, SSL3_RANDOM_SIZE) || |
| 954 | !CBB_add_u8_length_prefixed(&body, &session_id_bytes) || |
| 955 | !CBB_add_bytes(&session_id_bytes, session_id.data(), session_id.size()) || |
| 956 | !CBB_add_u16(&body, SSL_CIPHER_get_protocol_id(hs->new_cipher)) || |
| 957 | !CBB_add_u8(&body, 0 /* no compression */) || |
| 958 | !ssl_add_serverhello_tlsext(hs, &body) || |
| 959 | !ssl_add_message_cbb(ssl, cbb.get())) { |
| 960 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 961 | return ssl_hs_error; |
| 962 | } |
| 963 |
| 964 | if (ssl->session != nullptr) { |
| 965 | // No additional hints to generate in resumption. |
| 966 | if (hs->hints_requested) { |
| 967 | return ssl_hs_hints_ready; |
| 968 | } |
| 969 | hs->state = state12_send_server_finished; |
| 970 | } else { |
| 971 | hs->state = state12_send_server_certificate; |
| 972 | } |
| 973 | return ssl_hs_ok; |
| 974 | } |
| 975 |
| 976 | static enum ssl_hs_wait_t do_send_server_certificate(SSL_HANDSHAKE *hs) { |
| 977 | SSL *const ssl = hs->ssl; |
| 978 | ScopedCBB cbb; |
| 979 |
| 980 | if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) { |
| 981 | assert(hs->credential != nullptr); |
| 982 | if (!ssl_send_tls12_certificate(hs)) { |
| 983 | return ssl_hs_error; |
| 984 | } |
| 985 |
| 986 | if (hs->certificate_status_expected) { |
| 987 | CBB body, ocsp_response; |
| 988 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
| 989 | SSL3_MT_CERTIFICATE_STATUS) || |
| 990 | !CBB_add_u8(&body, TLSEXT_STATUSTYPE_ocsp) || |
| 991 | !CBB_add_u24_length_prefixed(&body, &ocsp_response) || |
| 992 | !CBB_add_bytes( |
| 993 | &ocsp_response, |
| 994 | CRYPTO_BUFFER_data(hs->credential->ocsp_response.get()), |
| 995 | CRYPTO_BUFFER_len(hs->credential->ocsp_response.get())) || |
| 996 | !ssl_add_message_cbb(ssl, cbb.get())) { |
| 997 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 998 | return ssl_hs_error; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 |
| 1003 | // Assemble ServerKeyExchange parameters if needed. |
| 1004 | uint32_t alg_k = hs->new_cipher->algorithm_mkey; |
| 1005 | uint32_t alg_a = hs->new_cipher->algorithm_auth; |
| 1006 | if (ssl_cipher_requires_server_key_exchange(hs->new_cipher) || |
| 1007 | ((alg_a & SSL_aPSK) && hs->config->psk_identity_hint)) { |
| 1008 | // Pre-allocate enough room to comfortably fit an ECDHE public key. Prepend |
| 1009 | // the client and server randoms for the signing transcript. |
| 1010 | CBB child; |
| 1011 | if (!CBB_init(cbb.get(), SSL3_RANDOM_SIZE * 2 + 128) || |
| 1012 | !CBB_add_bytes(cbb.get(), ssl->s3->client_random, SSL3_RANDOM_SIZE) || |
| 1013 | !CBB_add_bytes(cbb.get(), ssl->s3->server_random, SSL3_RANDOM_SIZE)) { |
| 1014 | return ssl_hs_error; |
| 1015 | } |
| 1016 |
| 1017 | // PSK ciphers begin with an identity hint. |
| 1018 | if (alg_a & SSL_aPSK) { |
| 1019 | size_t len = hs->config->psk_identity_hint == nullptr |
| 1020 | ? 0 |
| 1021 | : strlen(hs->config->psk_identity_hint.get()); |
| 1022 | if (!CBB_add_u16_length_prefixed(cbb.get(), &child) || |
| 1023 | !CBB_add_bytes(&child, |
| 1024 | (const uint8_t *)hs->config->psk_identity_hint.get(), |
| 1025 | len)) { |
| 1026 | return ssl_hs_error; |
| 1027 | } |
| 1028 | } |
| 1029 |
| 1030 | if (alg_k & SSL_kECDHE) { |
| 1031 | assert(hs->new_session->group_id != 0); |
| 1032 | hs->key_shares[0] = SSLKeyShare::Create(hs->new_session->group_id); |
| 1033 | if (!hs->key_shares[0] || // |
| 1034 | !CBB_add_u8(cbb.get(), NAMED_CURVE_TYPE) || // |
| 1035 | !CBB_add_u16(cbb.get(), hs->new_session->group_id) || // |
| 1036 | !CBB_add_u8_length_prefixed(cbb.get(), &child)) { |
| 1037 | return ssl_hs_error; |
| 1038 | } |
| 1039 |
| 1040 | SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); |
| 1041 | bool hint_ok = false; |
| 1042 | if (hints && !hs->hints_requested && |
| 1043 | hints->ecdhe_group_id == hs->new_session->group_id && |
| 1044 | !hints->ecdhe_public_key.empty() && |
| 1045 | !hints->ecdhe_private_key.empty()) { |
| 1046 | CBS cbs = CBS(hints->ecdhe_private_key); |
| 1047 | hint_ok = hs->key_shares[0]->DeserializePrivateKey(&cbs); |
| 1048 | } |
| 1049 | if (hint_ok) { |
| 1050 | // Reuse the ECDH key from handshake hints. |
| 1051 | if (!CBB_add_bytes(&child, hints->ecdhe_public_key.data(), |
| 1052 | hints->ecdhe_public_key.size())) { |
| 1053 | return ssl_hs_error; |
| 1054 | } |
| 1055 | } else { |
| 1056 | // Generate a key, and emit the public half. |
| 1057 | if (!hs->key_shares[0]->Generate(&child)) { |
| 1058 | return ssl_hs_error; |
| 1059 | } |
| 1060 | // If generating hints, save the ECDHE key. |
| 1061 | if (hints && hs->hints_requested) { |
| 1062 | bssl::ScopedCBB private_key_cbb; |
| 1063 | if (!hints->ecdhe_public_key.CopyFrom( |
| 1064 | Span(CBB_data(&child), CBB_len(&child))) || |
| 1065 | !CBB_init(private_key_cbb.get(), 32) || |
| 1066 | !hs->key_shares[0]->SerializePrivateKey(private_key_cbb.get()) || |
| 1067 | !CBBFinishArray(private_key_cbb.get(), |
| 1068 | &hints->ecdhe_private_key)) { |
| 1069 | return ssl_hs_error; |
| 1070 | } |
| 1071 | hints->ecdhe_group_id = hs->new_session->group_id; |
| 1072 | } |
| 1073 | } |
| 1074 | } else { |
| 1075 | assert(alg_k & SSL_kPSK); |
| 1076 | } |
| 1077 |
| 1078 | if (!CBBFinishArray(cbb.get(), &hs->server_params)) { |
| 1079 | return ssl_hs_error; |
| 1080 | } |
| 1081 | } |
| 1082 |
| 1083 | hs->state = state12_send_server_key_exchange; |
| 1084 | return ssl_hs_ok; |
| 1085 | } |
| 1086 |
| 1087 | static enum ssl_hs_wait_t do_send_server_key_exchange(SSL_HANDSHAKE *hs) { |
| 1088 | SSL *const ssl = hs->ssl; |
| 1089 |
| 1090 | if (hs->server_params.size() == 0) { |
| 1091 | hs->state = state12_send_server_hello_done; |
| 1092 | return ssl_hs_ok; |
| 1093 | } |
| 1094 |
| 1095 | ScopedCBB cbb; |
| 1096 | CBB body, child; |
| 1097 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
| 1098 | SSL3_MT_SERVER_KEY_EXCHANGE) || |
| 1099 | // |hs->server_params| contains a prefix for signing. |
| 1100 | hs->server_params.size() < 2 * SSL3_RANDOM_SIZE || |
| 1101 | !CBB_add_bytes(&body, hs->server_params.data() + 2 * SSL3_RANDOM_SIZE, |
| 1102 | hs->server_params.size() - 2 * SSL3_RANDOM_SIZE)) { |
| 1103 | return ssl_hs_error; |
| 1104 | } |
| 1105 |
| 1106 | // Add a signature. |
| 1107 | if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) { |
| 1108 | // Determine the signature algorithm. |
| 1109 | uint16_t signature_algorithm; |
| 1110 | if (!tls1_choose_signature_algorithm(hs, hs->credential.get(), |
| 1111 | &signature_algorithm)) { |
| 1112 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 1113 | return ssl_hs_error; |
| 1114 | } |
| 1115 | if (ssl_protocol_version(ssl) >= TLS1_2_VERSION) { |
| 1116 | if (!CBB_add_u16(&body, signature_algorithm)) { |
| 1117 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1118 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 1119 | return ssl_hs_error; |
| 1120 | } |
| 1121 | } |
| 1122 |
| 1123 | // Add space for the signature. |
| 1124 | const size_t max_sig_len = EVP_PKEY_size(hs->credential->pubkey.get()); |
| 1125 | uint8_t *ptr; |
| 1126 | if (!CBB_add_u16_length_prefixed(&body, &child) || |
| 1127 | !CBB_reserve(&child, &ptr, max_sig_len)) { |
| 1128 | return ssl_hs_error; |
| 1129 | } |
| 1130 |
| 1131 | size_t sig_len; |
| 1132 | switch (ssl_private_key_sign(hs, ptr, &sig_len, max_sig_len, |
| 1133 | signature_algorithm, hs->server_params)) { |
| 1134 | case ssl_private_key_success: |
| 1135 | if (!CBB_did_write(&child, sig_len)) { |
| 1136 | return ssl_hs_error; |
| 1137 | } |
| 1138 | break; |
| 1139 | case ssl_private_key_failure: |
| 1140 | return ssl_hs_error; |
| 1141 | case ssl_private_key_retry: |
| 1142 | return ssl_hs_private_key_operation; |
| 1143 | } |
| 1144 | } |
| 1145 |
| 1146 | hs->can_release_private_key = true; |
| 1147 | if (!ssl_add_message_cbb(ssl, cbb.get())) { |
| 1148 | return ssl_hs_error; |
| 1149 | } |
| 1150 |
| 1151 | hs->server_params.Reset(); |
| 1152 |
| 1153 | hs->state = state12_send_server_hello_done; |
| 1154 | return ssl_hs_ok; |
| 1155 | } |
| 1156 |
| 1157 | static enum ssl_hs_wait_t do_send_server_hello_done(SSL_HANDSHAKE *hs) { |
| 1158 | SSL *const ssl = hs->ssl; |
| 1159 | if (hs->hints_requested) { |
| 1160 | return ssl_hs_hints_ready; |
| 1161 | } |
| 1162 |
| 1163 | ScopedCBB cbb; |
| 1164 | CBB body; |
| 1165 |
| 1166 | if (hs->cert_request) { |
| 1167 | CBB cert_types, sigalgs_cbb; |
| 1168 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
| 1169 | SSL3_MT_CERTIFICATE_REQUEST) || |
| 1170 | !CBB_add_u8_length_prefixed(&body, &cert_types) || |
| 1171 | !CBB_add_u8(&cert_types, SSL3_CT_RSA_SIGN) || |
| 1172 | !CBB_add_u8(&cert_types, TLS_CT_ECDSA_SIGN) || |
| 1173 | (ssl_protocol_version(ssl) >= TLS1_2_VERSION && |
| 1174 | (!CBB_add_u16_length_prefixed(&body, &sigalgs_cbb) || |
| 1175 | !tls12_add_verify_sigalgs(hs, &sigalgs_cbb))) || |
| 1176 | !ssl_add_client_CA_list(hs, &body) || |
| 1177 | !ssl_add_message_cbb(ssl, cbb.get())) { |
| 1178 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1179 | return ssl_hs_error; |
| 1180 | } |
| 1181 | } |
| 1182 |
| 1183 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
| 1184 | SSL3_MT_SERVER_HELLO_DONE) || |
| 1185 | !ssl_add_message_cbb(ssl, cbb.get())) { |
| 1186 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1187 | return ssl_hs_error; |
| 1188 | } |
| 1189 |
| 1190 | hs->state = state12_read_client_certificate; |
| 1191 | return ssl_hs_flush; |
| 1192 | } |
| 1193 |
| 1194 | static enum ssl_hs_wait_t do_read_client_certificate(SSL_HANDSHAKE *hs) { |
| 1195 | SSL *const ssl = hs->ssl; |
| 1196 |
| 1197 | if (hs->handback && hs->new_cipher->algorithm_mkey == SSL_kECDHE) { |
| 1198 | return ssl_hs_handback; |
| 1199 | } |
| 1200 | if (!hs->cert_request) { |
| 1201 | hs->state = state12_verify_client_certificate; |
| 1202 | return ssl_hs_ok; |
| 1203 | } |
| 1204 |
| 1205 | SSLMessage msg; |
| 1206 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1207 | return ssl_hs_read_message; |
| 1208 | } |
| 1209 |
| 1210 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE)) { |
| 1211 | return ssl_hs_error; |
| 1212 | } |
| 1213 |
| 1214 | if (!ssl_hash_message(hs, msg)) { |
| 1215 | return ssl_hs_error; |
| 1216 | } |
| 1217 |
| 1218 | CBS certificate_msg = msg.body; |
| 1219 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 1220 | if (!ssl_parse_cert_chain(&alert, &hs->new_session->certs, &hs->peer_pubkey, |
| 1221 | hs->config->retain_only_sha256_of_client_certs |
| 1222 | ? hs->new_session->peer_sha256 |
| 1223 | : nullptr, |
| 1224 | &certificate_msg, ssl->ctx->pool)) { |
| 1225 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 1226 | return ssl_hs_error; |
| 1227 | } |
| 1228 |
| 1229 | if (CBS_len(&certificate_msg) != 0 || |
| 1230 | !ssl->ctx->x509_method->session_cache_objects(hs->new_session.get())) { |
| 1231 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1232 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1233 | return ssl_hs_error; |
| 1234 | } |
| 1235 |
| 1236 | if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0) { |
| 1237 | // No client certificate so the handshake buffer may be discarded. |
| 1238 | hs->transcript.FreeBuffer(); |
| 1239 |
| 1240 | if (hs->config->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) { |
| 1241 | // Fail for TLS only if we required a certificate |
| 1242 | OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); |
| 1243 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 1244 | return ssl_hs_error; |
| 1245 | } |
| 1246 |
| 1247 | // OpenSSL returns X509_V_OK when no certificates are received. This is |
| 1248 | // classed by them as a bug, but it's assumed by at least NGINX. |
| 1249 | hs->new_session->verify_result = X509_V_OK; |
| 1250 | } else if (hs->config->retain_only_sha256_of_client_certs) { |
| 1251 | // The hash will have been filled in. |
| 1252 | hs->new_session->peer_sha256_valid = true; |
| 1253 | } |
| 1254 |
| 1255 | ssl->method->next_message(ssl); |
| 1256 | hs->state = state12_verify_client_certificate; |
| 1257 | return ssl_hs_ok; |
| 1258 | } |
| 1259 |
| 1260 | static enum ssl_hs_wait_t do_verify_client_certificate(SSL_HANDSHAKE *hs) { |
| 1261 | if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) > 0) { |
| 1262 | switch (ssl_verify_peer_cert(hs)) { |
| 1263 | case ssl_verify_ok: |
| 1264 | break; |
| 1265 | case ssl_verify_invalid: |
| 1266 | return ssl_hs_error; |
| 1267 | case ssl_verify_retry: |
| 1268 | return ssl_hs_certificate_verify; |
| 1269 | } |
| 1270 | } |
| 1271 |
| 1272 | hs->state = state12_read_client_key_exchange; |
| 1273 | return ssl_hs_ok; |
| 1274 | } |
| 1275 |
| 1276 | static enum ssl_hs_wait_t do_read_client_key_exchange(SSL_HANDSHAKE *hs) { |
| 1277 | SSL *const ssl = hs->ssl; |
| 1278 | SSLMessage msg; |
| 1279 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1280 | return ssl_hs_read_message; |
| 1281 | } |
| 1282 |
| 1283 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CLIENT_KEY_EXCHANGE)) { |
| 1284 | return ssl_hs_error; |
| 1285 | } |
| 1286 |
| 1287 | CBS client_key_exchange = msg.body; |
| 1288 | uint32_t alg_k = hs->new_cipher->algorithm_mkey; |
| 1289 | uint32_t alg_a = hs->new_cipher->algorithm_auth; |
| 1290 |
| 1291 | // If using a PSK key exchange, parse the PSK identity. |
| 1292 | if (alg_a & SSL_aPSK) { |
| 1293 | CBS psk_identity; |
| 1294 |
| 1295 | // If using PSK, the ClientKeyExchange contains a psk_identity. If PSK, |
| 1296 | // then this is the only field in the message. |
| 1297 | if (!CBS_get_u16_length_prefixed(&client_key_exchange, &psk_identity) || |
| 1298 | ((alg_k & SSL_kPSK) && CBS_len(&client_key_exchange) != 0)) { |
| 1299 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1300 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1301 | return ssl_hs_error; |
| 1302 | } |
| 1303 |
| 1304 | if (CBS_len(&psk_identity) > PSK_MAX_IDENTITY_LEN || |
| 1305 | CBS_contains_zero_byte(&psk_identity)) { |
| 1306 | OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG); |
| 1307 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 1308 | return ssl_hs_error; |
| 1309 | } |
| 1310 | char *raw = nullptr; |
| 1311 | if (!CBS_strdup(&psk_identity, &raw)) { |
| 1312 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 1313 | return ssl_hs_error; |
| 1314 | } |
| 1315 | hs->new_session->psk_identity.reset(raw); |
| 1316 | } |
| 1317 |
| 1318 | // Depending on the key exchange method, compute |premaster_secret|. |
| 1319 | Array<uint8_t> premaster_secret; |
| 1320 | if (alg_k & SSL_kRSA) { |
| 1321 | CBS encrypted_premaster_secret; |
| 1322 | if (!CBS_get_u16_length_prefixed(&client_key_exchange, |
| 1323 | &encrypted_premaster_secret) || |
| 1324 | CBS_len(&client_key_exchange) != 0) { |
| 1325 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1326 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1327 | return ssl_hs_error; |
| 1328 | } |
| 1329 |
| 1330 | // Allocate a buffer large enough for an RSA decryption. |
| 1331 | Array<uint8_t> decrypt_buf; |
| 1332 | if (!decrypt_buf.InitForOverwrite( |
| 1333 | EVP_PKEY_size(hs->credential->pubkey.get()))) { |
| 1334 | return ssl_hs_error; |
| 1335 | } |
| 1336 |
| 1337 | // Decrypt with no padding. PKCS#1 padding will be removed as part of the |
| 1338 | // timing-sensitive code below. |
| 1339 | size_t decrypt_len; |
| 1340 | switch (ssl_private_key_decrypt(hs, decrypt_buf.data(), &decrypt_len, |
| 1341 | decrypt_buf.size(), |
| 1342 | encrypted_premaster_secret)) { |
| 1343 | case ssl_private_key_success: |
| 1344 | break; |
| 1345 | case ssl_private_key_failure: |
| 1346 | return ssl_hs_error; |
| 1347 | case ssl_private_key_retry: |
| 1348 | return ssl_hs_private_key_operation; |
| 1349 | } |
| 1350 |
| 1351 | if (decrypt_len != decrypt_buf.size()) { |
| 1352 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED); |
| 1353 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR); |
| 1354 | return ssl_hs_error; |
| 1355 | } |
| 1356 |
| 1357 | CONSTTIME_SECRET(decrypt_buf.data(), decrypt_len); |
| 1358 |
| 1359 | // Prepare a random premaster, to be used on invalid padding. See RFC 5246, |
| 1360 | // section 7.4.7.1. |
| 1361 | if (!premaster_secret.InitForOverwrite(SSL_MAX_MASTER_KEY_LENGTH) || |
| 1362 | !RAND_bytes(premaster_secret.data(), premaster_secret.size())) { |
| 1363 | return ssl_hs_error; |
| 1364 | } |
| 1365 |
| 1366 | // The smallest padded premaster is 11 bytes of overhead. Small keys are |
| 1367 | // publicly invalid. |
| 1368 | if (decrypt_len < 11 + premaster_secret.size()) { |
| 1369 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED); |
| 1370 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR); |
| 1371 | return ssl_hs_error; |
| 1372 | } |
| 1373 |
| 1374 | // Check the padding. See RFC 3447, section 7.2.2. |
| 1375 | size_t padding_len = decrypt_len - premaster_secret.size(); |
| 1376 | uint8_t good = constant_time_eq_int_8(decrypt_buf[0], 0) & |
| 1377 | constant_time_eq_int_8(decrypt_buf[1], 2); |
| 1378 | for (size_t i = 2; i < padding_len - 1; i++) { |
| 1379 | good &= ~constant_time_is_zero_8(decrypt_buf[i]); |
| 1380 | } |
| 1381 | good &= constant_time_is_zero_8(decrypt_buf[padding_len - 1]); |
| 1382 |
| 1383 | // The premaster secret must begin with |client_version|. This too must be |
| 1384 | // checked in constant time (http://eprint.iacr.org/2003/052/). |
| 1385 | good &= constant_time_eq_8(decrypt_buf[padding_len], |
| 1386 | (unsigned)(hs->client_version >> 8)); |
| 1387 | good &= constant_time_eq_8(decrypt_buf[padding_len + 1], |
| 1388 | (unsigned)(hs->client_version & 0xff)); |
| 1389 |
| 1390 | // Select, in constant time, either the decrypted premaster or the random |
| 1391 | // premaster based on |good|. |
| 1392 | for (size_t i = 0; i < premaster_secret.size(); i++) { |
| 1393 | premaster_secret[i] = constant_time_select_8( |
| 1394 | good, decrypt_buf[padding_len + i], premaster_secret[i]); |
| 1395 | } |
| 1396 | } else if (alg_k & SSL_kECDHE) { |
| 1397 | // Parse the ClientKeyExchange. |
| 1398 | CBS ciphertext; |
| 1399 | if (!CBS_get_u8_length_prefixed(&client_key_exchange, &ciphertext) || |
| 1400 | CBS_len(&client_key_exchange) != 0) { |
| 1401 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1402 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1403 | return ssl_hs_error; |
| 1404 | } |
| 1405 |
| 1406 | // Decapsulate the premaster secret. |
| 1407 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 1408 | if (!hs->key_shares[0]->Decap(&premaster_secret, &alert, ciphertext)) { |
| 1409 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 1410 | return ssl_hs_error; |
| 1411 | } |
| 1412 |
| 1413 | // The key exchange state may now be discarded. |
| 1414 | hs->key_shares[0].reset(); |
| 1415 | hs->key_shares[1].reset(); |
| 1416 | } else if (!(alg_k & SSL_kPSK)) { |
| 1417 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1418 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 1419 | return ssl_hs_error; |
| 1420 | } |
| 1421 |
| 1422 | // For a PSK cipher suite, the actual pre-master secret is combined with the |
| 1423 | // pre-shared key. |
| 1424 | if (alg_a & SSL_aPSK) { |
| 1425 | if (hs->config->psk_server_callback == NULL) { |
| 1426 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1427 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 1428 | return ssl_hs_error; |
| 1429 | } |
| 1430 |
| 1431 | // Look up the key for the identity. |
| 1432 | uint8_t psk[PSK_MAX_PSK_LEN]; |
| 1433 | unsigned psk_len = hs->config->psk_server_callback( |
| 1434 | ssl, hs->new_session->psk_identity.get(), psk, sizeof(psk)); |
| 1435 | if (psk_len > PSK_MAX_PSK_LEN) { |
| 1436 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 1437 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 1438 | return ssl_hs_error; |
| 1439 | } else if (psk_len == 0) { |
| 1440 | // PSK related to the given identity not found. |
| 1441 | OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND); |
| 1442 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNKNOWN_PSK_IDENTITY); |
| 1443 | return ssl_hs_error; |
| 1444 | } |
| 1445 |
| 1446 | if (alg_k & SSL_kPSK) { |
| 1447 | // In plain PSK, other_secret is a block of 0s with the same length as the |
| 1448 | // pre-shared key. |
| 1449 | if (!premaster_secret.Init(psk_len)) { |
| 1450 | return ssl_hs_error; |
| 1451 | } |
| 1452 | } |
| 1453 |
| 1454 | ScopedCBB new_premaster; |
| 1455 | CBB child; |
| 1456 | if (!CBB_init(new_premaster.get(), |
| 1457 | 2 + psk_len + 2 + premaster_secret.size()) || |
| 1458 | !CBB_add_u16_length_prefixed(new_premaster.get(), &child) || |
| 1459 | !CBB_add_bytes(&child, premaster_secret.data(), |
| 1460 | premaster_secret.size()) || |
| 1461 | !CBB_add_u16_length_prefixed(new_premaster.get(), &child) || |
| 1462 | !CBB_add_bytes(&child, psk, psk_len) || |
| 1463 | !CBBFinishArray(new_premaster.get(), &premaster_secret)) { |
| 1464 | return ssl_hs_error; |
| 1465 | } |
| 1466 | } |
| 1467 |
| 1468 | if (!ssl_hash_message(hs, msg)) { |
| 1469 | return ssl_hs_error; |
| 1470 | } |
| 1471 |
| 1472 | // Compute the master secret. |
| 1473 | hs->new_session->secret.ResizeForOverwrite(SSL3_MASTER_SECRET_SIZE); |
| 1474 | if (!tls1_generate_master_secret(hs, Span(hs->new_session->secret), |
| 1475 | premaster_secret)) { |
| 1476 | return ssl_hs_error; |
| 1477 | } |
| 1478 | hs->new_session->extended_master_secret = hs->extended_master_secret; |
| 1479 | // Declassify the secret to undo the RSA decryption validation above. We are |
| 1480 | // not currently running most of the TLS library with constant-time |
| 1481 | // validation. |
| 1482 | // TODO(crbug.com/42290551): Remove this and cover the TLS library too. |
| 1483 | CONSTTIME_DECLASSIFY(hs->new_session->secret.data(), |
| 1484 | hs->new_session->secret.size()); |
| 1485 | hs->can_release_private_key = true; |
| 1486 |
| 1487 | ssl->method->next_message(ssl); |
| 1488 | hs->state = state12_read_client_certificate_verify; |
| 1489 | return ssl_hs_ok; |
| 1490 | } |
| 1491 |
| 1492 | static enum ssl_hs_wait_t do_read_client_certificate_verify(SSL_HANDSHAKE *hs) { |
| 1493 | SSL *const ssl = hs->ssl; |
| 1494 |
| 1495 | // Only RSA and ECDSA client certificates are supported, so a |
| 1496 | // CertificateVerify is required if and only if there's a client certificate. |
| 1497 | if (!hs->peer_pubkey) { |
| 1498 | hs->transcript.FreeBuffer(); |
| 1499 | hs->state = state12_read_change_cipher_spec; |
| 1500 | return ssl_hs_ok; |
| 1501 | } |
| 1502 |
| 1503 | SSLMessage msg; |
| 1504 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1505 | return ssl_hs_read_message; |
| 1506 | } |
| 1507 |
| 1508 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE_VERIFY)) { |
| 1509 | return ssl_hs_error; |
| 1510 | } |
| 1511 |
| 1512 | // The peer certificate must be valid for signing. |
| 1513 | const CRYPTO_BUFFER *leaf = |
| 1514 | sk_CRYPTO_BUFFER_value(hs->new_session->certs.get(), 0); |
| 1515 | CBS leaf_cbs; |
| 1516 | CRYPTO_BUFFER_init_CBS(leaf, &leaf_cbs); |
| 1517 | if (!ssl_cert_check_key_usage(&leaf_cbs, key_usage_digital_signature)) { |
| 1518 | return ssl_hs_error; |
| 1519 | } |
| 1520 |
| 1521 | CBS certificate_verify = msg.body, signature; |
| 1522 |
| 1523 | // Determine the signature algorithm. |
| 1524 | uint16_t signature_algorithm = 0; |
| 1525 | if (ssl_protocol_version(ssl) >= TLS1_2_VERSION) { |
| 1526 | if (!CBS_get_u16(&certificate_verify, &signature_algorithm)) { |
| 1527 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1528 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1529 | return ssl_hs_error; |
| 1530 | } |
| 1531 | uint8_t alert = SSL_AD_DECODE_ERROR; |
| 1532 | if (!tls12_check_peer_sigalg(hs, &alert, signature_algorithm, |
| 1533 | hs->peer_pubkey.get())) { |
| 1534 | ssl_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 1535 | return ssl_hs_error; |
| 1536 | } |
| 1537 | hs->new_session->peer_signature_algorithm = signature_algorithm; |
| 1538 | } else if (!tls1_get_legacy_signature_algorithm(&signature_algorithm, |
| 1539 | hs->peer_pubkey.get())) { |
| 1540 | OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE); |
| 1541 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNSUPPORTED_CERTIFICATE); |
| 1542 | return ssl_hs_error; |
| 1543 | } |
| 1544 |
| 1545 | // Parse and verify the signature. |
| 1546 | if (!CBS_get_u16_length_prefixed(&certificate_verify, &signature) || |
| 1547 | CBS_len(&certificate_verify) != 0) { |
| 1548 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1549 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1550 | return ssl_hs_error; |
| 1551 | } |
| 1552 |
| 1553 | if (!ssl_public_key_verify(ssl, signature, signature_algorithm, |
| 1554 | hs->peer_pubkey.get(), hs->transcript.buffer())) { |
| 1555 | OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SIGNATURE); |
| 1556 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR); |
| 1557 | return ssl_hs_error; |
| 1558 | } |
| 1559 |
| 1560 | // The handshake buffer is no longer necessary, and we may hash the current |
| 1561 | // message. |
| 1562 | hs->transcript.FreeBuffer(); |
| 1563 | if (!ssl_hash_message(hs, msg)) { |
| 1564 | return ssl_hs_error; |
| 1565 | } |
| 1566 |
| 1567 | ssl->method->next_message(ssl); |
| 1568 | hs->state = state12_read_change_cipher_spec; |
| 1569 | return ssl_hs_ok; |
| 1570 | } |
| 1571 |
| 1572 | static enum ssl_hs_wait_t do_read_change_cipher_spec(SSL_HANDSHAKE *hs) { |
| 1573 | if (hs->handback && hs->ssl->session != NULL) { |
| 1574 | return ssl_hs_handback; |
| 1575 | } |
| 1576 | hs->state = state12_process_change_cipher_spec; |
| 1577 | return ssl_hs_read_change_cipher_spec; |
| 1578 | } |
| 1579 |
| 1580 | static enum ssl_hs_wait_t do_process_change_cipher_spec(SSL_HANDSHAKE *hs) { |
| 1581 | if (!tls1_change_cipher_state(hs, evp_aead_open)) { |
| 1582 | return ssl_hs_error; |
| 1583 | } |
| 1584 |
| 1585 | hs->state = state12_read_next_proto; |
| 1586 | return ssl_hs_ok; |
| 1587 | } |
| 1588 |
| 1589 | static enum ssl_hs_wait_t do_read_next_proto(SSL_HANDSHAKE *hs) { |
| 1590 | SSL *const ssl = hs->ssl; |
| 1591 |
| 1592 | if (!hs->next_proto_neg_seen) { |
| 1593 | hs->state = state12_read_channel_id; |
| 1594 | return ssl_hs_ok; |
| 1595 | } |
| 1596 |
| 1597 | SSLMessage msg; |
| 1598 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1599 | return ssl_hs_read_message; |
| 1600 | } |
| 1601 |
| 1602 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_NEXT_PROTO) || |
| 1603 | !ssl_hash_message(hs, msg)) { |
| 1604 | return ssl_hs_error; |
| 1605 | } |
| 1606 |
| 1607 | CBS next_protocol = msg.body, selected_protocol, padding; |
| 1608 | if (!CBS_get_u8_length_prefixed(&next_protocol, &selected_protocol) || |
| 1609 | !CBS_get_u8_length_prefixed(&next_protocol, &padding) || |
| 1610 | CBS_len(&next_protocol) != 0) { |
| 1611 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 1612 | ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1613 | return ssl_hs_error; |
| 1614 | } |
| 1615 |
| 1616 | if (!ssl->s3->next_proto_negotiated.CopyFrom(selected_protocol)) { |
| 1617 | return ssl_hs_error; |
| 1618 | } |
| 1619 |
| 1620 | ssl->method->next_message(ssl); |
| 1621 | hs->state = state12_read_channel_id; |
| 1622 | return ssl_hs_ok; |
| 1623 | } |
| 1624 |
| 1625 | static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) { |
| 1626 | SSL *const ssl = hs->ssl; |
| 1627 |
| 1628 | if (!hs->channel_id_negotiated) { |
| 1629 | hs->state = state12_read_client_finished; |
| 1630 | return ssl_hs_ok; |
| 1631 | } |
| 1632 |
| 1633 | SSLMessage msg; |
| 1634 | if (!ssl->method->get_message(ssl, &msg)) { |
| 1635 | return ssl_hs_read_message; |
| 1636 | } |
| 1637 |
| 1638 | if (!ssl_check_message_type(ssl, msg, SSL3_MT_CHANNEL_ID) || |
| 1639 | !tls1_verify_channel_id(hs, msg) || // |
| 1640 | !ssl_hash_message(hs, msg)) { |
| 1641 | return ssl_hs_error; |
| 1642 | } |
| 1643 |
| 1644 | ssl->method->next_message(ssl); |
| 1645 | hs->state = state12_read_client_finished; |
| 1646 | return ssl_hs_ok; |
| 1647 | } |
| 1648 |
| 1649 | static enum ssl_hs_wait_t do_read_client_finished(SSL_HANDSHAKE *hs) { |
| 1650 | SSL *const ssl = hs->ssl; |
| 1651 | enum ssl_hs_wait_t wait = ssl_get_finished(hs); |
| 1652 | if (wait != ssl_hs_ok) { |
| 1653 | return wait; |
| 1654 | } |
| 1655 |
| 1656 | if (ssl->session != NULL) { |
| 1657 | hs->state = state12_finish_server_handshake; |
| 1658 | } else { |
| 1659 | hs->state = state12_send_server_finished; |
| 1660 | } |
| 1661 |
| 1662 | // If this is a full handshake with ChannelID then record the handshake |
| 1663 | // hashes in |hs->new_session| in case we need them to verify a |
| 1664 | // ChannelID signature on a resumption of this session in the future. |
| 1665 | if (ssl->session == NULL && ssl->s3->channel_id_valid && |
| 1666 | !tls1_record_handshake_hashes_for_channel_id(hs)) { |
| 1667 | return ssl_hs_error; |
| 1668 | } |
| 1669 |
| 1670 | return ssl_hs_ok; |
| 1671 | } |
| 1672 |
| 1673 | static enum ssl_hs_wait_t do_send_server_finished(SSL_HANDSHAKE *hs) { |
| 1674 | SSL *const ssl = hs->ssl; |
| 1675 |
| 1676 | if (hs->ticket_expected) { |
| 1677 | const SSL_SESSION *session; |
| 1678 | UniquePtr<SSL_SESSION> session_copy; |
| 1679 | if (ssl->session == NULL) { |
| 1680 | // Fix the timeout to measure from the ticket issuance time. |
| 1681 | ssl_session_rebase_time(ssl, hs->new_session.get()); |
| 1682 | session = hs->new_session.get(); |
| 1683 | } else { |
| 1684 | // We are renewing an existing session. Duplicate the session to adjust |
| 1685 | // the timeout. |
| 1686 | session_copy = |
| 1687 | SSL_SESSION_dup(ssl->session.get(), SSL_SESSION_INCLUDE_NONAUTH); |
| 1688 | if (!session_copy) { |
| 1689 | return ssl_hs_error; |
| 1690 | } |
| 1691 |
| 1692 | ssl_session_rebase_time(ssl, session_copy.get()); |
| 1693 | session = session_copy.get(); |
| 1694 | } |
| 1695 |
| 1696 | ScopedCBB cbb; |
| 1697 | CBB body, ticket; |
| 1698 | if (!ssl->method->init_message(ssl, cbb.get(), &body, |
| 1699 | SSL3_MT_NEW_SESSION_TICKET) || |
| 1700 | !CBB_add_u32(&body, session->timeout) || |
| 1701 | !CBB_add_u16_length_prefixed(&body, &ticket) || |
| 1702 | !ssl_encrypt_ticket(hs, &ticket, session) || |
| 1703 | // |ticket| may be empty to skip sending a ticket. In TLS 1.2, servers |
| 1704 | // skip sending tickets by sending empty NewSessionTicket, so no special |
| 1705 | // handling is needed. |
| 1706 | !ssl_add_message_cbb(ssl, cbb.get())) { |
| 1707 | return ssl_hs_error; |
| 1708 | } |
| 1709 | } |
| 1710 |
| 1711 | if (!ssl->method->add_change_cipher_spec(ssl) || // |
| 1712 | !tls1_change_cipher_state(hs, evp_aead_seal) || // |
| 1713 | !ssl_send_finished(hs)) { |
| 1714 | return ssl_hs_error; |
| 1715 | } |
| 1716 |
| 1717 | if (ssl->session != NULL) { |
| 1718 | hs->state = state12_read_change_cipher_spec; |
| 1719 | } else { |
| 1720 | hs->state = state12_finish_server_handshake; |
| 1721 | } |
| 1722 | return ssl_hs_flush; |
| 1723 | } |
| 1724 |
| 1725 | static enum ssl_hs_wait_t do_finish_server_handshake(SSL_HANDSHAKE *hs) { |
| 1726 | SSL *const ssl = hs->ssl; |
| 1727 |
| 1728 | if (hs->handback) { |
| 1729 | return ssl_hs_handback; |
| 1730 | } |
| 1731 |
| 1732 | ssl->method->on_handshake_complete(ssl); |
| 1733 |
| 1734 | // If we aren't retaining peer certificates then we can discard it now. |
| 1735 | if (hs->new_session != NULL && |
| 1736 | hs->config->retain_only_sha256_of_client_certs) { |
| 1737 | hs->new_session->certs.reset(); |
| 1738 | ssl->ctx->x509_method->session_clear(hs->new_session.get()); |
| 1739 | } |
| 1740 |
| 1741 | bool has_new_session = hs->new_session != nullptr; |
| 1742 | if (has_new_session) { |
| 1743 | assert(ssl->session == nullptr); |
| 1744 | ssl->s3->established_session = std::move(hs->new_session); |
| 1745 | ssl->s3->established_session->not_resumable = false; |
| 1746 | } else { |
| 1747 | assert(ssl->session != nullptr); |
| 1748 | ssl->s3->established_session = UpRef(ssl->session); |
| 1749 | } |
| 1750 |
| 1751 | hs->handshake_finalized = true; |
| 1752 | ssl->s3->initial_handshake_complete = true; |
| 1753 | if (has_new_session) { |
| 1754 | ssl_update_cache(ssl); |
| 1755 | } |
| 1756 |
| 1757 | hs->state = state12_done; |
| 1758 | return ssl_hs_ok; |
| 1759 | } |
| 1760 |
| 1761 | enum ssl_hs_wait_t ssl_server_handshake(SSL_HANDSHAKE *hs) { |
| 1762 | while (hs->state != state12_done) { |
| 1763 | enum ssl_hs_wait_t ret = ssl_hs_error; |
| 1764 | enum tls12_server_hs_state_t state = |
| 1765 | static_cast<enum tls12_server_hs_state_t>(hs->state); |
| 1766 | switch (state) { |
| 1767 | case state12_start_accept: |
| 1768 | ret = do_start_accept(hs); |
| 1769 | break; |
| 1770 | case state12_read_client_hello: |
| 1771 | ret = do_read_client_hello(hs); |
| 1772 | break; |
| 1773 | case state12_read_client_hello_after_ech: |
| 1774 | ret = do_read_client_hello_after_ech(hs); |
| 1775 | break; |
| 1776 | case state12_cert_callback: |
| 1777 | ret = do_cert_callback(hs); |
| 1778 | break; |
| 1779 | case state12_tls13: |
| 1780 | ret = do_tls13(hs); |
| 1781 | break; |
| 1782 | case state12_select_parameters: |
| 1783 | ret = do_select_parameters(hs); |
| 1784 | break; |
| 1785 | case state12_send_server_hello: |
| 1786 | ret = do_send_server_hello(hs); |
| 1787 | break; |
| 1788 | case state12_send_server_certificate: |
| 1789 | ret = do_send_server_certificate(hs); |
| 1790 | break; |
| 1791 | case state12_send_server_key_exchange: |
| 1792 | ret = do_send_server_key_exchange(hs); |
| 1793 | break; |
| 1794 | case state12_send_server_hello_done: |
| 1795 | ret = do_send_server_hello_done(hs); |
| 1796 | break; |
| 1797 | case state12_read_client_certificate: |
| 1798 | ret = do_read_client_certificate(hs); |
| 1799 | break; |
| 1800 | case state12_verify_client_certificate: |
| 1801 | ret = do_verify_client_certificate(hs); |
| 1802 | break; |
| 1803 | case state12_read_client_key_exchange: |
| 1804 | ret = do_read_client_key_exchange(hs); |
| 1805 | break; |
| 1806 | case state12_read_client_certificate_verify: |
| 1807 | ret = do_read_client_certificate_verify(hs); |
| 1808 | break; |
| 1809 | case state12_read_change_cipher_spec: |
| 1810 | ret = do_read_change_cipher_spec(hs); |
| 1811 | break; |
| 1812 | case state12_process_change_cipher_spec: |
| 1813 | ret = do_process_change_cipher_spec(hs); |
| 1814 | break; |
| 1815 | case state12_read_next_proto: |
| 1816 | ret = do_read_next_proto(hs); |
| 1817 | break; |
| 1818 | case state12_read_channel_id: |
| 1819 | ret = do_read_channel_id(hs); |
| 1820 | break; |
| 1821 | case state12_read_client_finished: |
| 1822 | ret = do_read_client_finished(hs); |
| 1823 | break; |
| 1824 | case state12_send_server_finished: |
| 1825 | ret = do_send_server_finished(hs); |
| 1826 | break; |
| 1827 | case state12_finish_server_handshake: |
| 1828 | ret = do_finish_server_handshake(hs); |
| 1829 | break; |
| 1830 | case state12_done: |
| 1831 | ret = ssl_hs_ok; |
| 1832 | break; |
| 1833 | } |
| 1834 |
| 1835 | if (hs->state != state) { |
| 1836 | ssl_do_info_callback(hs->ssl, SSL_CB_ACCEPT_LOOP, 1); |
| 1837 | } |
| 1838 |
| 1839 | if (ret != ssl_hs_ok) { |
| 1840 | return ret; |
| 1841 | } |
| 1842 | } |
| 1843 |
| 1844 | ssl_do_info_callback(hs->ssl, SSL_CB_HANDSHAKE_DONE, 1); |
| 1845 | return ssl_hs_ok; |
| 1846 | } |
| 1847 |
| 1848 | const char *ssl_server_handshake_state(SSL_HANDSHAKE *hs) { |
| 1849 | enum tls12_server_hs_state_t state = |
| 1850 | static_cast<enum tls12_server_hs_state_t>(hs->state); |
| 1851 | switch (state) { |
| 1852 | case state12_start_accept: |
| 1853 | return "TLS server start_accept"; |
| 1854 | case state12_read_client_hello: |
| 1855 | return "TLS server read_client_hello"; |
| 1856 | case state12_read_client_hello_after_ech: |
| 1857 | return "TLS server read_client_hello_after_ech"; |
| 1858 | case state12_cert_callback: |
| 1859 | return "TLS server cert_callback"; |
| 1860 | case state12_tls13: |
| 1861 | return tls13_server_handshake_state(hs); |
| 1862 | case state12_select_parameters: |
| 1863 | return "TLS server select_parameters"; |
| 1864 | case state12_send_server_hello: |
| 1865 | return "TLS server send_server_hello"; |
| 1866 | case state12_send_server_certificate: |
| 1867 | return "TLS server send_server_certificate"; |
| 1868 | case state12_send_server_key_exchange: |
| 1869 | return "TLS server send_server_key_exchange"; |
| 1870 | case state12_send_server_hello_done: |
| 1871 | return "TLS server send_server_hello_done"; |
| 1872 | case state12_read_client_certificate: |
| 1873 | return "TLS server read_client_certificate"; |
| 1874 | case state12_verify_client_certificate: |
| 1875 | return "TLS server verify_client_certificate"; |
| 1876 | case state12_read_client_key_exchange: |
| 1877 | return "TLS server read_client_key_exchange"; |
| 1878 | case state12_read_client_certificate_verify: |
| 1879 | return "TLS server read_client_certificate_verify"; |
| 1880 | case state12_read_change_cipher_spec: |
| 1881 | return "TLS server read_change_cipher_spec"; |
| 1882 | case state12_process_change_cipher_spec: |
| 1883 | return "TLS server process_change_cipher_spec"; |
| 1884 | case state12_read_next_proto: |
| 1885 | return "TLS server read_next_proto"; |
| 1886 | case state12_read_channel_id: |
| 1887 | return "TLS server read_channel_id"; |
| 1888 | case state12_read_client_finished: |
| 1889 | return "TLS server read_client_finished"; |
| 1890 | case state12_send_server_finished: |
| 1891 | return "TLS server send_server_finished"; |
| 1892 | case state12_finish_server_handshake: |
| 1893 | return "TLS server finish_server_handshake"; |
| 1894 | case state12_done: |
| 1895 | return "TLS server done"; |
| 1896 | } |
| 1897 |
| 1898 | return "TLS server unknown"; |
| 1899 | } |
| 1900 |
| 1901 | BSSL_NAMESPACE_END |
| 1902 |