Skip to content

Port the fork onto metacubex/utls v1.9.0-alpha.1 - #6

Merged
Nemu-x merged 27 commits into
dev-1.9from
port/utls-1.9
Nov 11, 2026
Merged

Nemu-x merged 27 commits into
dev-1.9from
port/utls-1.9

Conversation

@Nemu-x

@Nemu-x Nemu-x commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Ports the fork's commits (v1.8.8..dev, a6dee38) onto metacubex/utls v1.9.0-alpha.1 (go1.26 crypto/tls base). dev-1.9 was created at the v1.9.0-alpha.1 tag (89a07ad).

Commit classification

Old commit Subject Result
0eed8b0 fix(reality): imitate target TLS 1.3 post-handshake records kept
1a98a45 fix(reality): raise the target record buffer to 17 KiB kept (v1.9 only raised it to 16 KiB)
ebc62b0 feat(reality): sign the temporary certificate with ML-DSA-65 kept (import conflict: internal/mlkem -> mlkem)
37238a1 feat(reality): optionally require an X25519MLKEM768 key share kept, import fixed in the port commit
8cd1892 feat: add ff 148 spec and impl keyshare reuse dropped: in v1.9 (fc716b2, newer marker-based reuse)
f93f086 feat: add safari 26.3 dropped: in v1.9 (aa6edf4)
5ad21de test(reality): browser fingerprints pass the X25519MLKEM768 requirement kept
865a03c fix: re-check verified chains against the current roots on resumption dropped: v1.9 has the Go fixes (1dcb033, 6d07980, 2cf02ea)
3a71ed0 fix(ech): return the outer ClientHello build error kept
d00159d fix(ech): pass the server certificates to EncryptedClientHelloRejectionVerify kept
9f70311 fix: default the server minimum version to TLS 1.2 kept
a3a2a55 fix: return errors instead of panicking on malformed ClientHello imports kept
2b28146 fix(roller): close the TCP connection after a failed handshake kept
22b73c4 fix: bound compressed certificate decompression kept
5f40e26 fix(mlkem): panic when crypto/rand fails instead of using zero bytes reworked: files moved to mlkem/
fe273b2 fix: return errors for out-of-range HKDF and exporter lengths kept
e798688 crypto/tls: validate ECH outer extension references (CVE fix) kept (not in the go1.26 base used by v1.9)
c4444fe crypto/tls: do not count handshake messages as state-advancing post-handshake kept (not in the base)
b0d9724 ci: test the citrus branch on push and pull requests kept; upstream go.yml removed as on dev
50ca4c4 test: set serial numbers in the resumption trust certificates dropped with 865a03c
42cb40a test: report ApplyPreset errors without racing on err kept
a6af36b ci: run on main and dev, skip loopclosure in vet, keep LF on Windows kept
b76689d crypto/tls: write the records of one write together kept
5b1b53d test: wait for the client before closing in TestWriteSmallRecordsUnchanged kept
bc98cb6 fix: bound REALITY handshakes and preserve JLS application verification kept
9c481dd fix(reality): release hosting handshake guards on fallback kept
540608d feat: add HelloChrome_155 and make it HelloChrome_Auto kept, applied cleanly on the v1.9 parrots
a3a3d53 test: build the Chrome 155 tests with Go 1.20 kept

New commits:

  • port: follow the v1.9 mlkem and hpke package layout: REALITY key share imports and the ECH build test (the internal/hpke constants are gone).
  • test: check that ApplyPreset keeps the Chrome 155 preset unshared: v1.9 clones the spec in ApplyPreset, so the preset ownership test from refraction 6ebdceb that was left out before is now ported.
  • ci: run on dev-1.9.

go.mod still says go 1.20 (v1.9.0-alpha.1 keeps the Go 1.20 minimum), so the CI matrix stays Go 1.20 + 1.26.

Tests

  • go build ./..., go vet -loopclosure=false ./..., go test -count=1 ./... with Go 1.26.1 on Windows: pass
  • go test -count=1 ./... with Go 1.20 (golang:1.20, CGO off): pass
  • go test -race -count=1 ./... with Go 1.26.10 (golang:1.26): pass
  • Chrome 155 capture/round-trip, preset ownership, Chrome 133 preserved, ML-DSA JSON, trust anchors tests pass.

Nemu-x and others added 27 commits November 11, 2026 12:52
After ClientFinished, the REALITY server may remain silent where the configured target emits TLS 1.3 post-handshake records.

Learn target post-handshake record lengths asynchronously per destination, SNI, ALPN mode and cipher suite, then emit matching encrypted application-data records before marking the handshake complete.

Probe failures preserve existing behavior, probes are coalesced and rate-limited, and RealityConfig clones share the cache. Client-side REALITY behavior is unchanged.

(cherry picked from commit 0eed8b0)
A target whose first flight holds a full-size TLS 1.3 record (16384 bytes
of plaintext, up to 16645 bytes on the wire) exceeded the 16 KiB buffer and
the REALITY handshake was aborted. Use 17 KiB like XTLS/REALITY#33
(Xray v26.9.8).

(cherry picked from commit 1a98a45)
Add RealityConfig.Mldsa65Seed, the 32-byte seed of Xray's "mldsa65Seed".
When set, the server uses a temporary certificate whose first extension
(OID 0.0) carries an ML-DSA-65 signature, as XTLS/REALITY does: the HMAC
over the ed25519 public key keyed with the auth key is continued over the
raw ClientHello and the raw ServerHello, and its digest is signed
deterministically with an empty context. Xray clients configured with
"mldsa65Verify" require this signature.

Keys come from github.com/metacubex/mldsa (crypto/mldsa backported to
Go 1.20). Test vectors generated with cloudflare/circl, which Xray uses,
prove that seeds expand to the same public keys and produce the same
signatures. RealityMldsa65Verify returns the "mldsa65Verify" value for a
seed.

(cherry picked from commit ebc62b0)
Add RealityConfig.RequireX25519MLKEM768 (default off). When set, a
ClientHello is only considered for REALITY authentication if it carries
exactly one X25519MLKEM768 key share placed before an optional X25519 key
share; anything else is forwarded to the target. This mirrors Xray's rule
from XTLS/REALITY@8cdf7bf, which rejects outdated or unusual ClientHellos.

The key share selection moves to realityClientPeerPub; without the flag it
behaves as before (X25519, else the X25519 part of X25519MLKEM768).

(cherry picked from commit 37238a1)
UConn.MarshalClientHello ignored the error from
computeAndUpdateOuterECHExtension. With ECH configured and a
ClientHelloSpec that cannot carry ECH (e.g. no ECH extension), the
handshake went on and wrote a ClientHello without a sealed inner hello.
Return the error so nothing is sent.

(cherry picked from commit 3a71ed0)
…onVerify

The callback is documented to verify the ECH provider certificate, but
it was called before peerCertificates was set, so
ConnectionState.PeerCertificates was always empty (same as upstream Go,
golang/go#75242). Set the peer certificates before calling it.

(cherry picked from commit d00159d)
MinVersion documents TLS 1.2 as the default minimum, but with the
tls10server GODEBUG knob stubbed out the server side kept accepting
TLS 1.0 and 1.1 when MinVersion was 0. Apply the default to servers as
in crypto/tls; an explicit MinVersion still allows older versions.

(cherry picked from commit 9f70311)
ClientHelloSpec.UnmarshalJSON dereferenced nil cipher_suites,
compression_methods or extensions when they were missing; it now returns
an error, and the ClientHelloSpecJSONUnmarshaler accessors are nil-safe.

ImportTLSClientHello sliced key_share in 4-byte steps without checking
the length, panicking on truncated input, and read only the low byte of
each key_exchange length. Reject input that is not a whole number of
entries and use the full 16-bit length.

(cherry picked from commit a3a2a55)
Roller.Dial moved on to the next ClientHelloID without closing the
connection whose handshake had failed, leaking one socket per attempt.

(cherry picked from commit 2b28146)
decompressCert allocated the peer-declared uncompressed_length (up to
16 MiB) before any check. Reject lengths above maxHandshakeCertificateMsg,
the limit already applied to uncompressed Certificate messages.

It also used a single Read, which can return less than the full message
(zlib returns 32 KiB chunks), failing valid certificates over that size;
use io.ReadFull.

(cherry picked from commit 22b73c4)
The ML-KEM code ignored errors from crypto/rand.Read. Since Go 1.24
that call crashes on failure, but this module supports older Go, where
it returns the error and the seed or encapsulation message would stay
all-zero. Read through a helper that panics on failure, matching the
fatal behaviour of Go's own ML-KEM DRBG.

(cherry picked from commit 5f40e26)
internal/mlkem moved to mlkem and internal/hpke became the hpke package
with a different API. Point the REALITY key share code at mlkem and build
the ECH test config list from RFC 9180 identifiers.
hkdf.Expand and hkdf.Key panicked on a negative length or one above 255
hash blocks; check both and return an error, as crypto/hkdf does.

ConnectionState.ExportKeyingMaterial panicked on a negative length and,
in TLS 1.3, on a label longer than HkdfLabel allows or a length beyond
the HKDF limit (lengths over 65535 would also have been truncated in the
HkdfLabel). Return errors instead; signatures are unchanged.

(cherry picked from commit fe273b2)
Using a single cursor, reject malformed encodings
and esnure that each outer extension is copied at
most once.

Fixes CVE-2026-97031
For golang/go#81855
Fixes golang/go#81915

Change-Id: I5b09f2b6275d42f7701fae4e583eb3a2caeaa44d
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/5320
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/6160
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/847105
Auto-Submit: Gopher Robot <gobot@golang.org>
TryBot-Bypass: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Neal Patel <nealpatel@google.com>
(cherry picked from commit e798688)
…andshake

Port of Go commit b6432317a (release-branch.go1.26). After the handshake,
KeyUpdate messages reset the non-advancing record counter, so a peer could
keep sending them and force key derivation indefinitely. Only application
data, and handshake messages before the handshake completes, now count as
state-advancing.

(cherry picked from commit c4444fe)
Go 1.26 on Linux and Windows with go vet, the minimum Go 1.20 on Linux,
and a race detector run. Replaces the upstream matrix of 30 jobs.

(cherry picked from commit b0d9724)
The client goroutine in testUtlsHandshake assigned the ApplyPreset
result to the named return err, which the test goroutine also writes,
and returned without sending on errChan when it failed.

(cherry picked from commit 42cb40a)
A write of more than one record sent every record with its own write to
the connection, and the network stack is paid per write. The records of
one write are now encrypted in place one behind the other and written
together, up to eight full-sized records (about 128 KiB) at a time.
Nothing is held back: all of it is written before the call returns.

(cherry picked from commit b76689d)
Port the Chrome 155 profile from refraction-networking/utls 6ebdceb
("Add Chrome 155 fingerprint verified against a fresh browser capture"),
verified there against Chrome 155.0.8059.40.

Compared with Chrome 133 the ClientHello gains a GREASE value and the three
ML-DSA schemes (0x0904/0x0905/0x0906) in signature_algorithms and the
trust_anchors extension (0xca34) with 28 Chrome Root Store IDs.

- HelloChrome_155 and its spec; HelloChrome_Auto now points to it, as
  upstream does. HelloChrome_133 is unchanged.
- TrustAnchorsExtension (typed, JSON, Fingerprinter via ExtensionFromID).
- GREASE in signature_algorithms drawn from its own BoringSSL seed slot;
  the internal seed grows to 8 slots while GetBoringGREASEValue keeps its
  [5]uint16 signature.
- MLDSA44/65/87 SignatureScheme constants and dicttls names. Unlike
  upstream (go 1.27 sync) this fork does not implement ML-DSA, so the
  codepoints are only advertised.
- Upstream tests and the captured ClientHello fixture. Not ported: the
  ML-DSA handshake test (needs crypto/mldsa) and the preset ownership test
  (needs upstream's ClientHelloSpec.clone).

(cherry picked from commit 540608d)
slices is not in the Go 1.20 standard library; use reflect.DeepEqual and a
loop instead.

(cherry picked from commit a3a3d53)
v1.9 clones the ClientHelloSpec in ApplyPreset, so the preset ownership
test from refraction-networking/utls 6ebdceb can now be ported: neither
the reusable spec nor other connections may see per-connection changes,
including the nested trust anchor IDs.
The v1.9 port lives on dev-1.9 next to dev; test pushes and pull requests
there too. go.mod still says go 1.20, so the matrix keeps Go 1.20 and 1.26.
@Nemu-x
Nemu-x merged commit b60cfbd into dev-1.9 Nov 11, 2026
4 checks passed
@Nemu-x
Nemu-x deleted the port/utls-1.9 branch November 11, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants