gosocks5

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: MIT Imports: 10 Imported by: 94

README

gosocks5

golang and SOCKSV5

Documentation

Overview

SOCKS Protocol Version 5 http://tools.ietf.org/html/rfc1928 http://tools.ietf.org/html/rfc1929

Index

Constants

View Source
const (
	Ver5        = 5
	UserPassVer = 1
)
View Source
const (
	MethodNoAuth uint8 = iota
	MethodGSSAPI
	MethodUserPass
	// X'03' to X'7F' IANA ASSIGNED
	// X'80' to X'FE' RESERVED FOR PRIVATE METHODS
	MethodNoAcceptable = 0xFF
)
View Source
const (
	CmdConnect uint8 = 1
	CmdBind          = 2
	CmdUdp           = 3
)
View Source
const (
	AddrIPv4   uint8 = 1
	AddrDomain       = 3
	AddrIPv6         = 4
)
View Source
const (
	Succeeded uint8 = iota
	Failure
	NotAllowed
	NetUnreachable
	HostUnreachable
	ConnRefused
	TTLExpired
	CmdUnsupported
	AddrUnsupported
)

Variables

View Source
var (
	ErrBadVersion  = errors.New("Bad version")
	ErrBadFormat   = errors.New("Bad format")
	ErrBadAddrType = errors.New("Bad address type")
	ErrShortBuffer = errors.New("Short buffer")
	ErrBadMethod   = errors.New("Bad method")
	ErrAuthFailure = errors.New("Auth failure")
)

Functions

func ReadMethods

func ReadMethods(r io.Reader) ([]uint8, error)

Method selection

+----+----------+----------+
|VER | NMETHODS | METHODS  |
+----+----------+----------+
| 1  |    1     | 1 to 255 |
+----+----------+----------+

func WriteMethod

func WriteMethod(method uint8, w io.Writer) error

Types

type Addr

type Addr struct {
	Type uint8
	Host string
	Port uint16
}

Address

+------+----------+----------+
| ATYP |   ADDR   |   PORT   |
+------+----------+----------+
|  1   | Variable |    2     |
+------+----------+----------+

func NewAddr

func NewAddr(sa string) (addr *Addr, err error)

func (*Addr) Decode

func (addr *Addr) Decode(b []byte) error

func (*Addr) Encode

func (addr *Addr) Encode(b []byte) (int, error)

func (*Addr) Length

func (addr *Addr) Length() (n int)

func (*Addr) String

func (addr *Addr) String() string

type Conn

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

func ClientConn

func ClientConn(conn net.Conn, selector Selector) *Conn

func ServerConn

func ServerConn(conn net.Conn, selector Selector) *Conn

func (*Conn) Close

func (conn *Conn) Close() error

func (*Conn) Handleshake

func (conn *Conn) Handleshake() error

func (*Conn) LocalAddr

func (conn *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (conn *Conn) Read(b []byte) (n int, err error)

func (*Conn) RemoteAddr

func (conn *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (conn *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (conn *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (conn *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (conn *Conn) Write(b []byte) (n int, err error)

type Reply

type Reply struct {
	Rep  uint8
	Addr *Addr
}

The SOCKSv5 reply

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

func NewReply

func NewReply(rep uint8, addr *Addr) *Reply

func ReadReply

func ReadReply(r io.Reader) (*Reply, error)

func (*Reply) String

func (r *Reply) String() string

func (*Reply) Write

func (r *Reply) Write(w io.Writer) (err error)

type Request

type Request struct {
	Cmd  uint8
	Addr *Addr
}

The SOCKSv5 request

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

func NewRequest

func NewRequest(cmd uint8, addr *Addr) *Request

func ReadRequest

func ReadRequest(r io.Reader) (*Request, error)

func (*Request) String

func (r *Request) String() string

func (*Request) Write

func (r *Request) Write(w io.Writer) (err error)

type Selector

type Selector interface {
	// return supported methods
	Methods() []uint8
	// select method
	Select(methods ...uint8) (method uint8)
	// on method selected
	OnSelected(method uint8, conn net.Conn) (net.Conn, error)
}

type UDPDatagram

type UDPDatagram struct {
	Header *UDPHeader
	Data   []byte
}

func NewUDPDatagram

func NewUDPDatagram(header *UDPHeader, data []byte) *UDPDatagram

func ReadUDPDatagram

func ReadUDPDatagram(r io.Reader) (*UDPDatagram, error)

func (*UDPDatagram) Write

func (d *UDPDatagram) Write(w io.Writer) error

type UDPHeader

type UDPHeader struct {
	Rsv  uint16
	Frag uint8
	Addr *Addr
}

UDP request

+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
+----+------+------+----------+----------+----------+
| 2  |  1   |  1   | Variable |    2     | Variable |
+----+------+------+----------+----------+----------+

func NewUDPHeader

func NewUDPHeader(rsv uint16, frag uint8, addr *Addr) *UDPHeader

func (*UDPHeader) String

func (h *UDPHeader) String() string

func (*UDPHeader) Write

func (h *UDPHeader) Write(w io.Writer) error

type UserPassRequest

type UserPassRequest struct {
	Version  byte
	Username string
	Password string
}

Username/Password authentication request

+----+------+----------+------+----------+
|VER | ULEN |  UNAME   | PLEN |  PASSWD  |
+----+------+----------+------+----------+
| 1  |  1   | 1 to 255 |  1   | 1 to 255 |
+----+------+----------+------+----------+

func NewUserPassRequest

func NewUserPassRequest(ver byte, u, p string) *UserPassRequest

func ReadUserPassRequest

func ReadUserPassRequest(r io.Reader) (*UserPassRequest, error)

func (*UserPassRequest) String

func (req *UserPassRequest) String() string

func (*UserPassRequest) Write

func (req *UserPassRequest) Write(w io.Writer) error

type UserPassResponse

type UserPassResponse struct {
	Version byte
	Status  byte
}

Username/Password authentication response

+----+--------+
|VER | STATUS |
+----+--------+
| 1  |   1    |
+----+--------+

func NewUserPassResponse

func NewUserPassResponse(ver, status byte) *UserPassResponse

func ReadUserPassResponse

func ReadUserPassResponse(r io.Reader) (*UserPassResponse, error)

func (*UserPassResponse) String

func (res *UserPassResponse) String() string

func (*UserPassResponse) Write

func (res *UserPassResponse) Write(w io.Writer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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