David Benjamin | c895d6b | 2016-08-11 13:26:41 -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> |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 18 | #include <limits.h> |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 19 | #include <string.h> |
| 20 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 21 | #include <utility> |
| 22 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 23 | #include <openssl/bytestring.h> |
| 24 | #include <openssl/digest.h> |
| 25 | #include <openssl/err.h> |
| 26 | #include <openssl/mem.h> |
| 27 | #include <openssl/stack.h> |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 28 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 29 | #include "../crypto/internal.h" |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 30 | #include "internal.h" |
| 31 | |
| 32 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 33 | namespace bssl { |
| 34 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 35 | enum client_hs_state_t { |
| 36 | state_process_hello_retry_request = 0, |
| 37 | state_send_second_client_hello, |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 38 | state_process_server_hello, |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 39 | state_process_change_cipher_spec, |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 40 | state_process_encrypted_extensions, |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 41 | state_continue_second_server_flight, |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 42 | state_process_certificate_request, |
| 43 | state_process_server_certificate, |
| 44 | state_process_server_certificate_verify, |
| 45 | state_process_server_finished, |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 46 | state_send_end_of_early_data, |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 47 | state_send_client_certificate, |
| 48 | state_send_client_certificate_verify, |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 49 | state_complete_second_flight, |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 50 | state_done, |
| 51 | }; |
| 52 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 53 | static const uint8_t kZeroes[EVP_MAX_MD_SIZE] = {0}; |
| 54 | |
| 55 | static enum ssl_hs_wait_t do_process_hello_retry_request(SSL_HANDSHAKE *hs) { |
| 56 | SSL *const ssl = hs->ssl; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 57 | if (ssl->s3->tmp.message_type != SSL3_MT_HELLO_RETRY_REQUEST) { |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 58 | hs->tls13_state = state_process_server_hello; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 59 | return ssl_hs_ok; |
| 60 | } |
| 61 | |
| 62 | CBS cbs, extensions; |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 63 | uint16_t server_version; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 64 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 65 | if (!CBS_get_u16(&cbs, &server_version) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 66 | !CBS_get_u16_length_prefixed(&cbs, &extensions) || |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 67 | /* HelloRetryRequest may not be empty. */ |
| 68 | CBS_len(&extensions) == 0 || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 69 | CBS_len(&cbs) != 0) { |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 70 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 71 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 72 | return ssl_hs_error; |
| 73 | } |
| 74 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 75 | int have_cookie, have_key_share; |
| 76 | CBS cookie, key_share; |
| 77 | const SSL_EXTENSION_TYPE ext_types[] = { |
| 78 | {TLSEXT_TYPE_key_share, &have_key_share, &key_share}, |
| 79 | {TLSEXT_TYPE_cookie, &have_cookie, &cookie}, |
| 80 | }; |
| 81 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 82 | uint8_t alert = SSL_AD_DECODE_ERROR; |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 83 | if (!ssl_parse_extensions(&extensions, &alert, ext_types, |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 84 | OPENSSL_ARRAY_SIZE(ext_types), |
| 85 | 0 /* reject unknown */)) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 86 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 87 | return ssl_hs_error; |
| 88 | } |
| 89 | |
| 90 | if (have_cookie) { |
| 91 | CBS cookie_value; |
| 92 | if (!CBS_get_u16_length_prefixed(&cookie, &cookie_value) || |
| 93 | CBS_len(&cookie_value) == 0 || |
| 94 | CBS_len(&cookie) != 0) { |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 95 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 96 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 97 | return ssl_hs_error; |
| 98 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 99 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 100 | if (!CBS_stow(&cookie_value, &hs->cookie, &hs->cookie_len)) { |
| 101 | return ssl_hs_error; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 105 | if (have_key_share) { |
| 106 | uint16_t group_id; |
| 107 | if (!CBS_get_u16(&key_share, &group_id) || CBS_len(&key_share) != 0) { |
| 108 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 109 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 110 | return ssl_hs_error; |
| 111 | } |
| 112 | |
| 113 | /* The group must be supported. */ |
| 114 | const uint16_t *groups; |
| 115 | size_t groups_len; |
| 116 | tls1_get_grouplist(ssl, &groups, &groups_len); |
| 117 | int found = 0; |
| 118 | for (size_t i = 0; i < groups_len; i++) { |
| 119 | if (groups[i] == group_id) { |
| 120 | found = 1; |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if (!found) { |
| 126 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 127 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE); |
| 128 | return ssl_hs_error; |
| 129 | } |
| 130 | |
| 131 | /* Check that the HelloRetryRequest does not request the key share that |
| 132 | * was provided in the initial ClientHello. */ |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 133 | if (hs->key_share->GroupID() == group_id) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 134 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 135 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE); |
| 136 | return ssl_hs_error; |
| 137 | } |
| 138 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 139 | hs->key_share.reset(); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 140 | hs->retry_group = group_id; |
| 141 | } |
| 142 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 143 | if (!ssl_hash_current_message(hs)) { |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 144 | return ssl_hs_error; |
| 145 | } |
| 146 | |
David Benjamin | 95add82 | 2016-10-19 01:09:12 -0400 | [diff] [blame] | 147 | hs->received_hello_retry_request = 1; |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 148 | hs->tls13_state = state_send_second_client_hello; |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 149 | /* 0-RTT is rejected if we receive a HelloRetryRequest. */ |
| 150 | if (hs->in_early_data) { |
| 151 | return ssl_hs_early_data_rejected; |
| 152 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 153 | return ssl_hs_ok; |
| 154 | } |
| 155 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 156 | static enum ssl_hs_wait_t do_send_second_client_hello(SSL_HANDSHAKE *hs) { |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 157 | SSL *const ssl = hs->ssl; |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 158 | /* Restore the null cipher. We may have switched due to 0-RTT. */ |
| 159 | bssl::UniquePtr<SSLAEADContext> null_ctx = SSLAEADContext::CreateNullCipher(); |
| 160 | if (!null_ctx || |
| 161 | !ssl->method->set_write_state(ssl, std::move(null_ctx)) || |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 162 | !ssl_write_client_hello(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 163 | return ssl_hs_error; |
| 164 | } |
| 165 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 166 | hs->tls13_state = state_process_server_hello; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 167 | return ssl_hs_flush_and_read_message; |
| 168 | } |
| 169 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 170 | static enum ssl_hs_wait_t do_process_server_hello(SSL_HANDSHAKE *hs) { |
| 171 | SSL *const ssl = hs->ssl; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 172 | if (!ssl_check_message_type(ssl, SSL3_MT_SERVER_HELLO)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 173 | return ssl_hs_error; |
| 174 | } |
| 175 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 176 | CBS cbs, server_random, session_id, extensions; |
| 177 | uint16_t server_version; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 178 | uint16_t cipher_suite; |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 179 | uint8_t compression_method; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 180 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 181 | if (!CBS_get_u16(&cbs, &server_version) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 182 | !CBS_get_bytes(&cbs, &server_random, SSL3_RANDOM_SIZE) || |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 183 | (ssl->version == TLS1_3_EXPERIMENT_VERSION && |
| 184 | !CBS_get_u8_length_prefixed(&cbs, &session_id)) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 185 | !CBS_get_u16(&cbs, &cipher_suite) || |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 186 | (ssl->version == TLS1_3_EXPERIMENT_VERSION && |
| 187 | (!CBS_get_u8(&cbs, &compression_method) || compression_method != 0)) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 188 | !CBS_get_u16_length_prefixed(&cbs, &extensions) || |
| 189 | CBS_len(&cbs) != 0) { |
| 190 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 191 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 192 | return ssl_hs_error; |
| 193 | } |
| 194 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 195 | uint16_t expected_version = |
| 196 | ssl->version == TLS1_3_EXPERIMENT_VERSION ? TLS1_2_VERSION : ssl->version; |
| 197 | if (server_version != expected_version) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 198 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 199 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_VERSION_NUMBER); |
| 200 | return ssl_hs_error; |
| 201 | } |
| 202 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 203 | assert(ssl->s3->have_version); |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 204 | OPENSSL_memcpy(ssl->s3->server_random, CBS_data(&server_random), |
| 205 | SSL3_RANDOM_SIZE); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 206 | |
| 207 | const SSL_CIPHER *cipher = SSL_get_cipher_by_value(cipher_suite); |
| 208 | if (cipher == NULL) { |
| 209 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CIPHER_RETURNED); |
| 210 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 211 | return ssl_hs_error; |
| 212 | } |
| 213 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 214 | /* Check if the cipher is a TLS 1.3 cipher. */ |
| 215 | if (SSL_CIPHER_get_min_version(cipher) > ssl3_protocol_version(ssl) || |
| 216 | SSL_CIPHER_get_max_version(cipher) < ssl3_protocol_version(ssl)) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 217 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED); |
| 218 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 219 | return ssl_hs_error; |
| 220 | } |
| 221 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 222 | /* Parse out the extensions. */ |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 223 | int have_key_share = 0, have_pre_shared_key = 0, have_supported_versions = 0; |
| 224 | CBS key_share, pre_shared_key, supported_versions; |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 225 | const SSL_EXTENSION_TYPE ext_types[] = { |
| 226 | {TLSEXT_TYPE_key_share, &have_key_share, &key_share}, |
| 227 | {TLSEXT_TYPE_pre_shared_key, &have_pre_shared_key, &pre_shared_key}, |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 228 | {TLSEXT_TYPE_supported_versions, &have_supported_versions, |
| 229 | &supported_versions}, |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 230 | }; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 231 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 232 | uint8_t alert = SSL_AD_DECODE_ERROR; |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 233 | if (!ssl_parse_extensions(&extensions, &alert, ext_types, |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 234 | OPENSSL_ARRAY_SIZE(ext_types), |
| 235 | 0 /* reject unknown */)) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 236 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 237 | return ssl_hs_error; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 240 | /* supported_versions is parsed in handshake_client to select the experimental |
| 241 | * TLS 1.3 version. */ |
| 242 | if (have_supported_versions && ssl->version != TLS1_3_EXPERIMENT_VERSION) { |
| 243 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION); |
| 244 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNSUPPORTED_EXTENSION); |
| 245 | return ssl_hs_error; |
| 246 | } |
| 247 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 248 | alert = SSL_AD_DECODE_ERROR; |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 249 | if (have_pre_shared_key) { |
| 250 | if (ssl->session == NULL) { |
| 251 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION); |
| 252 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNSUPPORTED_EXTENSION); |
| 253 | return ssl_hs_error; |
| 254 | } |
| 255 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 256 | if (!ssl_ext_pre_shared_key_parse_serverhello(hs, &alert, |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 257 | &pre_shared_key)) { |
| 258 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 259 | return ssl_hs_error; |
| 260 | } |
| 261 | |
| 262 | if (ssl->session->ssl_version != ssl->version) { |
| 263 | OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED); |
| 264 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 265 | return ssl_hs_error; |
| 266 | } |
| 267 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 268 | if (ssl->session->cipher->algorithm_prf != cipher->algorithm_prf) { |
| 269 | OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_PRF_HASH_MISMATCH); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 270 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 271 | return ssl_hs_error; |
| 272 | } |
| 273 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 274 | if (!ssl_session_is_context_valid(ssl, ssl->session)) { |
| 275 | /* This is actually a client application bug. */ |
| 276 | OPENSSL_PUT_ERROR(SSL, |
| 277 | SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); |
| 278 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); |
| 279 | return ssl_hs_error; |
| 280 | } |
| 281 | |
| 282 | ssl->s3->session_reused = 1; |
| 283 | /* Only authentication information carries over in TLS 1.3. */ |
Robert Sloan | a94fe05 | 2017-02-21 08:49:28 -0800 | [diff] [blame] | 284 | hs->new_session = SSL_SESSION_dup(ssl->session, SSL_SESSION_DUP_AUTH_ONLY); |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 285 | if (!hs->new_session) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 286 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 287 | return ssl_hs_error; |
| 288 | } |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 289 | ssl_set_session(ssl, NULL); |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 290 | |
| 291 | /* Resumption incorporates fresh key material, so refresh the timeout. */ |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 292 | ssl_session_renew_timeout(ssl, hs->new_session.get(), |
Robert Sloan | 1c9db53 | 2017-03-13 08:03:59 -0700 | [diff] [blame] | 293 | ssl->session_ctx->session_psk_dhe_timeout); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 294 | } else if (!ssl_get_new_session(hs, 0)) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 295 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 296 | return ssl_hs_error; |
| 297 | } |
| 298 | |
Robert Sloan | a94fe05 | 2017-02-21 08:49:28 -0800 | [diff] [blame] | 299 | hs->new_session->cipher = cipher; |
| 300 | hs->new_cipher = cipher; |
| 301 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 302 | /* The PRF hash is now known. Set up the key schedule. */ |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 303 | if (!tls13_init_key_schedule(hs)) { |
| 304 | return ssl_hs_error; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 305 | } |
| 306 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 307 | /* Incorporate the PSK into the running secret. */ |
| 308 | if (ssl->s3->session_reused) { |
Robert Sloan | a94fe05 | 2017-02-21 08:49:28 -0800 | [diff] [blame] | 309 | if (!tls13_advance_key_schedule(hs, hs->new_session->master_key, |
| 310 | hs->new_session->master_key_length)) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 311 | return ssl_hs_error; |
| 312 | } |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 313 | } else if (!tls13_advance_key_schedule(hs, kZeroes, hs->hash_len)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 314 | return ssl_hs_error; |
| 315 | } |
| 316 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 317 | if (!have_key_share) { |
| 318 | /* We do not support psk_ke and thus always require a key share. */ |
| 319 | OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_KEY_SHARE); |
| 320 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION); |
| 321 | return ssl_hs_error; |
| 322 | } |
| 323 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 324 | /* Resolve ECDHE and incorporate it into the secret. */ |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 325 | uint8_t *dhe_secret; |
| 326 | size_t dhe_secret_len; |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 327 | alert = SSL_AD_DECODE_ERROR; |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 328 | if (!ssl_ext_key_share_parse_serverhello(hs, &dhe_secret, &dhe_secret_len, |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 329 | &alert, &key_share)) { |
| 330 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 331 | return ssl_hs_error; |
| 332 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 333 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 334 | if (!tls13_advance_key_schedule(hs, dhe_secret, dhe_secret_len)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 335 | OPENSSL_free(dhe_secret); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 336 | return ssl_hs_error; |
| 337 | } |
| 338 | OPENSSL_free(dhe_secret); |
| 339 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 340 | if (!ssl_hash_current_message(hs) || |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 341 | !tls13_derive_handshake_secrets(hs)) { |
| 342 | return ssl_hs_error; |
| 343 | } |
| 344 | hs->tls13_state = state_process_change_cipher_spec; |
| 345 | return ssl->version == TLS1_3_EXPERIMENT_VERSION |
| 346 | ? ssl_hs_read_change_cipher_spec |
| 347 | : ssl_hs_ok; |
| 348 | } |
| 349 | |
| 350 | static enum ssl_hs_wait_t do_process_change_cipher_spec(SSL_HANDSHAKE *hs) { |
| 351 | SSL *const ssl = hs->ssl; |
| 352 | if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->server_handshake_secret, |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 353 | hs->hash_len)) { |
| 354 | return ssl_hs_error; |
| 355 | } |
| 356 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 357 | if (!hs->early_data_offered) { |
| 358 | /* If not sending early data, set client traffic keys now so that alerts are |
| 359 | * encrypted. */ |
| 360 | if ((ssl->version == TLS1_3_EXPERIMENT_VERSION && |
| 361 | !ssl3_add_change_cipher_spec(ssl)) || |
| 362 | !tls13_set_traffic_key(ssl, evp_aead_seal, hs->client_handshake_secret, |
| 363 | hs->hash_len)) { |
| 364 | return ssl_hs_error; |
| 365 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 368 | hs->tls13_state = state_process_encrypted_extensions; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 369 | return ssl_hs_read_message; |
| 370 | } |
| 371 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 372 | static enum ssl_hs_wait_t do_process_encrypted_extensions(SSL_HANDSHAKE *hs) { |
| 373 | SSL *const ssl = hs->ssl; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 374 | if (!ssl_check_message_type(ssl, SSL3_MT_ENCRYPTED_EXTENSIONS)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 375 | return ssl_hs_error; |
| 376 | } |
| 377 | |
| 378 | CBS cbs; |
| 379 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 380 | if (!ssl_parse_serverhello_tlsext(hs, &cbs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 381 | OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT); |
| 382 | return ssl_hs_error; |
| 383 | } |
| 384 | if (CBS_len(&cbs) != 0) { |
| 385 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 386 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 387 | return ssl_hs_error; |
| 388 | } |
| 389 | |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 390 | /* Store the negotiated ALPN in the session. */ |
| 391 | if (ssl->s3->alpn_selected != NULL) { |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 392 | hs->new_session->early_alpn = (uint8_t *)BUF_memdup( |
| 393 | ssl->s3->alpn_selected, ssl->s3->alpn_selected_len); |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 394 | if (hs->new_session->early_alpn == NULL) { |
| 395 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 396 | return ssl_hs_error; |
| 397 | } |
| 398 | hs->new_session->early_alpn_len = ssl->s3->alpn_selected_len; |
| 399 | } |
| 400 | |
| 401 | if (ssl->early_data_accepted) { |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 402 | if (hs->early_session->cipher != hs->new_session->cipher || |
| 403 | hs->early_session->early_alpn_len != ssl->s3->alpn_selected_len || |
| 404 | OPENSSL_memcmp(hs->early_session->early_alpn, ssl->s3->alpn_selected, |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 405 | ssl->s3->alpn_selected_len) != 0) { |
| 406 | OPENSSL_PUT_ERROR(SSL, SSL_R_ALPN_MISMATCH_ON_EARLY_DATA); |
| 407 | return ssl_hs_error; |
| 408 | } |
| 409 | if (ssl->s3->tlsext_channel_id_valid) { |
| 410 | OPENSSL_PUT_ERROR(SSL, SSL_R_CHANNEL_ID_ON_EARLY_DATA); |
| 411 | return ssl_hs_error; |
| 412 | } |
| 413 | } |
| 414 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 415 | if (!ssl_hash_current_message(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 416 | return ssl_hs_error; |
| 417 | } |
| 418 | |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 419 | hs->tls13_state = state_continue_second_server_flight; |
| 420 | if (hs->in_early_data && !ssl->early_data_accepted) { |
| 421 | return ssl_hs_early_data_rejected; |
| 422 | } |
| 423 | return ssl_hs_ok; |
| 424 | } |
| 425 | |
| 426 | static enum ssl_hs_wait_t do_continue_second_server_flight(SSL_HANDSHAKE *hs) { |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 427 | hs->tls13_state = state_process_certificate_request; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 428 | return ssl_hs_read_message; |
| 429 | } |
| 430 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 431 | static enum ssl_hs_wait_t do_process_certificate_request(SSL_HANDSHAKE *hs) { |
| 432 | SSL *const ssl = hs->ssl; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 433 | /* CertificateRequest may only be sent in non-resumption handshakes. */ |
| 434 | if (ssl->s3->session_reused) { |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 435 | hs->tls13_state = state_process_server_finished; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 436 | return ssl_hs_ok; |
| 437 | } |
| 438 | |
| 439 | /* CertificateRequest is optional. */ |
| 440 | if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) { |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 441 | hs->tls13_state = state_process_server_certificate; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 442 | return ssl_hs_ok; |
| 443 | } |
| 444 | |
| 445 | CBS cbs, context, supported_signature_algorithms; |
| 446 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
| 447 | if (!CBS_get_u8_length_prefixed(&cbs, &context) || |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 448 | /* The request context is always empty during the handshake. */ |
| 449 | CBS_len(&context) != 0 || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 450 | !CBS_get_u16_length_prefixed(&cbs, &supported_signature_algorithms) || |
| 451 | CBS_len(&supported_signature_algorithms) == 0 || |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 452 | !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 453 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 454 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 455 | return ssl_hs_error; |
| 456 | } |
| 457 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 458 | uint8_t alert = SSL_AD_DECODE_ERROR; |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 459 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> ca_names = |
Robert Sloan | 7d422bc | 2017-03-06 10:04:29 -0800 | [diff] [blame] | 460 | ssl_parse_client_CA_list(ssl, &alert, &cbs); |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 461 | if (!ca_names) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 462 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
| 463 | return ssl_hs_error; |
| 464 | } |
| 465 | |
| 466 | /* Ignore extensions. */ |
| 467 | CBS extensions; |
| 468 | if (!CBS_get_u16_length_prefixed(&cbs, &extensions) || |
| 469 | CBS_len(&cbs) != 0) { |
| 470 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 471 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
| 472 | return ssl_hs_error; |
| 473 | } |
| 474 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 475 | hs->cert_request = 1; |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 476 | hs->ca_names = std::move(ca_names); |
Robert Sloan | 7d422bc | 2017-03-06 10:04:29 -0800 | [diff] [blame] | 477 | ssl->ctx->x509_method->hs_flush_cached_ca_names(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 478 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 479 | if (!ssl_hash_current_message(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 480 | return ssl_hs_error; |
| 481 | } |
| 482 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 483 | hs->tls13_state = state_process_server_certificate; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 484 | return ssl_hs_read_message; |
| 485 | } |
| 486 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 487 | static enum ssl_hs_wait_t do_process_server_certificate(SSL_HANDSHAKE *hs) { |
| 488 | SSL *const ssl = hs->ssl; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 489 | if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE) || |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 490 | !tls13_process_certificate(hs, 0 /* certificate required */) || |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 491 | !ssl_hash_current_message(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 492 | return ssl_hs_error; |
| 493 | } |
| 494 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 495 | hs->tls13_state = state_process_server_certificate_verify; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 496 | return ssl_hs_read_message; |
| 497 | } |
| 498 | |
| 499 | static enum ssl_hs_wait_t do_process_server_certificate_verify( |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 500 | SSL_HANDSHAKE *hs) { |
| 501 | SSL *const ssl = hs->ssl; |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 502 | switch (ssl_verify_peer_cert(hs)) { |
| 503 | case ssl_verify_ok: |
| 504 | break; |
| 505 | case ssl_verify_invalid: |
| 506 | return ssl_hs_error; |
| 507 | case ssl_verify_retry: |
| 508 | hs->tls13_state = state_process_server_certificate_verify; |
| 509 | return ssl_hs_certificate_verify; |
| 510 | } |
| 511 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 512 | if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE_VERIFY) || |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 513 | !tls13_process_certificate_verify(hs) || |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 514 | !ssl_hash_current_message(hs)) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 515 | return ssl_hs_error; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 518 | hs->tls13_state = state_process_server_finished; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 519 | return ssl_hs_read_message; |
| 520 | } |
| 521 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 522 | static enum ssl_hs_wait_t do_process_server_finished(SSL_HANDSHAKE *hs) { |
| 523 | SSL *const ssl = hs->ssl; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 524 | if (!ssl_check_message_type(ssl, SSL3_MT_FINISHED) || |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 525 | !tls13_process_finished(hs, 0 /* don't use saved value */) || |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 526 | !ssl_hash_current_message(hs) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 527 | /* Update the secret to the master secret and derive traffic keys. */ |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 528 | !tls13_advance_key_schedule(hs, kZeroes, hs->hash_len) || |
| 529 | !tls13_derive_application_secrets(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 530 | return ssl_hs_error; |
| 531 | } |
| 532 | |
| 533 | ssl->method->received_flight(ssl); |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 534 | hs->tls13_state = state_send_end_of_early_data; |
| 535 | return ssl_hs_ok; |
| 536 | } |
| 537 | |
| 538 | static enum ssl_hs_wait_t do_send_end_of_early_data(SSL_HANDSHAKE *hs) { |
| 539 | SSL *const ssl = hs->ssl; |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 540 | |
| 541 | if (ssl->early_data_accepted) { |
| 542 | hs->can_early_write = 0; |
| 543 | if (!ssl->method->add_alert(ssl, SSL3_AL_WARNING, |
| 544 | TLS1_AD_END_OF_EARLY_DATA)) { |
| 545 | return ssl_hs_error; |
| 546 | } |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 549 | if (hs->early_data_offered) { |
| 550 | if ((ssl->version == TLS1_3_EXPERIMENT_VERSION && |
| 551 | !ssl3_add_change_cipher_spec(ssl)) || |
| 552 | !tls13_set_traffic_key(ssl, evp_aead_seal, hs->client_handshake_secret, |
| 553 | hs->hash_len)) { |
| 554 | return ssl_hs_error; |
| 555 | } |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 558 | hs->tls13_state = state_send_client_certificate; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 559 | return ssl_hs_ok; |
| 560 | } |
| 561 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 562 | static enum ssl_hs_wait_t do_send_client_certificate(SSL_HANDSHAKE *hs) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 563 | SSL *const ssl = hs->ssl; |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 564 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 565 | /* The peer didn't request a certificate. */ |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 566 | if (!hs->cert_request) { |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 567 | hs->tls13_state = state_complete_second_flight; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 568 | return ssl_hs_ok; |
| 569 | } |
| 570 | |
| 571 | /* Call cert_cb to update the certificate. */ |
| 572 | if (ssl->cert->cert_cb != NULL) { |
| 573 | int rv = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg); |
| 574 | if (rv == 0) { |
| 575 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); |
| 576 | OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR); |
| 577 | return ssl_hs_error; |
| 578 | } |
| 579 | if (rv < 0) { |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 580 | hs->tls13_state = state_send_client_certificate; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 581 | return ssl_hs_x509_lookup; |
| 582 | } |
| 583 | } |
| 584 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 585 | if (!ssl_on_certificate_selected(hs) || |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 586 | !tls13_add_certificate(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 587 | return ssl_hs_error; |
| 588 | } |
| 589 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 590 | hs->tls13_state = state_send_client_certificate_verify; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 591 | return ssl_hs_ok; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 594 | static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 595 | SSL *const ssl = hs->ssl; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 596 | /* Don't send CertificateVerify if there is no certificate. */ |
| 597 | if (!ssl_has_certificate(ssl)) { |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 598 | hs->tls13_state = state_complete_second_flight; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 599 | return ssl_hs_ok; |
| 600 | } |
| 601 | |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 602 | switch (tls13_add_certificate_verify(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 603 | case ssl_private_key_success: |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 604 | hs->tls13_state = state_complete_second_flight; |
| 605 | return ssl_hs_ok; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 606 | |
| 607 | case ssl_private_key_retry: |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 608 | hs->tls13_state = state_send_client_certificate_verify; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 609 | return ssl_hs_private_key_operation; |
| 610 | |
| 611 | case ssl_private_key_failure: |
| 612 | return ssl_hs_error; |
| 613 | } |
| 614 | |
| 615 | assert(0); |
| 616 | return ssl_hs_error; |
| 617 | } |
| 618 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 619 | static enum ssl_hs_wait_t do_complete_second_flight(SSL_HANDSHAKE *hs) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 620 | SSL *const ssl = hs->ssl; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 621 | |
| 622 | /* Send a Channel ID assertion if necessary. */ |
| 623 | if (ssl->s3->tlsext_channel_id_valid) { |
| 624 | if (!ssl_do_channel_id_callback(ssl)) { |
| 625 | hs->tls13_state = state_complete_second_flight; |
| 626 | return ssl_hs_error; |
| 627 | } |
| 628 | |
| 629 | if (ssl->tlsext_channel_id_private == NULL) { |
| 630 | return ssl_hs_channel_id_lookup; |
| 631 | } |
| 632 | |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 633 | ScopedCBB cbb; |
| 634 | CBB body; |
| 635 | if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_CHANNEL_ID) || |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 636 | !tls1_write_channel_id(hs, &body) || |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 637 | !ssl_add_message_cbb(ssl, cbb.get())) { |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 638 | return ssl_hs_error; |
| 639 | } |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 640 | } |
| 641 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 642 | /* Send a Finished message. */ |
| 643 | if (!tls13_add_finished(hs)) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 644 | return ssl_hs_error; |
| 645 | } |
| 646 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 647 | /* Derive the final keys and enable them. */ |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 648 | if (!tls13_set_traffic_key(ssl, evp_aead_open, hs->server_traffic_secret_0, |
| 649 | hs->hash_len) || |
| 650 | !tls13_set_traffic_key(ssl, evp_aead_seal, hs->client_traffic_secret_0, |
| 651 | hs->hash_len) || |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 652 | !tls13_derive_resumption_secret(hs)) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 653 | return ssl_hs_error; |
| 654 | } |
| 655 | |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 656 | hs->tls13_state = state_done; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 657 | return ssl_hs_flush; |
| 658 | } |
| 659 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 660 | enum ssl_hs_wait_t tls13_client_handshake(SSL_HANDSHAKE *hs) { |
Steven Valdez | e7531f0 | 2016-12-14 13:29:57 -0500 | [diff] [blame] | 661 | while (hs->tls13_state != state_done) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 662 | enum ssl_hs_wait_t ret = ssl_hs_error; |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 663 | enum client_hs_state_t state = |
| 664 | static_cast<enum client_hs_state_t>(hs->tls13_state); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 665 | switch (state) { |
| 666 | case state_process_hello_retry_request: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 667 | ret = do_process_hello_retry_request(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 668 | break; |
| 669 | case state_send_second_client_hello: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 670 | ret = do_send_second_client_hello(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 671 | break; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 672 | case state_process_server_hello: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 673 | ret = do_process_server_hello(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 674 | break; |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 675 | case state_process_change_cipher_spec: |
| 676 | ret = do_process_change_cipher_spec(hs); |
| 677 | break; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 678 | case state_process_encrypted_extensions: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 679 | ret = do_process_encrypted_extensions(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 680 | break; |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 681 | case state_continue_second_server_flight: |
| 682 | ret = do_continue_second_server_flight(hs); |
| 683 | break; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 684 | case state_process_certificate_request: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 685 | ret = do_process_certificate_request(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 686 | break; |
| 687 | case state_process_server_certificate: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 688 | ret = do_process_server_certificate(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 689 | break; |
| 690 | case state_process_server_certificate_verify: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 691 | ret = do_process_server_certificate_verify(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 692 | break; |
| 693 | case state_process_server_finished: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 694 | ret = do_process_server_finished(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 695 | break; |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 696 | case state_send_end_of_early_data: |
| 697 | ret = do_send_end_of_early_data(hs); |
| 698 | break; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 699 | case state_send_client_certificate: |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 700 | ret = do_send_client_certificate(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 701 | break; |
| 702 | case state_send_client_certificate_verify: |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 703 | ret = do_send_client_certificate_verify(hs); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 704 | break; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 705 | case state_complete_second_flight: |
| 706 | ret = do_complete_second_flight(hs); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 707 | break; |
| 708 | case state_done: |
| 709 | ret = ssl_hs_ok; |
| 710 | break; |
| 711 | } |
| 712 | |
| 713 | if (ret != ssl_hs_ok) { |
| 714 | return ret; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | return ssl_hs_ok; |
| 719 | } |
| 720 | |
| 721 | int tls13_process_new_session_ticket(SSL *ssl) { |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 722 | UniquePtr<SSL_SESSION> session(SSL_SESSION_dup(ssl->s3->established_session, |
| 723 | SSL_SESSION_INCLUDE_NONAUTH)); |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 724 | if (!session) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 725 | return 0; |
| 726 | } |
| 727 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 728 | ssl_session_rebase_time(ssl, session.get()); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 729 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 730 | uint32_t server_timeout; |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 731 | CBS cbs, ticket, extensions; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 732 | CBS_init(&cbs, ssl->init_msg, ssl->init_num); |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 733 | if (!CBS_get_u32(&cbs, &server_timeout) || |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 734 | !CBS_get_u32(&cbs, &session->ticket_age_add) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 735 | !CBS_get_u16_length_prefixed(&cbs, &ticket) || |
| 736 | !CBS_stow(&ticket, &session->tlsext_tick, &session->tlsext_ticklen) || |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 737 | !CBS_get_u16_length_prefixed(&cbs, &extensions) || |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 738 | CBS_len(&cbs) != 0) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 739 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 740 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 741 | return 0; |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 744 | /* Cap the renewable lifetime by the server advertised value. This avoids |
Robert Sloan | 7d422bc | 2017-03-06 10:04:29 -0800 | [diff] [blame] | 745 | * wasting bandwidth on 0-RTT when we know the server will reject it. */ |
| 746 | if (session->timeout > server_timeout) { |
| 747 | session->timeout = server_timeout; |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 750 | /* Parse out the extensions. */ |
| 751 | int have_early_data_info = 0; |
| 752 | CBS early_data_info; |
| 753 | const SSL_EXTENSION_TYPE ext_types[] = { |
| 754 | {TLSEXT_TYPE_ticket_early_data_info, &have_early_data_info, |
| 755 | &early_data_info}, |
| 756 | }; |
| 757 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 758 | uint8_t alert = SSL_AD_DECODE_ERROR; |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 759 | if (!ssl_parse_extensions(&extensions, &alert, ext_types, |
| 760 | OPENSSL_ARRAY_SIZE(ext_types), |
| 761 | 1 /* ignore unknown */)) { |
| 762 | ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 763 | return 0; |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 766 | if (have_early_data_info && ssl->cert->enable_early_data) { |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 767 | if (!CBS_get_u32(&early_data_info, &session->ticket_max_early_data) || |
| 768 | CBS_len(&early_data_info) != 0) { |
| 769 | ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 770 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 771 | return 0; |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 772 | } |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 773 | } |
| 774 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 775 | session->ticket_age_add_valid = 1; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 776 | session->not_resumable = 0; |
| 777 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 778 | if (ssl->ctx->new_session_cb != NULL && |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 779 | ssl->ctx->new_session_cb(ssl, session.get())) { |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 780 | /* |new_session_cb|'s return value signals that it took ownership. */ |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 781 | session.release(); |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 784 | return 1; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 785 | } |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 786 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 787 | void ssl_clear_tls13_state(SSL_HANDSHAKE *hs) { |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 788 | hs->key_share.reset(); |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 789 | |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 790 | OPENSSL_free(hs->key_share_bytes); |
| 791 | hs->key_share_bytes = NULL; |
| 792 | hs->key_share_bytes_len = 0; |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 793 | } |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame^] | 794 | |
| 795 | } // namespace bssl |