152 lines
4.1 KiB
Go
152 lines
4.1 KiB
Go
package socks5
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
const (
|
|
// Version is the protocol version
|
|
Version byte = 0x05
|
|
// Reserved is the reserved field value
|
|
Reserved byte = 0x00
|
|
// PasswordVersion is the username/password auth protocol version
|
|
PasswordVersion byte = 0x01
|
|
// DatagramStandalone is the standalone datagram fragment field value
|
|
DatagramStandalone byte = 0x00
|
|
)
|
|
|
|
// AuthMethod is the auth method
|
|
type AuthMethod byte
|
|
|
|
// Auth methods
|
|
const (
|
|
AuthMethodNone AuthMethod = 0x00
|
|
AuthMethodGSSAPI AuthMethod = 0x01
|
|
AuthMethodPassword AuthMethod = 0x02
|
|
AuthMethodNotSupported AuthMethod = 0xFF
|
|
)
|
|
|
|
func (am AuthMethod) String() string {
|
|
return authMethodNames[am]
|
|
}
|
|
|
|
var authMethodNames = map[AuthMethod]string{
|
|
AuthMethodNone: "none",
|
|
AuthMethodGSSAPI: "gssapi",
|
|
AuthMethodPassword: "password",
|
|
AuthMethodNotSupported: "not supported",
|
|
}
|
|
|
|
// PasswordStatus is the password auth status
|
|
type PasswordStatus byte
|
|
|
|
// Password statuses
|
|
const (
|
|
PasswordStatusSuccess PasswordStatus = 0x00
|
|
PasswordStatusFailure PasswordStatus = 0x01
|
|
)
|
|
|
|
func (ps PasswordStatus) String() string {
|
|
return passwordStatusNames[ps]
|
|
}
|
|
|
|
var passwordStatusNames = map[PasswordStatus]string{
|
|
PasswordStatusSuccess: "success",
|
|
PasswordStatusFailure: "failure",
|
|
}
|
|
|
|
// Command is the command
|
|
type Command byte
|
|
|
|
// Commands
|
|
const (
|
|
CommandConnect Command = 0x01
|
|
CommandBind Command = 0x02
|
|
CommandUDPAssociate Command = 0x03
|
|
)
|
|
|
|
func (c Command) String() string {
|
|
return commandNames[c]
|
|
}
|
|
|
|
var commandNames = map[Command]string{
|
|
CommandConnect: "connect",
|
|
CommandBind: "bind",
|
|
CommandUDPAssociate: "udp associate",
|
|
}
|
|
|
|
// ATYP is the address type
|
|
type ATYP byte
|
|
|
|
// Address types
|
|
const (
|
|
ATYPIPv4 ATYP = 0x01
|
|
ATYPFQDN ATYP = 0x03
|
|
ATYPIPv6 ATYP = 0x04
|
|
)
|
|
|
|
func (a ATYP) String() string {
|
|
return atypNames[a]
|
|
}
|
|
|
|
var atypNames = map[ATYP]string{
|
|
ATYPIPv4: "ipv4",
|
|
ATYPFQDN: "fqdn",
|
|
ATYPIPv6: "ipv6",
|
|
}
|
|
|
|
// ReplyStatus is the reply status
|
|
type ReplyStatus byte
|
|
|
|
// Reply statuses
|
|
const (
|
|
ReplyStatusSuccess ReplyStatus = 0x00
|
|
ReplyStatusServerFailure ReplyStatus = 0x01
|
|
ReplyStatusNotAllowed ReplyStatus = 0x02
|
|
ReplyStatusNetworkUnreachable ReplyStatus = 0x03
|
|
ReplyStatusHostUnreachable ReplyStatus = 0x04
|
|
ReplyStatusConnectionRefused ReplyStatus = 0x05
|
|
ReplyStatusTTLExpired ReplyStatus = 0x06
|
|
ReplyStatusCommandNotSupported ReplyStatus = 0x07
|
|
ReplyStatusAddressNotSupported ReplyStatus = 0x08
|
|
)
|
|
|
|
func (rs ReplyStatus) String() string {
|
|
return replyStatusNames[rs]
|
|
}
|
|
|
|
var replyStatusNames = map[ReplyStatus]string{
|
|
ReplyStatusSuccess: "success",
|
|
ReplyStatusServerFailure: "server failure",
|
|
ReplyStatusNotAllowed: "not allowed",
|
|
ReplyStatusNetworkUnreachable: "network unreachable",
|
|
ReplyStatusHostUnreachable: "host unreachable",
|
|
ReplyStatusConnectionRefused: "connection refused",
|
|
ReplyStatusTTLExpired: "TTL expired",
|
|
ReplyStatusCommandNotSupported: "command not supported",
|
|
ReplyStatusAddressNotSupported: "address not supported",
|
|
}
|
|
|
|
var (
|
|
// ErrVersion is the protocol version error
|
|
ErrVersion = errors.New("invalid protocol version")
|
|
// ErrBadReply is the bad reply error
|
|
ErrBadReply = errors.New("bad reply")
|
|
// ErrBadRequest is the bad request error
|
|
ErrBadRequest = errors.New("bad request")
|
|
// ErrBadDatagram is the bad datagram error
|
|
ErrBadDatagram = errors.New("bad datagram")
|
|
// ErrFragmentedDatagram us the fragmented datagram error
|
|
ErrFragmentedDatagram = errors.New("fragmented datagram")
|
|
// ErrIPAuth is the invalid ip error
|
|
ErrIPAuth = errors.New("invalid ip auth")
|
|
// ErrPasswordAuth is the invalid username or password error
|
|
ErrPasswordAuth = errors.New("invalid username or password")
|
|
// ErrAuthMethodNotSupported is the error when auth method not supported
|
|
ErrAuthMethodNotSupported = errors.New("auth method not supported")
|
|
// ErrCommandNotSupported is the error when command not supported
|
|
ErrCommandNotSupported = errors.New("command not supported")
|
|
// ErrPasswordAuthVersion is the password auth version error
|
|
ErrPasswordAuthVersion = errors.New("invalid password auth version")
|
|
)
|