proxy

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2017 License: MIT Imports: 29 Imported by: 16

Documentation

Index

Constants

View Source
const (
	IV_LENGTH          = 16
	SSL_RECORD_MAX     = 18 * 1024 // 18kb
	STREAM_BUFFER_SIZE = 512
)
View Source
const (
	SOCKS5_VERSION  = byte(0x05)
	SOCKS_TYPE_IPv4 = 1
	SOCKS_TYPE_Dm   = 3
	SOCKS_TYPE_IPv6 = 4

	DO_HTTP   = 0
	DO_SOCKS5 = 1

	HOST_HTTP_CONNECT  = byte(0x00)
	HOST_HTTP_FORWARD  = byte(0x01)
	HOST_SOCKS_CONNECT = byte(0x02)
	HOST_IPV6          = byte(0x04)

	AUTH_HEADER     = "X-Authorization"
	CANNOT_READ_BUF = "socks server: cannot read buffer: "
	NOT_SOCKS5      = "invalid socks version (socks5 only)"

	UDP_TIMEOUT = 30
	TCP_TIMEOUT = 60
)
View Source
const (
	UOT_HEADER = byte(0x07)
)

Variables

View Source
var (
	OK_HTTP = []byte("HTTP/1.0 200 OK\r\n\r\n")
	//                       version, granted = 0, 0, ipv4, 0, 0, 0, 0, (port) 0, 0
	OK_SOCKS = []byte{SOCKS5_VERSION, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
	//                                 RSV | FRAG | ATYP |       DST.ADDR      | DST.PORT |
	UDP_REQUEST_HEADER  = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
	UDP_REQUEST_HEADER6 = []byte{0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

	DUMMY_FIELDS = []string{"Accept-Language", "User-Agent", "Referer", "Cache-Control", "Accept-Encoding", "Connection"}
)

Functions

func Base32Decode added in v1.0.9

func Base32Decode(text string) []byte

func Base32Encode added in v1.0.9

func Base32Encode(buf []byte) string

func DecryptHost

func DecryptHost(c *GCipher, text string, mark byte) string

func EncryptHost

func EncryptHost(c *GCipher, text string, mark byte) string

func SafeAddHeader

func SafeAddHeader(req *http.Request, k, v string)

func SafeGetHeader

func SafeGetHeader(req *http.Request, k string) string

func StartServer

func StartServer(addr string, config *ServerConfig)

func TryDecryptHost added in v1.0.9

func TryDecryptHost(c *GCipher, text string) (h string, m byte)

Types

type ClientConfig added in v1.0.9

type ClientConfig struct {
	Upstream       string
	GlobalProxy    bool
	NoProxy        bool
	DisableConsole bool
	UserAuth       string
	DNSCacheSize   int

	UDPRelayPort   int
	UDPRelayCoconn int

	*GCipher
}

type GCipher added in v1.0.9

type GCipher struct {
	Key       []byte
	KeyString string
	Block     cipher.Block
	Partial   bool
	Rand      *rand.Rand
}

func (*GCipher) Bridge added in v1.0.9

func (gc *GCipher) Bridge(target, source net.Conn, key []byte, options *IOConfig)

func (*GCipher) Decrypt added in v1.0.9

func (gc *GCipher) Decrypt(buf []byte) []byte

func (*GCipher) DecryptString added in v1.0.9

func (gc *GCipher) DecryptString(text string) string

func (*GCipher) Encrypt added in v1.0.9

func (gc *GCipher) Encrypt(buf []byte) []byte

func (*GCipher) EncryptString added in v1.0.9

func (gc *GCipher) EncryptString(text string) string

func (*GCipher) GenerateIV added in v1.0.9

func (gc *GCipher) GenerateIV(s, s2 byte) []byte

func (*GCipher) GetCipherStream added in v1.0.9

func (gc *GCipher) GetCipherStream(key []byte) *InplaceCTR

func (*GCipher) New added in v1.0.9

func (gc *GCipher) New() (err error)

func (*GCipher) NewRand added in v1.0.9

func (gc *GCipher) NewRand() *rand.Rand

func (*GCipher) RandomIV added in v1.0.9

func (gc *GCipher) RandomIV() (string, []byte)

func (*GCipher) ReverseIV added in v1.0.9

func (gc *GCipher) ReverseIV(key string) []byte

func (*GCipher) WrapIO added in v1.0.9

func (gc *GCipher) WrapIO(dst io.Writer, src io.Reader, key []byte, options *IOConfig) *IOCopyCipher

type IOConfig added in v1.0.9

type IOConfig struct {
	Bucket *TokenBucket
}

type IOCopyCipher

type IOCopyCipher struct {
	Dst        io.Writer
	Src        io.Reader
	Key        []byte
	Throttling *TokenBucket
	Partial    bool
	Cipher     *GCipher
}

func (*IOCopyCipher) DoCopy

func (cc *IOCopyCipher) DoCopy() (written int64, err error)

type IOReaderCipher

type IOReaderCipher struct {
	Src    io.Reader
	Key    []byte
	Cipher *GCipher
	// contains filtered or unexported fields
}

func (*IOReaderCipher) Init

func (rc *IOReaderCipher) Init() *IOReaderCipher

func (*IOReaderCipher) Read

func (rc *IOReaderCipher) Read(p []byte) (n int, err error)

type InplaceCTR

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

func (*InplaceCTR) XorBuffer

func (x *InplaceCTR) XorBuffer(buf []byte)

From src/crypto/cipher/ctr.go

type OneBytePool added in v1.0.9

type OneBytePool chan []byte

func NewOneBytePool added in v1.0.9

func NewOneBytePool(s int) *OneBytePool

func (*OneBytePool) Free added in v1.0.9

func (p *OneBytePool) Free(buf []byte)

func (*OneBytePool) Get added in v1.0.9

func (p *OneBytePool) Get() []byte

type ProxyClient added in v1.0.9

type ProxyClient struct {
	*ClientConfig

	DNSCache  *lru.Cache
	Nickname  string
	Localaddr string
	Listener  *listenerWrapper
	// contains filtered or unexported fields
}

func NewClient added in v1.0.10

func NewClient(localaddr string, config *ClientConfig) *ProxyClient

func (*ProxyClient) PleaseUnlockMe added in v1.0.10

func (proxy *ProxyClient) PleaseUnlockMe()

func (*ProxyClient) ServeHTTP added in v1.0.9

func (proxy *ProxyClient) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ProxyClient) Start added in v1.0.10

func (proxy *ProxyClient) Start() error

func (*ProxyClient) UpdateKey added in v1.0.10

func (proxy *ProxyClient) UpdateKey(newKey string)

type ProxyUpstream added in v1.0.9

type ProxyUpstream struct {
	*ServerConfig
	// contains filtered or unexported fields
}

func (*ProxyUpstream) ServeHTTP added in v1.0.9

func (proxy *ProxyUpstream) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ProxyUpstream) Write added in v1.0.9

func (proxy *ProxyUpstream) Write(w http.ResponseWriter, r *http.Request, p []byte, code int) (n int, err error)

type ServerConfig added in v1.0.9

type ServerConfig struct {
	Throttling     int64
	ThrottlingMax  int64
	UDPRelayListen int
	ProxyPassAddr  string

	Users map[string]UserConfig

	*GCipher
}

type TokenBucket

type TokenBucket struct {
	Speed int64 // bytes per second
	// contains filtered or unexported fields
}

func NewTokenBucket

func NewTokenBucket(speed, max int64) *TokenBucket

func (*TokenBucket) Consume

func (tb *TokenBucket) Consume(n int64)

type UserConfig added in v1.0.9

type UserConfig struct {
	Auth          string
	Throttling    int64
	ThrottlingMax int64
}

for multi-users server, not implemented yet

Jump to

Keyboard shortcuts

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