2016-07-11 18:19:03 +01:00
|
|
|
/* Copyright (c) 2016, Google Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2017-01-28 19:00:32 +00:00
|
|
|
#include <limits.h>
|
2016-07-11 18:19:03 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-07-20 19:49:15 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2016-07-11 18:19:03 +01:00
|
|
|
#include <openssl/bytestring.h>
|
|
|
|
#include <openssl/digest.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/mem.h>
|
2018-08-31 22:35:22 +01:00
|
|
|
#include <openssl/sha.h>
|
2016-07-11 18:19:03 +01:00
|
|
|
#include <openssl/stack.h>
|
|
|
|
|
2016-11-13 01:32:10 +00:00
|
|
|
#include "../crypto/internal.h"
|
2016-07-11 18:19:03 +01:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
|
Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-08-27 02:53:36 +01:00
|
|
|
BSSL_NAMESPACE_BEGIN
|
Move libssl's internals into the bssl namespace.
This is horrible, but everything else I tried was worse. The goal with
this CL is to take the extern "C" out of ssl/internal.h and move most
symbols to namespace bssl, so we can start using C++ helpers and
destructors without worry.
Complications:
- Public API functions must be extern "C" and match their declaration in
ssl.h, which is unnamespaced. C++ really does not want you to
interleave namespaced and unnamespaced things. One can actually write
a namespaced extern "C" function, but this means, from C++'s
perspective, the function is namespaced. Trying to namespace the
public header would worked but ended up too deep a rabbithole.
- Our STACK_OF macros do not work right in namespaces.
- The typedefs for our exposed but opaque types are visible in the
header files and copied into consuming projects as forward
declarations. We ultimately want to give SSL a destructor, but
clobbering an unnamespaced ssl_st::~ssl_st seems bad manners.
- MSVC complains about ambiguous names if one typedefs SSL to bssl::SSL.
This CL opts for:
- ssl/*.cc must begin with #define BORINGSSL_INTERNAL_CXX_TYPES. This
informs the public headers to create forward declarations which are
compatible with our namespaces.
- For now, C++-defined type FOO ends up at bssl::FOO with a typedef
outside. Later I imagine we'll rename many of them.
- Internal functions get namespace bssl, so we stop worrying about
stomping the tls1_prf symbol. Exported C functions are stuck as they
are. Rather than try anything weird, bite the bullet and reorder files
which have a mix of public and private functions. I expect that over
time, the public functions will become fairly small as we move logic
to more idiomatic C++.
Files without any public C functions can just be written normally.
- To avoid MSVC troubles, some bssl types are renamed to CPlusPlusStyle
in advance of them being made idiomatic C++.
Bug: 132
Change-Id: Ic931895e117c38b14ff8d6e5a273e868796c7581
Reviewed-on: https://boringssl-review.googlesource.com/18124
Reviewed-by: David Benjamin <davidben@google.com>
2017-07-18 21:34:25 +01:00
|
|
|
|
2016-07-11 18:19:03 +01:00
|
|
|
enum client_hs_state_t {
|
2017-08-01 21:32:25 +01:00
|
|
|
state_read_hello_retry_request = 0,
|
2016-07-18 17:40:30 +01:00
|
|
|
state_send_second_client_hello,
|
2017-08-01 21:32:25 +01:00
|
|
|
state_read_server_hello,
|
|
|
|
state_read_encrypted_extensions,
|
|
|
|
state_read_certificate_request,
|
|
|
|
state_read_server_certificate,
|
|
|
|
state_read_server_certificate_verify,
|
2018-08-10 18:28:47 +01:00
|
|
|
state_server_certificate_reverify,
|
2017-08-01 21:32:25 +01:00
|
|
|
state_read_server_finished,
|
2017-01-11 16:34:52 +00:00
|
|
|
state_send_end_of_early_data,
|
2016-07-11 18:19:03 +01:00
|
|
|
state_send_client_certificate,
|
|
|
|
state_send_client_certificate_verify,
|
2017-01-13 00:44:57 +00:00
|
|
|
state_complete_second_flight,
|
2016-07-11 18:19:03 +01:00
|
|
|
state_done,
|
|
|
|
};
|
|
|
|
|
2016-11-30 16:24:40 +00:00
|
|
|
static const uint8_t kZeroes[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_hello_retry_request(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-11-16 23:36:38 +00:00
|
|
|
assert(ssl->s3->have_version);
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
2016-07-18 17:40:30 +01:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
// Queue up a ChangeCipherSpec for whenever we next send something. This
|
|
|
|
// will be before the second ClientHello. If we offered early data, this was
|
|
|
|
// already done.
|
|
|
|
if (!hs->early_data_offered &&
|
|
|
|
!ssl->method->add_change_cipher_spec(ssl)) {
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-11-07 22:09:52 +00:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
if (!ssl_check_message_type(ssl, msg, SSL3_MT_SERVER_HELLO)) {
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-11-07 22:09:52 +00:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
CBS body = msg.body, extensions, server_random, session_id;
|
|
|
|
uint16_t server_version, cipher_suite;
|
|
|
|
uint8_t compression_method;
|
|
|
|
if (!CBS_get_u16(&body, &server_version) ||
|
|
|
|
!CBS_get_bytes(&body, &server_random, SSL3_RANDOM_SIZE) ||
|
|
|
|
!CBS_get_u8_length_prefixed(&body, &session_id) ||
|
|
|
|
!CBS_mem_equal(&session_id, hs->session_id, hs->session_id_len) ||
|
|
|
|
!CBS_get_u16(&body, &cipher_suite) ||
|
|
|
|
!CBS_get_u8(&body, &compression_method) ||
|
|
|
|
compression_method != 0 ||
|
|
|
|
!CBS_get_u16_length_prefixed(&body, &extensions) ||
|
|
|
|
CBS_len(&extensions) == 0 ||
|
|
|
|
CBS_len(&body) != 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-11-07 22:09:52 +00:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
if (!CBS_mem_equal(&server_random, kHelloRetryRequest, SSL3_RANDOM_SIZE)) {
|
|
|
|
hs->tls13_state = state_read_server_hello;
|
|
|
|
return ssl_hs_ok;
|
2016-07-18 17:40:30 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
const SSL_CIPHER *cipher = SSL_get_cipher_by_value(cipher_suite);
|
|
|
|
// Check if the cipher is a TLS 1.3 cipher.
|
|
|
|
if (cipher == NULL ||
|
|
|
|
SSL_CIPHER_get_min_version(cipher) > ssl_protocol_version(ssl) ||
|
|
|
|
SSL_CIPHER_get_max_version(cipher) < ssl_protocol_version(ssl)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-10-11 17:29:36 +01:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
hs->new_cipher = cipher;
|
2017-10-11 17:29:36 +01:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
if (!hs->transcript.InitHash(ssl_protocol_version(ssl), hs->new_cipher) ||
|
|
|
|
!hs->transcript.UpdateForHelloRetryRequest()) {
|
|
|
|
return ssl_hs_error;
|
2017-10-11 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-07 22:09:52 +00:00
|
|
|
bool have_cookie, have_key_share, have_supported_versions;
|
|
|
|
CBS cookie, key_share, supported_versions;
|
2018-01-09 11:18:36 +00:00
|
|
|
SSL_EXTENSION_TYPE ext_types[] = {
|
2018-01-22 20:20:31 +00:00
|
|
|
{TLSEXT_TYPE_key_share, &have_key_share, &key_share},
|
2016-11-13 01:32:10 +00:00
|
|
|
{TLSEXT_TYPE_cookie, &have_cookie, &cookie},
|
2017-11-07 22:09:52 +00:00
|
|
|
{TLSEXT_TYPE_supported_versions, &have_supported_versions,
|
|
|
|
&supported_versions},
|
2016-11-13 01:32:10 +00:00
|
|
|
};
|
|
|
|
|
2017-02-08 21:33:15 +00:00
|
|
|
uint8_t alert = SSL_AD_DECODE_ERROR;
|
2016-11-13 01:32:10 +00:00
|
|
|
if (!ssl_parse_extensions(&extensions, &alert, ext_types,
|
2016-12-07 20:29:45 +00:00
|
|
|
OPENSSL_ARRAY_SIZE(ext_types),
|
|
|
|
0 /* reject unknown */)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
2016-11-13 01:32:10 +00:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:36:38 +00:00
|
|
|
if (!have_cookie && !have_key_share) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_EMPTY_HELLO_RETRY_REQUEST);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-11-13 01:32:10 +00:00
|
|
|
if (have_cookie) {
|
|
|
|
CBS cookie_value;
|
|
|
|
if (!CBS_get_u16_length_prefixed(&cookie, &cookie_value) ||
|
|
|
|
CBS_len(&cookie_value) == 0 ||
|
|
|
|
CBS_len(&cookie) != 0) {
|
2016-10-08 02:10:38 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2016-10-08 02:10:38 +01:00
|
|
|
return ssl_hs_error;
|
2016-07-18 17:40:30 +01:00
|
|
|
}
|
|
|
|
|
2017-09-21 07:43:05 +01:00
|
|
|
if (!hs->cookie.CopyFrom(cookie_value)) {
|
2016-11-13 01:32:10 +00:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 02:10:38 +01:00
|
|
|
|
2016-11-13 01:32:10 +00:00
|
|
|
if (have_key_share) {
|
|
|
|
uint16_t group_id;
|
|
|
|
if (!CBS_get_u16(&key_share, &group_id) || CBS_len(&key_share) != 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2016-11-13 01:32:10 +00:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-10-08 02:10:38 +01:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// The group must be supported.
|
2018-04-13 23:51:30 +01:00
|
|
|
if (!tls1_check_group_id(hs, group_id)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-11-13 01:32:10 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-10-08 02:10:38 +01:00
|
|
|
|
2018-11-12 21:53:42 +00:00
|
|
|
// Check that the HelloRetryRequest does not request a key share that was
|
|
|
|
// provided in the initial ClientHello.
|
|
|
|
if (hs->key_shares[0]->GroupID() == group_id ||
|
|
|
|
(hs->key_shares[1] && hs->key_shares[1]->GroupID() == group_id)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-11-13 01:32:10 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
|
|
|
|
return ssl_hs_error;
|
2016-10-08 02:10:38 +01:00
|
|
|
}
|
2016-11-13 01:32:10 +00:00
|
|
|
|
2018-11-12 21:53:42 +00:00
|
|
|
hs->key_shares[0].reset();
|
|
|
|
hs->key_shares[1].reset();
|
2016-11-13 01:32:10 +00:00
|
|
|
hs->retry_group = group_id;
|
2016-10-08 02:10:38 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!ssl_hash_message(hs, msg)) {
|
2017-01-21 19:49:39 +00:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:35:55 +01:00
|
|
|
ssl->method->next_message(ssl);
|
2017-08-31 19:49:09 +01:00
|
|
|
hs->received_hello_retry_request = true;
|
2016-12-11 18:30:41 +00:00
|
|
|
hs->tls13_state = state_send_second_client_hello;
|
2017-08-29 21:33:21 +01:00
|
|
|
// 0-RTT is rejected if we receive a HelloRetryRequest.
|
2017-03-09 19:56:07 +00:00
|
|
|
if (hs->in_early_data) {
|
|
|
|
return ssl_hs_early_data_rejected;
|
|
|
|
}
|
2016-07-18 17:40:30 +01:00
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2016-11-14 01:32:04 +00:00
|
|
|
static enum ssl_hs_wait_t do_send_second_client_hello(SSL_HANDSHAKE *hs) {
|
2017-01-11 16:34:52 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-29 21:33:21 +01:00
|
|
|
// Restore the null cipher. We may have switched due to 0-RTT.
|
2017-09-11 18:53:08 +01:00
|
|
|
bssl::UniquePtr<SSLAEADContext> null_ctx =
|
|
|
|
SSLAEADContext::CreateNullCipher(SSL_is_dtls(ssl));
|
2017-07-19 03:45:18 +01:00
|
|
|
if (!null_ctx ||
|
2017-09-11 18:53:08 +01:00
|
|
|
!ssl->method->set_write_state(ssl, std::move(null_ctx))) {
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl->s3->aead_write_ctx->SetVersionIfNullCipher(ssl->version);
|
|
|
|
|
|
|
|
if (!ssl_write_client_hello(hs)) {
|
2016-07-18 17:40:30 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_server_hello;
|
|
|
|
return ssl_hs_flush;
|
2016-07-18 17:40:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
|
|
|
if (!ssl_check_message_type(ssl, msg, SSL3_MT_SERVER_HELLO)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
CBS body = msg.body, server_random, session_id, extensions;
|
2017-07-10 17:57:25 +01:00
|
|
|
uint16_t server_version;
|
2016-07-11 18:19:03 +01:00
|
|
|
uint16_t cipher_suite;
|
2017-06-13 17:45:25 +01:00
|
|
|
uint8_t compression_method;
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!CBS_get_u16(&body, &server_version) ||
|
|
|
|
!CBS_get_bytes(&body, &server_random, SSL3_RANDOM_SIZE) ||
|
2017-12-04 16:15:37 +00:00
|
|
|
!CBS_get_u8_length_prefixed(&body, &session_id) ||
|
|
|
|
!CBS_mem_equal(&session_id, hs->session_id, hs->session_id_len) ||
|
2017-08-01 21:32:25 +01:00
|
|
|
!CBS_get_u16(&body, &cipher_suite) ||
|
2017-12-04 16:15:37 +00:00
|
|
|
!CBS_get_u8(&body, &compression_method) ||
|
|
|
|
compression_method != 0 ||
|
2017-08-01 21:32:25 +01:00
|
|
|
!CBS_get_u16_length_prefixed(&body, &extensions) ||
|
|
|
|
CBS_len(&body) != 0) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2016-07-18 17:40:30 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-12-04 16:15:37 +00:00
|
|
|
if (server_version != TLS1_2_VERSION) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2016-07-18 17:40:30 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_VERSION_NUMBER);
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:36:38 +00:00
|
|
|
// Forbid a second HelloRetryRequest.
|
2018-01-22 20:20:31 +00:00
|
|
|
if (CBS_mem_equal(&server_random, kHelloRetryRequest, SSL3_RANDOM_SIZE)) {
|
2017-11-16 23:36:38 +00:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memcpy(ssl->s3->server_random, CBS_data(&server_random),
|
|
|
|
SSL3_RANDOM_SIZE);
|
2016-09-06 19:13:43 +01:00
|
|
|
|
2017-10-11 17:29:36 +01:00
|
|
|
// Check if the cipher is a TLS 1.3 cipher.
|
2016-09-06 19:13:43 +01:00
|
|
|
const SSL_CIPHER *cipher = SSL_get_cipher_by_value(cipher_suite);
|
2017-10-11 17:29:36 +01:00
|
|
|
if (cipher == nullptr ||
|
|
|
|
SSL_CIPHER_get_min_version(cipher) > ssl_protocol_version(ssl) ||
|
|
|
|
SSL_CIPHER_get_max_version(cipher) < ssl_protocol_version(ssl)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-09-06 19:13:43 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:29:36 +01:00
|
|
|
// Check that the cipher matches the one in the HelloRetryRequest.
|
2018-01-22 20:20:31 +00:00
|
|
|
if (hs->received_hello_retry_request &&
|
2017-10-11 17:29:36 +01:00
|
|
|
hs->new_cipher != cipher) {
|
2016-09-06 19:13:43 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-09-06 19:13:43 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Parse out the extensions.
|
2017-08-31 20:13:12 +01:00
|
|
|
bool have_key_share = false, have_pre_shared_key = false,
|
|
|
|
have_supported_versions = false;
|
2017-07-10 17:57:25 +01:00
|
|
|
CBS key_share, pre_shared_key, supported_versions;
|
2018-01-09 11:18:36 +00:00
|
|
|
SSL_EXTENSION_TYPE ext_types[] = {
|
2018-01-22 20:20:31 +00:00
|
|
|
{TLSEXT_TYPE_key_share, &have_key_share, &key_share},
|
2016-11-13 01:32:10 +00:00
|
|
|
{TLSEXT_TYPE_pre_shared_key, &have_pre_shared_key, &pre_shared_key},
|
2017-07-10 17:57:25 +01:00
|
|
|
{TLSEXT_TYPE_supported_versions, &have_supported_versions,
|
|
|
|
&supported_versions},
|
2016-11-13 01:32:10 +00:00
|
|
|
};
|
|
|
|
|
2017-02-08 21:33:15 +00:00
|
|
|
uint8_t alert = SSL_AD_DECODE_ERROR;
|
2016-11-13 01:32:10 +00:00
|
|
|
if (!ssl_parse_extensions(&extensions, &alert, ext_types,
|
2016-12-07 20:29:45 +00:00
|
|
|
OPENSSL_ARRAY_SIZE(ext_types),
|
|
|
|
0 /* reject unknown */)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
2016-11-13 01:32:10 +00:00
|
|
|
return ssl_hs_error;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-08-28 15:14:07 +01:00
|
|
|
// Recheck supported_versions, in case this is the second ServerHello.
|
|
|
|
uint16_t version;
|
|
|
|
if (!have_supported_versions ||
|
|
|
|
!CBS_get_u16(&supported_versions, &version) ||
|
|
|
|
version != ssl->version) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_SECOND_SERVERHELLO_VERSION_MISMATCH);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
|
|
|
return ssl_hs_error;
|
2018-05-05 03:00:33 +01:00
|
|
|
}
|
|
|
|
|
2016-11-13 01:32:10 +00:00
|
|
|
alert = SSL_AD_DECODE_ERROR;
|
2016-07-29 19:32:55 +01:00
|
|
|
if (have_pre_shared_key) {
|
|
|
|
if (ssl->session == NULL) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNSUPPORTED_EXTENSION);
|
2016-07-29 19:32:55 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2016-11-17 08:11:16 +00:00
|
|
|
if (!ssl_ext_pre_shared_key_parse_serverhello(hs, &alert,
|
2016-07-29 19:32:55 +01:00
|
|
|
&pre_shared_key)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
2016-07-29 19:32:55 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssl->session->ssl_version != ssl->version) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-07-29 19:32:55 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2016-11-16 07:25:58 +00:00
|
|
|
if (ssl->session->cipher->algorithm_prf != cipher->algorithm_prf) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_PRF_HASH_MISMATCH);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-09-06 19:13:43 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:47:27 +01:00
|
|
|
if (!ssl_session_is_context_valid(hs, ssl->session.get())) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// This is actually a client application bug.
|
2016-07-29 19:32:55 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL,
|
|
|
|
SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2016-07-29 19:32:55 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-31 20:06:42 +01:00
|
|
|
ssl->s3->session_reused = true;
|
2017-08-29 21:33:21 +01:00
|
|
|
// Only authentication information carries over in TLS 1.3.
|
2018-07-03 00:47:27 +01:00
|
|
|
hs->new_session =
|
|
|
|
SSL_SESSION_dup(ssl->session.get(), SSL_SESSION_DUP_AUTH_ONLY);
|
2017-07-20 19:49:15 +01:00
|
|
|
if (!hs->new_session) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
2016-07-29 19:32:55 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-03-09 19:56:07 +00:00
|
|
|
ssl_set_session(ssl, NULL);
|
2017-01-28 19:00:32 +00:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Resumption incorporates fresh key material, so refresh the timeout.
|
2017-07-20 19:49:15 +01:00
|
|
|
ssl_session_renew_timeout(ssl, hs->new_session.get(),
|
2018-05-02 21:05:36 +01:00
|
|
|
ssl->session_ctx->session_psk_dhe_timeout);
|
2016-11-17 08:20:47 +00:00
|
|
|
} else if (!ssl_get_new_session(hs, 0)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-02-10 01:01:26 +00:00
|
|
|
hs->new_session->cipher = cipher;
|
|
|
|
hs->new_cipher = cipher;
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2017-10-11 17:29:36 +01:00
|
|
|
size_t hash_len =
|
|
|
|
EVP_MD_size(ssl_get_handshake_digest(ssl_protocol_version(ssl), cipher));
|
2016-09-06 19:13:43 +01:00
|
|
|
|
2017-10-11 17:29:36 +01:00
|
|
|
// Set up the key schedule and incorporate the PSK into the running secret.
|
2016-07-29 19:32:55 +01:00
|
|
|
if (ssl->s3->session_reused) {
|
2017-10-11 17:29:36 +01:00
|
|
|
if (!tls13_init_key_schedule(hs, hs->new_session->master_key,
|
|
|
|
hs->new_session->master_key_length)) {
|
2016-07-29 19:32:55 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-10-11 17:29:36 +01:00
|
|
|
} else if (!tls13_init_key_schedule(hs, kZeroes, hash_len)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2016-12-08 23:21:27 +00:00
|
|
|
if (!have_key_share) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// We do not support psk_ke and thus always require a key share.
|
2016-12-08 23:21:27 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_KEY_SHARE);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION);
|
2016-12-08 23:21:27 +00:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Resolve ECDHE and incorporate it into the secret.
|
2017-07-22 17:45:38 +01:00
|
|
|
Array<uint8_t> dhe_secret;
|
2017-02-08 21:33:15 +00:00
|
|
|
alert = SSL_AD_DECODE_ERROR;
|
2017-07-22 17:45:38 +01:00
|
|
|
if (!ssl_ext_key_share_parse_serverhello(hs, &dhe_secret, &alert,
|
|
|
|
&key_share)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
2016-09-06 19:13:43 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2017-07-22 17:45:38 +01:00
|
|
|
if (!tls13_advance_key_schedule(hs, dhe_secret.data(), dhe_secret.size()) ||
|
2018-07-14 16:23:01 +01:00
|
|
|
!ssl_hash_message(hs, msg) || !tls13_derive_handshake_secrets(hs) ||
|
|
|
|
!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open,
|
|
|
|
hs->server_handshake_secret, hs->hash_len)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-06-13 17:45:25 +01:00
|
|
|
if (!hs->early_data_offered) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// If not sending early data, set client traffic keys now so that alerts are
|
|
|
|
// encrypted.
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal,
|
|
|
|
hs->client_handshake_secret, hs->hash_len)) {
|
2017-06-13 17:45:25 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 22:09:52 +00:00
|
|
|
ssl->method->next_message(ssl);
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_encrypted_extensions;
|
|
|
|
return ssl_hs_ok;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_encrypted_extensions(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
|
|
|
if (!ssl_check_message_type(ssl, msg, SSL3_MT_ENCRYPTED_EXTENSIONS)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
CBS body = msg.body;
|
|
|
|
if (!ssl_parse_serverhello_tlsext(hs, &body)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-08-01 21:32:25 +01:00
|
|
|
if (CBS_len(&body) != 0) {
|
2016-07-11 18:19:03 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Store the negotiated ALPN in the session.
|
Give SSL_SESSION a destructor.
Previously we'd partially attempted the ssl_st / bssl::SSLConnection
subclassing split, but that gets messy when we actually try to add a
destructor, because CRYPTO_EX_DATA's cleanup function needs an ssl_st*,
not a bssl::SSLConnection*. Downcasting is technically undefined at this
point and will likely offend some CFI-like check.
Moreover, it appears that even with today's subclassing split,
New<SSL>() emits symbols like:
W ssl_st*& std::forward<ssl_st*&>(std::remove_reference<ssl_st*&>::type&)
The compiler does not bother emitting them in optimized builds, but it
does suggest we can't really avoid claiming the ssl_st type name at the
symbol level, short of doing reinterpret_casts at all API boundaries.
And, of course, we've already long claimed it at the #include level.
So I've just left this defining directly on ssl_session_st. The cost is
we need to write some silly "bssl::" prefixes in the headers, but so it
goes. In the likely event we change our minds again, we can always
revise this.
Change-Id: Ieb429e8eaabe7c2961ef7f8d9234fb71f19a5e2a
Reviewed-on: https://boringssl-review.googlesource.com/29587
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2018-06-29 21:26:38 +01:00
|
|
|
if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
|
|
|
return ssl_hs_error;
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 23:04:01 +00:00
|
|
|
if (ssl->s3->early_data_accepted) {
|
2017-03-09 19:56:07 +00:00
|
|
|
if (hs->early_session->cipher != hs->new_session->cipher ||
|
Give SSL_SESSION a destructor.
Previously we'd partially attempted the ssl_st / bssl::SSLConnection
subclassing split, but that gets messy when we actually try to add a
destructor, because CRYPTO_EX_DATA's cleanup function needs an ssl_st*,
not a bssl::SSLConnection*. Downcasting is technically undefined at this
point and will likely offend some CFI-like check.
Moreover, it appears that even with today's subclassing split,
New<SSL>() emits symbols like:
W ssl_st*& std::forward<ssl_st*&>(std::remove_reference<ssl_st*&>::type&)
The compiler does not bother emitting them in optimized builds, but it
does suggest we can't really avoid claiming the ssl_st type name at the
symbol level, short of doing reinterpret_casts at all API boundaries.
And, of course, we've already long claimed it at the #include level.
So I've just left this defining directly on ssl_session_st. The cost is
we need to write some silly "bssl::" prefixes in the headers, but so it
goes. In the likely event we change our minds again, we can always
revise this.
Change-Id: Ieb429e8eaabe7c2961ef7f8d9234fb71f19a5e2a
Reviewed-on: https://boringssl-review.googlesource.com/29587
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2018-06-29 21:26:38 +01:00
|
|
|
MakeConstSpan(hs->early_session->early_alpn) !=
|
2017-10-13 22:18:35 +01:00
|
|
|
ssl->s3->alpn_selected) {
|
2017-01-11 16:34:52 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_ALPN_MISMATCH_ON_EARLY_DATA);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2018-07-09 21:28:22 +01:00
|
|
|
if (ssl->s3->channel_id_valid || ssl->s3->token_binding_negotiated) {
|
2017-08-10 19:02:56 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION_ON_EARLY_DATA);
|
2017-03-26 02:54:16 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!ssl_hash_message(hs, msg)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:35:55 +01:00
|
|
|
ssl->method->next_message(ssl);
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_certificate_request;
|
2017-12-18 23:04:01 +00:00
|
|
|
if (hs->in_early_data && !ssl->s3->early_data_accepted) {
|
2017-03-09 19:56:07 +00:00
|
|
|
return ssl_hs_early_data_rejected;
|
|
|
|
}
|
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_certificate_request(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-29 21:33:21 +01:00
|
|
|
// CertificateRequest may only be sent in non-resumption handshakes.
|
2016-09-06 19:13:43 +01:00
|
|
|
if (ssl->s3->session_reused) {
|
2018-11-16 18:42:13 +00:00
|
|
|
if (ssl->ctx->reverify_on_resume && !ssl->s3->early_data_accepted) {
|
2018-08-10 18:28:47 +01:00
|
|
|
hs->tls13_state = state_server_certificate_reverify;
|
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_server_finished;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// CertificateRequest is optional.
|
2017-08-01 21:32:25 +01:00
|
|
|
if (msg.type != SSL3_MT_CERTIFICATE_REQUEST) {
|
|
|
|
hs->tls13_state = state_read_server_certificate;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
bool have_sigalgs = false, have_ca = false;
|
|
|
|
CBS sigalgs, ca;
|
|
|
|
const SSL_EXTENSION_TYPE ext_types[] = {
|
|
|
|
{TLSEXT_TYPE_signature_algorithms, &have_sigalgs, &sigalgs},
|
|
|
|
{TLSEXT_TYPE_certificate_authorities, &have_ca, &ca},
|
|
|
|
};
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
CBS body = msg.body, context, extensions, supported_signature_algorithms;
|
|
|
|
uint8_t alert = SSL_AD_DECODE_ERROR;
|
|
|
|
if (!CBS_get_u8_length_prefixed(&body, &context) ||
|
|
|
|
// The request context is always empty during the handshake.
|
|
|
|
CBS_len(&context) != 0 ||
|
|
|
|
!CBS_get_u16_length_prefixed(&body, &extensions) ||
|
|
|
|
CBS_len(&body) != 0 ||
|
|
|
|
!ssl_parse_extensions(&extensions, &alert, ext_types,
|
|
|
|
OPENSSL_ARRAY_SIZE(ext_types),
|
|
|
|
1 /* accept unknown */) ||
|
|
|
|
(have_ca && CBS_len(&ca) == 0) ||
|
|
|
|
!have_sigalgs ||
|
|
|
|
!CBS_get_u16_length_prefixed(&sigalgs,
|
|
|
|
&supported_signature_algorithms) ||
|
|
|
|
!tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-10-11 17:29:36 +01:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
if (have_ca) {
|
|
|
|
hs->ca_names = ssl_parse_client_CA_list(ssl, &alert, &ca);
|
2017-10-11 17:29:36 +01:00
|
|
|
if (!hs->ca_names) {
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2018-01-22 20:20:31 +00:00
|
|
|
} else {
|
|
|
|
hs->ca_names.reset(sk_CRYPTO_BUFFER_new_null());
|
|
|
|
if (!hs->ca_names) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
2017-10-11 17:29:36 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-31 19:49:09 +01:00
|
|
|
hs->cert_request = true;
|
2017-02-02 18:57:17 +00:00
|
|
|
ssl->ctx->x509_method->hs_flush_cached_ca_names(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!ssl_hash_message(hs, msg)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:35:55 +01:00
|
|
|
ssl->method->next_message(ssl);
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_server_certificate;
|
|
|
|
return ssl_hs_ok;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_server_certificate(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
2018-06-08 00:39:49 +01:00
|
|
|
|
|
|
|
if (msg.type != SSL3_MT_COMPRESSED_CERTIFICATE &&
|
|
|
|
!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE)) {
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2018-08-28 23:06:31 +01:00
|
|
|
if (!tls13_process_certificate(hs, msg, false /* certificate required */) ||
|
2017-08-01 21:32:25 +01:00
|
|
|
!ssl_hash_message(hs, msg)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:35:55 +01:00
|
|
|
ssl->method->next_message(ssl);
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_server_certificate_verify;
|
|
|
|
return ssl_hs_ok;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_server_certificate_verify(
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL_HANDSHAKE *hs) {
|
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
2017-07-11 21:13:10 +01:00
|
|
|
switch (ssl_verify_peer_cert(hs)) {
|
|
|
|
case ssl_verify_ok:
|
|
|
|
break;
|
|
|
|
case ssl_verify_invalid:
|
|
|
|
return ssl_hs_error;
|
|
|
|
case ssl_verify_retry:
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_server_certificate_verify;
|
2017-07-11 21:13:10 +01:00
|
|
|
return ssl_hs_certificate_verify;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!ssl_check_message_type(ssl, msg, SSL3_MT_CERTIFICATE_VERIFY) ||
|
|
|
|
!tls13_process_certificate_verify(hs, msg) ||
|
|
|
|
!ssl_hash_message(hs, msg)) {
|
2016-11-16 10:10:08 +00:00
|
|
|
return ssl_hs_error;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 22:35:55 +01:00
|
|
|
ssl->method->next_message(ssl);
|
2017-08-01 21:32:25 +01:00
|
|
|
hs->tls13_state = state_read_server_finished;
|
|
|
|
return ssl_hs_ok;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 18:28:47 +01:00
|
|
|
static enum ssl_hs_wait_t do_server_certificate_reverify(
|
|
|
|
SSL_HANDSHAKE *hs) {
|
|
|
|
switch (ssl_reverify_peer_cert(hs)) {
|
|
|
|
case ssl_verify_ok:
|
|
|
|
break;
|
|
|
|
case ssl_verify_invalid:
|
|
|
|
return ssl_hs_error;
|
|
|
|
case ssl_verify_retry:
|
|
|
|
hs->tls13_state = state_server_certificate_reverify;
|
|
|
|
return ssl_hs_certificate_verify;
|
|
|
|
}
|
|
|
|
hs->tls13_state = state_read_server_finished;
|
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:32:25 +01:00
|
|
|
static enum ssl_hs_wait_t do_read_server_finished(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-08-01 21:32:25 +01:00
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
|
|
|
if (!ssl_check_message_type(ssl, msg, SSL3_MT_FINISHED) ||
|
2018-08-28 23:06:31 +01:00
|
|
|
!tls13_process_finished(hs, msg, false /* don't use saved value */) ||
|
2017-08-01 21:32:25 +01:00
|
|
|
!ssl_hash_message(hs, msg) ||
|
2017-08-29 21:33:21 +01:00
|
|
|
// Update the secret to the master secret and derive traffic keys.
|
2016-11-17 07:43:08 +00:00
|
|
|
!tls13_advance_key_schedule(hs, kZeroes, hs->hash_len) ||
|
|
|
|
!tls13_derive_application_secrets(hs)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:35:55 +01:00
|
|
|
ssl->method->next_message(ssl);
|
2017-01-11 16:34:52 +00:00
|
|
|
hs->tls13_state = state_send_end_of_early_data;
|
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum ssl_hs_wait_t do_send_end_of_early_data(SSL_HANDSHAKE *hs) {
|
|
|
|
SSL *const ssl = hs->ssl;
|
2017-03-09 19:56:07 +00:00
|
|
|
|
2017-12-18 23:04:01 +00:00
|
|
|
if (ssl->s3->early_data_accepted) {
|
2017-08-31 19:49:09 +01:00
|
|
|
hs->can_early_write = false;
|
2018-01-22 20:20:31 +00:00
|
|
|
ScopedCBB cbb;
|
|
|
|
CBB body;
|
|
|
|
if (!ssl->method->init_message(ssl, cbb.get(), &body,
|
|
|
|
SSL3_MT_END_OF_EARLY_DATA) ||
|
|
|
|
!ssl_add_message_cbb(ssl, cbb.get())) {
|
|
|
|
return ssl_hs_error;
|
2017-03-09 19:56:07 +00:00
|
|
|
}
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2017-06-13 17:45:25 +01:00
|
|
|
if (hs->early_data_offered) {
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal,
|
|
|
|
hs->client_handshake_secret, hs->hash_len)) {
|
2017-06-13 17:45:25 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2016-12-10 20:46:58 +00:00
|
|
|
hs->tls13_state = state_send_client_certificate;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:46:58 +00:00
|
|
|
static enum ssl_hs_wait_t do_send_client_certificate(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-01-11 16:34:52 +00:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// The peer didn't request a certificate.
|
2016-11-14 01:32:04 +00:00
|
|
|
if (!hs->cert_request) {
|
2017-01-13 00:44:57 +00:00
|
|
|
hs->tls13_state = state_complete_second_flight;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Call cert_cb to update the certificate.
|
2018-04-13 23:51:30 +01:00
|
|
|
if (hs->config->cert->cert_cb != NULL) {
|
|
|
|
int rv = hs->config->cert->cert_cb(ssl, hs->config->cert->cert_cb_arg);
|
2016-07-11 18:19:03 +01:00
|
|
|
if (rv == 0) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
2016-07-11 18:19:03 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
if (rv < 0) {
|
2016-12-11 18:30:41 +00:00
|
|
|
hs->tls13_state = state_send_client_certificate;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_x509_lookup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 21:51:53 +01:00
|
|
|
if (!ssl_on_certificate_selected(hs) ||
|
2017-01-13 00:46:50 +00:00
|
|
|
!tls13_add_certificate(hs)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:30:41 +00:00
|
|
|
hs->tls13_state = state_send_client_certificate_verify;
|
2017-01-13 00:31:28 +00:00
|
|
|
return ssl_hs_ok;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-06-17 18:20:59 +01:00
|
|
|
static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// Don't send CertificateVerify if there is no certificate.
|
2018-07-17 19:36:36 +01:00
|
|
|
if (!ssl_has_certificate(hs)) {
|
2017-01-13 00:44:57 +00:00
|
|
|
hs->tls13_state = state_complete_second_flight;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2017-06-17 18:20:59 +01:00
|
|
|
switch (tls13_add_certificate_verify(hs)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
case ssl_private_key_success:
|
2017-01-13 00:44:57 +00:00
|
|
|
hs->tls13_state = state_complete_second_flight;
|
2017-01-13 00:31:28 +00:00
|
|
|
return ssl_hs_ok;
|
2016-07-11 18:19:03 +01:00
|
|
|
|
|
|
|
case ssl_private_key_retry:
|
2017-06-17 18:20:59 +01:00
|
|
|
hs->tls13_state = state_send_client_certificate_verify;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_private_key_operation;
|
|
|
|
|
|
|
|
case ssl_private_key_failure:
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-01-13 00:44:57 +00:00
|
|
|
static enum ssl_hs_wait_t do_complete_second_flight(SSL_HANDSHAKE *hs) {
|
2016-11-14 01:32:04 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2016-09-24 00:25:11 +01:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Send a Channel ID assertion if necessary.
|
2018-07-03 19:01:26 +01:00
|
|
|
if (ssl->s3->channel_id_valid) {
|
2018-04-13 23:51:30 +01:00
|
|
|
if (!ssl_do_channel_id_callback(hs)) {
|
2017-01-13 00:44:57 +00:00
|
|
|
hs->tls13_state = state_complete_second_flight;
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-09-24 00:25:11 +01:00
|
|
|
|
2018-07-03 19:01:26 +01:00
|
|
|
if (hs->config->channel_id_private == NULL) {
|
2017-01-13 00:44:57 +00:00
|
|
|
return ssl_hs_channel_id_lookup;
|
|
|
|
}
|
2016-09-24 00:25:11 +01:00
|
|
|
|
2017-07-20 04:57:40 +01:00
|
|
|
ScopedCBB cbb;
|
|
|
|
CBB body;
|
|
|
|
if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_CHANNEL_ID) ||
|
2017-01-12 18:17:07 +00:00
|
|
|
!tls1_write_channel_id(hs, &body) ||
|
2017-07-20 04:57:40 +01:00
|
|
|
!ssl_add_message_cbb(ssl, cbb.get())) {
|
2017-01-13 00:44:57 +00:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2016-09-24 00:25:11 +01:00
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Send a Finished message.
|
2017-01-13 00:46:50 +00:00
|
|
|
if (!tls13_add_finished(hs)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Derive the final keys and enable them.
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_open,
|
|
|
|
hs->server_traffic_secret_0, hs->hash_len) ||
|
|
|
|
!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_seal,
|
|
|
|
hs->client_traffic_secret_0, hs->hash_len) ||
|
2016-11-17 07:43:08 +00:00
|
|
|
!tls13_derive_resumption_secret(hs)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:30:41 +00:00
|
|
|
hs->tls13_state = state_done;
|
2016-07-11 18:19:03 +01:00
|
|
|
return ssl_hs_flush;
|
|
|
|
}
|
|
|
|
|
2016-11-14 01:32:04 +00:00
|
|
|
enum ssl_hs_wait_t tls13_client_handshake(SSL_HANDSHAKE *hs) {
|
2016-12-11 18:30:41 +00:00
|
|
|
while (hs->tls13_state != state_done) {
|
2016-07-11 18:19:03 +01:00
|
|
|
enum ssl_hs_wait_t ret = ssl_hs_error;
|
2017-07-13 04:00:28 +01:00
|
|
|
enum client_hs_state_t state =
|
|
|
|
static_cast<enum client_hs_state_t>(hs->tls13_state);
|
2016-07-11 18:19:03 +01:00
|
|
|
switch (state) {
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_hello_retry_request:
|
|
|
|
ret = do_read_hello_retry_request(hs);
|
2016-07-18 17:40:30 +01:00
|
|
|
break;
|
|
|
|
case state_send_second_client_hello:
|
2016-11-14 01:32:04 +00:00
|
|
|
ret = do_send_second_client_hello(hs);
|
2016-07-18 17:40:30 +01:00
|
|
|
break;
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_server_hello:
|
|
|
|
ret = do_read_server_hello(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_encrypted_extensions:
|
|
|
|
ret = do_read_encrypted_extensions(hs);
|
2017-03-09 19:56:07 +00:00
|
|
|
break;
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_certificate_request:
|
|
|
|
ret = do_read_certificate_request(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_server_certificate:
|
|
|
|
ret = do_read_server_certificate(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_server_certificate_verify:
|
|
|
|
ret = do_read_server_certificate_verify(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
2018-08-10 18:28:47 +01:00
|
|
|
case state_server_certificate_reverify:
|
|
|
|
ret = do_server_certificate_reverify(hs);
|
|
|
|
break;
|
2017-08-01 21:32:25 +01:00
|
|
|
case state_read_server_finished:
|
|
|
|
ret = do_read_server_finished(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
2017-01-11 16:34:52 +00:00
|
|
|
case state_send_end_of_early_data:
|
|
|
|
ret = do_send_end_of_early_data(hs);
|
|
|
|
break;
|
2016-07-11 18:19:03 +01:00
|
|
|
case state_send_client_certificate:
|
2016-11-14 01:32:04 +00:00
|
|
|
ret = do_send_client_certificate(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
|
|
|
case state_send_client_certificate_verify:
|
2017-06-17 18:20:59 +01:00
|
|
|
ret = do_send_client_certificate_verify(hs);
|
2016-09-24 00:25:11 +01:00
|
|
|
break;
|
2017-01-13 00:44:57 +00:00
|
|
|
case state_complete_second_flight:
|
|
|
|
ret = do_complete_second_flight(hs);
|
2016-07-11 18:19:03 +01:00
|
|
|
break;
|
|
|
|
case state_done:
|
|
|
|
ret = ssl_hs_ok;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-14 20:08:34 +01:00
|
|
|
if (hs->tls13_state != state) {
|
2017-08-18 20:23:44 +01:00
|
|
|
ssl_do_info_callback(hs->ssl, SSL_CB_CONNECT_LOOP, 1);
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:19:03 +01:00
|
|
|
if (ret != ssl_hs_ok) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
2016-07-27 16:10:52 +01:00
|
|
|
|
2017-08-18 20:23:44 +01:00
|
|
|
const char *tls13_client_handshake_state(SSL_HANDSHAKE *hs) {
|
|
|
|
enum client_hs_state_t state =
|
|
|
|
static_cast<enum client_hs_state_t>(hs->tls13_state);
|
|
|
|
switch (state) {
|
|
|
|
case state_read_hello_retry_request:
|
|
|
|
return "TLS 1.3 client read_hello_retry_request";
|
|
|
|
case state_send_second_client_hello:
|
|
|
|
return "TLS 1.3 client send_second_client_hello";
|
|
|
|
case state_read_server_hello:
|
|
|
|
return "TLS 1.3 client read_server_hello";
|
|
|
|
case state_read_encrypted_extensions:
|
|
|
|
return "TLS 1.3 client read_encrypted_extensions";
|
|
|
|
case state_read_certificate_request:
|
|
|
|
return "TLS 1.3 client read_certificate_request";
|
|
|
|
case state_read_server_certificate:
|
|
|
|
return "TLS 1.3 client read_server_certificate";
|
|
|
|
case state_read_server_certificate_verify:
|
|
|
|
return "TLS 1.3 client read_server_certificate_verify";
|
2018-08-10 18:28:47 +01:00
|
|
|
case state_server_certificate_reverify:
|
|
|
|
return "TLS 1.3 client server_certificate_reverify";
|
2017-08-18 20:23:44 +01:00
|
|
|
case state_read_server_finished:
|
|
|
|
return "TLS 1.3 client read_server_finished";
|
|
|
|
case state_send_end_of_early_data:
|
|
|
|
return "TLS 1.3 client send_end_of_early_data";
|
|
|
|
case state_send_client_certificate:
|
|
|
|
return "TLS 1.3 client send_client_certificate";
|
|
|
|
case state_send_client_certificate_verify:
|
|
|
|
return "TLS 1.3 client send_client_certificate_verify";
|
|
|
|
case state_complete_second_flight:
|
|
|
|
return "TLS 1.3 client complete_second_flight";
|
|
|
|
case state_done:
|
|
|
|
return "TLS 1.3 client done";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "TLS 1.3 client unknown";
|
|
|
|
}
|
|
|
|
|
2018-08-28 23:06:31 +01:00
|
|
|
bool tls13_process_new_session_ticket(SSL *ssl, const SSLMessage &msg) {
|
2017-10-12 01:48:25 +01:00
|
|
|
if (ssl->s3->write_shutdown != ssl_shutdown_none) {
|
|
|
|
// Ignore tickets on shutdown. Callers tend to indiscriminately call
|
|
|
|
// |SSL_shutdown| before destroying an |SSL|, at which point calling the new
|
|
|
|
// session callback may be confusing.
|
2018-08-28 23:06:31 +01:00
|
|
|
return true;
|
2017-10-12 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
2017-10-13 22:18:35 +01:00
|
|
|
UniquePtr<SSL_SESSION> session = SSL_SESSION_dup(
|
|
|
|
ssl->s3->established_session.get(), SSL_SESSION_INCLUDE_NONAUTH);
|
2017-07-13 04:00:28 +01:00
|
|
|
if (!session) {
|
2018-08-28 23:06:31 +01:00
|
|
|
return false;
|
2016-07-27 16:10:52 +01:00
|
|
|
}
|
|
|
|
|
2017-07-13 04:00:28 +01:00
|
|
|
ssl_session_rebase_time(ssl, session.get());
|
2016-11-03 20:59:25 +00:00
|
|
|
|
2017-01-28 19:00:32 +00:00
|
|
|
uint32_t server_timeout;
|
2017-10-11 17:29:36 +01:00
|
|
|
CBS body = msg.body, ticket_nonce, ticket, extensions;
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!CBS_get_u32(&body, &server_timeout) ||
|
|
|
|
!CBS_get_u32(&body, &session->ticket_age_add) ||
|
2018-01-22 20:20:31 +00:00
|
|
|
!CBS_get_u8_length_prefixed(&body, &ticket_nonce) ||
|
2017-08-01 21:32:25 +01:00
|
|
|
!CBS_get_u16_length_prefixed(&body, &ticket) ||
|
Give SSL_SESSION a destructor.
Previously we'd partially attempted the ssl_st / bssl::SSLConnection
subclassing split, but that gets messy when we actually try to add a
destructor, because CRYPTO_EX_DATA's cleanup function needs an ssl_st*,
not a bssl::SSLConnection*. Downcasting is technically undefined at this
point and will likely offend some CFI-like check.
Moreover, it appears that even with today's subclassing split,
New<SSL>() emits symbols like:
W ssl_st*& std::forward<ssl_st*&>(std::remove_reference<ssl_st*&>::type&)
The compiler does not bother emitting them in optimized builds, but it
does suggest we can't really avoid claiming the ssl_st type name at the
symbol level, short of doing reinterpret_casts at all API boundaries.
And, of course, we've already long claimed it at the #include level.
So I've just left this defining directly on ssl_session_st. The cost is
we need to write some silly "bssl::" prefixes in the headers, but so it
goes. In the likely event we change our minds again, we can always
revise this.
Change-Id: Ieb429e8eaabe7c2961ef7f8d9234fb71f19a5e2a
Reviewed-on: https://boringssl-review.googlesource.com/29587
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2018-06-29 21:26:38 +01:00
|
|
|
!session->ticket.CopyFrom(ticket) ||
|
2017-08-01 21:32:25 +01:00
|
|
|
!CBS_get_u16_length_prefixed(&body, &extensions) ||
|
|
|
|
CBS_len(&body) != 0) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2016-07-27 16:10:52 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
2018-08-28 23:06:31 +01:00
|
|
|
return false;
|
2016-07-27 16:10:52 +01:00
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Cap the renewable lifetime by the server advertised value. This avoids
|
|
|
|
// wasting bandwidth on 0-RTT when we know the server will reject it.
|
2017-02-20 22:00:20 +00:00
|
|
|
if (session->timeout > server_timeout) {
|
|
|
|
session->timeout = server_timeout;
|
2017-01-28 19:00:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 11:35:17 +00:00
|
|
|
if (!tls13_derive_session_psk(session.get(), ticket_nonce)) {
|
2018-08-28 23:06:31 +01:00
|
|
|
return false;
|
2017-10-11 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Parse out the extensions.
|
2017-08-31 20:13:12 +01:00
|
|
|
bool have_early_data_info = false;
|
2016-12-07 20:29:45 +00:00
|
|
|
CBS early_data_info;
|
|
|
|
const SSL_EXTENSION_TYPE ext_types[] = {
|
2018-01-22 20:20:31 +00:00
|
|
|
{TLSEXT_TYPE_early_data, &have_early_data_info, &early_data_info},
|
2016-12-07 20:29:45 +00:00
|
|
|
};
|
|
|
|
|
2017-02-08 21:33:15 +00:00
|
|
|
uint8_t alert = SSL_AD_DECODE_ERROR;
|
2016-12-07 20:29:45 +00:00
|
|
|
if (!ssl_parse_extensions(&extensions, &alert, ext_types,
|
|
|
|
OPENSSL_ARRAY_SIZE(ext_types),
|
|
|
|
1 /* ignore unknown */)) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
2018-08-28 23:06:31 +01:00
|
|
|
return false;
|
2016-12-07 20:29:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 23:51:30 +01:00
|
|
|
if (have_early_data_info && ssl->enable_early_data) {
|
2016-12-07 20:29:45 +00:00
|
|
|
if (!CBS_get_u32(&early_data_info, &session->ticket_max_early_data) ||
|
|
|
|
CBS_len(&early_data_info) != 0) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
2017-01-08 11:04:43 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
2018-08-28 23:06:31 +01:00
|
|
|
return false;
|
2016-12-07 20:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 22:35:22 +01:00
|
|
|
// Generate a session ID for this session. Some callers expect all sessions to
|
|
|
|
// have a session ID.
|
|
|
|
SHA256(CBS_data(&ticket), CBS_len(&ticket), session->session_id);
|
|
|
|
session->session_id_length = SHA256_DIGEST_LENGTH;
|
|
|
|
|
2018-06-29 18:24:45 +01:00
|
|
|
session->ticket_age_add_valid = true;
|
|
|
|
session->not_resumable = false;
|
2016-07-27 16:10:52 +01:00
|
|
|
|
2018-05-02 21:05:36 +01:00
|
|
|
if ((ssl->session_ctx->session_cache_mode & SSL_SESS_CACHE_CLIENT) &&
|
|
|
|
ssl->session_ctx->new_session_cb != NULL &&
|
|
|
|
ssl->session_ctx->new_session_cb(ssl, session.get())) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// |new_session_cb|'s return value signals that it took ownership.
|
2017-07-13 04:00:28 +01:00
|
|
|
session.release();
|
2016-07-27 16:10:52 +01:00
|
|
|
}
|
|
|
|
|
2018-08-28 23:06:31 +01:00
|
|
|
return true;
|
2016-07-27 16:10:52 +01:00
|
|
|
}
|
2016-08-16 07:17:03 +01:00
|
|
|
|
Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-08-27 02:53:36 +01:00
|
|
|
BSSL_NAMESPACE_END
|