2017-08-14 20:08:34 +01:00
|
|
|
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This package is an SSL implementation written
|
|
|
|
* by Eric Young (eay@cryptsoft.com).
|
|
|
|
* The implementation was written so as to conform with Netscapes SSL.
|
|
|
|
*
|
|
|
|
* This library is free for commercial and non-commercial use as long as
|
|
|
|
* the following conditions are aheared to. The following conditions
|
|
|
|
* apply to all code found in this distribution, be it the RC4, RSA,
|
|
|
|
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
|
|
|
* included with this distribution is covered by the same copyright terms
|
|
|
|
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
|
|
|
*
|
|
|
|
* Copyright remains Eric Young's, and as such any Copyright notices in
|
|
|
|
* the code are not to be removed.
|
|
|
|
* If this package is used in a product, Eric Young should be given attribution
|
|
|
|
* as the author of the parts of the library used.
|
|
|
|
* This can be in the form of a textual message at program startup or
|
|
|
|
* in documentation (online or textual) provided with the package.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* "This product includes cryptographic software written by
|
|
|
|
* Eric Young (eay@cryptsoft.com)"
|
|
|
|
* The word 'cryptographic' can be left out if the rouines from the library
|
|
|
|
* being used are not cryptographic related :-).
|
|
|
|
* 4. If you include any Windows specific code (or a derivative thereof) from
|
|
|
|
* the apps directory (application code) you must include an acknowledgement:
|
|
|
|
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* The licence and distribution terms for any publically available version or
|
|
|
|
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
|
|
|
* copied and put under another distribution licence
|
|
|
|
* [including the GNU Public Licence.]
|
|
|
|
*/
|
|
|
|
/* ====================================================================
|
|
|
|
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* 3. All advertising materials mentioning features or use of this
|
|
|
|
* software must display the following acknowledgment:
|
|
|
|
* "This product includes software developed by the OpenSSL Project
|
|
|
|
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
|
|
|
*
|
|
|
|
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* prior written permission. For written permission, please contact
|
|
|
|
* openssl-core@openssl.org.
|
|
|
|
*
|
|
|
|
* 5. Products derived from this software may not be called "OpenSSL"
|
|
|
|
* nor may "OpenSSL" appear in their names without prior written
|
|
|
|
* permission of the OpenSSL Project.
|
|
|
|
*
|
|
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
|
|
|
* acknowledgment:
|
|
|
|
* "This product includes software developed by the OpenSSL Project
|
|
|
|
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
|
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
|
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* ====================================================================
|
|
|
|
*
|
|
|
|
* This product includes cryptographic software written by Eric Young
|
|
|
|
* (eay@cryptsoft.com). This product includes software written by Tim
|
|
|
|
* Hudson (tjh@cryptsoft.com). */
|
|
|
|
/* ====================================================================
|
|
|
|
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
|
|
|
* ECC cipher suite support in OpenSSL originally developed by
|
|
|
|
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. */
|
|
|
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2017-09-21 16:20:53 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2018-01-18 15:08:53 +00:00
|
|
|
#include <openssl/rand.h>
|
|
|
|
|
2017-08-14 20:08:34 +01:00
|
|
|
#include "../crypto/internal.h"
|
|
|
|
#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
|
2017-08-14 20:08:34 +01:00
|
|
|
|
|
|
|
SSL_HANDSHAKE::SSL_HANDSHAKE(SSL *ssl_arg)
|
|
|
|
: ssl(ssl_arg),
|
2017-08-31 19:49:09 +01:00
|
|
|
scts_requested(false),
|
|
|
|
needs_psk_binder(false),
|
|
|
|
received_hello_retry_request(false),
|
2017-11-07 22:09:52 +00:00
|
|
|
sent_hello_retry_request(false),
|
2017-08-31 19:49:09 +01:00
|
|
|
handshake_finalized(false),
|
|
|
|
accept_psk_mode(false),
|
|
|
|
cert_request(false),
|
|
|
|
certificate_status_expected(false),
|
|
|
|
ocsp_stapling_requested(false),
|
|
|
|
should_ack_sni(false),
|
|
|
|
in_false_start(false),
|
|
|
|
in_early_data(false),
|
|
|
|
early_data_offered(false),
|
|
|
|
can_early_read(false),
|
|
|
|
can_early_write(false),
|
|
|
|
next_proto_neg_seen(false),
|
|
|
|
ticket_expected(false),
|
|
|
|
extended_master_secret(false),
|
2018-01-18 15:08:53 +00:00
|
|
|
pending_private_key_op(false),
|
2018-04-13 23:51:30 +01:00
|
|
|
grease_seeded(false),
|
2018-05-02 17:06:48 +01:00
|
|
|
handback(false),
|
2018-11-19 21:49:56 +00:00
|
|
|
cert_compression_negotiated(false),
|
|
|
|
apply_jdk11_workaround(false) {
|
2018-04-13 23:51:30 +01:00
|
|
|
assert(ssl);
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SSL_HANDSHAKE::~SSL_HANDSHAKE() {
|
|
|
|
ssl->ctx->x509_method->hs_flush_cached_ca_names(this);
|
|
|
|
}
|
|
|
|
|
2017-10-13 22:18:35 +01:00
|
|
|
UniquePtr<SSL_HANDSHAKE> ssl_handshake_new(SSL *ssl) {
|
2017-08-14 20:08:34 +01:00
|
|
|
UniquePtr<SSL_HANDSHAKE> hs = MakeUnique<SSL_HANDSHAKE>(ssl);
|
2018-08-10 18:28:47 +01:00
|
|
|
if (!hs || !hs->transcript.Init()) {
|
2017-08-14 20:08:34 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-03 00:47:27 +01:00
|
|
|
hs->config = ssl->config.get();
|
2018-04-13 23:51:30 +01:00
|
|
|
if (!hs->config) {
|
|
|
|
assert(hs->config);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-10-13 22:18:35 +01:00
|
|
|
return hs;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-07 09:12:35 +01:00
|
|
|
bool ssl_check_message_type(SSL *ssl, const SSLMessage &msg, int type) {
|
2017-08-14 20:08:34 +01:00
|
|
|
if (msg.type != type) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
2017-08-14 20:08:34 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
|
|
|
|
ERR_add_error_dataf("got type %d, wanted type %d", msg.type, type);
|
2017-10-07 09:12:35 +01:00
|
|
|
return false;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-07 09:12:35 +01:00
|
|
|
return true;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-07 09:12:35 +01:00
|
|
|
bool ssl_add_message_cbb(SSL *ssl, CBB *cbb) {
|
2017-09-21 16:20:53 +01:00
|
|
|
Array<uint8_t> msg;
|
|
|
|
if (!ssl->method->finish_message(ssl, cbb, &msg) ||
|
|
|
|
!ssl->method->add_message(ssl, std::move(msg))) {
|
2017-10-07 09:12:35 +01:00
|
|
|
return false;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-07 09:12:35 +01:00
|
|
|
return true;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t ssl_max_handshake_message_len(const SSL *ssl) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// kMaxMessageLen is the default maximum message size for handshakes which do
|
|
|
|
// not accept peer certificate chains.
|
2017-08-14 20:08:34 +01:00
|
|
|
static const size_t kMaxMessageLen = 16384;
|
|
|
|
|
|
|
|
if (SSL_in_init(ssl)) {
|
2018-07-03 00:47:27 +01:00
|
|
|
SSL_CONFIG *config = ssl->config.get(); // SSL_in_init() implies not NULL.
|
2018-04-13 23:51:30 +01:00
|
|
|
if ((!ssl->server || (config->verify_mode & SSL_VERIFY_PEER)) &&
|
2017-08-14 20:08:34 +01:00
|
|
|
kMaxMessageLen < ssl->max_cert_list) {
|
|
|
|
return ssl->max_cert_list;
|
|
|
|
}
|
|
|
|
return kMaxMessageLen;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:31:15 +01:00
|
|
|
if (ssl_protocol_version(ssl) < TLS1_3_VERSION) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// In TLS 1.2 and below, the largest acceptable post-handshake message is
|
|
|
|
// a HelloRequest.
|
2017-08-14 20:08:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssl->server) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// The largest acceptable post-handshake message for a server is a
|
|
|
|
// KeyUpdate. We will never initiate post-handshake auth.
|
2017-08-14 20:08:34 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-06 22:48:58 +01:00
|
|
|
// Clients must accept NewSessionTicket, so allow the default size.
|
2017-08-14 20:08:34 +01:00
|
|
|
return kMaxMessageLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ssl_hash_message(SSL_HANDSHAKE *hs, const SSLMessage &msg) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// V2ClientHello messages are pre-hashed.
|
2017-08-14 20:08:34 +01:00
|
|
|
if (msg.is_v2_hello) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-11 22:19:19 +01:00
|
|
|
return hs->transcript.Update(msg.raw);
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ssl_parse_extensions(const CBS *cbs, uint8_t *out_alert,
|
|
|
|
const SSL_EXTENSION_TYPE *ext_types,
|
|
|
|
size_t num_ext_types, int ignore_unknown) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// Reset everything.
|
2017-08-14 20:08:34 +01:00
|
|
|
for (size_t i = 0; i < num_ext_types; i++) {
|
|
|
|
*ext_types[i].out_present = 0;
|
|
|
|
CBS_init(ext_types[i].out_data, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CBS copy = *cbs;
|
|
|
|
while (CBS_len(©) != 0) {
|
|
|
|
uint16_t type;
|
|
|
|
CBS data;
|
|
|
|
if (!CBS_get_u16(©, &type) ||
|
|
|
|
!CBS_get_u16_length_prefixed(©, &data)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
|
|
|
|
*out_alert = SSL_AD_DECODE_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SSL_EXTENSION_TYPE *ext_type = NULL;
|
|
|
|
for (size_t i = 0; i < num_ext_types; i++) {
|
|
|
|
if (type == ext_types[i].type) {
|
|
|
|
ext_type = &ext_types[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext_type == NULL) {
|
|
|
|
if (ignore_unknown) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION);
|
|
|
|
*out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Duplicate ext_types are forbidden.
|
2017-08-14 20:08:34 +01:00
|
|
|
if (*ext_type->out_present) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DUPLICATE_EXTENSION);
|
|
|
|
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ext_type->out_present = 1;
|
|
|
|
*ext_type->out_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs) {
|
|
|
|
SSL *const ssl = hs->ssl;
|
2017-10-13 22:18:35 +01:00
|
|
|
const SSL_SESSION *prev_session = ssl->s3->established_session.get();
|
2017-08-14 20:08:34 +01:00
|
|
|
if (prev_session != NULL) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// If renegotiating, the server must not change the server certificate. See
|
|
|
|
// https://mitls.org/pages/attacks/3SHAKE. We never resume on renegotiation,
|
|
|
|
// so this check is sufficient to ensure the reported peer certificate never
|
|
|
|
// changes on renegotiation.
|
2017-08-14 20:08:34 +01:00
|
|
|
assert(!ssl->server);
|
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 (sk_CRYPTO_BUFFER_num(prev_session->certs.get()) !=
|
|
|
|
sk_CRYPTO_BUFFER_num(hs->new_session->certs.get())) {
|
2017-08-14 20:08:34 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_SERVER_CERT_CHANGED);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2017-08-14 20:08:34 +01:00
|
|
|
return ssl_verify_invalid;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
for (size_t i = 0; i < sk_CRYPTO_BUFFER_num(hs->new_session->certs.get());
|
|
|
|
i++) {
|
2017-08-14 20:08:34 +01:00
|
|
|
const CRYPTO_BUFFER *old_cert =
|
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
|
|
|
sk_CRYPTO_BUFFER_value(prev_session->certs.get(), i);
|
2017-08-14 20:08:34 +01:00
|
|
|
const CRYPTO_BUFFER *new_cert =
|
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
|
|
|
sk_CRYPTO_BUFFER_value(hs->new_session->certs.get(), i);
|
2017-08-14 20:08:34 +01:00
|
|
|
if (CRYPTO_BUFFER_len(old_cert) != CRYPTO_BUFFER_len(new_cert) ||
|
|
|
|
OPENSSL_memcmp(CRYPTO_BUFFER_data(old_cert),
|
|
|
|
CRYPTO_BUFFER_data(new_cert),
|
|
|
|
CRYPTO_BUFFER_len(old_cert)) != 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_SERVER_CERT_CHANGED);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
2017-08-14 20:08:34 +01:00
|
|
|
return ssl_verify_invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// The certificate is identical, so we may skip re-verifying the
|
|
|
|
// certificate. Since we only authenticated the previous one, copy other
|
|
|
|
// authentication from the established session and ignore what was newly
|
|
|
|
// received.
|
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
|
|
|
hs->new_session->ocsp_response = UpRef(prev_session->ocsp_response);
|
|
|
|
hs->new_session->signed_cert_timestamp_list =
|
|
|
|
UpRef(prev_session->signed_cert_timestamp_list);
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->new_session->verify_result = prev_session->verify_result;
|
|
|
|
return ssl_verify_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t alert = SSL_AD_CERTIFICATE_UNKNOWN;
|
|
|
|
enum ssl_verify_result_t ret;
|
2018-04-13 23:51:30 +01:00
|
|
|
if (hs->config->custom_verify_callback != nullptr) {
|
|
|
|
ret = hs->config->custom_verify_callback(ssl, &alert);
|
2017-08-14 20:08:34 +01:00
|
|
|
switch (ret) {
|
|
|
|
case ssl_verify_ok:
|
|
|
|
hs->new_session->verify_result = X509_V_OK;
|
|
|
|
break;
|
|
|
|
case ssl_verify_invalid:
|
2018-01-23 20:08:55 +00:00
|
|
|
// If |SSL_VERIFY_NONE|, the error is non-fatal, but we keep the result.
|
2018-04-13 23:51:30 +01:00
|
|
|
if (hs->config->verify_mode == SSL_VERIFY_NONE) {
|
2018-01-23 20:08:55 +00:00
|
|
|
ERR_clear_error();
|
|
|
|
ret = ssl_verify_ok;
|
|
|
|
}
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->new_session->verify_result = X509_V_ERR_APPLICATION_VERIFICATION;
|
|
|
|
break;
|
|
|
|
case ssl_verify_retry:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = ssl->ctx->x509_method->session_verify_cert_chain(
|
2018-04-13 23:51:30 +01:00
|
|
|
hs->new_session.get(), hs, &alert)
|
2017-08-14 20:08:34 +01:00
|
|
|
? ssl_verify_ok
|
|
|
|
: ssl_verify_invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == ssl_verify_invalid) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_VERIFY_FAILED);
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
2018-05-11 00:55:02 +01:00
|
|
|
// Emulate OpenSSL's client OCSP callback. OpenSSL verifies certificates
|
|
|
|
// before it receives the OCSP, so it needs a second callback for OCSP.
|
|
|
|
if (ret == ssl_verify_ok && !ssl->server &&
|
2018-05-15 19:22:17 +01:00
|
|
|
hs->config->ocsp_stapling_enabled &&
|
2018-05-11 00:55:02 +01:00
|
|
|
ssl->ctx->legacy_ocsp_callback != nullptr) {
|
|
|
|
int cb_ret =
|
|
|
|
ssl->ctx->legacy_ocsp_callback(ssl, ssl->ctx->legacy_ocsp_callback_arg);
|
|
|
|
if (cb_ret <= 0) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_OCSP_CB_ERROR);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL,
|
|
|
|
cb_ret == 0 ? SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE
|
|
|
|
: SSL_AD_INTERNAL_ERROR);
|
|
|
|
ret = ssl_verify_invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-14 20:08:34 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-10 18:28:47 +01:00
|
|
|
// Verifies a stored certificate when resuming a session. A few things are
|
|
|
|
// different from verify_peer_cert:
|
|
|
|
// 1. We can't be renegotiating if we're resuming a session.
|
|
|
|
// 2. The session is immutable, so we don't support verify_mode ==
|
|
|
|
// SSL_VERIFY_NONE
|
|
|
|
// 3. We don't call the OCSP callback.
|
|
|
|
// 4. We only support custom verify callbacks.
|
|
|
|
enum ssl_verify_result_t ssl_reverify_peer_cert(SSL_HANDSHAKE *hs) {
|
|
|
|
SSL *const ssl = hs->ssl;
|
|
|
|
assert(ssl->s3->established_session == nullptr);
|
|
|
|
assert(hs->config->verify_mode != SSL_VERIFY_NONE);
|
|
|
|
|
|
|
|
uint8_t alert = SSL_AD_CERTIFICATE_UNKNOWN;
|
|
|
|
enum ssl_verify_result_t ret = ssl_verify_invalid;
|
|
|
|
if (hs->config->custom_verify_callback != nullptr) {
|
|
|
|
ret = hs->config->custom_verify_callback(ssl, &alert);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == ssl_verify_invalid) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_VERIFY_FAILED);
|
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-18 15:08:53 +00:00
|
|
|
uint16_t ssl_get_grease_value(SSL_HANDSHAKE *hs,
|
|
|
|
enum ssl_grease_index_t index) {
|
|
|
|
// Draw entropy for all GREASE values at once. This avoids calling
|
|
|
|
// |RAND_bytes| repeatedly and makes the values consistent within a
|
|
|
|
// connection. The latter is so the second ClientHello matches after
|
|
|
|
// HelloRetryRequest and so supported_groups and key_shares are consistent.
|
|
|
|
if (!hs->grease_seeded) {
|
|
|
|
RAND_bytes(hs->grease_seed, sizeof(hs->grease_seed));
|
|
|
|
hs->grease_seeded = true;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// This generates a random value of the form 0xωaωa, for all 0 ≤ ω < 16.
|
2018-01-18 15:08:53 +00:00
|
|
|
uint16_t ret = hs->grease_seed[index];
|
2017-08-14 20:08:34 +01:00
|
|
|
ret = (ret & 0xf0) | 0x0a;
|
|
|
|
ret |= ret << 8;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ssl_hs_wait_t ssl_get_finished(SSL_HANDSHAKE *hs) {
|
|
|
|
SSL *const ssl = hs->ssl;
|
|
|
|
SSLMessage msg;
|
|
|
|
if (!ssl->method->get_message(ssl, &msg)) {
|
|
|
|
return ssl_hs_read_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ssl_check_message_type(ssl, msg, SSL3_MT_FINISHED)) {
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Snapshot the finished hash before incorporating the new message.
|
2017-08-14 20:08:34 +01:00
|
|
|
uint8_t finished[EVP_MAX_MD_SIZE];
|
|
|
|
size_t finished_len;
|
|
|
|
if (!hs->transcript.GetFinishedMAC(finished, &finished_len,
|
2017-08-31 06:12:28 +01:00
|
|
|
SSL_get_session(ssl), !ssl->server) ||
|
2017-08-14 20:08:34 +01:00
|
|
|
!ssl_hash_message(hs, msg)) {
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int finished_ok = CBS_mem_equal(&msg.body, finished, finished_len);
|
|
|
|
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
|
|
|
finished_ok = 1;
|
|
|
|
#endif
|
|
|
|
if (!finished_ok) {
|
2017-10-06 23:31:15 +01:00
|
|
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
|
2017-08-14 20:08:34 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DIGEST_CHECK_FAILED);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Copy the Finished so we can use it for renegotiation checks.
|
2018-06-26 05:07:40 +01:00
|
|
|
if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
|
|
|
|
finished_len > sizeof(ssl->s3->previous_server_finished)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
|
|
|
return ssl_hs_error;
|
|
|
|
}
|
2017-08-14 20:08:34 +01:00
|
|
|
|
2018-06-26 05:07:40 +01:00
|
|
|
if (ssl->server) {
|
|
|
|
OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
|
|
|
|
ssl->s3->previous_client_finished_len = finished_len;
|
|
|
|
} else {
|
|
|
|
OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
|
|
|
|
ssl->s3->previous_server_finished_len = finished_len;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ssl->method->next_message(ssl);
|
|
|
|
return ssl_hs_ok;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:43:53 +01:00
|
|
|
bool ssl_send_finished(SSL_HANDSHAKE *hs) {
|
|
|
|
SSL *const ssl = hs->ssl;
|
|
|
|
const SSL_SESSION *session = SSL_get_session(ssl);
|
|
|
|
|
|
|
|
uint8_t finished[EVP_MAX_MD_SIZE];
|
|
|
|
size_t finished_len;
|
|
|
|
if (!hs->transcript.GetFinishedMAC(finished, &finished_len, session,
|
|
|
|
ssl->server)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log the master secret, if logging is enabled.
|
2018-08-10 18:28:47 +01:00
|
|
|
if (!ssl_log_secret(ssl, "CLIENT_RANDOM", session->master_key,
|
2017-10-06 23:43:53 +01:00
|
|
|
session->master_key_length)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the Finished so we can use it for renegotiation checks.
|
2018-06-26 05:07:40 +01:00
|
|
|
if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
|
|
|
|
finished_len > sizeof(ssl->s3->previous_server_finished)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-06 23:43:53 +01:00
|
|
|
|
2018-06-26 05:07:40 +01:00
|
|
|
if (ssl->server) {
|
|
|
|
OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
|
|
|
|
ssl->s3->previous_server_finished_len = finished_len;
|
|
|
|
} else {
|
|
|
|
OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
|
|
|
|
ssl->s3->previous_client_finished_len = finished_len;
|
2017-10-06 23:43:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedCBB cbb;
|
|
|
|
CBB body;
|
|
|
|
if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_FINISHED) ||
|
|
|
|
!CBB_add_bytes(&body, finished, finished_len) ||
|
|
|
|
!ssl_add_message_cbb(ssl, cbb.get())) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:51:30 +01:00
|
|
|
bool ssl_output_cert_chain(SSL_HANDSHAKE *hs) {
|
2017-10-06 23:43:53 +01:00
|
|
|
ScopedCBB cbb;
|
|
|
|
CBB body;
|
2018-04-13 23:51:30 +01:00
|
|
|
if (!hs->ssl->method->init_message(hs->ssl, cbb.get(), &body,
|
|
|
|
SSL3_MT_CERTIFICATE) ||
|
|
|
|
!ssl_add_cert_chain(hs, &body) ||
|
|
|
|
!ssl_add_message_cbb(hs->ssl, cbb.get())) {
|
2017-10-06 23:43:53 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-31 20:13:12 +01:00
|
|
|
int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return) {
|
2017-08-14 20:08:34 +01:00
|
|
|
SSL *const ssl = hs->ssl;
|
|
|
|
for (;;) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// Resolve the operation the handshake was waiting on.
|
2017-08-14 20:08:34 +01:00
|
|
|
switch (hs->wait) {
|
|
|
|
case ssl_hs_error:
|
2017-10-02 03:35:10 +01:00
|
|
|
ERR_restore_state(hs->error.get());
|
2017-08-14 20:08:34 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_flush: {
|
|
|
|
int ret = ssl->method->flush_flight(ssl);
|
|
|
|
if (ret <= 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ssl_hs_read_server_hello:
|
2017-10-06 22:36:20 +01:00
|
|
|
case ssl_hs_read_message:
|
|
|
|
case ssl_hs_read_change_cipher_spec: {
|
2018-07-14 16:23:01 +01:00
|
|
|
if (ssl->ctx->quic_method) {
|
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
// The change cipher spec is omitted in QUIC.
|
|
|
|
if (hs->wait != ssl_hs_read_change_cipher_spec) {
|
|
|
|
ssl->s3->rwstate = SSL_READING;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-06 22:36:20 +01:00
|
|
|
uint8_t alert = SSL_AD_DECODE_ERROR;
|
|
|
|
size_t consumed = 0;
|
|
|
|
ssl_open_record_t ret;
|
|
|
|
if (hs->wait == ssl_hs_read_change_cipher_spec) {
|
2017-10-13 00:11:47 +01:00
|
|
|
ret = ssl_open_change_cipher_spec(ssl, &consumed, &alert,
|
2017-10-13 21:50:39 +01:00
|
|
|
ssl->s3->read_buffer.span());
|
2017-10-13 00:11:47 +01:00
|
|
|
} else {
|
2017-10-13 21:50:39 +01:00
|
|
|
ret = ssl_open_handshake(ssl, &consumed, &alert,
|
|
|
|
ssl->s3->read_buffer.span());
|
2017-10-06 22:36:20 +01:00
|
|
|
}
|
|
|
|
if (ret == ssl_open_record_error &&
|
|
|
|
hs->wait == ssl_hs_read_server_hello) {
|
2017-08-14 20:08:34 +01:00
|
|
|
uint32_t err = ERR_peek_error();
|
2017-10-06 22:36:20 +01:00
|
|
|
if (ERR_GET_LIB(err) == ERR_LIB_SSL &&
|
2017-08-14 20:08:34 +01:00
|
|
|
ERR_GET_REASON(err) == SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// Add a dedicated error code to the queue for a handshake_failure
|
|
|
|
// alert in response to ClientHello. This matches NSS's client
|
|
|
|
// behavior and gives a better error on a (probable) failure to
|
|
|
|
// negotiate initial parameters. Note: this error code comes after
|
|
|
|
// the original one.
|
|
|
|
//
|
|
|
|
// See https://crbug.com/446505.
|
2017-08-14 20:08:34 +01:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_HANDSHAKE_FAILURE_ON_CLIENT_HELLO);
|
|
|
|
}
|
|
|
|
}
|
2017-10-06 22:36:20 +01:00
|
|
|
bool retry;
|
|
|
|
int bio_ret = ssl_handle_open_record(ssl, &retry, ret, consumed, alert);
|
|
|
|
if (bio_ret <= 0) {
|
|
|
|
return bio_ret;
|
|
|
|
}
|
|
|
|
if (retry) {
|
|
|
|
continue;
|
2017-08-14 20:08:34 +01:00
|
|
|
}
|
2017-10-13 21:50:39 +01:00
|
|
|
ssl->s3->read_buffer.DiscardConsumed();
|
2017-08-14 20:08:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ssl_hs_read_end_of_early_data: {
|
|
|
|
if (ssl->s3->hs->can_early_read) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// While we are processing early data, the handshake returns early.
|
2017-08-31 20:13:12 +01:00
|
|
|
*out_early_return = true;
|
2017-08-14 20:08:34 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ssl_hs_certificate_selection_pending:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_CERTIFICATE_SELECTION_PENDING;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
2018-01-26 17:14:30 +00:00
|
|
|
case ssl_hs_handoff:
|
|
|
|
ssl->s3->rwstate = SSL_HANDOFF;
|
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
2018-03-22 18:48:33 +00:00
|
|
|
case ssl_hs_handback:
|
|
|
|
ssl->s3->rwstate = SSL_HANDBACK;
|
|
|
|
hs->wait = ssl_hs_handback;
|
|
|
|
return -1;
|
|
|
|
|
2017-08-14 20:08:34 +01:00
|
|
|
case ssl_hs_x509_lookup:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_X509_LOOKUP;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_channel_id_lookup:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_CHANNEL_ID_LOOKUP;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_private_key_operation:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_PRIVATE_KEY_OPERATION;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_pending_session:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_PENDING_SESSION;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_pending_ticket:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_PENDING_TICKET;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_certificate_verify:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_CERTIFICATE_VERIFY;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_early_data_rejected:
|
2017-10-14 00:17:22 +01:00
|
|
|
ssl->s3->rwstate = SSL_EARLY_DATA_REJECTED;
|
2017-08-29 21:33:21 +01:00
|
|
|
// Cause |SSL_write| to start failing immediately.
|
2017-08-31 19:49:09 +01:00
|
|
|
hs->can_early_write = false;
|
2017-08-14 20:08:34 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
case ssl_hs_early_return:
|
2017-08-31 20:13:12 +01:00
|
|
|
*out_early_return = true;
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl_hs_ok;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case ssl_hs_ok:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Run the state machine again.
|
2017-08-14 20:08:34 +01:00
|
|
|
hs->wait = ssl->do_handshake(hs);
|
|
|
|
if (hs->wait == ssl_hs_error) {
|
2017-10-02 03:35:10 +01:00
|
|
|
hs->error.reset(ERR_save_state());
|
2017-08-14 20:08:34 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (hs->wait == ssl_hs_ok) {
|
2017-08-29 21:33:21 +01:00
|
|
|
// The handshake has completed.
|
2017-08-31 20:13:12 +01:00
|
|
|
*out_early_return = false;
|
2017-08-14 20:08:34 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Otherwise, loop to the beginning and resolve what was blocking the
|
|
|
|
// handshake.
|
2017-08-14 20:08:34 +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
|