statute

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandConnect   = byte(0x01)
	CommandBind      = byte(0x02)
	CommandAssociate = byte(0x03)
)

request command defined

View Source
const (
	MethodNoAuth       = byte(0x00)
	MethodGSSAPI       = byte(0x01) // TODO: not support now
	MethodUserPassAuth = byte(0x02)
	MethodNoAcceptable = byte(0xff)
)

method defined

View Source
const (
	ATYPIPv4   = byte(0x01)
	ATYPDomain = byte(0x03)
	ATYPIPv6   = byte(0x04)
)

address type defined

View Source
const (
	RepSuccess uint8 = iota
	RepServerFailure
	RepRuleFailure
	RepNetworkUnreachable
	RepHostUnreachable
	RepConnectionRefused
	RepTTLExpired
	RepCommandNotSupported
	RepAddrTypeNotSupported
)

reply status

View Source
const (
	// user password version
	UserPassAuthVersion = byte(0x01)
	// auth status
	AuthSuccess = byte(0x00)
	AuthFailure = byte(0x01)
)

auth defined

View Source
const VersionSocks5 = byte(0x05)

VersionSocks5 socks protocol version

Variables

View Source
var (
	ErrUserAuthFailed  = fmt.Errorf("user authentication failed")
	ErrNoSupportedAuth = fmt.Errorf("no supported authentication mechanism")
)

auth error defined

View Source
var (
	ErrUnrecognizedAddrType = errors.New("unrecognized address type")
	ErrNotSupportVersion    = errors.New("not support version")
	ErrNotSupportMethod     = errors.New("not support method")
)

error defined

Functions

This section is empty.

Types

type AddrSpec

type AddrSpec struct {
	FQDN string
	IP   net.IP
	Port int
	// private stuff set when Request parsed
	AddrType byte
}

AddrSpec is used to return the target AddrSpec which may be specified as IPv4, IPv6, or a FQDN

func ParseAddrSpec

func ParseAddrSpec(addr string) (as AddrSpec, err error)

ParseAddrSpec parse addr(host:port) to the AddrSpec address

func (AddrSpec) Address

func (sf AddrSpec) Address() string

Address returns a string which may be specified if IPv4/IPv6 will return < ip:port > if FQDN will return < domain ip:port > Note: do not used to dial, Please use String

func (*AddrSpec) String

func (sf *AddrSpec) String() string

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

type Datagram

type Datagram struct {
	RSV     uint16
	Frag    byte
	DstAddr AddrSpec
	Data    []byte
}

Datagram udp packet The SOCKS UDP request/response is formed as follows: +-----+------+-------+----------+----------+----------+ | RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA | +-----+------+-------+----------+----------+----------+ | 2 | 1 | X'00' | Variable | 2 | Variable | +-----+------+-------+----------+----------+----------+

func NewDatagram

func NewDatagram(destAddr string, data []byte) (p Datagram, err error)

NewDatagram new packet with dest addr and data

func ParseDatagram

func ParseDatagram(b []byte) (da Datagram, err error)

ParseDatagram parse to datagram from bytes

func (*Datagram) Bytes

func (sf *Datagram) Bytes() []byte

Bytes datagram to bytes

func (*Datagram) Header

func (sf *Datagram) Header() []byte

Header returns s slice of datagram header except data

type MethodReply

type MethodReply struct {
	Ver    byte
	Method byte
}

MethodReply is the negotiation method reply packet The SOCKS handshake method response is formed as follows:

+-----+--------+
| VER | METHOD |
+-----+--------+
|  1  |     1  |
+-----+--------+

func ParseMethodReply

func ParseMethodReply(r io.Reader) (n MethodReply, err error)

ParseMethodReply parse method reply.

type MethodRequest

type MethodRequest struct {
	Ver      byte
	NMethods byte
	Methods  []byte // 1-255 bytes
}

MethodRequest is the negotiation method request packet The SOCKS handshake method request is formed as follows:

+-----+----------+---------------+
| VER | NMETHODS |    METHODS    |
+-----+----------+---------------+
|  1  |     1    | X'00' - X'FF' |
+-----+----------+---------------+

func NewMethodRequest

func NewMethodRequest(ver byte, medthods []byte) MethodRequest

NewMethodRequest new negotiation method request

func ParseMethodRequest

func ParseMethodRequest(r io.Reader) (mr MethodRequest, err error)

ParseMethodRequest parse method request.

func (MethodRequest) Bytes

func (sf MethodRequest) Bytes() []byte

Bytes method request to bytes

type Reply

type Reply struct {
	// Version of socks protocol for message
	Version byte
	// Socks Response status"
	Response byte
	// Reserved byte
	Reserved byte
	// Bind Address in socks message
	BndAddr AddrSpec
}

Reply represents the SOCKS5 reply, it contains everything that is not payload The SOCKS5 reply is formed as follows:

+-----+-----+-------+------+----------+-----------+
| VER | REP |  RSV  | ATYP | BND.ADDR | BND].PORT |
+-----+-----+-------+------+----------+-----------+
|  1  |  1  | X'00' |  1   | Variable |    2      |
+-----+-----+-------+------+----------+-----------+

func ParseReply

func ParseReply(r io.Reader) (rep Reply, err error)

ParseReply parse to reply from io.Reader

func (Reply) Bytes

func (sf Reply) Bytes() (b []byte)

Bytes returns a slice of request

type Request

type Request struct {
	// Version of socks protocol for message
	Version byte
	// Socks Command "connect","bind","associate"
	Command byte
	// Reserved byte
	Reserved byte
	// DstAddr in socks message
	DstAddr AddrSpec
}

Request represents the SOCKS5 request, it contains everything that is not payload The SOCKS5 request is formed as follows:

+-----+-----+-------+------+----------+----------+
| VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
+-----+-----+-------+------+----------+----------+
|  1  |  1  | X'00' |  1   | Variable |    2     |
+-----+-----+-------+------+----------+----------+

func ParseRequest

func ParseRequest(r io.Reader) (req Request, err error)

ParseRequest to request from io.Reader

func (Request) Bytes

func (h Request) Bytes() (b []byte)

Bytes returns a slice of request

type UserPassReply

type UserPassReply struct {
	Ver    byte
	Status byte
}

UserPassReply is the negotiation user's password reply packet The SOCKS handshake user's password response is formed as follows:

+-----+--------+
| VER | status |
+-----+--------+
|  1  |     1  |
+-----+--------+

func ParseUserPassReply

func ParseUserPassReply(r io.Reader) (upr UserPassReply, err error)

ParseUserPassReply parse user's password reply packet.

type UserPassRequest

type UserPassRequest struct {
	Ver  byte
	Ulen byte
	Plen byte
	User []byte // 1-255 bytes
	Pass []byte // 1-255 bytes
}

UserPassRequest is the negotiation user's password request packet The SOCKS handshake user's password request is formed as follows:

+--------------+------+----------+------+----------+
| USERPASS_VER | ULEN |   USER   | PLEN |   PASS   |
+--------------+------+----------+------+----------+
|      1      |   1  | Variable |   1  | Variable |
+--------------+------+----------+------+----------+

func NewUserPassRequest

func NewUserPassRequest(ver byte, user, pass []byte) UserPassRequest

NewUserPassRequest new user's password request packet with ver,user, pass

func ParseUserPassRequest

func ParseUserPassRequest(r io.Reader) (nup UserPassRequest, err error)

ParseUserPassRequest parse user's password request.

func (UserPassRequest) Bytes

func (sf UserPassRequest) Bytes() []byte

Bytes to bytes

Jump to

Keyboard shortcuts

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