From 856d49d0277e0d475a049a2568b9469b1636aed8 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Wed, 15 Mar 2023 15:55:18 +0800 Subject: [PATCH] chore: Improve REALITY handshake --- component/tls/reality.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/component/tls/reality.go b/component/tls/reality.go index a060de92..85309fb5 100644 --- a/component/tls/reality.go +++ b/component/tls/reality.go @@ -62,16 +62,12 @@ func GetRealityConn(ctx context.Context, conn net.Conn, ClientFingerprint string } hello := uConn.HandshakeState.Hello - hello.SessionId = make([]byte, 32) + for i := range hello.SessionId { // https://github.com/golang/go/issues/5373 + hello.SessionId[i] = 0 + } 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())) + binary.BigEndian.PutUint64(hello.SessionId, uint64(time.Now().Unix())) hello.SessionId[0] = 1 hello.SessionId[1] = 7 @@ -130,7 +126,7 @@ func realityClientFallback(uConn net.Conn, serverName string, fingerprint utls.C return } //_, _ = io.Copy(io.Discard, response.Body) - time.Sleep(time.Duration(5 + fastrand.Int63n(10))) + time.Sleep(time.Duration(5+fastrand.Int63n(10)) * time.Second) response.Body.Close() client.CloseIdleConnections() }