Skip to content

Commit b832653

Browse files
committed
Fix tests that assume X25519 will be negotiated
1 parent 5f1d0d2 commit b832653

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

ssl/extensions.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ static const uint16_t kDefaultGroups[] = {
312312
SSL_GROUP_SECP384R1,
313313
};
314314

315+
Span<const uint16_t> tls1_get_default_grouplist(void) {
316+
return Span<const uint16_t>(kDefaultGroups);
317+
}
318+
315319
Span<const uint16_t> tls1_get_grouplist(const SSL_HANDSHAKE *hs) {
316320
if (!hs->config->supported_group_list.empty()) {
317321
return hs->config->supported_group_list;

ssl/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,9 @@ bool tls1_change_cipher_state(SSL_HANDSHAKE *hs,
36383638
int tls1_generate_master_secret(SSL_HANDSHAKE *hs, uint8_t *out,
36393639
Span<const uint8_t> premaster);
36403640

3641+
// tls1_get_default_grouplist returns the default group list
3642+
extern Span<const uint16_t> tls1_get_default_grouplist(void);
3643+
36413644
// tls1_get_grouplist returns the locally-configured group preference list.
36423645
Span<const uint16_t> tls1_get_grouplist(const SSL_HANDSHAKE *ssl);
36433646

ssl/ssl_encoding_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ static size_t GetClientHelloLen(uint16_t max_version, uint16_t session_version,
342342
bssl::UniquePtr<SSL> ssl(SSL_new(ctx.get()));
343343
if (!ssl || !SSL_set_session(ssl.get(), session.get()) ||
344344
!SSL_set_strict_cipher_list(ssl.get(), "ECDHE-RSA-AES128-GCM-SHA256") ||
345+
!SSL_set1_curves_list(ssl.get(), "x25519:P-256:P-384") ||
345346
!SSL_set_max_proto_version(ssl.get(), max_version)) {
346347
return 0;
347348
}

ssl/ssl_version_test.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,29 @@ TEST_P(SSLVersionTest, PeerTmpKey) {
23282328
GTEST_SKIP();
23292329
}
23302330

2331-
// Default should be using X5519 as the key exchange.
2331+
ASSERT_TRUE(Connect());
2332+
for (SSL *ssl : {client_.get(), server_.get()}) {
2333+
SCOPED_TRACE(SSL_is_server(ssl) ? "server" : "client");
2334+
EVP_PKEY *key = nullptr;
2335+
uint16_t preferred_group = tls1_get_default_grouplist()[0];
2336+
if (getVersionParam().version == TLS1_3_VERSION && preferred_group == SSL_GROUP_X25519_MLKEM768) {
2337+
// TLS 1.3 default should be using X25519MLKEM768 as the key exchange.
2338+
// We expect SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE because there is no EVP_PKEY type
2339+
// for hybrid keys, only individual X25519 or MLKEM768 keys.
2340+
ERR_clear_error();
2341+
EXPECT_FALSE(SSL_get_peer_tmp_key(ssl, &key));
2342+
ErrorEquals(ERR_get_error(), ERR_LIB_SSL, SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
2343+
} else {
2344+
// Otherwise x25519 should be used
2345+
EXPECT_TRUE(preferred_group == SSL_GROUP_X25519);
2346+
EXPECT_TRUE(SSL_get_peer_tmp_key(ssl, &key));
2347+
EXPECT_EQ(EVP_PKEY_id(key), EVP_PKEY_X25519);
2348+
bssl::UniquePtr<EVP_PKEY> pkey(key);
2349+
}
2350+
}
2351+
2352+
// Check that x25519 works.
2353+
ASSERT_TRUE(SSL_CTX_set1_groups_list(server_ctx_.get(), "x25519"));
23322354
ASSERT_TRUE(Connect());
23332355
for (SSL *ssl : {client_.get(), server_.get()}) {
23342356
SCOPED_TRACE(SSL_is_server(ssl) ? "server" : "client");

ssl/test/runner/runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8697,8 +8697,12 @@ func addExtensionTests() {
86978697
},
86988698
// This hostname just needs to be long enough to push the
86998699
// ClientHello into F5's danger zone between 256 and 511 bytes
8700-
// long.
8701-
flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
8700+
// long. Also override curves to just x25519 to remove any PQ
8701+
// KeyShares that might push ClientHello above 512 bytes.
8702+
flags: []string{
8703+
"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com",
8704+
"-curves", strconv.Itoa(int(CurveX25519)),
8705+
},
87028706
})
87038707

87048708
// Test that illegal extensions in TLS 1.3 are rejected by the client if

0 commit comments

Comments
 (0)