Skip to content

Commit 372501f

Browse files
authored
fix(patch): Fix alps use new codepoint negotiation (#53)
1 parent 50437d5 commit 372501f

File tree

1 file changed

+126
-8
lines changed

1 file changed

+126
-8
lines changed

boring-sys/patches/boringssl-44b3df6f03d85c901767250329c571db405122d5.patch

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,7 +4270,7 @@ index 4dd8841b1..23ffcd446 100644
42704270
#if defined(__cplusplus)
42714271
} /* extern C */
42724272
diff --git a/src/include/openssl/ssl.h b/src/include/openssl/ssl.h
4273-
index 53aa9b453..1e93efda3 100644
4273+
index 53aa9b453..ea01fd665 100644
42744274
--- a/src/include/openssl/ssl.h
42754275
+++ b/src/include/openssl/ssl.h
42764276
@@ -718,6 +718,12 @@ OPENSSL_EXPORT int SSL_version(const SSL *ssl);
@@ -4357,6 +4357,14 @@ index 53aa9b453..1e93efda3 100644
43574357
#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0
43584358
#define SSL_OP_NO_SSLv2 0
43594359
#define SSL_OP_NO_SSLv3 0
4360+
@@ -5779,6 +5819,7 @@ BSSL_NAMESPACE_END
4361+
#define SSL_R_ECH_REJECTED 319
4362+
#define SSL_R_INVALID_OUTER_EXTENSION 320
4363+
#define SSL_R_INCONSISTENT_ECH_NEGOTIATION 321
4364+
+#define SSL_R_INVALID_ALPS_CODEPOINT 322
4365+
#define SSL_R_SSLV3_ALERT_CLOSE_NOTIFY 1000
4366+
#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
4367+
#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
43604368
diff --git a/src/include/openssl/tls1.h b/src/include/openssl/tls1.h
43614369
index 772fb87a3..955126a7a 100644
43624370
--- a/src/include/openssl/tls1.h
@@ -4400,7 +4408,7 @@ index 5c7e881bf..3c0770cf3 100644
44004408
crypto/pkcs8/test/no_encryption.p12
44014409
crypto/pkcs8/test/nss.p12
44024410
diff --git a/src/ssl/extensions.cc b/src/ssl/extensions.cc
4403-
index 5ee280221..dbdd8b305 100644
4411+
index 5ee280221..d1ae70aa1 100644
44044412
--- a/src/ssl/extensions.cc
44054413
+++ b/src/ssl/extensions.cc
44064414
@@ -207,6 +207,10 @@ static bool tls1_check_duplicate_extensions(const CBS *cbs) {
@@ -4694,7 +4702,24 @@ index 5ee280221..dbdd8b305 100644
46944702
bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
46954703
const SSL_CLIENT_HELLO *client_hello) {
46964704
SSL *const ssl = hs->ssl;
4697-
@@ -3094,6 +3211,39 @@ bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
4705+
@@ -3052,11 +3169,15 @@ bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
4706+
// If we negotiate ALPN over TLS 1.3, try to negotiate ALPS.
4707+
CBS alps_contents;
4708+
Span<const uint8_t> settings;
4709+
+ uint16_t extension_type = TLSEXT_TYPE_application_settings;
4710+
+ if (hs->config->alps_use_new_codepoint) {
4711+
+ extension_type = TLSEXT_TYPE_application_settings_new;
4712+
+ }
4713+
if (ssl_protocol_version(ssl) >= TLS1_3_VERSION &&
4714+
ssl_get_local_application_settings(hs, &settings,
4715+
ssl->s3->alpn_selected) &&
4716+
ssl_client_hello_get_extension(client_hello, &alps_contents,
4717+
- TLSEXT_TYPE_application_settings)) {
4718+
+ extension_type)) {
4719+
// Check if the client supports ALPS with the selected ALPN.
4720+
bool found = false;
4721+
CBS alps_list;
4722+
@@ -3094,6 +3215,39 @@ bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
46984723
return true;
46994724
}
47004725

@@ -4734,7 +4759,7 @@ index 5ee280221..dbdd8b305 100644
47344759
// kExtensions contains all the supported extensions.
47354760
static const struct tls_extension kExtensions[] = {
47364761
{
4737-
@@ -3267,6 +3417,21 @@ static const struct tls_extension kExtensions[] = {
4762+
@@ -3267,6 +3421,21 @@ static const struct tls_extension kExtensions[] = {
47384763
ignore_parse_clienthello,
47394764
ext_alps_add_serverhello,
47404765
},
@@ -4756,7 +4781,7 @@ index 5ee280221..dbdd8b305 100644
47564781
};
47574782

47584783
#define kNumExtensions (sizeof(kExtensions) / sizeof(struct tls_extension))
4759-
@@ -3280,6 +3445,12 @@ static_assert(kNumExtensions <=
4784+
@@ -3280,6 +3449,12 @@ static_assert(kNumExtensions <=
47604785

47614786
bool ssl_setup_extension_permutation(SSL_HANDSHAKE *hs) {
47624787
if (!hs->config->permute_extensions) {
@@ -4769,7 +4794,7 @@ index 5ee280221..dbdd8b305 100644
47694794
return true;
47704795
}
47714796

4772-
@@ -3357,10 +3528,16 @@ static bool ssl_add_clienthello_tlsext_inner(SSL_HANDSHAKE *hs, CBB *out,
4797+
@@ -3357,10 +3532,16 @@ static bool ssl_add_clienthello_tlsext_inner(SSL_HANDSHAKE *hs, CBB *out,
47734798
}
47744799
}
47754800

@@ -4787,7 +4812,7 @@ index 5ee280221..dbdd8b305 100644
47874812
const size_t len_before = CBB_len(&extensions);
47884813
const size_t len_compressed_before = CBB_len(compressed.get());
47894814
if (!kExtensions[i].add_clienthello(hs, &extensions, compressed.get(),
4790-
@@ -3466,10 +3643,16 @@ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded,
4815+
@@ -3466,10 +3647,16 @@ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded,
47914816
}
47924817

47934818
bool last_was_empty = false;
@@ -4806,7 +4831,7 @@ index 5ee280221..dbdd8b305 100644
48064831
if (!kExtensions[i].add_clienthello(hs, &extensions, &extensions, type)) {
48074832
OPENSSL_PUT_ERROR(SSL, SSL_R_ERROR_ADDING_EXTENSION);
48084833
diff --git a/src/ssl/handoff.cc b/src/ssl/handoff.cc
4809-
index 6e5cc2da1..6cd3ca430 100644
4834+
index 6e5cc2da1..b1b31f3a7 100644
48104835
--- a/src/ssl/handoff.cc
48114836
+++ b/src/ssl/handoff.cc
48124837
@@ -169,46 +169,46 @@ static bool apply_remote_features(SSL *ssl, CBS *in) {
@@ -4889,6 +4914,62 @@ index 6e5cc2da1..6cd3ca430 100644
48894914
supports_alps = true;
48904915
break;
48914916
}
4917+
@@ -442,6 +445,16 @@ bool SSL_serialize_handback(const SSL *ssl, CBB *out) {
4918+
hs->early_traffic_secret().size())) {
4919+
return false;
4920+
}
4921+
+
4922+
+ if (session->has_application_settings) {
4923+
+ uint16_t alps_codepoint = TLSEXT_TYPE_application_settings;
4924+
+ if (hs->config->alps_use_new_codepoint) {
4925+
+ alps_codepoint = TLSEXT_TYPE_application_settings_new;
4926+
+ }
4927+
+ if (!CBB_add_asn1_uint64(&seq, alps_codepoint)) {
4928+
+ return false;
4929+
+ }
4930+
+ }
4931+
}
4932+
return CBB_flush(out);
4933+
}
4934+
@@ -461,7 +474,8 @@ bool SSL_apply_handback(SSL *ssl, Span<const uint8_t> handback) {
4935+
}
4936+
4937+
SSL3_STATE *const s3 = ssl->s3;
4938+
- uint64_t handback_version, unused_token_binding_param, cipher, type_u64;
4939+
+ uint64_t handback_version, unused_token_binding_param, cipher, type_u64,
4940+
+ alps_codepoint;
4941+
4942+
CBS seq, read_seq, write_seq, server_rand, client_rand, read_iv, write_iv,
4943+
next_proto, alpn, hostname, unused_channel_id, transcript, key_share;
4944+
@@ -561,6 +575,28 @@ bool SSL_apply_handback(SSL *ssl, Span<const uint8_t> handback) {
4945+
!CBS_get_asn1(&seq, &early_traffic_secret, CBS_ASN1_OCTETSTRING)) {
4946+
return false;
4947+
}
4948+
+
4949+
+ if (session->has_application_settings) {
4950+
+ // Making it optional to keep compatibility with older handshakers.
4951+
+ // Older handshakers won't send the field.
4952+
+ if (CBS_len(&seq) == 0) {
4953+
+ hs->config->alps_use_new_codepoint = false;
4954+
+ } else {
4955+
+ if (!CBS_get_asn1_uint64(&seq, &alps_codepoint)) {
4956+
+ return false;
4957+
+ }
4958+
+
4959+
+ if (alps_codepoint == TLSEXT_TYPE_application_settings_new) {
4960+
+ hs->config->alps_use_new_codepoint = true;
4961+
+ } else if (alps_codepoint == TLSEXT_TYPE_application_settings) {
4962+
+ hs->config->alps_use_new_codepoint = false;
4963+
+ } else {
4964+
+ OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_ALPS_CODEPOINT);
4965+
+ return false;
4966+
+ }
4967+
+ }
4968+
+ }
4969+
+
4970+
if (ticket_age_skew > std::numeric_limits<int32_t>::max() ||
4971+
ticket_age_skew < std::numeric_limits<int32_t>::min()) {
4972+
return false;
48924973
diff --git a/src/ssl/handshake_client.cc b/src/ssl/handshake_client.cc
48934974
index 971ebd0b1..348fb93dc 100644
48944975
--- a/src/ssl/handshake_client.cc
@@ -6509,6 +6590,43 @@ index ef43a9e98..22178b5f6 100644
65096590
{
65106591
"P-256:P-384:P-521:X25519",
65116592
{
6593+
diff --git a/src/ssl/tls13_client.cc b/src/ssl/tls13_client.cc
6594+
index 1971596c9..fbc273540 100644
6595+
--- a/src/ssl/tls13_client.cc
6596+
+++ b/src/ssl/tls13_client.cc
6597+
@@ -812,10 +812,14 @@ static enum ssl_hs_wait_t do_send_client_encrypted_extensions(
6598+
!ssl->s3->early_data_accepted) {
6599+
ScopedCBB cbb;
6600+
CBB body, extensions, extension;
6601+
+ uint16_t extension_type = TLSEXT_TYPE_application_settings;
6602+
+ if (hs->config->alps_use_new_codepoint) {
6603+
+ extension_type = TLSEXT_TYPE_application_settings_new;
6604+
+ }
6605+
if (!ssl->method->init_message(ssl, cbb.get(), &body,
6606+
SSL3_MT_ENCRYPTED_EXTENSIONS) ||
6607+
!CBB_add_u16_length_prefixed(&body, &extensions) ||
6608+
- !CBB_add_u16(&extensions, TLSEXT_TYPE_application_settings) ||
6609+
+ !CBB_add_u16(&extensions, extension_type) ||
6610+
!CBB_add_u16_length_prefixed(&extensions, &extension) ||
6611+
!CBB_add_bytes(&extension,
6612+
hs->new_session->local_application_settings.data(),
6613+
diff --git a/src/ssl/tls13_server.cc b/src/ssl/tls13_server.cc
6614+
index 9d26f4e00..4ae95721a 100644
6615+
--- a/src/ssl/tls13_server.cc
6616+
+++ b/src/ssl/tls13_server.cc
6617+
@@ -1051,7 +1051,11 @@ static enum ssl_hs_wait_t do_read_client_encrypted_extensions(
6618+
return ssl_hs_error;
6619+
}
6620+
6621+
- SSLExtension application_settings(TLSEXT_TYPE_application_settings);
6622+
+ uint16_t extension_type = TLSEXT_TYPE_application_settings;
6623+
+ if (hs->config->alps_use_new_codepoint) {
6624+
+ extension_type = TLSEXT_TYPE_application_settings_new;
6625+
+ }
6626+
+ SSLExtension application_settings(extension_type);
6627+
uint8_t alert = SSL_AD_DECODE_ERROR;
6628+
if (!ssl_parse_extensions(&extensions, &alert, {&application_settings},
6629+
/*ignore_unknown=*/false)) {
65126630
diff --git a/src/tool/speed.cc b/src/tool/speed.cc
65136631
index 5b0205953..6b3c67dab 100644
65146632
--- a/src/tool/speed.cc

0 commit comments

Comments
 (0)