From b0d08910926599eb34c4b54ab71bdee414017605 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 10 May 2025 15:42:49 -0400 Subject: [PATCH] crypto/tls: align cert decode alert w/ BSSL For malformed client/server certificates in a TLS handshake send a decode_error alert, matching BoringSSL behaviour. Previously crypto/tls used a bad_certificate alert for this purpose. The TLS specification is imprecise enough to allow this to be considered a spec. justified choice, but since all other places in the protocol encourage using decode_error for structurally malformed messages we may as well do the same here and get some extra cross-impl consistency for free. This also allows un-ignoring the BoGo GarbageCertificate-[Client|Server]-[TLS12|TLS13] tests. Updates #72006 Change-Id: Ide45ba1602816e71c3289a60e77587266c3b9036 Reviewed-on: https://go-review.googlesource.com/c/go/+/652995 LUCI-TryBot-Result: Go LUCI Reviewed-by: Junyang Shao Reviewed-by: Roland Shoemaker --- handshake_client.go | 2 +- handshake_server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/handshake_client.go b/handshake_client.go index e1cf0bc..1be44d8 100644 --- a/handshake_client.go +++ b/handshake_client.go @@ -1089,7 +1089,7 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error { for i, asn1Data := range certificates { cert, err := globalCertCache.newCert(asn1Data) if err != nil { - c.sendAlert(alertBadCertificate) + c.sendAlert(alertDecodeError) return errors.New("tls: failed to parse certificate from server: " + err.Error()) } if cert.cert.PublicKeyAlgorithm == x509.RSA { diff --git a/handshake_server.go b/handshake_server.go index 333b179..1216368 100644 --- a/handshake_server.go +++ b/handshake_server.go @@ -896,7 +896,7 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error { var err error for i, asn1Data := range certificates { if certs[i], err = x509.ParseCertificate(asn1Data); err != nil { - c.sendAlert(alertBadCertificate) + c.sendAlert(alertDecodeError) return errors.New("tls: failed to parse client certificate: " + err.Error()) } if certs[i].PublicKeyAlgorithm == x509.RSA {