Skip to content

Commit 3c63f0b

Browse files
authored
fix: Fix key share patch (#46)
1 parent 4edbff8 commit 3c63f0b

File tree

1 file changed

+51
-14
lines changed

1 file changed

+51
-14
lines changed

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

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4400,7 +4400,7 @@ index 5c7e881bf..3c0770cf3 100644
44004400
crypto/pkcs8/test/no_encryption.p12
44014401
crypto/pkcs8/test/nss.p12
44024402
diff --git a/src/ssl/extensions.cc b/src/ssl/extensions.cc
4403-
index 5ee280221..b42f332a1 100644
4403+
index 5ee280221..dbdd8b305 100644
44044404
--- a/src/ssl/extensions.cc
44054405
+++ b/src/ssl/extensions.cc
44064406
@@ -207,6 +207,10 @@ static bool tls1_check_duplicate_extensions(const CBS *cbs) {
@@ -4499,7 +4499,44 @@ index 5ee280221..b42f332a1 100644
44994499
return CBBFinishArray(cbb.get(), &hs->key_share_bytes);
45004500
}
45014501

4502-
@@ -2808,9 +2835,30 @@ static bool ext_quic_transport_params_add_serverhello_legacy(SSL_HANDSHAKE *hs,
4502+
@@ -2372,13 +2399,20 @@ bool ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
4503+
}
4504+
4505+
SSLKeyShare *key_share = hs->key_shares[0].get();
4506+
+ // group_id is the server chosen group_id, and if key_share[0] is not chosen
4507+
if (key_share->GroupID() != group_id) {
4508+
+ // the server also did not choose the second one
4509+
if (!hs->key_shares[1] || hs->key_shares[1]->GroupID() != group_id) {
4510+
- *out_alert = SSL_AD_ILLEGAL_PARAMETER;
4511+
- OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
4512+
- return false;
4513+
+ // the server also did not choose the third one, we are out of options
4514+
+ if (!hs->key_shares[2] || hs->key_shares[2]->GroupID() != group_id) {
4515+
+ *out_alert = SSL_AD_ILLEGAL_PARAMETER;
4516+
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
4517+
+ return false;
4518+
+ }
4519+
+ key_share = hs->key_shares[2].get(); // choose the third one
4520+
+ } else {
4521+
+ key_share = hs->key_shares[1].get(); // choose the second one
4522+
}
4523+
- key_share = hs->key_shares[1].get();
4524+
}
4525+
4526+
if (!key_share->Decap(out_secret, out_alert, ciphertext)) {
4527+
@@ -2386,9 +2420,11 @@ bool ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
4528+
return false;
4529+
}
4530+
4531+
+ // choose the first one
4532+
hs->new_session->group_id = group_id;
4533+
hs->key_shares[0].reset();
4534+
hs->key_shares[1].reset();
4535+
+ hs->key_shares[2].reset();
4536+
return true;
4537+
}
4538+
4539+
@@ -2808,9 +2844,30 @@ static bool ext_quic_transport_params_add_serverhello_legacy(SSL_HANDSHAKE *hs,
45034540
static bool ext_delegated_credential_add_clienthello(
45044541
const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible,
45054542
ssl_client_hello_type_t type) {
@@ -4530,7 +4567,7 @@ index 5ee280221..b42f332a1 100644
45304567
static bool ext_delegated_credential_parse_clienthello(SSL_HANDSHAKE *hs,
45314568
uint8_t *out_alert,
45324569
CBS *contents) {
4533-
@@ -2957,9 +3005,10 @@ bool ssl_get_local_application_settings(const SSL_HANDSHAKE *hs,
4570+
@@ -2957,9 +3014,10 @@ bool ssl_get_local_application_settings(const SSL_HANDSHAKE *hs,
45344571
return false;
45354572
}
45364573

@@ -4544,7 +4581,7 @@ index 5ee280221..b42f332a1 100644
45444581
const SSL *const ssl = hs->ssl;
45454582
if (// ALPS requires TLS 1.3.
45464583
hs->max_version < TLS1_3_VERSION ||
4547-
@@ -2972,8 +3021,18 @@ static bool ext_alps_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out,
4584+
@@ -2972,8 +3030,18 @@ static bool ext_alps_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out,
45484585
return true;
45494586
}
45504587

@@ -4564,7 +4601,7 @@ index 5ee280221..b42f332a1 100644
45644601
!CBB_add_u16_length_prefixed(out_compressible, &contents) ||
45654602
!CBB_add_u16_length_prefixed(&contents, &proto_list)) {
45664603
return false;
4567-
@@ -2990,8 +3049,24 @@ static bool ext_alps_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out,
4604+
@@ -2990,8 +3058,24 @@ static bool ext_alps_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out,
45684605
return CBB_flush(out_compressible);
45694606
}
45704607

@@ -4591,15 +4628,15 @@ index 5ee280221..b42f332a1 100644
45914628
SSL *const ssl = hs->ssl;
45924629
if (contents == nullptr) {
45934630
return true;
4594-
@@ -3000,6 +3075,7 @@ static bool ext_alps_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
4631+
@@ -3000,6 +3084,7 @@ static bool ext_alps_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
45954632
assert(!ssl->s3->initial_handshake_complete);
45964633
assert(!hs->config->alpn_client_proto_list.empty());
45974634
assert(!hs->config->alps_configs.empty());
45984635
+ assert(use_new_codepoint == hs->config->alps_use_new_codepoint);
45994636

46004637
// ALPS requires TLS 1.3.
46014638
if (ssl_protocol_version(ssl) < TLS1_3_VERSION) {
4602-
@@ -3019,7 +3095,21 @@ static bool ext_alps_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
4639+
@@ -3019,7 +3104,21 @@ static bool ext_alps_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
46034640
return true;
46044641
}
46054642

@@ -4622,7 +4659,7 @@ index 5ee280221..b42f332a1 100644
46224659
SSL *const ssl = hs->ssl;
46234660
// If early data is accepted, we omit the ALPS extension. It is implicitly
46244661
// carried over from the previous connection.
4625-
@@ -3029,8 +3119,18 @@ static bool ext_alps_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
4662+
@@ -3029,8 +3128,18 @@ static bool ext_alps_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
46264663
return true;
46274664
}
46284665

@@ -4642,7 +4679,7 @@ index 5ee280221..b42f332a1 100644
46424679
!CBB_add_u16_length_prefixed(out, &contents) ||
46434680
!CBB_add_bytes(&contents,
46444681
hs->new_session->local_application_settings.data(),
4645-
@@ -3042,6 +3142,14 @@ static bool ext_alps_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
4682+
@@ -3042,6 +3151,14 @@ static bool ext_alps_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
46464683
return true;
46474684
}
46484685

@@ -4657,7 +4694,7 @@ index 5ee280221..b42f332a1 100644
46574694
bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
46584695
const SSL_CLIENT_HELLO *client_hello) {
46594696
SSL *const ssl = hs->ssl;
4660-
@@ -3094,6 +3202,39 @@ bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
4697+
@@ -3094,6 +3211,39 @@ bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert,
46614698
return true;
46624699
}
46634700

@@ -4697,7 +4734,7 @@ index 5ee280221..b42f332a1 100644
46974734
// kExtensions contains all the supported extensions.
46984735
static const struct tls_extension kExtensions[] = {
46994736
{
4700-
@@ -3267,6 +3408,21 @@ static const struct tls_extension kExtensions[] = {
4737+
@@ -3267,6 +3417,21 @@ static const struct tls_extension kExtensions[] = {
47014738
ignore_parse_clienthello,
47024739
ext_alps_add_serverhello,
47034740
},
@@ -4719,7 +4756,7 @@ index 5ee280221..b42f332a1 100644
47194756
};
47204757

47214758
#define kNumExtensions (sizeof(kExtensions) / sizeof(struct tls_extension))
4722-
@@ -3280,6 +3436,12 @@ static_assert(kNumExtensions <=
4759+
@@ -3280,6 +3445,12 @@ static_assert(kNumExtensions <=
47234760

47244761
bool ssl_setup_extension_permutation(SSL_HANDSHAKE *hs) {
47254762
if (!hs->config->permute_extensions) {
@@ -4732,7 +4769,7 @@ index 5ee280221..b42f332a1 100644
47324769
return true;
47334770
}
47344771

4735-
@@ -3357,10 +3519,16 @@ static bool ssl_add_clienthello_tlsext_inner(SSL_HANDSHAKE *hs, CBB *out,
4772+
@@ -3357,10 +3528,16 @@ static bool ssl_add_clienthello_tlsext_inner(SSL_HANDSHAKE *hs, CBB *out,
47364773
}
47374774
}
47384775

@@ -4750,7 +4787,7 @@ index 5ee280221..b42f332a1 100644
47504787
const size_t len_before = CBB_len(&extensions);
47514788
const size_t len_compressed_before = CBB_len(compressed.get());
47524789
if (!kExtensions[i].add_clienthello(hs, &extensions, compressed.get(),
4753-
@@ -3466,10 +3634,16 @@ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded,
4790+
@@ -3466,10 +3643,16 @@ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded,
47544791
}
47554792

47564793
bool last_was_empty = false;

0 commit comments

Comments
 (0)