handshake: generate CRYPTO_ERRORs for internal_error TLS alerts (#4601)

* handshake: generate CRYPTO_ERRORs for internal_error TLS alerts

* remove stray comment
This commit is contained in:
Marten Seemann
2024-08-03 17:04:03 -07:00
committed by GitHub
parent a147bee190
commit f5ceb73171
3 changed files with 33 additions and 10 deletions

View File

@@ -624,8 +624,7 @@ func (h *cryptoSetup) ConnectionState() ConnectionState {
}
func wrapError(err error) error {
// alert 80 is an internal error
if alertErr := tls.AlertError(0); errors.As(err, &alertErr) && alertErr != 80 {
if alertErr := tls.AlertError(0); errors.As(err, &alertErr) {
return qerr.NewLocalCryptoError(uint8(alertErr), err)
}
return &qerr.TransportError{ErrorCode: qerr.InternalError, ErrorMessage: err.Error()}

View File

@@ -7,6 +7,7 @@ import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"errors"
"math/big"
"net"
"time"
@@ -96,10 +97,11 @@ var _ = Describe("Crypto Setup TLS", func() {
protocol.Version1,
)
Expect(cl.StartHandshake(context.Background())).To(MatchError(&qerr.TransportError{
ErrorCode: qerr.InternalError,
ErrorMessage: "tls: invalid NextProtos value",
}))
var terr *qerr.TransportError
err := cl.StartHandshake(context.Background())
Expect(errors.As(err, &terr)).To(BeTrue())
Expect(terr.ErrorCode).To(BeEquivalentTo(0x100 + 0x50))
Expect(err.Error()).To(ContainSubstring("tls: invalid NextProtos value"))
})
It("errors when a message is received at the wrong encryption level", func() {