socks5

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package socks5 implements a SOCKS5 client/server. For more information see RFC 1928 and RFC 1929.

Notes:

  • GSSAPI authentication, is NOT supported.
  • The authentication provided by the client is always accepted.
  • A lot of the code is shamelessly stolen from obfs4proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redispatch

func Redispatch(proxyNet, proxyAddr string, req *Request) (net.Conn, error)

Redispatch dials the provided proxy and redispatches an existing request.

Types

type Address

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

Address is a SOCKS 5 address + port.

func (*Address) FromString

func (addr *Address) FromString(addrStr string) (err error)

FromString parses the provided "host:port" format address and populates the Address fields.

func (*Address) HostPort

func (addr *Address) HostPort() (string, string)

HostPort returns the string representation of the addess, split into the host and port components.

func (*Address) String

func (addr *Address) String() string

String returns the string representation of the address, in "host:port" format.

type AuthInfo

type AuthInfo struct {
	Uname  []byte
	Passwd []byte
}

AuthInfo is the RFC 1929 Username/Password authentication data.

type Command

type Command byte

Command is a SOCKS 5 command.

const (
	CommandConnect       Command = 0x01
	CommandTorResolve    Command = 0xf0
	CommandTorResolvePTR Command = 0xf1
)

The various SOCKS 5 commands.

type ReplyCode

type ReplyCode byte

ReplyCode is a SOCKS 5 reply code.

const (
	ReplySucceeded ReplyCode = iota
	ReplyGeneralFailure
	ReplyConnectionNotAllowed
	ReplyNetworkUnreachable
	ReplyHostUnreachable
	ReplyConnectionRefused
	ReplyTTLExpired
	ReplyCommandNotSupported
	ReplyAddressNotSupported
)

The various SOCKS 5 reply codes from RFC 1928.

func ErrorToReplyCode

func ErrorToReplyCode(err error) ReplyCode

ErrorToReplyCode converts an error to the "best" reply code.

type Request

type Request struct {
	Auth AuthInfo
	Cmd  Command
	Addr Address
	// contains filtered or unexported fields
}

Request describes a SOCKS 5 request.

func Handshake

func Handshake(conn net.Conn) (*Request, error)

Handshake attempts to handle a incoming client handshake over the provided connection and receive the SOCKS5 request. The routine handles sending appropriate errors if applicable, but will not close the connection.

func (*Request) Reply

func (req *Request) Reply(code ReplyCode) error

Reply sends a SOCKS5 reply to the corresponding request. The BND.ADDR and BND.PORT fields are always set to an address/port corresponding to "0.0.0.0:0".

func (*Request) ReplyAddr

func (req *Request) ReplyAddr(code ReplyCode, addr *Address) error

ReplyAddr sends a SOCKS5 reply to the corresponding request. The BND.ADDR and BND.PORT fields are specified by addr, or "0.0.0.0:0" if not provided.

Jump to

Keyboard shortcuts

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