s5

package
v0.0.0-...-b941c5f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandConnect uint8 = iota + 1
	CommandBind
	CommandAssociate
)
View Source
const (
	AddressTypeIPv4 uint8 = iota + 1

	AddressTypeDomainName
	AddressTypeIPv6
)
View Source
const (
	DestIPv4Size = 4 + 2  // IPv4 + Port
	DestIPv6Size = 16 + 2 // IPv6 + Port
)
View Source
const AuthUserPWVersion = 0x1
View Source
const VERSION uint8 = 0x05

Variables

View Source
var (
	ErrUnimplemented          = errors.New("unimplemented")
	ErrUnsupportedVersion     = errors.New("unsupported version")
	ErrUnsupportedAddressType = errors.New("unsupported address type")
	ErrUnknownNetwork         = errors.New("unknown network")
	ErrAuthNoneAcceptable     = errors.New("auth none acceptable")
	ErrInvalidHostnameLength  = errors.New("invalid hostname length")
)

General

View Source
var (
	ErrReplyGeneralFailure          = errors.New("general SOCKS server failure")
	ErrReplyConnectionNotAllowed    = errors.New("connection not allowed by ruleset")
	ErrReplyNetworkUnreachable      = errors.New("network unreachable")
	ErrReplyHostUnreachable         = errors.New("host unreachable")
	ErrReplyConnectionRefused       = errors.New("connection refused")
	ErrReplyTTLExpired              = errors.New("TTL expired")
	ErrReplyCommandNotSupported     = errors.New("command not supported")
	ErrReplyAddressTypeNotSupported = errors.New("address type not supported")
)

Reply

View Source
var (
	ErrAuthVersion = errors.New("invalid version")
	ErrAuthUnknown = errors.New("unknown authentication method")
)

Auth UserPW

View Source
var ErrInvalidBufferSize = errors.New("invalid buffer size")
View Source
var ErrMethodsLimit = errors.New("reached the limit of methods")

Functions

This section is empty.

Types

type AuthGSSAPI

type AuthGSSAPI struct {
}

AuthGSSAPI is the GSSAPI authentication method. Currently unimplemented

type AuthHandler

type AuthHandler func(authMethod AuthMethod, authData any) bool

AuthHandler used to determine if the authentication is valid or not

type AuthMethod

type AuthMethod uint8

AuthMethod ...

X'03' to X'7F' IANA ASSIGNED
X'80' to X'FE' RESERVED FOR PRIVATE METHODS
const (
	MethodAuthNone   AuthMethod = iota // no authentication required
	MethodAuthGSSAPI                   // GSSAPI
	MethodAuthUserPW                   // username/password
	MethodAuthCHAP                     // Challenge-Handshake Authentication Protocol

	MerhodAuthCRAM                             // Challenge-Response Authentication Method
	MethodAuthSSL                              // Secure Sockets Layer
	MethodAuthNDS                              // NDS Authentication
	MethodAuthMAF                              // Multi-Authentication Framework
	MethodAuthJSB                              // JSON Parameter Block
	MethodAuthNoneAcceptable AuthMethod = 0xFF // no acceptable methods
)

type AuthReply

type AuthReply struct {
	Version  uint8 // required, should be the version of the authentication method
	Status   ReplyStatus
	Validate func(uint8) error
}

AuthReply is the reply after SOCKS5 authentication method.

func AuthReplyFromConn

func AuthReplyFromConn(conn net.Conn, validateCb func(authVersion uint8) error) (_ *AuthReply, err error)

AuthReplyFromConn for client-side

func (*AuthReply) Pack

func (t *AuthReply) Pack(w io.Writer) (err error)

Pack for server-side

func (*AuthReply) Unpack

func (t *AuthReply) Unpack(r io.Reader) (err error)

Unpack for client-side

type AuthUserPW

type AuthUserPW struct {
	Version        uint8 // unrequired, only used by Unpack
	UsernameLength uint8 // unrequired, only used by Unpack
	Username       []byte
	PasswordLength uint8 // unrequired, only used by Unpack
	Password       []byte
}

AuthUserPW is the username/password authentication method.

func (AuthUserPW) Method

func (AuthUserPW) Method() uint8

func (*AuthUserPW) Pack

func (auth *AuthUserPW) Pack(w io.Writer) (err error)

Pack writes the authentication method to the given writer.

func (*AuthUserPW) Unpack

func (auth *AuthUserPW) Unpack(r io.Reader) (err error)

Unpack reads the authentication method from the given reader.

func (AuthUserPW) Ver

func (AuthUserPW) Ver() uint8

type Destination

type Destination interface {
	// Put has to be used appropriately together with Size
	Put([]byte) error

	// Size returns binary length of the struct
	Size() uint8

	// Unpack ...
	Unpack(r io.Reader) error

	// Kind returns AddressType
	Kind() uint8
}

type HandshakeReply

type HandshakeReply struct {
	Version uint8
	Method  AuthMethod
}

HandshakeReply is the handshake reply for SOCKS V5.

func (*HandshakeReply) Pack

func (t *HandshakeReply) Pack(w io.Writer) (err error)

func (*HandshakeReply) Unpack

func (t *HandshakeReply) Unpack(r io.Reader) (err error)

type HandshakeRequest

type HandshakeRequest struct {
	Version  uint8 // unrequired, only used by Unpack
	NMethods uint8 // unrequired, only used by Unpack
	Methods  []AuthMethod
}

HandshakeRequest is the handshake request for SOCKS V5.

func (*HandshakeRequest) Pack

func (h *HandshakeRequest) Pack(w io.Writer) (err error)

func (*HandshakeRequest) Unpack

func (h *HandshakeRequest) Unpack(r io.Reader) (err error)

type Reply

type Reply struct {
	Version     uint8 // unrequired, only used by Unpack
	Status      ReplyStatus
	Reserved    uint8 // unrequired, only used by Unpack
	AddressType uint8
	Bind        ReplyBind
}

Reply is a reply structure for SOCKS V5.

func (*Reply) Pack

func (t *Reply) Pack(w io.Writer) (err error)

Pack writes the structure to the given writer as bytes.

func (*Reply) Unpack

func (t *Reply) Unpack(r io.Reader) (err error)

Unpack reads from the given reader into the structure.

type ReplyBind

type ReplyBind struct {
	Address netip.Addr
	Port    uint16
}

Bind structure for IPv4 or IPv6

func (*ReplyBind) Kind

func (b *ReplyBind) Kind() uint8

Kind ...

func (*ReplyBind) Pack

func (b *ReplyBind) Pack(buf []byte)

func (*ReplyBind) Size

func (b *ReplyBind) Size() uint8

func (*ReplyBind) Unpack

func (b *ReplyBind) Unpack(r io.Reader, v6 bool) (err error)

type ReplyStatus

type ReplyStatus uint8

ReplyStatus ...

X'09' to X'FF' unassigned
const (
	ReplySuccess                 ReplyStatus = iota // succeeded
	ReplyGeneralFailure                             // general SOCKS server failure
	ReplyConnectionNotAllowed                       // connection not allowed by ruleset
	ReplyNetworkUnreachable                         // Network unreachable
	ReplyHostUnreachable                            // Host unreachable
	ReplyConnectionRefused                          // Connection refused
	ReplyTTLExpired                                 // TTL expired
	ReplyCommandNotSupported                        // Command not supported
	ReplyAddressTypeNotSupported                    // Address type not supported
)

func (ReplyStatus) Error

func (s ReplyStatus) Error() error

Error ...

func (ReplyStatus) String

func (i ReplyStatus) String() string

type Request

type Request struct {
	Version     uint8       // unrequired, only used by Unpack
	Command     uint8       // required only by Pack
	Reserved    uint8       // unrequired, only used by Unpack
	AddressType uint8       // unrequired, only used by Unpack
	Destination Destination // required only by Pack
}

Request is the request for SOCKS V5.

func (*Request) Pack

func (v *Request) Pack(w io.Writer) (err error)

func (*Request) Unpack

func (v *Request) Unpack(r io.Reader) (err error)

type RequestV5DestDomainName

type RequestV5DestDomainName struct {
	Address []byte
	Port    uint16
}

RequestV5DestDomainName is a domaim name destination.

func (*RequestV5DestDomainName) Kind

func (h *RequestV5DestDomainName) Kind() uint8

Kind returns AddressType

func (*RequestV5DestDomainName) Put

func (h *RequestV5DestDomainName) Put(buf []byte) error

func (*RequestV5DestDomainName) Size

func (h *RequestV5DestDomainName) Size() uint8

Size returns binary length of struct

func (*RequestV5DestDomainName) Unpack

func (h *RequestV5DestDomainName) Unpack(r io.Reader) (err error)

ReadFrom reads from the given reader into the structure.

type RequestV5DestIPv4

type RequestV5DestIPv4 struct {
	Address [4]byte
	Port    uint16
}

RequestV5DestinationIPv4 is a IPv4 destination.

func (*RequestV5DestIPv4) Kind

func (h *RequestV5DestIPv4) Kind() uint8

Kind returns AddressType

func (*RequestV5DestIPv4) Put

func (d *RequestV5DestIPv4) Put(buf []byte) error

Put ..

func (*RequestV5DestIPv4) Size

func (h *RequestV5DestIPv4) Size() uint8

Size returns binary length of struct

func (*RequestV5DestIPv4) Unpack

func (d *RequestV5DestIPv4) Unpack(r io.Reader) (err error)

type RequestV5DestIPv6

type RequestV5DestIPv6 struct {
	Address [16]byte
	Port    uint16
}

RequestV5DestinationIPv6 is a IPv6 destination.

func (*RequestV5DestIPv6) Kind

func (h *RequestV5DestIPv6) Kind() uint8

Kind returns AddressType

func (*RequestV5DestIPv6) Put

func (h *RequestV5DestIPv6) Put(buf []byte) error

func (*RequestV5DestIPv6) Size

func (h *RequestV5DestIPv6) Size() uint8

Size returns binary length of struct

func (*RequestV5DestIPv6) Unpack

func (h *RequestV5DestIPv6) Unpack(r io.Reader) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL