From a9f309039a0b3f760717fd18c4790de84c28cf78 Mon Sep 17 00:00:00 2001 From: roach Date: Thu, 22 Oct 2026 15:23:53 -0500 Subject: [PATCH] Keep GREASE signature algorithms out of the handshake state Chrome 155 sends a GREASE signature algorithm. It belongs on the wire, but writeToUConn also copied it into HandshakeState.Hello, where Go's handshake checks treat it as an offered algorithm. Copy the list without GREASE when one is present; the wire bytes are unchanged. ECH is unaffected because the inner transcript is rebuilt from the outer wire extensions. TestChrome155SignatureGREASESeed asserted the GREASE value in the handshake state; its wire assertion stays, the state one is replaced by TestSignatureAlgorithmGREASEStaysOnTheWire. Based on the writeToUConn part of sardanioss/utls d737ca1. --- u_chrome155_test.go | 3 --- u_sigalg_grease_test.go | 29 +++++++++++++++++++++++++++++ u_tls_extensions.go | 9 ++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 u_sigalg_grease_test.go diff --git a/u_chrome155_test.go b/u_chrome155_test.go index e8317eda446..b6d048ce59d 100644 --- a/u_chrome155_test.go +++ b/u_chrome155_test.go @@ -385,9 +385,6 @@ func TestChrome155SignatureGREASESeed(t *testing.T) { if got != want || got == GREASE_PLACEHOLDER { t.Fatalf("signature GREASE = %#04x, want %#04x from BoringSSL seed slot 7", got, want) } - if gotState := uint16(client.HandshakeState.Hello.SupportedSignatureAlgorithms[0]); gotState != want { - t.Fatalf("signature GREASE in handshake state = %#04x, want %#04x", gotState, want) - } } func TestChrome133CapabilitiesPreserved(t *testing.T) { diff --git a/u_sigalg_grease_test.go b/u_sigalg_grease_test.go new file mode 100644 index 00000000000..ec6dabd6ddc --- /dev/null +++ b/u_sigalg_grease_test.go @@ -0,0 +1,29 @@ +package tls + +import ( + "net" + "slices" + "testing" +) + +// A GREASE signature algorithm is advertised on the wire but must not reach +// the handshake state, where Go's checks would treat it as offered. +func TestSignatureAlgorithmGREASEStaysOnTheWire(t *testing.T) { + client := UClient(&net.TCPConn{}, &Config{ServerName: "example.com"}, HelloChrome_155) + if err := client.BuildHandshakeState(); err != nil { + t.Fatal(err) + } + + var wire clientHelloMsg + if !wire.unmarshal(client.HandshakeState.Hello.Raw) { + t.Fatal("malformed ClientHello") + } + if len(wire.supportedSignatureAlgorithms) == 0 || !isGREASEUint16(uint16(wire.supportedSignatureAlgorithms[0])) { + t.Fatalf("wire signature_algorithms %v, want a leading GREASE value", wire.supportedSignatureAlgorithms) + } + + want := wire.supportedSignatureAlgorithms[1:] + if got := client.HandshakeState.Hello.SupportedSignatureAlgorithms; !slices.Equal(got, want) { + t.Fatalf("handshake state signature algorithms = %v, want %v", got, want) + } +} diff --git a/u_tls_extensions.go b/u_tls_extensions.go index 91162063e0e..0acbc971507 100644 --- a/u_tls_extensions.go +++ b/u_tls_extensions.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io" + "slices" "strings" "github.com/roachadam/utls/dicttls" @@ -470,7 +471,13 @@ func (e *SignatureAlgorithmsExtension) Write(b []byte) (int, error) { } func (e *SignatureAlgorithmsExtension) writeToUConn(uc *UConn) error { - uc.HandshakeState.Hello.SupportedSignatureAlgorithms = e.SupportedSignatureAlgorithms + // GREASE goes on the wire (Read writes it) but is never a real candidate. + isGREASE := func(s SignatureScheme) bool { return isGREASEUint16(uint16(s)) } + algs := e.SupportedSignatureAlgorithms + if slices.ContainsFunc(algs, isGREASE) { + algs = slices.DeleteFunc(slices.Clone(algs), isGREASE) + } + uc.HandshakeState.Hello.SupportedSignatureAlgorithms = algs return nil }