Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use illegal_parameter instead of decode_error for invalid key shares #1923

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ssl/ssl_key_share.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ECKeyShare : public SSLKeyShare {
!EC_POINT_oct2point(group_, peer_point.get(), peer_key.data(),
peer_key.size(), /*ctx=*/nullptr)) {
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
*out_alert = SSL_AD_DECODE_ERROR;
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
return false;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ class X25519KeyShare : public SSLKeyShare {

if (peer_key.size() != 32 ||
!X25519(secret.data(), private_key_, peer_key.data())) {
*out_alert = SSL_AD_DECODE_ERROR;
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
return false;
}
Expand Down Expand Up @@ -286,7 +286,7 @@ class KEMKeyShare : public SSLKeyShare {
EVP_PKEY_kem_new_raw_public_key(nid_, peer_key.begin(), peer_key.size()));

if (!pkey) {
*out_alert = SSL_AD_DECODE_ERROR;
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
return false;
}
Expand Down Expand Up @@ -387,7 +387,7 @@ class KEMKeyShare : public SSLKeyShare {
&secret_bytes_written, ciphertext,
peer_key.size()) ||
secret_bytes_written != secret_len) {
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_KEM_CIPHERTEXT);
OPENSSL_PUT_ERROR(SSL, SSL_AD_ILLEGAL_PARAMETER);
return false;
}

Expand Down Expand Up @@ -504,7 +504,7 @@ class HybridKeyShare : public SSLKeyShare {
// Verify that |peer_key| contains enough data
if (peer_key_read_index + component_key_size > peer_key.size()) {
CBB_cleanup(&hybrid_shared_secret);
*out_alert = SSL_AD_DECODE_ERROR;
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_HYBRID_KEYSHARE);
return false;
}
Expand Down Expand Up @@ -612,7 +612,7 @@ class HybridKeyShare : public SSLKeyShare {
// Final validation that |peer_key| was the correct size
if (peer_key_index != peer_key.size()) {
CBB_cleanup(&hybrid_shared_secret);
*out_alert = SSL_AD_DECODE_ERROR;
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions ssl/ssl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11905,7 +11905,7 @@ TEST_P(BadKemKeyShareAcceptTest, BadKemKeyShareAccept) {
EXPECT_FALSE(server_key_share->Accept(&server_out_public_key,
&server_secret, &server_alert,
client_public_key));
EXPECT_EQ(server_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(server_alert, SSL_AD_ILLEGAL_PARAMETER);
CBB_cleanup(&server_out_public_key);
CBB_cleanup(&client_out_public_key);
}
Expand Down Expand Up @@ -11935,7 +11935,7 @@ TEST_P(BadKemKeyShareAcceptTest, BadKemKeyShareAccept) {
EXPECT_FALSE(server_key_share->Accept(&server_out_public_key,
&server_secret, &server_alert,
client_public_key));
EXPECT_EQ(server_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(server_alert, SSL_AD_ILLEGAL_PARAMETER);
CBB_cleanup(&server_out_public_key);
CBB_cleanup(&client_out_public_key);
}
Expand Down Expand Up @@ -12394,7 +12394,7 @@ TEST_P(BadHybridKeyShareAcceptTest, BadHybridKeyShareAccept) {
EXPECT_FALSE(server_key_share->Accept(&server_out_public_key,
&server_secret, &server_alert,
client_public_key));
EXPECT_EQ(server_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(server_alert, SSL_AD_ILLEGAL_PARAMETER);
CBB_cleanup(&server_out_public_key);
}

Expand Down Expand Up @@ -12422,7 +12422,7 @@ TEST_P(BadHybridKeyShareAcceptTest, BadHybridKeyShareAccept) {
EXPECT_FALSE(server_key_share->Accept(&server_out_public_key,
&server_secret, &server_alert,
client_public_key));
EXPECT_EQ(server_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(server_alert, SSL_AD_ILLEGAL_PARAMETER);
CBB_cleanup(&server_out_public_key);
CBB_cleanup(&client_out_public_key);
}
Expand Down Expand Up @@ -12547,7 +12547,7 @@ TEST_P(BadHybridKeyShareAcceptTest, BadHybridKeyShareAccept) {
// The Accept() functionality for the NIST curves (e.g. P256) is
// written so that it will return failure if the key share is invalid.
EXPECT_EQ(hybrid_group->component_group_ids[i], SSL_GROUP_SECP256R1);
EXPECT_EQ(server_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(server_alert, SSL_AD_ILLEGAL_PARAMETER);
}

client_public_key_index += t.offer_share_sizes[i];
Expand Down Expand Up @@ -12713,7 +12713,7 @@ TEST_P(BadHybridKeyShareFinishTest, BadHybridKeyShareFinish) {
CBB_len(&server_out_public_key));

EXPECT_FALSE(client_key_share->Finish(&client_secret, &client_alert, server_public_key));
EXPECT_EQ(client_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(client_alert, SSL_AD_ILLEGAL_PARAMETER);

CBB_cleanup(&server_out_public_key);
CBB_cleanup(&client_out_public_key);
Expand Down Expand Up @@ -12809,7 +12809,7 @@ TEST_P(BadHybridKeyShareFinishTest, BadHybridKeyShareFinish) {
// The Finish() functionality for the NIST curves (e.g. P256) is
// written so that it will return failure if the key share is invalid.
EXPECT_EQ(hybrid_group->component_group_ids[i], SSL_GROUP_SECP256R1);
EXPECT_EQ(client_alert, SSL_AD_DECODE_ERROR);
EXPECT_EQ(client_alert, SSL_AD_ILLEGAL_PARAMETER);
}

server_public_key_index += t.accept_share_sizes[i];
Expand Down
Loading