Implement ClientHelloOuter handshakes.
If a client offers ECH, but the server rejects it, the client completes
the handshake with ClientHelloOuter in order to authenticate retry keys.
Implement this flow. This is largely allowing the existing handshake to
proceed, but with some changes:
- Certificate verification uses the other name. This CL routes this up to
the built-in verifier and adds SSL_get0_ech_name_override for the
callback.
- We need to disable False Start to pick up server Finished in TLS 1.2.
- Client certificates, notably in TLS 1.3 where they're encrypted,
should only be revealed to the true server. Fortunately, not sending
client certs is always an option, so do that.
Channel ID has a similar issue. I've just omitted the extension in
ClientHelloOuter because it's deprecated and is unlikely to be used
with ECH at this point. ALPS may be worth some pondering but, the way
it's currently used, is not sensitive.
(Possibly we should change the draft to terminate the handshake before
even sending that flight...)
- The session is never offered in ClientHelloOuter, but our internal
book-keeping doesn't quite notice.
I had to replace ech_accept with a tri-state ech_status to correctly
handle an edge case in SSL_get0_ech_name_override: when ECH + 0-RTT +
reverify_on_resume are all enabled, the first certificate verification
is for the 0-RTT session and should be against the true name, yet we
have selected_ech_config && !ech_accept. A tri-state tracks when ECH is
actually rejected. I've maintained this on the server as well, though
the server never actually cares.
Bug: 275
Change-Id: Ie55966ca3dc4ffcc8c381479f0fe9bcacd34d0f8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/48135
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/ssl/extensions.cc b/ssl/extensions.cc
index 69a2bdc..4950d26 100644
--- a/ssl/extensions.cc
+++ b/ssl/extensions.cc
@@ -654,6 +654,11 @@
return false;
}
+ if (!ssl_is_valid_ech_config_list(*contents)) {
+ *out_alert = SSL_AD_DECODE_ERROR;
+ return false;
+ }
+
// The server may only send retry configs in response to ClientHelloOuter (or
// ECH GREASE), not ClientHelloInner. The unsolicited extension rule checks
// this implicitly because the ClientHelloInner has no encrypted_client_hello
@@ -663,14 +668,13 @@
// https://github.com/tlswg/draft-ietf-tls-esni/pull/422 is merged, a later
// draft will fold encrypted_client_hello and ech_is_inner together. Then this
// assert should become a runtime check.
- assert(!ssl->s3->ech_accept);
-
- // TODO(https://crbug.com/boringssl/275): When the implementing the
- // ClientHelloOuter flow, save the retry configs.
- if (!ssl_is_valid_ech_config_list(*contents)) {
- *out_alert = SSL_AD_DECODE_ERROR;
+ assert(ssl->s3->ech_status != ssl_ech_accepted);
+ if (hs->selected_ech_config &&
+ !hs->ech_retry_configs.CopyFrom(*contents)) {
+ *out_alert = SSL_AD_INTERNAL_ERROR;
return false;
}
+
return true;
}
@@ -685,8 +689,8 @@
static bool ext_ech_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
SSL *const ssl = hs->ssl;
- if (ssl_protocol_version(ssl) < TLS1_3_VERSION || //
- ssl->s3->ech_accept || //
+ if (ssl_protocol_version(ssl) < TLS1_3_VERSION ||
+ ssl->s3->ech_status == ssl_ech_accepted || //
hs->ech_keys == nullptr) {
return true;
}
@@ -1634,12 +1638,21 @@
CBB *out_compressible,
ssl_client_hello_type_t type) {
const SSL *const ssl = hs->ssl;
- if (!hs->config->channel_id_private || SSL_is_dtls(ssl)) {
+ if (!hs->config->channel_id_private || SSL_is_dtls(ssl) ||
+ // Don't offer Channel ID in ClientHelloOuter. ClientHelloOuter handshakes
+ // are not authenticated for the name that can learn the Channel ID.
+ //
+ // We could alternatively offer the extension but sign with a random key.
+ // For other extensions, we try to align |ssl_client_hello_outer| and
+ // |ssl_client_hello_unencrypted|, to improve the effectiveness of ECH
+ // GREASE. However, Channel ID is deprecated and unlikely to be used with
+ // ECH, so do the simplest thing.
+ type == ssl_client_hello_outer) {
return true;
}
- if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_channel_id) ||
- !CBB_add_u16(out_compressible, 0 /* length */)) {
+ if (!CBB_add_u16(out, TLSEXT_TYPE_channel_id) ||
+ !CBB_add_u16(out, 0 /* length */)) {
return false;
}