From 25d6a21f751cbb778407fabac6e1ee2786fdaa61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 14 Nov 2026 07:52:37 +0000 Subject: [PATCH] Use configured time and root pool in reality client The reality session id carried time.Now() instead of the configured time, which is the NTP clock when ntp is enabled, so a client whose system clock was off failed every handshake against a server that sets max_time_difference. The certificate check after a failed authentication also used the system clock and system roots instead of the configured clock and certificate store, so it rejected a valid target and skipped the fallback request. --- common/tls/reality_client.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/common/tls/reality_client.go b/common/tls/reality_client.go index 815cf2cf..80edad8c 100644 --- a/common/tls/reality_client.go +++ b/common/tls/reality_client.go @@ -132,10 +132,18 @@ func (e *RealityClientConfig) Client(conn net.Conn) (Conn, error) { } func (e *RealityClientConfig) ClientHandshake(ctx context.Context, conn net.Conn) (aTLS.Conn, error) { - verifier := &realityVerifier{ - serverName: e.uClient.ServerName(), - } uConfig := e.uClient.config.Clone() + var nowTime time.Time + if uConfig.Time != nil { + nowTime = uConfig.Time() + } else { + nowTime = time.Now() + } + verifier := &realityVerifier{ + serverName: e.uClient.ServerName(), + rootCAs: uConfig.RootCAs, + currentTime: nowTime, + } uConfig.InsecureSkipVerify = true uConfig.SessionTicketsDisabled = true uConfig.VerifyPeerCertificate = verifier.VerifyPeerCertificate @@ -150,18 +158,10 @@ func (e *RealityClientConfig) ClientHandshake(ctx context.Context, conn net.Conn hello.SessionId = make([]byte, 32) copy(hello.Raw[39:], hello.SessionId) - var nowTime time.Time - if uConfig.Time != nil { - nowTime = uConfig.Time() - } else { - nowTime = time.Now() - } - binary.BigEndian.PutUint64(hello.SessionId, uint64(nowTime.Unix())) - hello.SessionId[0] = 1 hello.SessionId[1] = 8 hello.SessionId[2] = 2 - binary.BigEndian.PutUint32(hello.SessionId[4:], uint32(time.Now().Unix())) + binary.BigEndian.PutUint32(hello.SessionId[4:], uint32(nowTime.Unix())) copy(hello.SessionId[8:], e.shortID[:]) if debug.Enabled { fmt.Printf("REALITY hello.sessionId[:16]: %v\n", hello.SessionId[:16]) @@ -259,9 +259,11 @@ func (e *RealityClientConfig) Clone() Config { type realityVerifier struct { *utls.UConn - serverName string - authKey []byte - verified bool + serverName string + rootCAs *x509.CertPool + currentTime time.Time + authKey []byte + verified bool } func (c *realityVerifier) VerifyPeerCertificate(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { @@ -276,6 +278,8 @@ func (c *realityVerifier) VerifyPeerCertificate(rawCerts [][]byte, verifiedChain } } opts := x509.VerifyOptions{ + Roots: c.rootCAs, + CurrentTime: c.currentTime, DNSName: c.serverName, Intermediates: x509.NewCertPool(), }