Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2016, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | #include <openssl/ssl.h> |
| 16 | |
| 17 | #include <assert.h> |
| 18 | #include <string.h> |
| 19 | |
| 20 | #include <openssl/bytestring.h> |
| 21 | #include <openssl/err.h> |
| 22 | #include <openssl/hkdf.h> |
| 23 | #include <openssl/mem.h> |
| 24 | #include <openssl/stack.h> |
| 25 | #include <openssl/x509.h> |
| 26 | #include <openssl/x509v3.h> |
| 27 | |
| 28 | #include "internal.h" |
| 29 | |
| 30 | |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 31 | /* kMaxKeyUpdates is the number of consecutive KeyUpdates that will be |
| 32 | * processed. Without this limit an attacker could force unbounded processing |
| 33 | * without being able to return application data. */ |
| 34 | static const uint8_t kMaxKeyUpdates = 32; |
| 35 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 36 | int tls13_handshake(SSL *ssl) { |
| 37 | SSL_HANDSHAKE *hs = ssl->s3->hs; |
| 38 | |
| 39 | for (;;) { |
| 40 | /* Resolve the operation the handshake was waiting on. */ |
| 41 | switch (hs->wait) { |
| 42 | case ssl_hs_error: |
| 43 | OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_HANDSHAKE_FAILURE); |
| 44 | return -1; |
| 45 | |
David Benjamin | f2401eb | 2016-07-18 22:25:05 +0200 | [diff] [blame] | 46 | case ssl_hs_flush: |
| 47 | case ssl_hs_flush_and_read_message: { |
| 48 | int ret = BIO_flush(ssl->wbio); |
| 49 | if (ret <= 0) { |
| 50 | ssl->rwstate = SSL_WRITING; |
| 51 | return ret; |
| 52 | } |
| 53 | if (hs->wait != ssl_hs_flush_and_read_message) { |
| 54 | break; |
| 55 | } |
David Benjamin | 613fe3b | 2016-07-22 17:39:29 +0200 | [diff] [blame] | 56 | ssl->method->expect_flight(ssl); |
David Benjamin | f2401eb | 2016-07-18 22:25:05 +0200 | [diff] [blame] | 57 | hs->wait = ssl_hs_read_message; |
| 58 | /* Fall-through. */ |
| 59 | } |
| 60 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 61 | case ssl_hs_read_message: { |
| 62 | int ret = ssl->method->ssl_get_message(ssl, -1, ssl_dont_hash_message); |
| 63 | if (ret <= 0) { |
| 64 | return ret; |
| 65 | } |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | case ssl_hs_write_message: { |
| 70 | int ret = ssl->method->write_message(ssl); |
| 71 | if (ret <= 0) { |
| 72 | return ret; |
| 73 | } |
| 74 | break; |
| 75 | } |
| 76 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 77 | case ssl_hs_x509_lookup: |
| 78 | ssl->rwstate = SSL_X509_LOOKUP; |
| 79 | hs->wait = ssl_hs_ok; |
| 80 | return -1; |
| 81 | |
| 82 | case ssl_hs_private_key_operation: |
| 83 | ssl->rwstate = SSL_PRIVATE_KEY_OPERATION; |
| 84 | hs->wait = ssl_hs_ok; |
| 85 | return -1; |
| 86 | |
| 87 | case ssl_hs_ok: |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | /* Run the state machine again. */ |
| 92 | hs->wait = hs->do_handshake(ssl); |
| 93 | if (hs->wait == ssl_hs_error) { |
| 94 | /* Don't loop around to avoid a stray |SSL_R_SSL_HANDSHAKE_FAILURE| the |
| 95 | * first time around. */ |
| 96 | return -1; |
| 97 | } |
| 98 | if (hs->wait == ssl_hs_ok) { |
| 99 | /* The handshake has completed. */ |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | /* Otherwise, loop to the beginning and resolve what was blocking the |
| 104 | * handshake. */ |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | static int tls13_get_cert_verify_signature_input(SSL *ssl, uint8_t **out, |
| 109 | size_t *out_len, int server) { |
| 110 | CBB cbb; |
| 111 | if (!CBB_init(&cbb, 64 + 33 + 1 + 2 * EVP_MAX_MD_SIZE)) { |
| 112 | goto err; |
| 113 | } |
| 114 | |
| 115 | for (size_t i = 0; i < 64; i++) { |
| 116 | if (!CBB_add_u8(&cbb, 0x20)) { |
| 117 | goto err; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (server) { |
| 122 | /* Include the NUL byte. */ |
| 123 | static const char kContext[] = "TLS 1.3, server CertificateVerify"; |
| 124 | if (!CBB_add_bytes(&cbb, (const uint8_t *)kContext, sizeof(kContext))) { |
| 125 | goto err; |
| 126 | } |
| 127 | } else { |
| 128 | static const char kContext[] = "TLS 1.3, client CertificateVerify"; |
| 129 | if (!CBB_add_bytes(&cbb, (const uint8_t *)kContext, sizeof(kContext))) { |
| 130 | goto err; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | uint8_t context_hashes[2 * EVP_MAX_MD_SIZE]; |
| 135 | size_t context_hashes_len; |
| 136 | if (!tls13_get_context_hashes(ssl, context_hashes, &context_hashes_len) || |
| 137 | !CBB_add_bytes(&cbb, context_hashes, context_hashes_len) || |
| 138 | !CBB_finish(&cbb, out, out_len)) { |
| 139 | goto err; |
| 140 | } |
| 141 | |
| 142 | return 1; |
| 143 | |
| 144 | err: |
| 145 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
| 146 | CBB_cleanup(&cbb); |
| 147 | return 0; |
| 148 | } |
| 149 | |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 150 | int tls13_process_certificate(SSL *ssl, int allow_anonymous) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 151 | CBS cbs, context; |
| 152 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
| 153 | if (!CBS_get_u8_length_prefixed(&cbs, &context) || |
| 154 | CBS_len(&context) != 0) { |
| 155 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 156 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 157 | return 0; |
| 158 | } |
| 159 | |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 160 | const int retain_sha256 = |
| 161 | ssl->server && ssl->ctx->retain_only_sha256_of_client_certs; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 162 | int ret = 0; |
| 163 | uint8_t alert; |
| 164 | STACK_OF(X509) *chain = ssl_parse_cert_chain( |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 165 | ssl, &alert, retain_sha256 ? ssl->s3->new_session->peer_sha256 : NULL, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 166 | &cbs); |
| 167 | if (chain == NULL) { |
| 168 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 169 | goto err; |
| 170 | } |
| 171 | |
| 172 | if (CBS_len(&cbs) != 0) { |
| 173 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 174 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 175 | goto err; |
| 176 | } |
| 177 | |
| 178 | if (sk_X509_num(chain) == 0) { |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 179 | if (!allow_anonymous) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 180 | OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); |
| 181 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 182 | goto err; |
| 183 | } |
| 184 | |
Adam Langley | 3764683 | 2016-08-01 16:16:46 -0700 | [diff] [blame] | 185 | /* OpenSSL returns X509_V_OK when no certificates are requested. This is |
David Benjamin | dd634eb | 2016-08-18 16:40:28 -0400 | [diff] [blame] | 186 | * classed by them as a bug, but it's assumed by at least NGINX. */ |
Adam Langley | 3764683 | 2016-08-01 16:16:46 -0700 | [diff] [blame] | 187 | ssl->s3->new_session->verify_result = X509_V_OK; |
| 188 | |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 189 | /* No certificate, so nothing more to do. */ |
| 190 | ret = 1; |
| 191 | goto err; |
| 192 | } |
| 193 | |
David Benjamin | 4087df9 | 2016-08-01 20:16:31 -0400 | [diff] [blame] | 194 | ssl->s3->new_session->peer_sha256_valid = retain_sha256; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 195 | |
David Benjamin | 7aa31d6 | 2016-08-08 21:38:32 -0400 | [diff] [blame] | 196 | if (!ssl_verify_cert_chain(ssl, &ssl->s3->new_session->verify_result, |
| 197 | chain)) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 198 | goto err; |
| 199 | } |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 200 | |
Steven Valdez | 87eab49 | 2016-06-27 16:34:59 -0400 | [diff] [blame] | 201 | X509_free(ssl->s3->new_session->peer); |
David Benjamin | 96a16cd | 2016-08-11 12:14:47 -0400 | [diff] [blame] | 202 | X509 *leaf = sk_X509_value(chain, 0); |
| 203 | X509_up_ref(leaf); |
| 204 | ssl->s3->new_session->peer = leaf; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 205 | |
Steven Valdez | 87eab49 | 2016-06-27 16:34:59 -0400 | [diff] [blame] | 206 | sk_X509_pop_free(ssl->s3->new_session->cert_chain, X509_free); |
| 207 | ssl->s3->new_session->cert_chain = chain; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 208 | chain = NULL; |
| 209 | |
| 210 | ret = 1; |
| 211 | |
| 212 | err: |
| 213 | sk_X509_pop_free(chain, X509_free); |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | int tls13_process_certificate_verify(SSL *ssl) { |
| 218 | int ret = 0; |
Steven Valdez | 87eab49 | 2016-06-27 16:34:59 -0400 | [diff] [blame] | 219 | X509 *peer = ssl->s3->new_session->peer; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 220 | EVP_PKEY *pkey = NULL; |
| 221 | uint8_t *msg = NULL; |
| 222 | size_t msg_len; |
| 223 | |
| 224 | /* Filter out unsupported certificate types. */ |
| 225 | pkey = X509_get_pubkey(peer); |
| 226 | if (pkey == NULL) { |
| 227 | goto err; |
| 228 | } |
| 229 | |
| 230 | CBS cbs, signature; |
| 231 | uint16_t signature_algorithm; |
| 232 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
| 233 | if (!CBS_get_u16(&cbs, &signature_algorithm) || |
| 234 | !CBS_get_u16_length_prefixed(&cbs, &signature) || |
| 235 | CBS_len(&cbs) != 0) { |
| 236 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 237 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 238 | goto err; |
| 239 | } |
| 240 | |
| 241 | int al; |
| 242 | if (!tls12_check_peer_sigalg(ssl, &al, signature_algorithm)) { |
| 243 | ssl3_send_alert(ssl, SSL3_AL_FATAL, al); |
| 244 | goto err; |
| 245 | } |
| 246 | ssl->s3->tmp.peer_signature_algorithm = signature_algorithm; |
| 247 | |
| 248 | if (!tls13_get_cert_verify_signature_input(ssl, &msg, &msg_len, |
| 249 | !ssl->server)) { |
| 250 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 251 | goto err; |
| 252 | } |
| 253 | |
| 254 | int sig_ok = |
| 255 | ssl_public_key_verify(ssl, CBS_data(&signature), CBS_len(&signature), |
| 256 | signature_algorithm, pkey, msg, msg_len); |
David Benjamin | 04aa694 | 2016-08-19 14:51:10 -0400 | [diff] [blame^] | 257 | #if defined(BORINGSSL_UNSAFE_FUZZER_MODE) |
| 258 | sig_ok = 1; |
| 259 | ERR_clear_error(); |
| 260 | #endif |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 261 | if (!sig_ok) { |
| 262 | OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SIGNATURE); |
| 263 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR); |
| 264 | goto err; |
| 265 | } |
| 266 | |
| 267 | ret = 1; |
| 268 | |
| 269 | err: |
| 270 | EVP_PKEY_free(pkey); |
| 271 | OPENSSL_free(msg); |
| 272 | return ret; |
| 273 | } |
| 274 | |
| 275 | int tls13_check_message_type(SSL *ssl, int type) { |
| 276 | if (ssl->s3->tmp.message_type != type) { |
| 277 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE); |
| 278 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE); |
David Benjamin | f2401eb | 2016-07-18 22:25:05 +0200 | [diff] [blame] | 279 | ERR_add_error_dataf("got type %d, wanted type %d", |
| 280 | ssl->s3->tmp.message_type, type); |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | return 1; |
| 285 | } |
| 286 | |
| 287 | int tls13_process_finished(SSL *ssl) { |
| 288 | uint8_t verify_data[EVP_MAX_MD_SIZE]; |
| 289 | size_t verify_data_len; |
| 290 | if (!tls13_finished_mac(ssl, verify_data, &verify_data_len, !ssl->server)) { |
| 291 | return 0; |
| 292 | } |
| 293 | |
David Benjamin | 04aa694 | 2016-08-19 14:51:10 -0400 | [diff] [blame^] | 294 | int finished_ok = |
| 295 | ssl->init_num == verify_data_len && |
| 296 | CRYPTO_memcmp(verify_data, ssl->init_msg, verify_data_len) == 0; |
| 297 | #if defined(BORINGSSL_UNSAFE_FUZZER_MODE) |
| 298 | finished_ok = 1; |
| 299 | #endif |
| 300 | if (!finished_ok) { |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 301 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR); |
| 302 | OPENSSL_PUT_ERROR(SSL, SSL_R_DIGEST_CHECK_FAILED); |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | int tls13_prepare_certificate(SSL *ssl) { |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 310 | CBB cbb, body; |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 311 | if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CERTIFICATE) || |
David Benjamin | 8a8349b | 2016-08-18 02:32:23 -0400 | [diff] [blame] | 312 | /* The request context is always empty in the handshake. */ |
| 313 | !CBB_add_u8(&body, 0) || |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 314 | !ssl_add_cert_chain(ssl, &body) || |
| 315 | !ssl->method->finish_message(ssl, &cbb)) { |
| 316 | CBB_cleanup(&cbb); |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | return 1; |
| 321 | } |
| 322 | |
| 323 | enum ssl_private_key_result_t tls13_prepare_certificate_verify( |
| 324 | SSL *ssl, int is_first_run) { |
| 325 | enum ssl_private_key_result_t ret = ssl_private_key_failure; |
| 326 | uint8_t *msg = NULL; |
| 327 | size_t msg_len; |
| 328 | CBB cbb, body; |
| 329 | CBB_zero(&cbb); |
| 330 | |
| 331 | uint16_t signature_algorithm; |
| 332 | if (!tls1_choose_signature_algorithm(ssl, &signature_algorithm)) { |
| 333 | goto err; |
| 334 | } |
| 335 | if (!ssl->method->init_message(ssl, &cbb, &body, |
| 336 | SSL3_MT_CERTIFICATE_VERIFY) || |
| 337 | !CBB_add_u16(&body, signature_algorithm)) { |
| 338 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 339 | goto err; |
| 340 | } |
| 341 | |
| 342 | /* Sign the digest. */ |
| 343 | CBB child; |
| 344 | const size_t max_sig_len = ssl_private_key_max_signature_len(ssl); |
| 345 | uint8_t *sig; |
| 346 | size_t sig_len; |
| 347 | if (!CBB_add_u16_length_prefixed(&body, &child) || |
| 348 | !CBB_reserve(&child, &sig, max_sig_len)) { |
| 349 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 350 | goto err; |
| 351 | } |
| 352 | |
| 353 | enum ssl_private_key_result_t sign_result; |
| 354 | if (is_first_run) { |
| 355 | if (!tls13_get_cert_verify_signature_input(ssl, &msg, &msg_len, |
| 356 | ssl->server)) { |
| 357 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 358 | goto err; |
| 359 | } |
| 360 | sign_result = ssl_private_key_sign(ssl, sig, &sig_len, max_sig_len, |
| 361 | signature_algorithm, msg, msg_len); |
| 362 | } else { |
| 363 | sign_result = ssl_private_key_complete(ssl, sig, &sig_len, max_sig_len); |
| 364 | } |
| 365 | |
| 366 | if (sign_result != ssl_private_key_success) { |
| 367 | ret = sign_result; |
| 368 | goto err; |
| 369 | } |
| 370 | |
| 371 | if (!CBB_did_write(&child, sig_len) || |
| 372 | !ssl->method->finish_message(ssl, &cbb)) { |
| 373 | goto err; |
| 374 | } |
| 375 | |
| 376 | ret = ssl_private_key_success; |
| 377 | |
| 378 | err: |
| 379 | CBB_cleanup(&cbb); |
| 380 | OPENSSL_free(msg); |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | int tls13_prepare_finished(SSL *ssl) { |
| 385 | size_t verify_data_len; |
| 386 | uint8_t verify_data[EVP_MAX_MD_SIZE]; |
| 387 | |
| 388 | if (!tls13_finished_mac(ssl, verify_data, &verify_data_len, ssl->server)) { |
| 389 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 390 | OPENSSL_PUT_ERROR(SSL, SSL_R_DIGEST_CHECK_FAILED); |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | CBB cbb, body; |
| 395 | if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_FINISHED) || |
| 396 | !CBB_add_bytes(&body, verify_data, verify_data_len) || |
| 397 | !ssl->method->finish_message(ssl, &cbb)) { |
| 398 | CBB_cleanup(&cbb); |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | return 1; |
| 403 | } |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 404 | |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 405 | static int tls13_receive_key_update(SSL *ssl) { |
| 406 | if (ssl->init_num != 0) { |
| 407 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 408 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | // TODO(svaldez): Send KeyUpdate. |
| 413 | return tls13_rotate_traffic_key(ssl, evp_aead_open); |
| 414 | } |
| 415 | |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 416 | int tls13_post_handshake(SSL *ssl) { |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 417 | if (ssl->s3->tmp.message_type == SSL3_MT_KEY_UPDATE) { |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 418 | ssl->s3->key_update_count++; |
| 419 | if (ssl->s3->key_update_count > kMaxKeyUpdates) { |
| 420 | OPENSSL_PUT_ERROR(SSL, SSL_R_TOO_MANY_KEY_UPDATES); |
| 421 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE); |
| 422 | return 0; |
| 423 | } |
| 424 | |
Steven Valdez | 1dc53d2 | 2016-07-26 12:27:38 -0400 | [diff] [blame] | 425 | return tls13_receive_key_update(ssl); |
| 426 | } |
| 427 | |
Steven Valdez | 32635b8 | 2016-08-16 11:25:03 -0400 | [diff] [blame] | 428 | ssl->s3->key_update_count = 0; |
| 429 | |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 430 | if (ssl->s3->tmp.message_type == SSL3_MT_NEW_SESSION_TICKET && |
| 431 | !ssl->server) { |
Steven Valdez | 1e6f11a | 2016-07-27 11:10:52 -0400 | [diff] [blame] | 432 | return tls13_process_new_session_ticket(ssl); |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | // TODO(svaldez): Handle post-handshake authentication. |
Steven Valdez | 8e1c7be | 2016-07-26 12:39:22 -0400 | [diff] [blame] | 436 | |
| 437 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE); |
| 438 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE); |
| 439 | return 0; |
| 440 | } |