mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
clean up errors
This commit is contained in:
parent
41fcffbfab
commit
a3cb770f77
@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidAuthentication = errors.New("Invalid authentication.")
|
||||
ErrInvalidProtocolVersion = errors.New("Invalid protocol version.")
|
||||
ErrAlreadyListening = errors.New("Already listening on another port.")
|
||||
)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"v2ray.com/core/common/log"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/common/crypto"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -70,13 +71,13 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
|
||||
auth.nMethods = buffer[1]
|
||||
if auth.nMethods <= 0 {
|
||||
log.Warning("Socks: Zero length of authentication methods")
|
||||
err = proxy.ErrInvalidAuthentication
|
||||
err = crypto.ErrAuthenticationFailed
|
||||
return
|
||||
}
|
||||
|
||||
if nBytes-2 != int(auth.nMethods) {
|
||||
log.Warning("Socks: Unmatching number of auth methods, expecting ", auth.nMethods, ", but got ", nBytes)
|
||||
err = proxy.ErrInvalidAuthentication
|
||||
err = crypto.ErrAuthenticationFailed
|
||||
return
|
||||
}
|
||||
copy(auth.authMethods[:], buffer[2:nBytes])
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/testing/assert"
|
||||
"v2ray.com/core/common/crypto"
|
||||
)
|
||||
|
||||
func TestHasAuthenticationMethod(t *testing.T) {
|
||||
@ -145,7 +146,7 @@ func TestZeroAuthenticationMethod(t *testing.T) {
|
||||
buffer := alloc.NewBuffer()
|
||||
buffer.AppendBytes(5, 0)
|
||||
_, _, err := ReadAuthentication(buffer)
|
||||
assert.Error(err).Equals(proxy.ErrInvalidAuthentication)
|
||||
assert.Error(err).Equals(crypto.ErrAuthenticationFailed)
|
||||
}
|
||||
func TestWrongProtocolVersion(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/common/crypto"
|
||||
"v2ray.com/core/common/errors"
|
||||
v2io "v2ray.com/core/common/io"
|
||||
"v2ray.com/core/common/loader"
|
||||
@ -171,8 +172,8 @@ func (v *Server) handleSocks5(clientAddr v2net.Destination, reader *v2io.Buffere
|
||||
}
|
||||
if status != byte(0) {
|
||||
log.Warning("Socks: Invalid user account: ", upRequest.AuthDetail())
|
||||
log.Access(clientAddr, "", log.AccessRejected, proxy.ErrInvalidAuthentication)
|
||||
return proxy.ErrInvalidAuthentication
|
||||
log.Access(clientAddr, "", log.AccessRejected, crypto.ErrAuthenticationFailed)
|
||||
return crypto.ErrAuthenticationFailed
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,14 +4,10 @@ import (
|
||||
"crypto/cipher"
|
||||
"hash/fnv"
|
||||
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/crypto"
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidAuth = errors.New("Invalid auth.")
|
||||
)
|
||||
|
||||
// SimpleAuthenticator is a legacy AEAD used for KCP encryption.
|
||||
type SimpleAuthenticator struct{}
|
||||
|
||||
@ -68,12 +64,12 @@ func (v *SimpleAuthenticator) Open(dst, nonce, cipherText, extra []byte) ([]byte
|
||||
fnvHash := fnv.New32a()
|
||||
fnvHash.Write(dst[4:])
|
||||
if serial.BytesToUint32(dst[:4]) != fnvHash.Sum32() {
|
||||
return nil, errInvalidAuth
|
||||
return nil, crypto.ErrAuthenticationFailed
|
||||
}
|
||||
|
||||
length := serial.BytesToUint16(dst[4:6])
|
||||
if len(dst)-6 != int(length) {
|
||||
return nil, errInvalidAuth
|
||||
return nil, crypto.ErrAuthenticationFailed
|
||||
}
|
||||
|
||||
return dst[6:], nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user