socks5

package
v0.12.9 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoAuth       AuthType = 0x00
	NoAcceptable AuthType = 0xFF
	UserPassAuth AuthType = 0x02

	AuthSuccess AuthStatus = 0x00
	AuthFailure AuthStatus = 0x01

	UserAuthVersion = 0x01
)
View Source
const (
	Version uint8 = 0x05

	CommandConnect   Command = 0x01
	CommandBind      Command = 0x02
	CommandAssociate Command = 0x03

	StatusRequestGranted       Status = 0x00
	StatusGeneralFailure       Status = 0x01
	StatusConnectionNotAllowed Status = 0x02
	StatusNetworkUnreachable   Status = 0x03
	StatusHostUnreachable      Status = 0x04
	StatusConnectionRefused    Status = 0x05
	StatusTTLExpired           Status = 0x06
	StatusCommandNotSupported  Status = 0x07
	StatusAddressNotSupported  Status = 0x08

	AddressTypeIPv4   AddrType = 0x01
	AddressTypeIPv6   AddrType = 0x04
	AddressTypeDomain AddrType = 0x03
)

Variables

View Source
var (
	ErrFailedToSendReply    = errors.New("failed to send reply")
	ErrUnrecognizedAddrType = errors.New("unrecognized address type")
)
View Source
var (
	ErrAuthFailure = fmt.Errorf("authentication failure")
)

Functions

This section is empty.

Types

type AddrSpec

type AddrSpec struct {
	FQDN string
	IP   net.IP
	Port int
}

AddrSpec is a SOCKS5 address specification

func (*AddrSpec) Address

func (a *AddrSpec) Address() string

Address returns a string suitable to dial; prefer returning IP-based address, fallback to FQDN

func (*AddrSpec) String

func (a *AddrSpec) String() string

String returns a string representation of the address

type AddrType added in v0.8.0

type AddrType uint8

func (AddrType) Uint8 added in v0.8.0

func (a AddrType) Uint8() uint8

type AddressRewriter

type AddressRewriter interface {
	Rewrite(request *Request) *AddrSpec
}

type AuthContext

type AuthContext struct {
	// Method is the provided auth method
	Method AuthType
	// Payload provided during negotiation.
	// Keys depend on the used auth method.
	// For UserPass-auth contains Username
	Payload map[string]string
}

AuthContext encapsulates authentication state provided during negotiation

type AuthStatus added in v0.8.0

type AuthStatus uint8

AuthStatus is the status of the authentication process

func (AuthStatus) Uint8 added in v0.8.0

func (a AuthStatus) Uint8() uint8

type AuthType added in v0.8.0

type AuthType uint8

AuthType is the type of authentication used by the client to connect to the proxy server (see RFC 1928, Section 2)

func (AuthType) Uint8 added in v0.8.0

func (a AuthType) Uint8() uint8

type Authenticator

type Authenticator interface {
	Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error)
	GetCode() AuthType
}

Authenticator is the interface implemented by types that can handle authentication

type Command added in v0.8.0

type Command uint8

func (Command) String added in v0.8.0

func (c Command) String() string

func (Command) Uint8 added in v0.8.0

func (c Command) Uint8() uint8

type Config

type Config struct {
	Authentication    []Authenticator
	Credentials       CredentialStore
	Logger            *zerolog.Logger
	DestConnTimeout   time.Duration
	ClientConnTimeout time.Duration
	Dial              func(network, addr string) (net.Conn, error)
	AfterRequest      func(req *Request, conn net.Conn)
	Resolver          Resolver
	Rewriter          AddressRewriter
}

type CredentialStore

type CredentialStore interface {
	Valid(user, password string) bool
}

type DNSResolver

type DNSResolver struct{}

func (*DNSResolver) Resolve

func (d *DNSResolver) Resolve(destAddr string) (net.IP, error)

type NoAuthAuthenticator

type NoAuthAuthenticator struct{}

NoAuthAuthenticator is used to handle the "No Authentication" mode

func (*NoAuthAuthenticator) Authenticate

func (a *NoAuthAuthenticator) Authenticate(_ io.Reader, writer io.Writer) (*AuthContext, error)

Authenticate handles the authentication process

func (*NoAuthAuthenticator) GetCode

func (a *NoAuthAuthenticator) GetCode() AuthType

GetCode returns the code of the authenticator

type Request

type Request struct {
	Version     uint8
	Command     Command
	AuthContext *AuthContext
	RemoteAddr  *AddrSpec
	DestAddr    *AddrSpec

	BufferConn io.Reader
	Latency    time.Duration
	// contains filtered or unexported fields
}

Request is a SOCKS5 request message

func NewRequest

func NewRequest(bufferConn io.Reader) (*Request, error)

type Resolver added in v0.8.0

type Resolver interface {
	Resolve(destAddr string) (net.IP, error)
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(conf *Config) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(network, addr string) error

func (*Server) Shutdown added in v0.8.0

func (s *Server) Shutdown() error

type StaticCredentialStore added in v0.8.0

type StaticCredentialStore map[string]string

func (StaticCredentialStore) Valid added in v0.8.0

func (s StaticCredentialStore) Valid(user, password string) bool

type Status added in v0.8.0

type Status uint8

func (Status) Uint8 added in v0.8.0

func (s Status) Uint8() uint8

type UserPassAuthenticator

type UserPassAuthenticator struct {
	Credentials CredentialStore
}

UserPassAuthenticator is used to handle username/password-based authentication

func (*UserPassAuthenticator) Authenticate

func (a *UserPassAuthenticator) Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error)

Authenticate handles the authentication process

func (*UserPassAuthenticator) GetCode

func (a *UserPassAuthenticator) GetCode() AuthType

GetCode returns the code of the authenticator

Jump to

Keyboard shortcuts

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