From 8f6f659bee2dc0f259a2c7d18adda338ac026188 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 13 Feb 2025 18:05:04 -0500 Subject: [PATCH] runner: Include the name of the message we failed to parse This should make debugging easier. Change-Id: I297e730b95a53eff2256abd6562b8eadf321b8fb Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76287 Auto-Submit: David Benjamin Commit-Queue: Bob Beck Reviewed-by: Bob Beck Commit-Queue: David Benjamin --- ssl/test/runner/common.go | 48 ++++++++++++++++++++++++++++++++++++++- ssl/test/runner/conn.go | 6 +++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/ssl/test/runner/common.go b/ssl/test/runner/common.go index d7a1ea40a..ee65687c9 100644 --- a/ssl/test/runner/common.go +++ b/ssl/test/runner/common.go @@ -91,12 +91,58 @@ const ( typeFinished uint8 = 20 typeCertificateStatus uint8 = 22 typeKeyUpdate uint8 = 24 - typeCompressedCertificate uint8 = 25 // Not IANA assigned + typeCompressedCertificate uint8 = 25 typeNextProtocol uint8 = 67 // Not IANA assigned typeChannelID uint8 = 203 // Not IANA assigned typeMessageHash uint8 = 254 ) +func messageTypeToString(typ uint8) string { + switch typ { + case typeHelloRequest: + return "HelloRequest" + case typeClientHello: + return "ClientHello" + case typeServerHello: + return "ServerHello" + case typeHelloVerifyRequest: + return "HelloVerifyRequest" + case typeNewSessionTicket: + return "NewSessionTicket" + case typeEndOfEarlyData: + return "EndOfEarlyData" + case typeEncryptedExtensions: + return "EncryptedExtensions" + case typeCertificate: + return "Certificate" + case typeServerKeyExchange: + return "ServerKeyExchange" + case typeCertificateRequest: + return "CertificateRequest" + case typeServerHelloDone: + return "ServerHelloDone" + case typeCertificateVerify: + return "CertificateVerify" + case typeClientKeyExchange: + return "ClientKeyExchange" + case typeFinished: + return "Finished" + case typeCertificateStatus: + return "CertificateStatus" + case typeKeyUpdate: + return "KeyUpdate" + case typeCompressedCertificate: + return "CompressedCertificate" + case typeNextProtocol: + return "NextProtocol" + case typeChannelID: + return "ChannelID" + case typeMessageHash: + return "MessageHash" + } + return fmt.Sprintf("unknown(%d)", typ) +} + // TLS compression types. const ( compressionNone uint8 = 0 diff --git a/ssl/test/runner/conn.go b/ssl/test/runner/conn.go index d2625070b..a3ca81736 100644 --- a/ssl/test/runner/conn.go +++ b/ssl/test/runner/conn.go @@ -1447,8 +1447,9 @@ func (c *Conn) readHandshake() (any, error) { return nil, err } + typ := data[0] var m handshakeMessage - switch data[0] { + switch typ { case typeHelloRequest: m = new(helloRequestMsg) case typeClientHello: @@ -1523,7 +1524,8 @@ func (c *Conn) readHandshake() (any, error) { } if !m.unmarshal(data) { - return nil, c.in.setErrorLocked(c.sendAlert(alertDecodeError)) + c.sendAlert(alertDecodeError) + return nil, c.in.setErrorLocked(fmt.Errorf("tls: error decoding %s message", messageTypeToString(typ))) } return m, nil }