fix: ShadowTLS v2 not work with X25519MLKEM768

The v2 server authenticates the client only if its HMAC covers all the
data relayed from the handshake server, or all but the last write. The
client hashed only the bytes the TLS stack asked for, which end at the
server Finished record, so session tickets sent in the same flight were
left out whenever the stack's last read did not happen to pick them up.
With an X25519MLKEM768 ServerHello this happened on every connection to
a Go crypto/tls handshake server, and the chrome fingerprint always fell
back. Read the socket through a 16 KiB buffer and hash everything each
read returns, as the original implementation does.
This commit is contained in:
wwqgtxx committed 2026-11-14 23:09:45 +08:00
1 parent a9e5c456e3
commit 7e73a9448b
3 files changed
+8 -12

No files matched your search

-5
View File
@@ -190,11 +190,6 @@ func uTLSHandshakeFunc(config *tls.Config, clientFingerprint string, version int
return err
}
}
if version == 2 { // ShadowTLS v2 not work with X25519MLKEM768
if err := tlsC.BuildRemovedX25519MLKEM768HandshakeState(tlsConn); err != nil {
return err
}
}
return tlsConn.HandshakeContext(ctx)
}
return tlsC.Client(conn, tlsConfig).HandshakeContext(ctx)
+1
View File
@@ -32,6 +32,7 @@ func TestServer(t *testing.T) {
}{
{name: "v1", version: 1},
{name: "v2", version: 2},
{name: "v2-utls", version: 2, fingerprint: "chrome"},
{name: "v2-utls-websocket", version: 2, fingerprint: "chrome", alpn: WsALPN},
{name: "v3", version: 3},
{name: "v3-utls", version: 3, fingerprint: "chrome"},
+7 -7
View File
@@ -1,6 +1,7 @@
package shadowtls
import (
"bufio"
"bytes"
"crypto/hmac"
"crypto/sha1"
@@ -17,19 +18,18 @@ import (
type hashReadConn struct {
net.Conn
hmac hash.Hash
reader *bufio.Reader
hmac hash.Hash
}
func newHashReadConn(conn net.Conn, password string) *hashReadConn {
return &hashReadConn{Conn: conn, hmac: hmac.New(sha1.New, []byte(password))}
readHMAC := hmac.New(sha1.New, []byte(password))
reader := bufio.NewReaderSize(io.TeeReader(conn, readHMAC), 16*1024)
return &hashReadConn{Conn: conn, reader: reader, hmac: readHMAC}
}
func (c *hashReadConn) Read(p []byte) (int, error) {
n, err := c.Conn.Read(p)
if n > 0 {
_, _ = c.hmac.Write(p[:n])
}
return n, err
return c.reader.Read(p)
}
func (c *hashReadConn) Sum() []byte {