Skip to content

Commit

Permalink
update master-with-bazel from master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
BoringSSL Robot committed Feb 14, 2020
2 parents 471134e + 754d4c9 commit e770d42
Show file tree
Hide file tree
Showing 12 changed files with 420 additions and 300 deletions.
566 changes: 284 additions & 282 deletions err_data.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/crypto/err/ssl.errordata
Expand Up @@ -36,6 +36,7 @@ SSL,292,CERT_DECOMPRESSION_FAILED
SSL,127,CERT_LENGTH_MISMATCH
SSL,128,CHANNEL_ID_NOT_P256
SSL,129,CHANNEL_ID_SIGNATURE_INVALID
SSL,304,CIPHER_MISMATCH_ON_EARLY_DATA
SSL,130,CIPHER_OR_HASH_UNAVAILABLE
SSL,131,CLIENTHELLO_PARSE_FAILED
SSL,132,CLIENTHELLO_TLSEXT
Expand Down
6 changes: 6 additions & 0 deletions src/include/openssl/ssl.h
Expand Up @@ -3192,6 +3192,11 @@ struct ssl_quic_method_st {
// This function should use |SSL_get_current_cipher| to determine the TLS
// cipher suite.
//
// TODO(davidben): The advice to use |SSL_get_current_cipher| does not work
// for 0-RTT rejects on the client. As part of the fix to
// https://crbug.com/boringssl/303, we will add an explicit cipher suite
// parameter.
//
// It returns one on success and zero on error.
int (*set_encryption_secrets)(SSL *ssl, enum ssl_encryption_level_t level,
const uint8_t *read_secret,
Expand Down Expand Up @@ -5070,6 +5075,7 @@ BSSL_NAMESPACE_END
#define SSL_R_INVALID_DELEGATED_CREDENTIAL 301
#define SSL_R_KEY_USAGE_BIT_INCORRECT 302
#define SSL_R_INCONSISTENT_CLIENT_HELLO 303
#define SSL_R_CIPHER_MISMATCH_ON_EARLY_DATA 304
#define SSL_R_SSLV3_ALERT_CLOSE_NOTIFY 1000
#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
Expand Down
1 change: 1 addition & 0 deletions src/ssl/handoff.cc
Expand Up @@ -654,6 +654,7 @@ bool SSL_apply_handback(SSL *ssl, Span<const uint8_t> handback) {
// none of the read keys. The read keys are installed in the state machine
// immediately after processing handback.
if (!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_seal,
hs->new_session.get(),
hs->server_traffic_secret_0())) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ssl/handshake_client.cc
Expand Up @@ -463,7 +463,7 @@ static enum ssl_hs_wait_t do_enter_early_data(SSL_HANDSHAKE *hs) {
}
if (ssl->quic_method == nullptr &&
!tls13_set_traffic_key(ssl, ssl_encryption_early_data, evp_aead_seal,
hs->early_traffic_secret())) {
ssl->session.get(), hs->early_traffic_secret())) {
return ssl_hs_error;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ssl/internal.h
Expand Up @@ -1356,9 +1356,11 @@ bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
bool tls13_advance_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> in);

// tls13_set_traffic_key sets the read or write traffic keys to
// |traffic_secret|. It returns true on success and false on error.
// |traffic_secret|. The version and cipher suite are determined from |session|.
// It returns true on success and false on error.
bool tls13_set_traffic_key(SSL *ssl, enum ssl_encryption_level_t level,
enum evp_aead_direction_t direction,
const SSL_SESSION *session,
Span<const uint8_t> traffic_secret);

// tls13_derive_early_secret derives the early traffic secret. It returns true
Expand Down
10 changes: 7 additions & 3 deletions src/ssl/ssl_session.cc
Expand Up @@ -624,10 +624,14 @@ int ssl_session_is_resumable(const SSL_HANDSHAKE *hs,
ssl->server == session->is_server &&
// The session must not be expired.
ssl_session_is_time_valid(ssl, session) &&
/* Only resume if the session's version matches the negotiated
* version. */
// Only resume if the session's version matches the negotiated
// version.
ssl->version == session->ssl_version &&
// Only resume if the session's cipher matches the negotiated one.
// Only resume if the session's cipher matches the negotiated one. This
// is stricter than necessary for TLS 1.3, which allows cross-cipher
// resumption if the PRF hashes match. We require an exact match for
// simplicity. If loosening this, the 0-RTT accept logic must be
// updated to check the cipher.
hs->new_cipher == session->cipher &&
// If the session contains a client certificate (either the full
// certificate or just the hash) then require that the form of the
Expand Down
2 changes: 1 addition & 1 deletion src/ssl/test/runner/fuzzer_mode.json
Expand Up @@ -42,7 +42,7 @@
"EarlyData-ALPNOmitted1-Server-*": "Trial decryption does not work with the NULL cipher.",
"EarlyData-ALPNOmitted2-Server-*": "Trial decryption does not work with the NULL cipher.",
"*-EarlyData-RejectUnfinishedWrite-Client-*": "Trial decryption does not work with the NULL cipher.",
"EarlyData-Reject*-Client-*": "Trial decryption does not work with the NULL cipher.",
"EarlyData-Reject*-Client*": "Trial decryption does not work with the NULL cipher.",
"CustomExtensions-Server-EarlyDataOffered": "Trial decryption does not work with the NULL cipher.",
"*-TicketAgeSkew-*-Reject*": "Trial decryption does not work with the NULL cipher.",

Expand Down
94 changes: 88 additions & 6 deletions src/ssl/test/runner/runner.go
Expand Up @@ -13565,8 +13565,9 @@ func addTLS13HandshakeTests() {
"-on-resume-expect-alpn", "foo",
"-on-retry-expect-alpn", "bar",
},
shouldFail: true,
expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
shouldFail: true,
expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
expectedLocalError: "remote error: illegal parameter",
})

// Test that the client does not offer early data if it is incompatible
Expand Down Expand Up @@ -13723,10 +13724,11 @@ func addTLS13HandshakeTests() {
MaxEarlyDataSize: 16384,
RequestChannelID: true,
},
resumeSession: true,
expectChannelID: true,
shouldFail: true,
expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
resumeSession: true,
expectChannelID: true,
shouldFail: true,
expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
expectedLocalError: "remote error: illegal parameter",
flags: []string{
"-enable-early-data",
"-expect-ticket-supports-early-data",
Expand Down Expand Up @@ -14042,6 +14044,86 @@ func addTLS13HandshakeTests() {
"-expect-early-data-reason", "protocol_version",
},
})

// On 0-RTT reject, the server may end up negotiating a cipher suite with a
// different PRF hash. Test that the client handles this correctly.
testCases = append(testCases, testCase{
testType: clientTest,
name: "EarlyData-Reject0RTT-DifferentPRF-Client",
config: Config{
MaxVersion: VersionTLS13,
CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
MaxEarlyDataSize: 16384,
},
resumeConfig: &Config{
MaxVersion: VersionTLS13,
MaxEarlyDataSize: 16384,
CipherSuites: []uint16{TLS_AES_256_GCM_SHA384},
},
resumeSession: true,
expectResumeRejected: true,
flags: []string{
"-enable-early-data",
"-expect-reject-early-data",
"-expect-ticket-supports-early-data",
"-on-resume-shim-writes-first",
},
})
testCases = append(testCases, testCase{
testType: clientTest,
name: "EarlyData-Reject0RTT-DifferentPRF-HRR-Client",
config: Config{
MaxVersion: VersionTLS13,
CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
MaxEarlyDataSize: 16384,
},
resumeConfig: &Config{
MaxVersion: VersionTLS13,
MaxEarlyDataSize: 16384,
CipherSuites: []uint16{TLS_AES_256_GCM_SHA384},
// P-384 requires a HelloRetryRequest against BoringSSL's default
// configuration. Assert this with ExpectMissingKeyShare.
CurvePreferences: []CurveID{CurveP384},
Bugs: ProtocolBugs{
ExpectMissingKeyShare: true,
},
},
resumeSession: true,
expectResumeRejected: true,
flags: []string{
"-enable-early-data",
"-expect-reject-early-data",
"-expect-ticket-supports-early-data",
"-on-resume-shim-writes-first",
},
})

// Test that the client enforces cipher suite match on 0-RTT accept.
testCases = append(testCases, testCase{
testType: clientTest,
name: "EarlyData-CipherMismatch-Client-TLS13",
config: Config{
MaxVersion: VersionTLS13,
MaxEarlyDataSize: 16384,
CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
},
resumeConfig: &Config{
MaxVersion: VersionTLS13,
MaxEarlyDataSize: 16384,
CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
Bugs: ProtocolBugs{
AlwaysAcceptEarlyData: true,
},
},
resumeSession: true,
flags: []string{
"-enable-early-data",
"-expect-ticket-supports-early-data",
},
shouldFail: true,
expectedError: ":CIPHER_MISMATCH_ON_EARLY_DATA:",
expectedLocalError: "remote error: illegal parameter",
})
}

func addTLS13CipherPreferenceTests() {
Expand Down
17 changes: 14 additions & 3 deletions src/ssl/tls13_client.cc
Expand Up @@ -400,6 +400,7 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
!ssl_hash_message(hs, msg) ||
!tls13_derive_handshake_secrets(hs) ||
!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open,
hs->new_session.get(),
hs->server_handshake_secret())) {
return ssl_hs_error;
}
Expand All @@ -408,6 +409,7 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
// If not sending early data, set client traffic keys now so that alerts are
// encrypted.
if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal,
hs->new_session.get(),
hs->client_handshake_secret())) {
return ssl_hs_error;
}
Expand Down Expand Up @@ -446,14 +448,20 @@ static enum ssl_hs_wait_t do_read_encrypted_extensions(SSL_HANDSHAKE *hs) {
}

if (ssl->s3->early_data_accepted) {
if (hs->early_session->cipher != hs->new_session->cipher ||
MakeConstSpan(hs->early_session->early_alpn) !=
ssl->s3->alpn_selected) {
if (hs->early_session->cipher != hs->new_session->cipher) {
OPENSSL_PUT_ERROR(SSL, SSL_R_CIPHER_MISMATCH_ON_EARLY_DATA);
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
return ssl_hs_error;
}
if (MakeConstSpan(hs->early_session->early_alpn) !=
ssl->s3->alpn_selected) {
OPENSSL_PUT_ERROR(SSL, SSL_R_ALPN_MISMATCH_ON_EARLY_DATA);
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
return ssl_hs_error;
}
if (ssl->s3->channel_id_valid || ssl->s3->token_binding_negotiated) {
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION_ON_EARLY_DATA);
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
return ssl_hs_error;
}
}
Expand Down Expand Up @@ -661,6 +669,7 @@ static enum ssl_hs_wait_t do_send_end_of_early_data(SSL_HANDSHAKE *hs) {

if (hs->early_data_offered) {
if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal,
hs->new_session.get(),
hs->client_handshake_secret())) {
return ssl_hs_error;
}
Expand Down Expand Up @@ -756,8 +765,10 @@ static enum ssl_hs_wait_t do_complete_second_flight(SSL_HANDSHAKE *hs) {

// Derive the final keys and enable them.
if (!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_open,
hs->new_session.get(),
hs->server_traffic_secret_0()) ||
!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_seal,
hs->new_session.get(),
hs->client_traffic_secret_0()) ||
!tls13_derive_resumption_secret(hs)) {
return ssl_hs_error;
Expand Down
7 changes: 4 additions & 3 deletions src/ssl/tls13_enc.cc
Expand Up @@ -139,8 +139,8 @@ static bool derive_secret(SSL_HANDSHAKE *hs, Span<uint8_t> out,

bool tls13_set_traffic_key(SSL *ssl, enum ssl_encryption_level_t level,
enum evp_aead_direction_t direction,
const SSL_SESSION *session,
Span<const uint8_t> traffic_secret) {
const SSL_SESSION *session = SSL_get_session(ssl);
uint16_t version = ssl_session_protocol_version(session);

UniquePtr<SSLAEADContext> traffic_aead;
Expand Down Expand Up @@ -341,11 +341,12 @@ bool tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction) {
ssl->s3->write_traffic_secret_len);
}

const EVP_MD *digest = ssl_session_get_digest(SSL_get_session(ssl));
const SSL_SESSION *session = SSL_get_session(ssl);
const EVP_MD *digest = ssl_session_get_digest(session);
return hkdf_expand_label(secret, digest, secret,
label_to_span(kTLS13LabelApplicationTraffic), {}) &&
tls13_set_traffic_key(ssl, ssl_encryption_application, direction,
secret);
session, secret);
}

static const char kTLS13LabelResumption[] = "res master";
Expand Down
10 changes: 10 additions & 0 deletions src/ssl/tls13_server.cc
Expand Up @@ -352,6 +352,10 @@ static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
return ssl_hs_error;
}

// |ssl_session_is_resumable| forbids cross-cipher resumptions even if the
// PRF hashes match.
assert(hs->new_cipher == session->cipher);

if (!ssl->enable_early_data) {
ssl->s3->early_data_reason = ssl_early_data_disabled;
} else if (session->ticket_max_early_data == 0) {
Expand Down Expand Up @@ -600,6 +604,7 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
// Derive and enable the handshake traffic secrets.
if (!tls13_derive_handshake_secrets(hs) ||
!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_seal,
hs->new_session.get(),
hs->server_handshake_secret())) {
return ssl_hs_error;
}
Expand Down Expand Up @@ -700,6 +705,7 @@ static enum ssl_hs_wait_t do_send_server_finished(SSL_HANDSHAKE *hs) {
hs, MakeConstSpan(kZeroes, hs->transcript.DigestLen())) ||
!tls13_derive_application_secrets(hs) ||
!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_seal,
hs->new_session.get(),
hs->server_traffic_secret_0())) {
return ssl_hs_error;
}
Expand Down Expand Up @@ -776,6 +782,7 @@ static enum ssl_hs_wait_t do_read_second_client_flight(SSL_HANDSHAKE *hs) {
// QUIC never receives handshake messages under 0-RTT keys.
if (ssl->quic_method == nullptr &&
!tls13_set_traffic_key(ssl, ssl_encryption_early_data, evp_aead_open,
hs->new_session.get(),
hs->early_traffic_secret())) {
return ssl_hs_error;
}
Expand All @@ -789,6 +796,7 @@ static enum ssl_hs_wait_t do_read_second_client_flight(SSL_HANDSHAKE *hs) {
// return.
if (ssl->quic_method != nullptr) {
if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open,
hs->new_session.get(),
hs->client_handshake_secret())) {
return ssl_hs_error;
}
Expand Down Expand Up @@ -821,6 +829,7 @@ static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) {
ssl->method->next_message(ssl);
}
if (!tls13_set_traffic_key(ssl, ssl_encryption_handshake, evp_aead_open,
hs->new_session.get(),
hs->client_handshake_secret())) {
return ssl_hs_error;
}
Expand Down Expand Up @@ -931,6 +940,7 @@ static enum ssl_hs_wait_t do_read_client_finished(SSL_HANDSHAKE *hs) {
!tls13_process_finished(hs, msg, ssl->s3->early_data_accepted) ||
// evp_aead_seal keys have already been switched.
!tls13_set_traffic_key(ssl, ssl_encryption_application, evp_aead_open,
hs->new_session.get(),
hs->client_traffic_secret_0())) {
return ssl_hs_error;
}
Expand Down

0 comments on commit e770d42

Please sign in to comment.