Skip to content

Commit

Permalink
Use illegal_parameter instead of decode_error for invalid key shares
Browse files Browse the repository at this point in the history
This is extremely silly and a huge waste of everyone's time (I deeply
regret disambiguating illegal_parameter and decode_error for RFC 8446),
but so it goes. Technically these errors pass the TLS syntax and are an
invalid value, so they should be illegal_parameter.

   Note: TLS defines two generic alerts (see Section 6) to use upon
   failure to parse a message.  Peers which receive a message which
   cannot be parsed according to the syntax (e.g., have a length
   extending beyond the message boundary or contain an out-of-range
   length) MUST terminate the connection with a "decode_error" alert.
   Peers which receive a message which is syntactically correct but
   semantically invalid (e.g., a DHE share of p - 1, or an invalid enum)
   MUST terminate the connection with an "illegal_parameter" alert.

Update-Note: The error sent on invalid key share is now more correct.
This does not change which connections do or do not fail, only which of
two practically identical alert codes is sent to the other side.

Change-Id: If0ddf511d6cf23383c6134ad30e3ae080c4f2769
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/71627
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
  • Loading branch information
davidben authored and Boringssl LUCI CQ committed Sep 27, 2024
1 parent 37571ee commit 72a6050
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions ssl/ssl_key_share.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ECKeyShare : public SSLKeyShare {
!EC_POINT_oct2point(group_, peer_point.get(), ciphertext.data(),
ciphertext.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 @@ -168,7 +168,7 @@ class X25519KeyShare : public SSLKeyShare {

if (ciphertext.size() != 32 || //
!X25519(secret.data(), private_key_, ciphertext.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 @@ -236,7 +236,7 @@ class X25519Kyber768KeyShare : public SSLKeyShare {
!X25519(secret.data(), x25519_private_key_,
CBS_data(&peer_x25519_cbs)) ||
!KYBER_parse_public_key(&peer_kyber_pub, &peer_kyber_cbs)) {
*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 @@ -266,7 +266,7 @@ class X25519Kyber768KeyShare : public SSLKeyShare {

if (ciphertext.size() != 32 + KYBER_CIPHERTEXT_BYTES ||
!X25519(secret.data(), x25519_private_key_, ciphertext.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 @@ -325,7 +325,7 @@ class X25519MLKEM768KeyShare : public SSLKeyShare {
CBS_len(&peer_key_cbs) != 0 ||
!X25519(secret.data() + MLKEM_SHARED_SECRET_BYTES, x25519_private_key_,
CBS_data(&peer_x25519_cbs))) {
*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 @@ -359,7 +359,7 @@ class X25519MLKEM768KeyShare : public SSLKeyShare {
MLKEM768_CIPHERTEXT_BYTES, &mlkem_private_key_) ||
!X25519(secret.data() + MLKEM_SHARED_SECRET_BYTES, x25519_private_key_,
ciphertext.data() + MLKEM768_CIPHERTEXT_BYTES)) {
*out_alert = SSL_AD_DECODE_ERROR;
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion ssl/test/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11868,7 +11868,7 @@ func addCurveTests() {
},
})

badKeyShareLocalError := "remote error: error decoding message"
badKeyShareLocalError := "remote error: illegal parameter"
if testType == clientTest && ver.version >= VersionTLS13 {
// If the shim is a TLS 1.3 client and the runner sends a bad
// key share, the runner never reads the client's cleartext
Expand Down

0 comments on commit 72a6050

Please sign in to comment.