From 8703e1ff980022bbfe80078946082429b68ffe1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 26 Oct 2022 20:25:49 +0800 Subject: [PATCH] Fix decrypt xplus packet --- transport/hysteria/xplus.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/transport/hysteria/xplus.go b/transport/hysteria/xplus.go index ed74c7dd..14e0eaa8 100644 --- a/transport/hysteria/xplus.go +++ b/transport/hysteria/xplus.go @@ -10,15 +10,12 @@ import ( "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" - E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" ) const xplusSaltLen = 16 -var errInalidPacket = E.New("invalid packet") - func NewXPlusPacketConn(conn net.PacketConn, key []byte) net.PacketConn { vectorisedWriter, isVectorised := bufio.CreateVectorisedPacketWriter(conn) if isVectorised { @@ -51,7 +48,8 @@ func (c *XPlusPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) { if err != nil { return } else if n < xplusSaltLen { - return 0, nil, errInalidPacket + n = 0 + return } key := sha256.Sum256(append(c.key, p[:xplusSaltLen]...)) for i := range p[xplusSaltLen:] {