mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 18:11:28 +00:00
Fix decrypt xplus packet
This commit is contained in:
parent
35886b88d7
commit
8703e1ff98
|
@ -10,15 +10,12 @@ import (
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
"github.com/sagernet/sing/common/buf"
|
"github.com/sagernet/sing/common/buf"
|
||||||
"github.com/sagernet/sing/common/bufio"
|
"github.com/sagernet/sing/common/bufio"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
const xplusSaltLen = 16
|
const xplusSaltLen = 16
|
||||||
|
|
||||||
var errInalidPacket = E.New("invalid packet")
|
|
||||||
|
|
||||||
func NewXPlusPacketConn(conn net.PacketConn, key []byte) net.PacketConn {
|
func NewXPlusPacketConn(conn net.PacketConn, key []byte) net.PacketConn {
|
||||||
vectorisedWriter, isVectorised := bufio.CreateVectorisedPacketWriter(conn)
|
vectorisedWriter, isVectorised := bufio.CreateVectorisedPacketWriter(conn)
|
||||||
if isVectorised {
|
if isVectorised {
|
||||||
|
@ -51,7 +48,8 @@ func (c *XPlusPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
} else if n < xplusSaltLen {
|
} else if n < xplusSaltLen {
|
||||||
return 0, nil, errInalidPacket
|
n = 0
|
||||||
|
return
|
||||||
}
|
}
|
||||||
key := sha256.Sum256(append(c.key, p[:xplusSaltLen]...))
|
key := sha256.Sum256(append(c.key, p[:xplusSaltLen]...))
|
||||||
for i := range p[xplusSaltLen:] {
|
for i := range p[xplusSaltLen:] {
|
||||||
|
|
Loading…
Reference in a new issue