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>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-07-19 03:45:18 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2016-07-11 18:19:03 +01:00
|
|
|
#include <openssl/aead.h>
|
|
|
|
#include <openssl/bytestring.h>
|
|
|
|
#include <openssl/digest.h>
|
|
|
|
#include <openssl/hkdf.h>
|
2016-11-01 17:39:36 +00:00
|
|
|
#include <openssl/hmac.h>
|
2016-07-11 18:19:03 +01:00
|
|
|
#include <openssl/mem.h>
|
|
|
|
|
2016-12-13 06:07:13 +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
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
static bool init_key_schedule(SSL_HANDSHAKE *hs, uint16_t version,
|
2017-08-09 20:02:34 +01:00
|
|
|
const SSL_CIPHER *cipher) {
|
|
|
|
if (!hs->transcript.InitHash(version, cipher)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2017-01-12 18:17:07 +00:00
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2017-07-19 21:38:21 +01:00
|
|
|
hs->hash_len = hs->transcript.DigestLen();
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Initialize the secret to the zero key.
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memset(hs->secret, 0, hs->hash_len);
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_init_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
|
|
|
|
size_t psk_len) {
|
2017-10-06 23:31:15 +01:00
|
|
|
if (!init_key_schedule(hs, ssl_protocol_version(hs->ssl), hs->new_cipher)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 21:38:21 +01:00
|
|
|
hs->transcript.FreeBuffer();
|
2017-10-11 17:29:36 +01:00
|
|
|
return HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), psk,
|
|
|
|
psk_len, hs->secret, hs->hash_len);
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
|
|
|
|
size_t psk_len) {
|
2017-01-11 16:34:52 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2018-07-03 00:47:27 +01:00
|
|
|
return init_key_schedule(hs, ssl_session_protocol_version(ssl->session.get()),
|
2017-10-11 17:29:36 +01:00
|
|
|
ssl->session->cipher) &&
|
|
|
|
HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), psk,
|
|
|
|
psk_len, hs->secret, hs->hash_len);
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
static bool hkdf_expand_label(uint8_t *out, const EVP_MD *digest,
|
|
|
|
const uint8_t *secret, size_t secret_len,
|
|
|
|
const char *label, size_t label_len,
|
2018-07-14 16:23:01 +01:00
|
|
|
const uint8_t *hash, size_t hash_len, size_t len,
|
|
|
|
bool use_quic_label) {
|
|
|
|
static const char kTLS13ProtocolLabel[] = "tls13 ";
|
|
|
|
static const char kQUICProtocolLabel[] = "quic ";
|
|
|
|
|
|
|
|
const char *protocol_label;
|
|
|
|
if (use_quic_label) {
|
|
|
|
protocol_label = kQUICProtocolLabel;
|
|
|
|
} else {
|
|
|
|
protocol_label = kTLS13ProtocolLabel;
|
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2017-07-20 04:57:40 +01:00
|
|
|
ScopedCBB cbb;
|
|
|
|
CBB child;
|
2018-07-14 18:27:25 +01:00
|
|
|
Array<uint8_t> hkdf_label;
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!CBB_init(cbb.get(),
|
|
|
|
2 + 1 + strlen(protocol_label) + label_len + 1 + hash_len) ||
|
2017-07-20 04:57:40 +01:00
|
|
|
!CBB_add_u16(cbb.get(), len) ||
|
|
|
|
!CBB_add_u8_length_prefixed(cbb.get(), &child) ||
|
2018-07-14 16:23:01 +01:00
|
|
|
!CBB_add_bytes(&child, (const uint8_t *)protocol_label,
|
|
|
|
strlen(protocol_label)) ||
|
2017-12-08 22:05:06 +00:00
|
|
|
!CBB_add_bytes(&child, (const uint8_t *)label, label_len) ||
|
2017-07-20 04:57:40 +01:00
|
|
|
!CBB_add_u8_length_prefixed(cbb.get(), &child) ||
|
2016-07-11 18:19:03 +01:00
|
|
|
!CBB_add_bytes(&child, hash, hash_len) ||
|
2018-07-14 18:27:25 +01:00
|
|
|
!CBBFinishArray(cbb.get(), &hkdf_label)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 18:27:25 +01:00
|
|
|
return HKDF_expand(out, len, digest, secret, secret_len, hkdf_label.data(),
|
|
|
|
hkdf_label.size());
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-10-11 17:29:36 +01:00
|
|
|
static const char kTLS13LabelDerived[] = "derived";
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_advance_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *in,
|
|
|
|
size_t len) {
|
2018-01-22 20:20:31 +00:00
|
|
|
uint8_t derive_context[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned derive_context_len;
|
|
|
|
if (!EVP_Digest(nullptr, 0, derive_context, &derive_context_len,
|
|
|
|
hs->transcript.Digest(), nullptr)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2018-01-22 20:20:31 +00:00
|
|
|
}
|
2017-10-11 17:29:36 +01:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
if (!hkdf_expand_label(hs->secret, hs->transcript.Digest(), hs->secret,
|
|
|
|
hs->hash_len, kTLS13LabelDerived,
|
|
|
|
strlen(kTLS13LabelDerived), derive_context,
|
2018-07-14 16:23:01 +01:00
|
|
|
derive_context_len, hs->hash_len,
|
|
|
|
hs->ssl->ctx->quic_method != nullptr)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2017-10-11 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return HKDF_extract(hs->secret, &hs->hash_len, hs->transcript.Digest(), in,
|
|
|
|
len, hs->secret, hs->hash_len);
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// derive_secret derives a secret of length |len| and writes the result in |out|
|
|
|
|
// with the given label and the current base secret and most recently-saved
|
2018-09-06 00:44:15 +01:00
|
|
|
// handshake context. It returns true on success and false on error.
|
|
|
|
static bool derive_secret(SSL_HANDSHAKE *hs, uint8_t *out, size_t len,
|
|
|
|
const char *label, size_t label_len) {
|
2016-11-01 17:39:36 +00:00
|
|
|
uint8_t context_hash[EVP_MAX_MD_SIZE];
|
|
|
|
size_t context_hash_len;
|
2017-07-19 21:38:21 +01:00
|
|
|
if (!hs->transcript.GetHash(context_hash, &context_hash_len)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
return hkdf_expand_label(out, hs->transcript.Digest(), hs->secret,
|
|
|
|
hs->hash_len, label, label_len, context_hash,
|
2018-07-14 16:23:01 +01:00
|
|
|
context_hash_len, len,
|
|
|
|
hs->ssl->ctx->quic_method != nullptr);
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
bool tls13_set_traffic_key(SSL *ssl, enum ssl_encryption_level_t level,
|
|
|
|
enum evp_aead_direction_t direction,
|
2018-09-06 00:44:15 +01:00
|
|
|
const uint8_t *traffic_secret,
|
|
|
|
size_t traffic_secret_len) {
|
2017-01-11 16:34:52 +00:00
|
|
|
const SSL_SESSION *session = SSL_get_session(ssl);
|
2017-10-03 20:06:29 +01:00
|
|
|
uint16_t version = ssl_session_protocol_version(session);
|
2017-01-11 16:34:52 +00:00
|
|
|
|
2016-07-11 18:19:03 +01:00
|
|
|
if (traffic_secret_len > 0xff) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
UniquePtr<SSLAEADContext> traffic_aead;
|
|
|
|
if (ssl->ctx->quic_method == nullptr) {
|
|
|
|
// Look up cipher suite properties.
|
|
|
|
const EVP_AEAD *aead;
|
|
|
|
size_t discard;
|
|
|
|
if (!ssl_cipher_get_evp_aead(&aead, &discard, &discard, session->cipher,
|
|
|
|
version, SSL_is_dtls(ssl))) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
const EVP_MD *digest = ssl_session_get_digest(session);
|
2017-01-12 18:17:07 +00:00
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
// Derive the key.
|
|
|
|
size_t key_len = EVP_AEAD_key_length(aead);
|
|
|
|
uint8_t key[EVP_AEAD_MAX_KEY_LENGTH];
|
|
|
|
if (!hkdf_expand_label(key, digest, traffic_secret, traffic_secret_len,
|
|
|
|
"key", 3, NULL, 0, key_len,
|
|
|
|
ssl->ctx->quic_method != nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
// Derive the IV.
|
|
|
|
size_t iv_len = EVP_AEAD_nonce_length(aead);
|
|
|
|
uint8_t iv[EVP_AEAD_MAX_NONCE_LENGTH];
|
|
|
|
if (!hkdf_expand_label(iv, digest, traffic_secret, traffic_secret_len, "iv",
|
|
|
|
2, NULL, 0, iv_len,
|
|
|
|
ssl->ctx->quic_method != nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
traffic_aead = SSLAEADContext::Create(
|
|
|
|
direction, session->ssl_version, SSL_is_dtls(ssl), session->cipher,
|
|
|
|
MakeConstSpan(key, key_len), Span<const uint8_t>(),
|
|
|
|
MakeConstSpan(iv, iv_len));
|
|
|
|
} else {
|
|
|
|
// Install a placeholder SSLAEADContext so that SSL accessors work. The
|
|
|
|
// encryption itself will be handled by the SSL_QUIC_METHOD.
|
|
|
|
traffic_aead =
|
|
|
|
SSLAEADContext::CreatePlaceholderForQUIC(version, session->cipher);
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 03:45:18 +01:00
|
|
|
if (!traffic_aead) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (direction == evp_aead_open) {
|
2017-07-19 03:45:18 +01:00
|
|
|
if (!ssl->method->set_read_state(ssl, std::move(traffic_aead))) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-07-19 03:45:18 +01:00
|
|
|
if (!ssl->method->set_write_state(ssl, std::move(traffic_aead))) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Save the traffic secret.
|
2016-07-11 18:19:03 +01:00
|
|
|
if (direction == evp_aead_open) {
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memmove(ssl->s3->read_traffic_secret, traffic_secret,
|
|
|
|
traffic_secret_len);
|
2016-07-11 18:19:03 +01:00
|
|
|
ssl->s3->read_traffic_secret_len = traffic_secret_len;
|
2018-07-14 16:23:01 +01:00
|
|
|
ssl->s3->read_level = level;
|
2016-07-11 18:19:03 +01:00
|
|
|
} else {
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memmove(ssl->s3->write_traffic_secret, traffic_secret,
|
|
|
|
traffic_secret_len);
|
2016-07-11 18:19:03 +01:00
|
|
|
ssl->s3->write_traffic_secret_len = traffic_secret_len;
|
2018-07-14 16:23:01 +01:00
|
|
|
ssl->s3->write_level = level;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
|
|
|
|
static const char kTLS13LabelExporter[] = "exp master";
|
|
|
|
static const char kTLS13LabelEarlyExporter[] = "e exp master";
|
|
|
|
|
|
|
|
static const char kTLS13LabelClientEarlyTraffic[] = "c e traffic";
|
|
|
|
static const char kTLS13LabelClientHandshakeTraffic[] = "c hs traffic";
|
|
|
|
static const char kTLS13LabelServerHandshakeTraffic[] = "s hs traffic";
|
|
|
|
static const char kTLS13LabelClientApplicationTraffic[] = "c ap traffic";
|
|
|
|
static const char kTLS13LabelServerApplicationTraffic[] = "s ap traffic";
|
2017-10-11 17:29:36 +01:00
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_derive_early_secrets(SSL_HANDSHAKE *hs) {
|
2017-01-11 16:34:52 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2017-12-08 22:05:06 +00:00
|
|
|
if (!derive_secret(hs, hs->early_traffic_secret, hs->hash_len,
|
2018-01-22 20:20:31 +00:00
|
|
|
kTLS13LabelClientEarlyTraffic,
|
|
|
|
strlen(kTLS13LabelClientEarlyTraffic)) ||
|
2017-12-08 22:05:06 +00:00
|
|
|
!ssl_log_secret(ssl, "CLIENT_EARLY_TRAFFIC_SECRET",
|
|
|
|
hs->early_traffic_secret, hs->hash_len) ||
|
|
|
|
!derive_secret(hs, ssl->s3->early_exporter_secret, hs->hash_len,
|
2018-01-22 20:20:31 +00:00
|
|
|
kTLS13LabelEarlyExporter,
|
|
|
|
strlen(kTLS13LabelEarlyExporter))) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2017-12-08 22:05:06 +00:00
|
|
|
}
|
|
|
|
ssl->s3->early_exporter_secret_len = hs->hash_len;
|
2018-07-14 16:23:01 +01:00
|
|
|
|
|
|
|
if (ssl->ctx->quic_method != nullptr) {
|
|
|
|
if (ssl->server) {
|
|
|
|
if (!ssl->ctx->quic_method->set_encryption_secrets(
|
|
|
|
ssl, ssl_encryption_early_data, nullptr, hs->early_traffic_secret,
|
|
|
|
hs->hash_len)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ssl->ctx->quic_method->set_encryption_secrets(
|
|
|
|
ssl, ssl_encryption_early_data, hs->early_traffic_secret, nullptr,
|
|
|
|
hs->hash_len)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2017-01-11 16:34:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_derive_handshake_secrets(SSL_HANDSHAKE *hs) {
|
2016-11-17 07:43:08 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!derive_secret(hs, hs->client_handshake_secret, hs->hash_len,
|
|
|
|
kTLS13LabelClientHandshakeTraffic,
|
|
|
|
strlen(kTLS13LabelClientHandshakeTraffic)) ||
|
|
|
|
!ssl_log_secret(ssl, "CLIENT_HANDSHAKE_TRAFFIC_SECRET",
|
|
|
|
hs->client_handshake_secret, hs->hash_len) ||
|
|
|
|
!derive_secret(hs, hs->server_handshake_secret, hs->hash_len,
|
|
|
|
kTLS13LabelServerHandshakeTraffic,
|
|
|
|
strlen(kTLS13LabelServerHandshakeTraffic)) ||
|
|
|
|
!ssl_log_secret(ssl, "SERVER_HANDSHAKE_TRAFFIC_SECRET",
|
|
|
|
hs->server_handshake_secret, hs->hash_len)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssl->ctx->quic_method != nullptr) {
|
|
|
|
if (ssl->server) {
|
|
|
|
if (!ssl->ctx->quic_method->set_encryption_secrets(
|
|
|
|
ssl, ssl_encryption_handshake, hs->client_handshake_secret,
|
|
|
|
hs->server_handshake_secret, hs->hash_len)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ssl->ctx->quic_method->set_encryption_secrets(
|
|
|
|
ssl, ssl_encryption_handshake, hs->server_handshake_secret,
|
|
|
|
hs->client_handshake_secret, hs->hash_len)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_derive_application_secrets(SSL_HANDSHAKE *hs) {
|
2016-11-17 07:43:08 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2016-11-01 17:39:36 +00:00
|
|
|
ssl->s3->exporter_secret_len = hs->hash_len;
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!derive_secret(hs, hs->client_traffic_secret_0, hs->hash_len,
|
|
|
|
kTLS13LabelClientApplicationTraffic,
|
|
|
|
strlen(kTLS13LabelClientApplicationTraffic)) ||
|
|
|
|
!ssl_log_secret(ssl, "CLIENT_TRAFFIC_SECRET_0",
|
|
|
|
hs->client_traffic_secret_0, hs->hash_len) ||
|
|
|
|
!derive_secret(hs, hs->server_traffic_secret_0, hs->hash_len,
|
|
|
|
kTLS13LabelServerApplicationTraffic,
|
|
|
|
strlen(kTLS13LabelServerApplicationTraffic)) ||
|
|
|
|
!ssl_log_secret(ssl, "SERVER_TRAFFIC_SECRET_0",
|
|
|
|
hs->server_traffic_secret_0, hs->hash_len) ||
|
|
|
|
!derive_secret(hs, ssl->s3->exporter_secret, hs->hash_len,
|
|
|
|
kTLS13LabelExporter, strlen(kTLS13LabelExporter)) ||
|
|
|
|
!ssl_log_secret(ssl, "EXPORTER_SECRET", ssl->s3->exporter_secret,
|
|
|
|
hs->hash_len)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssl->ctx->quic_method != nullptr) {
|
|
|
|
if (ssl->server) {
|
|
|
|
if (!ssl->ctx->quic_method->set_encryption_secrets(
|
|
|
|
ssl, ssl_encryption_application, hs->client_traffic_secret_0,
|
|
|
|
hs->server_traffic_secret_0, hs->hash_len)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ssl->ctx->quic_method->set_encryption_secrets(
|
|
|
|
ssl, ssl_encryption_application, hs->server_traffic_secret_0,
|
|
|
|
hs->client_traffic_secret_0, hs->hash_len)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_INTERNAL_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
static const char kTLS13LabelApplicationTraffic[] = "traffic upd";
|
2016-10-03 17:25:56 +01:00
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction) {
|
2016-07-26 17:27:38 +01:00
|
|
|
uint8_t *secret;
|
|
|
|
size_t secret_len;
|
|
|
|
if (direction == evp_aead_open) {
|
|
|
|
secret = ssl->s3->read_traffic_secret;
|
|
|
|
secret_len = ssl->s3->read_traffic_secret_len;
|
|
|
|
} else {
|
|
|
|
secret = ssl->s3->write_traffic_secret;
|
|
|
|
secret_len = ssl->s3->write_traffic_secret_len;
|
|
|
|
}
|
|
|
|
|
2017-10-03 20:06:29 +01:00
|
|
|
const EVP_MD *digest = ssl_session_get_digest(SSL_get_session(ssl));
|
2018-07-14 16:23:01 +01:00
|
|
|
if (!hkdf_expand_label(secret, digest, secret, secret_len,
|
|
|
|
kTLS13LabelApplicationTraffic,
|
|
|
|
strlen(kTLS13LabelApplicationTraffic), NULL, 0,
|
|
|
|
secret_len, ssl->ctx->quic_method != nullptr)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-26 17:27:38 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
return tls13_set_traffic_key(ssl, ssl_encryption_application, direction,
|
|
|
|
secret, secret_len);
|
2016-07-26 17:27:38 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
static const char kTLS13LabelResumption[] = "res master";
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_derive_resumption_secret(SSL_HANDSHAKE *hs) {
|
2017-02-10 01:01:26 +00:00
|
|
|
if (hs->hash_len > SSL_MAX_MASTER_KEY_LENGTH) {
|
2016-11-23 17:39:29 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-23 17:39:29 +00:00
|
|
|
}
|
2017-02-10 01:01:26 +00:00
|
|
|
hs->new_session->master_key_length = hs->hash_len;
|
2017-12-08 22:05:06 +00:00
|
|
|
return derive_secret(hs, hs->new_session->master_key,
|
2018-01-22 20:20:31 +00:00
|
|
|
hs->new_session->master_key_length,
|
|
|
|
kTLS13LabelResumption, strlen(kTLS13LabelResumption));
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
2016-07-11 18:19:03 +01:00
|
|
|
|
2016-11-01 17:39:36 +00:00
|
|
|
static const char kTLS13LabelFinished[] = "finished";
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// tls13_verify_data sets |out| to be the HMAC of |context| using a derived
|
|
|
|
// Finished key for both Finished messages and the PSK binder.
|
2018-09-06 00:44:15 +01:00
|
|
|
static bool tls13_verify_data(const EVP_MD *digest, uint16_t version,
|
|
|
|
uint8_t *out, size_t *out_len,
|
|
|
|
const uint8_t *secret, size_t hash_len,
|
2018-07-14 16:23:01 +01:00
|
|
|
uint8_t *context, size_t context_len,
|
|
|
|
bool use_quic) {
|
2016-11-01 17:39:36 +00:00
|
|
|
uint8_t key[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned len;
|
2018-01-22 20:20:31 +00:00
|
|
|
if (!hkdf_expand_label(key, digest, secret, hash_len, kTLS13LabelFinished,
|
2018-07-14 16:23:01 +01:00
|
|
|
strlen(kTLS13LabelFinished), NULL, 0, hash_len,
|
|
|
|
use_quic) ||
|
2016-11-01 17:39:36 +00:00
|
|
|
HMAC(digest, key, hash_len, context, context_len, out, &len) == NULL) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
2016-11-01 17:39:36 +00:00
|
|
|
*out_len = len;
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len,
|
|
|
|
bool is_server) {
|
2016-08-31 21:58:36 +01:00
|
|
|
const uint8_t *traffic_secret;
|
2017-03-26 04:24:23 +01:00
|
|
|
if (is_server) {
|
|
|
|
traffic_secret = hs->server_handshake_secret;
|
2016-07-11 18:19:03 +01:00
|
|
|
} else {
|
2017-03-26 04:24:23 +01:00
|
|
|
traffic_secret = hs->client_handshake_secret;
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
|
|
|
|
2016-11-01 17:39:36 +00:00
|
|
|
uint8_t context_hash[EVP_MAX_MD_SIZE];
|
|
|
|
size_t context_hash_len;
|
2017-07-19 21:38:21 +01:00
|
|
|
if (!hs->transcript.GetHash(context_hash, &context_hash_len) ||
|
2017-10-11 17:29:36 +01:00
|
|
|
!tls13_verify_data(hs->transcript.Digest(), hs->ssl->version, out,
|
|
|
|
out_len, traffic_secret, hs->hash_len, context_hash,
|
2018-07-14 16:23:01 +01:00
|
|
|
context_hash_len,
|
|
|
|
hs->ssl->ctx->quic_method != nullptr)) {
|
2016-07-11 18:19:03 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:29:36 +01:00
|
|
|
static const char kTLS13LabelResumptionPSK[] = "resumption";
|
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
bool tls13_derive_session_psk(SSL_SESSION *session, Span<const uint8_t> nonce,
|
|
|
|
bool use_quic) {
|
2017-10-11 17:29:36 +01:00
|
|
|
const EVP_MD *digest = ssl_session_get_digest(session);
|
2018-01-22 20:20:31 +00:00
|
|
|
return hkdf_expand_label(session->master_key, digest, session->master_key,
|
|
|
|
session->master_key_length, kTLS13LabelResumptionPSK,
|
2017-10-11 17:29:36 +01:00
|
|
|
strlen(kTLS13LabelResumptionPSK), nonce.data(),
|
2018-07-14 16:23:01 +01:00
|
|
|
nonce.size(), session->master_key_length, use_quic);
|
2017-10-11 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char kTLS13LabelExportKeying[] = "exporter";
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_export_keying_material(SSL *ssl, Span<uint8_t> out,
|
|
|
|
Span<const uint8_t> secret,
|
|
|
|
Span<const char> label,
|
|
|
|
Span<const uint8_t> context) {
|
2017-12-08 22:05:06 +00:00
|
|
|
if (secret.empty()) {
|
|
|
|
assert(0);
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2017-10-11 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
2017-10-03 20:06:29 +01:00
|
|
|
const EVP_MD *digest = ssl_session_get_digest(SSL_get_session(ssl));
|
2017-10-11 17:29:36 +01:00
|
|
|
|
|
|
|
uint8_t hash[EVP_MAX_MD_SIZE];
|
|
|
|
uint8_t export_context[EVP_MAX_MD_SIZE];
|
|
|
|
uint8_t derived_secret[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned hash_len;
|
|
|
|
unsigned export_context_len;
|
|
|
|
unsigned derived_secret_len = EVP_MD_size(digest);
|
2017-12-08 22:05:06 +00:00
|
|
|
return EVP_Digest(context.data(), context.size(), hash, &hash_len, digest,
|
|
|
|
nullptr) &&
|
|
|
|
EVP_Digest(nullptr, 0, export_context, &export_context_len, digest,
|
|
|
|
nullptr) &&
|
2018-01-22 20:20:31 +00:00
|
|
|
hkdf_expand_label(derived_secret, digest, secret.data(), secret.size(),
|
|
|
|
label.data(), label.size(), export_context,
|
2018-07-14 16:23:01 +01:00
|
|
|
export_context_len, derived_secret_len,
|
|
|
|
ssl->ctx->quic_method != nullptr) &&
|
2018-01-22 20:20:31 +00:00
|
|
|
hkdf_expand_label(out.data(), digest, derived_secret,
|
2017-12-08 22:05:06 +00:00
|
|
|
derived_secret_len, kTLS13LabelExportKeying,
|
|
|
|
strlen(kTLS13LabelExportKeying), hash, hash_len,
|
2018-07-14 16:23:01 +01:00
|
|
|
out.size(), ssl->ctx->quic_method != nullptr);
|
2016-07-11 18:19:03 +01:00
|
|
|
}
|
2016-11-01 17:39:36 +00:00
|
|
|
|
2018-01-22 20:20:31 +00:00
|
|
|
static const char kTLS13LabelPSKBinder[] = "res binder";
|
2016-11-01 17:39:36 +00:00
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
static bool tls13_psk_binder(uint8_t *out, uint16_t version,
|
|
|
|
const EVP_MD *digest, uint8_t *psk, size_t psk_len,
|
|
|
|
uint8_t *context, size_t context_len,
|
2018-07-14 16:23:01 +01:00
|
|
|
size_t hash_len, bool use_quic) {
|
2016-11-01 17:39:36 +00:00
|
|
|
uint8_t binder_context[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned binder_context_len;
|
|
|
|
if (!EVP_Digest(NULL, 0, binder_context, &binder_context_len, digest, NULL)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t early_secret[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
size_t early_secret_len;
|
|
|
|
if (!HKDF_extract(early_secret, &early_secret_len, digest, psk, hash_len,
|
|
|
|
NULL, 0)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t binder_key[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
size_t len;
|
2018-01-22 20:20:31 +00:00
|
|
|
if (!hkdf_expand_label(binder_key, digest, early_secret, hash_len,
|
|
|
|
kTLS13LabelPSKBinder, strlen(kTLS13LabelPSKBinder),
|
2018-07-14 16:23:01 +01:00
|
|
|
binder_context, binder_context_len, hash_len,
|
|
|
|
use_quic) ||
|
2017-10-11 17:29:36 +01:00
|
|
|
!tls13_verify_data(digest, version, out, &len, binder_key, hash_len,
|
2018-07-14 16:23:01 +01:00
|
|
|
context, context_len, use_quic)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_write_psk_binder(SSL_HANDSHAKE *hs, uint8_t *msg, size_t len) {
|
2017-01-12 18:17:07 +00:00
|
|
|
SSL *const ssl = hs->ssl;
|
2018-07-03 00:47:27 +01:00
|
|
|
const EVP_MD *digest = ssl_session_get_digest(ssl->session.get());
|
2016-11-01 17:39:36 +00:00
|
|
|
size_t hash_len = EVP_MD_size(digest);
|
|
|
|
|
|
|
|
if (len < hash_len + 3) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 04:57:40 +01:00
|
|
|
ScopedEVP_MD_CTX ctx;
|
2016-11-01 17:39:36 +00:00
|
|
|
uint8_t context[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned context_len;
|
2017-10-11 17:29:36 +01:00
|
|
|
|
2017-07-20 04:57:40 +01:00
|
|
|
if (!EVP_DigestInit_ex(ctx.get(), digest, NULL) ||
|
2017-10-11 22:19:19 +01:00
|
|
|
!EVP_DigestUpdate(ctx.get(), hs->transcript.buffer().data(),
|
|
|
|
hs->transcript.buffer().size()) ||
|
2017-07-20 04:57:40 +01:00
|
|
|
!EVP_DigestUpdate(ctx.get(), msg, len - hash_len - 3) ||
|
|
|
|
!EVP_DigestFinal_ex(ctx.get(), context, &context_len)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t verify_data[EVP_MAX_MD_SIZE] = {0};
|
2017-10-11 17:29:36 +01:00
|
|
|
if (!tls13_psk_binder(verify_data, ssl->session->ssl_version, digest,
|
|
|
|
ssl->session->master_key,
|
2017-01-12 18:17:07 +00:00
|
|
|
ssl->session->master_key_length, context, context_len,
|
2018-07-14 16:23:01 +01:00
|
|
|
hash_len, ssl->ctx->quic_method != nullptr)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 06:07:13 +00:00
|
|
|
OPENSSL_memcpy(msg + len - hash_len, verify_data, hash_len);
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
bool tls13_verify_psk_binder(SSL_HANDSHAKE *hs, SSL_SESSION *session,
|
|
|
|
const SSLMessage &msg, CBS *binders) {
|
2017-07-19 21:38:21 +01:00
|
|
|
size_t hash_len = hs->transcript.DigestLen();
|
2016-11-01 17:39:36 +00:00
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// The message must be large enough to exclude the binders.
|
2017-08-01 21:32:25 +01:00
|
|
|
if (CBS_len(&msg.raw) < CBS_len(binders) + 2) {
|
2016-11-01 17:39:36 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 21:33:21 +01:00
|
|
|
// Hash a ClientHello prefix up to the binders. This includes the header. For
|
|
|
|
// now, this assumes we only ever verify PSK binders on initial
|
|
|
|
// ClientHellos.
|
2016-11-01 17:39:36 +00:00
|
|
|
uint8_t context[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned context_len;
|
2017-08-01 21:32:25 +01:00
|
|
|
if (!EVP_Digest(CBS_data(&msg.raw), CBS_len(&msg.raw) - CBS_len(binders) - 2,
|
2017-07-19 21:38:21 +01:00
|
|
|
context, &context_len, hs->transcript.Digest(), NULL)) {
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t verify_data[EVP_MAX_MD_SIZE] = {0};
|
|
|
|
CBS binder;
|
2017-10-11 17:29:36 +01:00
|
|
|
if (!tls13_psk_binder(verify_data, hs->ssl->version, hs->transcript.Digest(),
|
2017-01-12 18:17:07 +00:00
|
|
|
session->master_key, session->master_key_length,
|
2018-07-14 16:23:01 +01:00
|
|
|
context, context_len, hash_len,
|
|
|
|
hs->ssl->ctx->quic_method != nullptr) ||
|
2017-08-29 21:33:21 +01:00
|
|
|
// We only consider the first PSK, so compare against the first binder.
|
2016-11-01 17:39:36 +00:00
|
|
|
!CBS_get_u8_length_prefixed(binders, &binder)) {
|
|
|
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 16:23:01 +01:00
|
|
|
bool binder_ok = CBS_len(&binder) == hash_len &&
|
|
|
|
CRYPTO_memcmp(CBS_data(&binder), verify_data, hash_len) == 0;
|
2016-11-14 12:19:17 +00:00
|
|
|
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
2018-09-06 00:44:15 +01:00
|
|
|
binder_ok = true;
|
2016-11-14 12:19:17 +00:00
|
|
|
#endif
|
|
|
|
if (!binder_ok) {
|
2016-11-01 17:39:36 +00:00
|
|
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DIGEST_CHECK_FAILED);
|
2018-09-06 00:44:15 +01:00
|
|
|
return false;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 00:44:15 +01:00
|
|
|
return true;
|
2016-11-01 17:39:36 +00:00
|
|
|
}
|
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
|
|
|
|
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
|