From 502aa61c0e82bfdd66eb5a73ddc37807103766f9 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 6 Nov 2018 17:34:19 +0800 Subject: [PATCH] Fix: vmess small probability invalid auth --- component/vmess/conn.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/component/vmess/conn.go b/component/vmess/conn.go index 8a284b2..8efe7ff 100644 --- a/component/vmess/conn.go +++ b/component/vmess/conn.go @@ -65,11 +65,10 @@ func (vc *Conn) Read(b []byte) (int, error) { } func (vc *Conn) sendRequest() error { - timestamp := make([]byte, 8) - binary.BigEndian.PutUint64(timestamp, uint64(time.Now().UTC().Unix())) + timestamp := time.Now() h := hmac.New(md5.New, vc.id.UUID.Bytes()) - h.Write(timestamp) + binary.Write(h, binary.BigEndian, uint64(timestamp.Unix())) _, err := vc.Conn.Write(h.Sum(nil)) if err != nil { return err @@ -111,7 +110,7 @@ func (vc *Conn) sendRequest() error { return err } - stream := cipher.NewCFBEncrypter(block, hashTimestamp(time.Now().UTC())) + stream := cipher.NewCFBEncrypter(block, hashTimestamp(timestamp)) stream.XORKeyStream(buf.Bytes(), buf.Bytes()) _, err = vc.Conn.Write(buf.Bytes()) return err @@ -145,7 +144,7 @@ func (vc *Conn) recvResponse() error { func hashTimestamp(t time.Time) []byte { md5hash := md5.New() ts := make([]byte, 8) - binary.BigEndian.PutUint64(ts, uint64(t.UTC().Unix())) + binary.BigEndian.PutUint64(ts, uint64(t.Unix())) md5hash.Write(ts) md5hash.Write(ts) md5hash.Write(ts)