Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
8b159d9
crypto/tls: disable additional SSLv2 bogo tests
rolandshoemaker Jan 24, 2025
e432235
all: use slices.Contains to simplify code
cuishuang Dec 31, 2024
70def38
crypto/tls: document FIPS 140-3 mode behavior
FiloSottile Feb 6, 2025
acdb801
crypto/tls: fix incorrect EncryptedClientHelloKey comment
rolandshoemaker Feb 19, 2025
3ac071d
crypto/tls: improve ech parsing errors
rolandshoemaker Feb 19, 2025
47de581
crypto/tls: require EMS in FIPS 140-3 mode
FiloSottile Feb 19, 2025
fe2ede9
crypto/tls: small bogo shim test tidying
cpu Feb 15, 2025
e9e3ed7
crypto/tls: reject empty TLS 1.3 session ticket
cpu Feb 17, 2025
9cf27ea
crypto/tls: run SkipNewSessionTicket bogo test
cpu Feb 18, 2025
9c64bb5
crypto/tls: ignore TLS 1.3 user canceled alerts
cpu Feb 19, 2025
8240c4c
crypto/tls: support bogo -wait-for-debugger
cpu Feb 19, 2025
a056a55
crypto/tls: update GREASE-Server-TLS13 BoGo skip
cpu Feb 19, 2025
72c2909
crypto/tls: align cert decode alert w/ BSSL
cpu Feb 26, 2025
0d36914
crypto/tls: reject TLS 1.3 compat session ID in TLS 1.2
cpu Feb 26, 2025
5094205
crypto/tls: allow P-521 in FIPS 140-3 mode and Go+BoringCrypto
FiloSottile Mar 12, 2025
fdf7df4
crypto/tls: add ConnectionState.CurveID
FiloSottile Feb 27, 2025
7e88eb9
crypto/tls: clean up supported/default/allowed parameters
FiloSottile Feb 19, 2025
2e090b9
crypto/tls: relax native FIPS 140-3 mode
FiloSottile Feb 19, 2025
b466731
crypto/tls/internal/fips140tls: use crypto/fips140
qmuntal Jan 10, 2025
be65dde
crypto/tls: fix ECH compatibility
gdy666 Feb 10, 2025
7724060
crypto/tls: add missing RUnlock in ticketKeys
espadolini Jul 26, 2024
50036e1
crypto/tls: use crypto/hkdf
qmuntal Mar 17, 2025
c07bd16
crypto/tls: add offered cipher suites to the handshake error
drakkan Nov 24, 2024
9039e1b
crypto/tls: fix a testing deadlock that occurs on a TLS protocol error
eay Jun 3, 2022
177adaa
crypto/tls: skip part of the test based on GOOS instead of GOARCH
nevkontakte Apr 21, 2025
1532716
crypto/internal/hpke: rename Receipient to Recipient
jbampton Apr 9, 2025
9120280
crypto/tls: use runtime.AddCleanup instead of runtime.SetFinalizer
cagedmantis Apr 9, 2025
1b23367
crypto/tls: add scheduler call to TestCertCache refcount timeout loop
mknyszek May 7, 2025
b902acb
crypto/tls: use runtime.Gosched instead of time.After in TestCertCache
mknyszek May 8, 2025
66ddf5a
crypto/tls: use illegal param alert for bad compression
cpu Apr 29, 2025
aaf27ba
crypto/tls: update TLS 1.3 client compression validation
cpu Apr 29, 2025
38816c4
crypto/tls: err for unsupported point format configs
cpu Apr 29, 2025
8d42058
crypto/tls: skip BadRSAClientKeyExchange-[4,5]
cpu Apr 30, 2025
3365473
crypto/tls: enable more large record bogo tests
cpu Apr 29, 2025
9718ee6
crypto/tls: fix TLS <1.3 client cert required alert
cpu May 8, 2025
3eb74a5
crypto/tls: handle client hello version too high
cpu May 8, 2025
b8a9055
crypto/tls: fix bogo IgnoreClientVersionOrder skip reason
cpu May 9, 2025
3a8b9c2
crypto/tls: replace custom intern cache with weak cache
rolandshoemaker Jan 25, 2025
0e880fe
crypto/tls: add GetEncryptedClientHelloKeys
rolandshoemaker May 7, 2025
f82ab19
crypto/tls: have servers prefer TLS 1.3 when supported
cpu May 15, 2025
1666573
crypto/tls: verify server chooses advertised curve
cpu May 16, 2025
4c06048
crypto/tls: delete dead code curveIDForCurve
cpu May 16, 2025
7f8864d
crypto/tls: match compression method alert across versions
cpu May 16, 2025
be7464f
crypto/tls: enable BoGo DisabledCurve-HelloRetryRequest-TLS13
cpu May 16, 2025
e24b728
crypto/tls: update BoGo SessionID test skip reasons
cpu May 16, 2025
7c3dc4e
crypto/tls: don't advertise TLS 1.2-only sigAlgs in TLS 1.3
FiloSottile Mar 15, 2025
8266169
crypto/tls: disable SHA-1 signature algorithms in TLS 1.2
FiloSottile Mar 15, 2025
aff60d2
crypto/tls: use decode alert for handshake msg unmarshal err
cpu May 17, 2025
12ed2be
crypto/tls: reject duplicate TLS 1.3 EncryptedExtensions
cpu May 17, 2025
0d0d00a
crypto/tls: signature_algorithms in CertificateRequest can't be empty
FiloSottile May 21, 2025
a9f726f
crypto/tls: enable signature algorithm BoGo tests (and fix two bugs)
FiloSottile May 23, 2025
4064318
crypto/tls: update bogo version
cpu Jun 23, 2025
87a83d2
crypto/tls: ensure the ECDSA curve matches the signature algorithm
FiloSottile May 23, 2025
5a54793
crypto/tls: empty server_name conf. ext. from server
cpu Jun 28, 2025
1cd2e41
crypto/tls: use standard chacha20-poly1305 cipher suite names
qmuntal Jul 21, 2025
ab8a9f1
crypto/tls: check if quic conn can send session ticket
ronaudinho Sep 15, 2023
5c4870e
crypto/tls: fix quic comment typo
testwill Aug 21, 2025
41b1260
crypto/tls: use hash.Cloner
qmuntal Jun 20, 2025
9f68549
crypto/tls: use context.AfterFunc in handshakeContext
database64128 Aug 29, 2025
2b90a70
crypto: use clear built-in
kolyshkin Sep 18, 2025
4ed9452
all: fix typos
aisk Sep 25, 2025
dbcf369
crypto/tls: quote protocols in ALPN error message
rolandshoemaker Sep 29, 2025
f87d949
crypto/tls: rm marshalEncryptedClientHelloConfigList dead code
cpu Sep 29, 2025
1aff74d
crypto/tls: add flag to render HTML BoGo report
cpu Jun 30, 2025
b43bbcd
crypto/tls: streamline BoGo testing w/ -bogo-local-dir
cpu Jul 11, 2025
24ab43a
all: replace calls to errors.As with errors.AsType
jub0bs Oct 1, 2025
f7604ee
all: remove unnecessary loop variable copies in tests
tklauser Oct 14, 2025
2a4cbf1
crypto/tls: add BetterTLS test coverage
cpu Nov 3, 2025
f7bfc40
std,cmd: go fix -any std cmd
adonovan Nov 11, 2025
90795e1
crypto/x509: move BetterTLS suite from crypto/tls
rolandshoemaker Nov 9, 2025
0ae5aea
std: fix printf("%q", int) mistakes
adonovan Nov 14, 2025
6eacc6b
crypto/tls: add QUICErrorEvent
neild Nov 8, 2025
a4264a9
crypto/internal/hpke: modularize API and support more ciphersuites
FiloSottile Sep 6, 2025
38240ff
crypto/internal/hpke: separate KEM and PublicKey/PrivateKey interfaces
FiloSottile Nov 11, 2025
3dac251
crypto/tls: use inner hello for earlyData when using QUIC and ECH
rolandshoemaker Nov 17, 2025
f0cba60
crypto/tls: expose HelloRetryRequest state
cpu Nov 3, 2025
dabb9c3
crypto/ecdsa: clean up ECDSA parsing and serialization paths
FiloSottile Nov 24, 2025
eb2a2c5
crypto/hpke: expose crypto/internal/hpke
FiloSottile Nov 22, 2025
5afee90
crypto/tls: add SecP256r1/SecP384r1MLKEM1024 hybrid post-quantum key …
FiloSottile Nov 19, 2025
8d0df07
crypto/tls: support crypto.MessageSigner private keys
FiloSottile Nov 26, 2025
de64813
crypto,testing/cryptotest: ignore random io.Reader params, add SetGlo…
FiloSottile Sep 15, 2025
a3557b1
all: fix some comment issues
cuishuang Dec 4, 2025
07eb9d4
crypto: clean up subprocess-spawning tests
FiloSottile Dec 9, 2025
590d34e
crypto/tls: reject trailing messages after client/server hello
rolandshoemaker Nov 24, 2025
9eb9ef0
crypto: use testenv.Executable(t) instead of os.Args[0] in tests
FiloSottile Jan 9, 2026
3c43796
[release-branch.go1.26] crypto/tls: don't copy auto-rotated session t…
rolandshoemaker Jan 6, 2026
8175d2a
crypto/tls: don't copy auto-rotated session ticket keys in Config.Clone
rolandshoemaker Jan 6, 2026
35ec5bf
[release-branch.go1.26] all: merge master (2baa1d1) into release-bran…
cagedmantis Jan 21, 2026
0e3bd90
[release-branch.go1.26] Revert "crypto/tls: don't copy auto-rotated s…
rolandshoemaker Jan 26, 2026
6d07980
[release-branch.go1.26] crypto/tls: add verifiedChains expiration che…
rolandshoemaker Jan 26, 2026
1dcb033
[release-branch.go1.26] crypto/tls: check verifiedChains roots when r…
rolandshoemaker Jan 26, 2026
2cf02ea
[release-branch.go1.26] crypto/tls: revalidate whole chain on resumpt…
FiloSottile Jan 30, 2026
fd5128b
[release-branch.go1.26] crypto/tls: document resumption behavior acro…
FiloSottile Jan 29, 2026
1c3a4d1
[release-branch.go1.26] crypto/tls: avoid data race when canceling a …
neild Feb 5, 2026
ec54fa8
sync: merge changes from go 1.26.0
mingyech Mar 2, 2026
9104d1f
fix: remove tests with tlssha1=1
mingyech Mar 2, 2026
98f1bbc
fix: ech broken after sync
mingyech Mar 11, 2026
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
146 changes: 80 additions & 66 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ import (
"fmt"
"hash"
"io"
"slices"
)

// verifyHandshakeSignature verifies a signature against pre-hashed
// (if required) handshake contents.
// verifyHandshakeSignature verifies a signature against unhashed handshake contents.
func verifyHandshakeSignature(sigType uint8, pubkey crypto.PublicKey, hashFunc crypto.Hash, signed, sig []byte) error {
if hashFunc != directSigning {
h := hashFunc.New()
h.Write(signed)
signed = h.Sum(nil)
}
switch sigType {
case signatureECDSA:
pubKey, ok := pubkey.(*ecdsa.PublicKey)
Expand Down Expand Up @@ -60,6 +65,32 @@ func verifyHandshakeSignature(sigType uint8, pubkey crypto.PublicKey, hashFunc c
return nil
}

// verifyLegacyHandshakeSignature verifies a TLS 1.0 and 1.1 signature against
// pre-hashed handshake contents.
func verifyLegacyHandshakeSignature(sigType uint8, pubkey crypto.PublicKey, hashFunc crypto.Hash, hashed, sig []byte) error {
switch sigType {
case signatureECDSA:
pubKey, ok := pubkey.(*ecdsa.PublicKey)
if !ok {
return fmt.Errorf("expected an ECDSA public key, got %T", pubkey)
}
if !ecdsa.VerifyASN1(pubKey, hashed, sig) {
return errors.New("ECDSA verification failure")
}
case signaturePKCS1v15:
pubKey, ok := pubkey.(*rsa.PublicKey)
if !ok {
return fmt.Errorf("expected an RSA public key, got %T", pubkey)
}
if err := rsa.VerifyPKCS1v15(pubKey, hashFunc, hashed, sig); err != nil {
return err
}
default:
return errors.New("internal error: unknown signature type")
}
return nil
}

const (
serverSignatureContext = "TLS 1.3, server CertificateVerify\x00"
clientSignatureContext = "TLS 1.3, client CertificateVerify\x00"
Expand All @@ -76,21 +107,15 @@ var signaturePadding = []byte{
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
}

// signedMessage returns the pre-hashed (if necessary) message to be signed by
// certificate keys in TLS 1.3. See RFC 8446, Section 4.4.3.
func signedMessage(sigHash crypto.Hash, context string, transcript hash.Hash) []byte {
if sigHash == directSigning {
b := &bytes.Buffer{}
b.Write(signaturePadding)
io.WriteString(b, context)
b.Write(transcript.Sum(nil))
return b.Bytes()
}
h := sigHash.New()
h.Write(signaturePadding)
io.WriteString(h, context)
h.Write(transcript.Sum(nil))
return h.Sum(nil)
// signedMessage returns the (unhashed) message to be signed by certificate keys
// in TLS 1.3. See RFC 8446, Section 4.4.3.
func signedMessage(context string, transcript hash.Hash) []byte {
const maxSize = 64 /* signaturePadding */ + len(serverSignatureContext) + 512/8 /* SHA-512 */
b := bytes.NewBuffer(make([]byte, 0, maxSize))
b.Write(signaturePadding)
io.WriteString(b, context)
b.Write(transcript.Sum(nil))
return b.Bytes()
}

// typeAndHashFromSignatureScheme returns the corresponding signature type and
Expand Down Expand Up @@ -148,105 +173,94 @@ func legacyTypeAndHashFromPublicKey(pub crypto.PublicKey) (sigType uint8, hash c
var rsaSignatureSchemes = []struct {
scheme SignatureScheme
minModulusBytes int
maxVersion uint16
}{
// RSA-PSS is used with PSSSaltLengthEqualsHash, and requires
// emLen >= hLen + sLen + 2
{PSSWithSHA256, crypto.SHA256.Size()*2 + 2, VersionTLS13},
{PSSWithSHA384, crypto.SHA384.Size()*2 + 2, VersionTLS13},
{PSSWithSHA512, crypto.SHA512.Size()*2 + 2, VersionTLS13},
{PSSWithSHA256, crypto.SHA256.Size()*2 + 2},
{PSSWithSHA384, crypto.SHA384.Size()*2 + 2},
{PSSWithSHA512, crypto.SHA512.Size()*2 + 2},
// PKCS #1 v1.5 uses prefixes from hashPrefixes in crypto/rsa, and requires
// emLen >= len(prefix) + hLen + 11
// TLS 1.3 dropped support for PKCS #1 v1.5 in favor of RSA-PSS.
{PKCS1WithSHA256, 19 + crypto.SHA256.Size() + 11, VersionTLS12},
{PKCS1WithSHA384, 19 + crypto.SHA384.Size() + 11, VersionTLS12},
{PKCS1WithSHA512, 19 + crypto.SHA512.Size() + 11, VersionTLS12},
{PKCS1WithSHA1, 15 + crypto.SHA1.Size() + 11, VersionTLS12},
{PKCS1WithSHA256, 19 + crypto.SHA256.Size() + 11},
{PKCS1WithSHA384, 19 + crypto.SHA384.Size() + 11},
{PKCS1WithSHA512, 19 + crypto.SHA512.Size() + 11},
{PKCS1WithSHA1, 15 + crypto.SHA1.Size() + 11},
}

// signatureSchemesForCertificate returns the list of supported SignatureSchemes
// for a given certificate, based on the public key and the protocol version,
// and optionally filtered by its explicit SupportedSignatureAlgorithms.
//
// This function must be kept in sync with supportedSignatureAlgorithms.
// FIPS filtering is applied in the caller, selectSignatureScheme.
func signatureSchemesForCertificate(version uint16, cert *Certificate) []SignatureScheme {
priv, ok := cert.PrivateKey.(crypto.Signer)
if !ok {
return nil
}

var sigAlgs []SignatureScheme
switch pub := priv.Public().(type) {
func signatureSchemesForPublicKey(version uint16, pub crypto.PublicKey) []SignatureScheme {
switch pub := pub.(type) {
case *ecdsa.PublicKey:
if version != VersionTLS13 {
if version < VersionTLS13 {
// In TLS 1.2 and earlier, ECDSA algorithms are not
// constrained to a single curve.
sigAlgs = []SignatureScheme{
return []SignatureScheme{
ECDSAWithP256AndSHA256,
ECDSAWithP384AndSHA384,
ECDSAWithP521AndSHA512,
ECDSAWithSHA1,
}
break
}
switch pub.Curve {
case elliptic.P256():
sigAlgs = []SignatureScheme{ECDSAWithP256AndSHA256}
return []SignatureScheme{ECDSAWithP256AndSHA256}
case elliptic.P384():
sigAlgs = []SignatureScheme{ECDSAWithP384AndSHA384}
return []SignatureScheme{ECDSAWithP384AndSHA384}
case elliptic.P521():
sigAlgs = []SignatureScheme{ECDSAWithP521AndSHA512}
return []SignatureScheme{ECDSAWithP521AndSHA512}
default:
return nil
}
case *rsa.PublicKey:
size := pub.Size()
sigAlgs = make([]SignatureScheme, 0, len(rsaSignatureSchemes))
sigAlgs := make([]SignatureScheme, 0, len(rsaSignatureSchemes))
for _, candidate := range rsaSignatureSchemes {
if size >= candidate.minModulusBytes && version <= candidate.maxVersion {
if size >= candidate.minModulusBytes {
sigAlgs = append(sigAlgs, candidate.scheme)
}
}
return sigAlgs
case ed25519.PublicKey:
sigAlgs = []SignatureScheme{Ed25519}
return []SignatureScheme{Ed25519}
default:
return nil
}

if cert.SupportedSignatureAlgorithms != nil {
var filteredSigAlgs []SignatureScheme
for _, sigAlg := range sigAlgs {
if isSupportedSignatureAlgorithm(sigAlg, cert.SupportedSignatureAlgorithms) {
filteredSigAlgs = append(filteredSigAlgs, sigAlg)
}
}
return filteredSigAlgs
}
return sigAlgs
}

// selectSignatureScheme picks a SignatureScheme from the peer's preference list
// that works with the selected certificate. It's only called for protocol
// versions that support signature algorithms, so TLS 1.2 and 1.3.
func selectSignatureScheme(vers uint16, c *Certificate, peerAlgs []SignatureScheme) (SignatureScheme, error) {
supportedAlgs := signatureSchemesForCertificate(vers, c)
priv, ok := c.PrivateKey.(crypto.Signer)
if !ok {
return 0, unsupportedCertificateError(c)
}
supportedAlgs := signatureSchemesForPublicKey(vers, priv.Public())
if c.SupportedSignatureAlgorithms != nil {
supportedAlgs = slices.DeleteFunc(supportedAlgs, func(sigAlg SignatureScheme) bool {
return !isSupportedSignatureAlgorithm(sigAlg, c.SupportedSignatureAlgorithms)
})
}
// Filter out any unsupported signature algorithms, for example due to
// FIPS 140-3 policy, tlssha1=0, or protocol version.
supportedAlgs = slices.DeleteFunc(supportedAlgs, func(sigAlg SignatureScheme) bool {
return isDisabledSignatureAlgorithm(vers, sigAlg, false)
})
if len(supportedAlgs) == 0 {
return 0, unsupportedCertificateError(c)
}
if len(peerAlgs) == 0 && vers == VersionTLS12 {
// For TLS 1.2, if the client didn't send signature_algorithms then we
// can assume that it supports SHA1. See RFC 5246, Section 7.4.1.4.1.
// RFC 9155 made signature_algorithms mandatory in TLS 1.2, and we gated
// it behind the tlssha1 GODEBUG setting.
if tlssha1.Value() != "1" {
return 0, errors.New("tls: missing signature_algorithms from TLS 1.2 peer")
}
peerAlgs = []SignatureScheme{PKCS1WithSHA1, ECDSAWithSHA1}
}
// Pick signature scheme in the peer's preference order, as our
// preference order is not configurable.
for _, preferredAlg := range peerAlgs {
// [uTLS] SECTION BEGIN
// if fips140tls.Required() && !isSupportedSignatureAlgorithm(preferredAlg, defaultSupportedSignatureAlgorithmsFIPS) {
// continue
// }
// [uTLS] SECTION END
if isSupportedSignatureAlgorithm(preferredAlg, supportedAlgs) {
return preferredAlg, nil
}
Expand Down
42 changes: 25 additions & 17 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tls

import (
"crypto"
"os"
"testing"

"github.com/refraction-networking/utls/internal/fips140tls"
Expand Down Expand Up @@ -34,35 +35,35 @@ func TestSignatureSelection(t *testing.T) {
cert *Certificate
peerSigAlgs []SignatureScheme
tlsVersion uint16
godebug string

expectedSigAlg SignatureScheme
expectedSigType uint8
expectedHash crypto.Hash
}{
{rsaCert, []SignatureScheme{PKCS1WithSHA1, PKCS1WithSHA256}, VersionTLS12, PKCS1WithSHA1, signaturePKCS1v15, crypto.SHA1},
{rsaCert, []SignatureScheme{PKCS1WithSHA512, PKCS1WithSHA1}, VersionTLS12, PKCS1WithSHA512, signaturePKCS1v15, crypto.SHA512},
{rsaCert, []SignatureScheme{PSSWithSHA256, PKCS1WithSHA256}, VersionTLS12, PSSWithSHA256, signatureRSAPSS, crypto.SHA256},
{pkcs1Cert, []SignatureScheme{PSSWithSHA256, PKCS1WithSHA256}, VersionTLS12, PKCS1WithSHA256, signaturePKCS1v15, crypto.SHA256},
{rsaCert, []SignatureScheme{PSSWithSHA384, PKCS1WithSHA1}, VersionTLS13, PSSWithSHA384, signatureRSAPSS, crypto.SHA384},
{ecdsaCert, []SignatureScheme{ECDSAWithSHA1}, VersionTLS12, ECDSAWithSHA1, signatureECDSA, crypto.SHA1},
{ecdsaCert, []SignatureScheme{ECDSAWithP256AndSHA256}, VersionTLS12, ECDSAWithP256AndSHA256, signatureECDSA, crypto.SHA256},
{ecdsaCert, []SignatureScheme{ECDSAWithP256AndSHA256}, VersionTLS13, ECDSAWithP256AndSHA256, signatureECDSA, crypto.SHA256},
{ed25519Cert, []SignatureScheme{Ed25519}, VersionTLS12, Ed25519, signatureEd25519, directSigning},
{ed25519Cert, []SignatureScheme{Ed25519}, VersionTLS13, Ed25519, signatureEd25519, directSigning},

// TLS 1.2 without signature_algorithms extension
{rsaCert, nil, VersionTLS12, PKCS1WithSHA1, signaturePKCS1v15, crypto.SHA1},
{ecdsaCert, nil, VersionTLS12, ECDSAWithSHA1, signatureECDSA, crypto.SHA1},
{rsaCert, []SignatureScheme{PKCS1WithSHA1, PKCS1WithSHA256}, VersionTLS12, "", PKCS1WithSHA256, signaturePKCS1v15, crypto.SHA256},
{rsaCert, []SignatureScheme{PKCS1WithSHA512, PKCS1WithSHA1}, VersionTLS12, "", PKCS1WithSHA512, signaturePKCS1v15, crypto.SHA512},
{rsaCert, []SignatureScheme{PSSWithSHA256, PKCS1WithSHA256}, VersionTLS12, "", PSSWithSHA256, signatureRSAPSS, crypto.SHA256},
{pkcs1Cert, []SignatureScheme{PSSWithSHA256, PKCS1WithSHA256}, VersionTLS12, "", PKCS1WithSHA256, signaturePKCS1v15, crypto.SHA256},
{rsaCert, []SignatureScheme{PSSWithSHA384, PKCS1WithSHA1}, VersionTLS13, "", PSSWithSHA384, signatureRSAPSS, crypto.SHA384},
{rsaCert, []SignatureScheme{PKCS1WithSHA1, PSSWithSHA384}, VersionTLS13, "", PSSWithSHA384, signatureRSAPSS, crypto.SHA384},
{ecdsaCert, []SignatureScheme{ECDSAWithSHA1, ECDSAWithP256AndSHA256}, VersionTLS12, "", ECDSAWithP256AndSHA256, signatureECDSA, crypto.SHA256},
{ecdsaCert, []SignatureScheme{ECDSAWithP256AndSHA256}, VersionTLS12, "", ECDSAWithP256AndSHA256, signatureECDSA, crypto.SHA256},
{ecdsaCert, []SignatureScheme{ECDSAWithP256AndSHA256}, VersionTLS13, "", ECDSAWithP256AndSHA256, signatureECDSA, crypto.SHA256},
{ed25519Cert, []SignatureScheme{Ed25519}, VersionTLS12, "", Ed25519, signatureEd25519, directSigning},
{ed25519Cert, []SignatureScheme{Ed25519}, VersionTLS13, "", Ed25519, signatureEd25519, directSigning},

// TLS 1.2 does not restrict the ECDSA curve (our ecdsaCert is P-256)
{ecdsaCert, []SignatureScheme{ECDSAWithP384AndSHA384}, VersionTLS12, ECDSAWithP384AndSHA384, signatureECDSA, crypto.SHA384},
{ecdsaCert, []SignatureScheme{ECDSAWithP384AndSHA384}, VersionTLS12, "", ECDSAWithP384AndSHA384, signatureECDSA, crypto.SHA384},
}

for testNo, test := range tests {
if fips140tls.Required() && (test.expectedHash == crypto.SHA1 || test.expectedSigAlg == Ed25519) {
if fips140tls.Required() && test.expectedHash == crypto.SHA1 {
t.Logf("skipping test[%d] - not compatible with TLS FIPS mode", testNo)
continue
}
savedGODEBUG := os.Getenv("GODEBUG")
os.Setenv("GODEBUG", savedGODEBUG+","+test.godebug)

sigAlg, err := selectSignatureScheme(test.tlsVersion, test.cert, test.peerSigAlgs)
if err != nil {
Expand All @@ -81,6 +82,8 @@ func TestSignatureSelection(t *testing.T) {
if test.expectedHash != hashFunc {
t.Errorf("test[%d]: expected hash function %#x, got %#x", testNo, test.expectedHash, hashFunc)
}

os.Setenv("GODEBUG", savedGODEBUG)
}

brokenCert := &Certificate{
Expand Down Expand Up @@ -117,6 +120,11 @@ func TestSignatureSelection(t *testing.T) {
{ecdsaCert, []SignatureScheme{ECDSAWithSHA1}, VersionTLS13},
// The key can be too small for the hash.
{rsaCert, []SignatureScheme{PSSWithSHA512}, VersionTLS12},
// SHA-1 requires tlssha1=1
{rsaCert, []SignatureScheme{PKCS1WithSHA1}, VersionTLS12},
{ecdsaCert, []SignatureScheme{ECDSAWithSHA1}, VersionTLS12},
{rsaCert, nil, VersionTLS12},
{ecdsaCert, nil, VersionTLS12},
}

for testNo, test := range badTests {
Expand Down Expand Up @@ -160,7 +168,7 @@ func TestLegacyTypeAndHash(t *testing.T) {
// TestSupportedSignatureAlgorithms checks that all supportedSignatureAlgorithms
// have valid type and hash information.
func TestSupportedSignatureAlgorithms(t *testing.T) {
for _, sigAlg := range supportedSignatureAlgorithms() {
for _, sigAlg := range supportedSignatureAlgorithms(VersionTLS12) {
sigType, hash, err := typeAndHashFromSignatureScheme(sigAlg)
if err != nil {
t.Errorf("%v: unexpected error: %v", sigAlg, err)
Expand Down
11 changes: 11 additions & 0 deletions bogo_shim_notunix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2025 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !unix || wasm

package tls

func pauseProcess() {
panic("-wait-for-debugger not supported on this OS")
}
18 changes: 18 additions & 0 deletions bogo_shim_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2025 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix && !wasm

package tls

import (
"os"
"syscall"
)

func pauseProcess() {
pid := os.Getpid()
process, _ := os.FindProcess(pid)
process.Signal(syscall.SIGSTOP)
}
Loading
Loading