mirror of https://github.com/v2ray/v2ray-core
refine error message
parent
26aa48d4f9
commit
2078f29142
|
@ -4,12 +4,10 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"v2ray.com/core/common/alloc"
|
"v2ray.com/core/common/alloc"
|
||||||
"v2ray.com/core/common/log"
|
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -98,8 +96,7 @@ func (this *ChunkReader) Read() (*alloc.Buffer, error) {
|
||||||
actualAuthBytes := this.auth.Authenticate(nil, payload)
|
actualAuthBytes := this.auth.Authenticate(nil, payload)
|
||||||
if !bytes.Equal(authBytes, actualAuthBytes) {
|
if !bytes.Equal(authBytes, actualAuthBytes) {
|
||||||
buffer.Release()
|
buffer.Release()
|
||||||
log.Debug("AuthenticationReader: Unexpected auth: ", authBytes)
|
return nil, errors.New("Shadowsocks|AuthenticationReader: Invalid auth.")
|
||||||
return nil, transport.ErrCorruptedPacket
|
|
||||||
}
|
}
|
||||||
buffer.SliceFrom(AuthSize)
|
buffer.SliceFrom(AuthSize)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"v2ray.com/core/common/alloc"
|
"v2ray.com/core/common/alloc"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -47,8 +47,7 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if nBytes < 2 {
|
if nBytes < 2 {
|
||||||
log.Warning("Socks: expected 2 bytes read, but only ", nBytes, " bytes read")
|
err = errors.New("Socks: Insufficient header.")
|
||||||
err = transport.ErrCorruptedPacket
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,8 +223,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Warning("Socks: Unexpected address type ", request.AddrType)
|
err = fmt.Errorf("Socks: Unexpected address type %d", request.AddrType)
|
||||||
err = transport.ErrCorruptedPacket
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
"v2ray.com/core/testing/assert"
|
"v2ray.com/core/testing/assert"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHasAuthenticationMethod(t *testing.T) {
|
func TestHasAuthenticationMethod(t *testing.T) {
|
||||||
|
@ -136,7 +135,7 @@ func TestSingleByteAuthRequest(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
_, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1)))
|
_, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1)))
|
||||||
assert.Error(err).Equals(transport.ErrCorruptedPacket)
|
assert.Error(err).IsNotNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestZeroAuthenticationMethod(t *testing.T) {
|
func TestZeroAuthenticationMethod(t *testing.T) {
|
||||||
|
|
|
@ -2,11 +2,9 @@ package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"v2ray.com/core/common/alloc"
|
"v2ray.com/core/common/alloc"
|
||||||
"v2ray.com/core/common/log"
|
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -40,7 +38,7 @@ func (request *Socks5UDPRequest) Write(buffer *alloc.Buffer) {
|
||||||
|
|
||||||
func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) {
|
func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) {
|
||||||
if len(packet) < 5 {
|
if len(packet) < 5 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("Socks|UDP: Insufficient length of packet.")
|
||||||
}
|
}
|
||||||
request := new(Socks5UDPRequest)
|
request := new(Socks5UDPRequest)
|
||||||
|
|
||||||
|
@ -53,7 +51,7 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) {
|
||||||
switch addrType {
|
switch addrType {
|
||||||
case AddrTypeIPv4:
|
case AddrTypeIPv4:
|
||||||
if len(packet) < 10 {
|
if len(packet) < 10 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("Socks|UDP: Insufficient length of packet.")
|
||||||
}
|
}
|
||||||
ip := packet[4:8]
|
ip := packet[4:8]
|
||||||
request.Port = v2net.PortFromBytes(packet[8:10])
|
request.Port = v2net.PortFromBytes(packet[8:10])
|
||||||
|
@ -61,7 +59,7 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) {
|
||||||
dataBegin = 10
|
dataBegin = 10
|
||||||
case AddrTypeIPv6:
|
case AddrTypeIPv6:
|
||||||
if len(packet) < 22 {
|
if len(packet) < 22 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("Socks|UDP: Insufficient length of packet.")
|
||||||
}
|
}
|
||||||
ip := packet[4:20]
|
ip := packet[4:20]
|
||||||
request.Port = v2net.PortFromBytes(packet[20:22])
|
request.Port = v2net.PortFromBytes(packet[20:22])
|
||||||
|
@ -70,15 +68,14 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) {
|
||||||
case AddrTypeDomain:
|
case AddrTypeDomain:
|
||||||
domainLength := int(packet[4])
|
domainLength := int(packet[4])
|
||||||
if len(packet) < 5+domainLength+2 {
|
if len(packet) < 5+domainLength+2 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("Socks|UDP: Insufficient length of packet.")
|
||||||
}
|
}
|
||||||
domain := string(packet[5 : 5+domainLength])
|
domain := string(packet[5 : 5+domainLength])
|
||||||
request.Port = v2net.PortFromBytes(packet[5+domainLength : 5+domainLength+2])
|
request.Port = v2net.PortFromBytes(packet[5+domainLength : 5+domainLength+2])
|
||||||
request.Address = v2net.ParseAddress(domain)
|
request.Address = v2net.ParseAddress(domain)
|
||||||
dataBegin = 5 + domainLength + 2
|
dataBegin = 5 + domainLength + 2
|
||||||
default:
|
default:
|
||||||
log.Warning("Unknown address type ", addrType)
|
return nil, fmt.Errorf("Socks|UDP: Unknown address type %d", addrType)
|
||||||
return nil, ErrorUnknownAddressType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(packet) > dataBegin {
|
if len(packet) > dataBegin {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/testing/assert"
|
"v2ray.com/core/testing/assert"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSingleByteUDPRequest(t *testing.T) {
|
func TestSingleByteUDPRequest(t *testing.T) {
|
||||||
|
@ -15,7 +14,7 @@ func TestSingleByteUDPRequest(t *testing.T) {
|
||||||
if request != nil {
|
if request != nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
assert.Error(err).Equals(transport.ErrCorruptedPacket)
|
assert.Error(err).IsNotNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDomainAddressRequest(t *testing.T) {
|
func TestDomainAddressRequest(t *testing.T) {
|
||||||
|
|
|
@ -3,15 +3,14 @@ package encoding
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"v2ray.com/core/common/crypto"
|
"v2ray.com/core/common/crypto"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func hashTimestamp(t protocol.Timestamp) []byte {
|
func hashTimestamp(t protocol.Timestamp) []byte {
|
||||||
|
@ -113,8 +112,7 @@ func (this *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Res
|
||||||
}
|
}
|
||||||
|
|
||||||
if buffer[0] != this.responseHeader {
|
if buffer[0] != this.responseHeader {
|
||||||
log.Info("Raw: Unexpected response header. Expecting ", this.responseHeader, " but actually ", buffer[0])
|
return nil, fmt.Errorf("VMess|Client: Unexpected response header. Expecting %d but actually %d", this.responseHeader, buffer[0])
|
||||||
return nil, transport.ErrCorruptedPacket
|
|
||||||
}
|
}
|
||||||
|
|
||||||
header := &protocol.ResponseHeader{
|
header := &protocol.ResponseHeader{
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/common/uuid"
|
"v2ray.com/core/common/uuid"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -54,12 +53,12 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
|
||||||
|
|
||||||
func UnmarshalCommand(cmdId byte, data []byte) (protocol.ResponseCommand, error) {
|
func UnmarshalCommand(cmdId byte, data []byte) (protocol.ResponseCommand, error) {
|
||||||
if len(data) <= 4 {
|
if len(data) <= 4 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|Command: Insufficient length.")
|
||||||
}
|
}
|
||||||
expectedAuth := Authenticate(data[4:])
|
expectedAuth := Authenticate(data[4:])
|
||||||
actualAuth := serial.BytesToUint32(data[:4])
|
actualAuth := serial.BytesToUint32(data[:4])
|
||||||
if expectedAuth != actualAuth {
|
if expectedAuth != actualAuth {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|Command: Invalid auth.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var factory CommandFactory
|
var factory CommandFactory
|
||||||
|
@ -111,38 +110,38 @@ func (this *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.
|
||||||
func (this *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
|
func (this *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
|
||||||
cmd := new(protocol.CommandSwitchAccount)
|
cmd := new(protocol.CommandSwitchAccount)
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
lenHost := int(data[0])
|
lenHost := int(data[0])
|
||||||
if len(data) < lenHost+1 {
|
if len(data) < lenHost+1 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
if lenHost > 0 {
|
if lenHost > 0 {
|
||||||
cmd.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
|
cmd.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
|
||||||
}
|
}
|
||||||
portStart := 1 + lenHost
|
portStart := 1 + lenHost
|
||||||
if len(data) < portStart+2 {
|
if len(data) < portStart+2 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
cmd.Port = v2net.PortFromBytes(data[portStart : portStart+2])
|
cmd.Port = v2net.PortFromBytes(data[portStart : portStart+2])
|
||||||
idStart := portStart + 2
|
idStart := portStart + 2
|
||||||
if len(data) < idStart+16 {
|
if len(data) < idStart+16 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
|
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
|
||||||
alterIdStart := idStart + 16
|
alterIdStart := idStart + 16
|
||||||
if len(data) < alterIdStart+2 {
|
if len(data) < alterIdStart+2 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
cmd.AlterIds = serial.BytesToUint16(data[alterIdStart : alterIdStart+2])
|
cmd.AlterIds = serial.BytesToUint16(data[alterIdStart : alterIdStart+2])
|
||||||
levelStart := alterIdStart + 2
|
levelStart := alterIdStart + 2
|
||||||
if len(data) < levelStart+1 {
|
if len(data) < levelStart+1 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
cmd.Level = uint32(data[levelStart])
|
cmd.Level = uint32(data[levelStart])
|
||||||
timeStart := levelStart + 1
|
timeStart := levelStart + 1
|
||||||
if len(data) < timeStart {
|
if len(data) < timeStart {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
|
||||||
}
|
}
|
||||||
cmd.ValidMin = data[timeStart]
|
cmd.ValidMin = data[timeStart]
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
|
|
|
@ -2,16 +2,15 @@ package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"errors"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"v2ray.com/core/common/crypto"
|
"v2ray.com/core/common/crypto"
|
||||||
"v2ray.com/core/common/log"
|
"v2ray.com/core/common/log"
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerSession struct {
|
type ServerSession struct {
|
||||||
|
@ -61,8 +60,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
|
||||||
iv := timestampHash.Sum(nil)
|
iv := timestampHash.Sum(nil)
|
||||||
account, err := user.GetTypedAccount()
|
account, err := user.GetTypedAccount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Vmess: Failed to get user account: ", err)
|
return nil, errors.New("VMess|Server: Failed to get user account: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aesStream := crypto.NewAesDecryptionStream(account.(*vmess.InternalAccount).ID.CmdKey(), iv)
|
aesStream := crypto.NewAesDecryptionStream(account.(*vmess.InternalAccount).ID.CmdKey(), iv)
|
||||||
|
@ -70,8 +68,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
|
||||||
|
|
||||||
nBytes, err := io.ReadFull(decryptor, buffer[:41])
|
nBytes, err := io.ReadFull(decryptor, buffer[:41])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Raw: Failed to read request header (", nBytes, " bytes): ", err)
|
return nil, errors.New("VMess|Server: Failed to read request header: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
bufferLen := nBytes
|
bufferLen := nBytes
|
||||||
|
|
||||||
|
@ -81,7 +78,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.Version != Version {
|
if request.Version != Version {
|
||||||
log.Info("Raw: Invalid protocol version ", request.Version)
|
log.Info("VMess|Server: Invalid protocol version ", request.Version)
|
||||||
return nil, protocol.ErrInvalidVersion
|
return nil, protocol.ErrInvalidVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,32 +95,28 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
|
||||||
nBytes, err = io.ReadFull(decryptor, buffer[41:45]) // 4 bytes
|
nBytes, err = io.ReadFull(decryptor, buffer[41:45]) // 4 bytes
|
||||||
bufferLen += 4
|
bufferLen += 4
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("VMess: Failed to read target IPv4 (", nBytes, " bytes): ", err)
|
return nil, errors.New("VMess|Server: Failed to read IPv4: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
request.Address = v2net.IPAddress(buffer[41:45])
|
request.Address = v2net.IPAddress(buffer[41:45])
|
||||||
case AddrTypeIPv6:
|
case AddrTypeIPv6:
|
||||||
nBytes, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
|
nBytes, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
|
||||||
bufferLen += 16
|
bufferLen += 16
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("VMess: Failed to read target IPv6 (", nBytes, " bytes): ", nBytes, err)
|
return nil, errors.New("VMess|Server: Failed to read IPv6 address: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
request.Address = v2net.IPAddress(buffer[41:57])
|
request.Address = v2net.IPAddress(buffer[41:57])
|
||||||
case AddrTypeDomain:
|
case AddrTypeDomain:
|
||||||
nBytes, err = io.ReadFull(decryptor, buffer[41:42])
|
_, err = io.ReadFull(decryptor, buffer[41:42])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("VMess: Failed to read target domain (", nBytes, " bytes): ", nBytes, err)
|
return nil, errors.New("VMess:Server: Failed to read domain: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
domainLength := int(buffer[41])
|
domainLength := int(buffer[41])
|
||||||
if domainLength == 0 {
|
if domainLength == 0 {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|Server: Zero domain length.")
|
||||||
}
|
}
|
||||||
nBytes, err = io.ReadFull(decryptor, buffer[42:42+domainLength])
|
nBytes, err = io.ReadFull(decryptor, buffer[42:42+domainLength])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("VMess: Failed to read target domain (", nBytes, " bytes): ", nBytes, err)
|
return nil, errors.New("VMess|Server: Failed to read domain: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
bufferLen += 1 + domainLength
|
bufferLen += 1 + domainLength
|
||||||
request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength]))
|
request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength]))
|
||||||
|
@ -131,8 +124,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
|
||||||
|
|
||||||
nBytes, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+4])
|
nBytes, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+4])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("VMess: Failed to read checksum (", nBytes, " bytes): ", nBytes, err)
|
return nil, errors.New("VMess|Server: Failed to read checksum: " + err.Error())
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv1a := fnv.New32a()
|
fnv1a := fnv.New32a()
|
||||||
|
@ -141,7 +133,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
|
||||||
expectedHash := serial.BytesToUint32(buffer[bufferLen : bufferLen+4])
|
expectedHash := serial.BytesToUint32(buffer[bufferLen : bufferLen+4])
|
||||||
|
|
||||||
if actualHash != expectedHash {
|
if actualHash != expectedHash {
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|Server: Invalid auth.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return request, nil
|
return request, nil
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package io
|
package io
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"hash"
|
"hash"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"v2ray.com/core/common/alloc"
|
"v2ray.com/core/common/alloc"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/transport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Private: Visible for testing.
|
// Private: Visible for testing.
|
||||||
|
@ -93,7 +92,7 @@ func (this *AuthChunkReader) Read() (*alloc.Buffer, error) {
|
||||||
this.validator.Consume(buffer.Value[:this.chunkLength])
|
this.validator.Consume(buffer.Value[:this.chunkLength])
|
||||||
if !this.validator.Validate() {
|
if !this.validator.Validate() {
|
||||||
buffer.Release()
|
buffer.Release()
|
||||||
return nil, transport.ErrCorruptedPacket
|
return nil, errors.New("VMess|AuthChunkReader: Invalid auth.")
|
||||||
}
|
}
|
||||||
leftLength := buffer.Len() - this.chunkLength
|
leftLength := buffer.Len() - this.chunkLength
|
||||||
if leftLength > 0 {
|
if leftLength > 0 {
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package transport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrCorruptedPacket = errors.New("Packet is corrupted.")
|
|
||||||
)
|
|
Loading…
Reference in New Issue