tunnel

package
v0.0.0-...-1e8f9cd Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2015 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RETRY_INTERVAL = time.Second * 5
	REST_INTERVAL  = RETRY_INTERVAL
)
View Source
const (
	D5                 = 0xd5
	IPV4               = byte(1)
	DOMAIN             = byte(3)
	IPV6               = byte(4)
	SOCKS5_VER         = byte(5)
	NULL               = ""
	DMLEN1             = 384
	DMLEN2             = TKSZ + 2
	GENERAL_SO_TIMEOUT = 10 * time.Second
	TUN_PARAMS_LEN     = 32

	REQ_PROT_UNKNOWN    = 1
	REQ_PROT_SOCKS5     = 2
	REQ_PROT_HTTP       = 3
	REQ_PROT_HTTP_T     = 4
	CRLF                = "\r\n"
	HTTP_PROXY_VER_LINE = "HTTP/1.1 200 Connection established"
	HTTP_PROXY_AGENT    = "Proxy-Agent: deblocus"
)
View Source
const (
	// frame action 8bit
	FRAME_ACTION_CLOSE = iota
	FRAME_ACTION_CLOSE_R
	FRAME_ACTION_CLOSE_W
	FRAME_ACTION_OPEN
	FRAME_ACTION_OPEN_N
	FRAME_ACTION_OPEN_Y
	FRAME_ACTION_DATA
	FRAME_ACTION_PING
	FRAME_ACTION_PONG
	FRAME_ACTION_SLOWDOWN = 0xff
)
View Source
const (
	WAITING_OPEN_TIMEOUT = GENERAL_SO_TIMEOUT * 2
	FRAME_HEADER_LEN     = 5
	FRAME_MAX_LEN        = 0xffff
	MUX_PENDING_CLOSE    = -1
	MUX_CLOSED           = -2
)
View Source
const (
	// idle error type
	ERR_PING_TIMEOUT = 0xe
	ERR_NEW_PING     = 0xf
	ERR_UNKNOWN      = 0x0
)
View Source
const (
	TCP_CLOSE_R uint8 = 1
	TCP_CLOSE_W uint8 = 1 << 1
	TCP_CLOSED        = TCP_CLOSE_R | TCP_CLOSE_W
)
View Source
const (
	// close code
	CLOSED_FORCE = iota
	CLOSED_WRITE
	CLOSED_BY_ERR
)
View Source
const (
	GENERATE_TOKEN_NUM = 16
	TOKENS_FLOOR       = 2
	PARALLEL_TUN_QTY   = 2
	TKSZ               = sha1.Size
)
View Source
const (
	CMD_HEADER_LEN    = 16
	CTL_PING          = byte(1)
	CTL_PONG          = byte(2)
	TOKEN_REQUEST     = byte(5)
	TOKEN_REPLY       = byte(6)
	CTL_PING_INTERVAL = 120 // time.Second
	DT_PING_INTERVAL  = 90
)
View Source
const (
	Bye                  = syscall.Signal(0xfffb8e)
	SER_KEY_TYPE         = "deblocus/SERVER-PRIVATEKEY"
	USER_CREDENTIAL_TYPE = "deblocus/CLIENT-CREDENTIAL"
	WORD_d5p             = "D5P"
	WORD_provider        = "Provider"
	SIZE_UNIT            = "BKMG"
)
View Source
const (
	TICKER_INTERVAL = time.Second * 15
)

Variables

View Source
var (
	// for main package injection
	VERSION    uint32
	VER_STRING string
	DEBUG      bool
)
View Source
var (
	// socks5 exceptions
	INVALID_SOCKS5_HEADER  = exception.New(0xff, "Invalid socks5 header")
	INVALID_SOCKS5_REQUEST = exception.New(0x07, "Invalid socks5 request")
	GENERAL_FAILURE        = exception.New(0x01, "General failure")
	HOST_UNREACHABLE       = exception.New(0x04, "Host is unreachable")
)
View Source
var (
	// D5 exceptions
	INVALID_D5PARAMS     = exception.NewW("Invalid D5Params")
	D5SER_UNREACHABLE    = exception.NewW("D5Server is unreachable")
	VALIDATION_FAILED    = exception.NewW("Validation failed")
	NEGOTIATION_FAILED   = exception.NewW("Negotiation failed")
	DATATUN_SESSION      = exception.NewW("DT")
	INCONSISTENT_HASH    = exception.NewW("Inconsistent hash")
	INCOMPATIBLE_VERSION = exception.NewW("Incompatible version")
)
View Source
var (
	ZERO_TIME               = time.Time{}
	FILE_NOT_FOUND          = exception.NewW("File not found")
	FILE_EXISTS             = exception.NewW("File is already exists")
	INVALID_D5P_FRAGMENT    = exception.NewW("Invalid d5p fragment")
	INVALID_D5C_FILE        = exception.NewW("Invalid d5c file format")
	INVALID_D5S_FILE        = exception.NewW("Invalid d5s file format")
	UNRECOGNIZED_SYMBOLS    = exception.NewW("Unrecognized symbols")
	UNRECOGNIZED_DIRECTIVES = exception.NewW("Unrecognized directives")
	LOCAL_BIND_ERROR        = exception.NewW("Local bind error")
	CONF_MISS               = exception.NewW("Missed config")
	CONF_ERROR              = exception.NewW("Error config")
)
View Source
var (
	SID_SEQ uint32
)
View Source
var (
	UNSUPPORTED_CIPHER = exception.NewW("Unsupported cipher")
)

Functions

func CreateClientCredential

func CreateClientCredential(file string, d5s *D5ServConf, user string) (e error)

public for external

func DetectFile

func DetectFile(isServ bool) (string, bool)

func DetectRunAsServ

func DetectRunAsServ() bool

func Generate_d5sFile

func Generate_d5sFile(file string, d5sConf *D5ServConf) (e error)

func IdentifierOf

func IdentifierOf(con net.Conn) string

func IsNotExist

func IsNotExist(file string) bool

func IsValidHost

func IsValidHost(hostport string) (ok bool, err error)

func NewClientMultiplexer

func NewClientMultiplexer() *multiplexer

func NewConnWithHash

func NewConnWithHash(conn *net.TCPConn) *hashedConn

func NewIdler

func NewIdler(interval int, isClient bool) *idler

func NewPushbackInputStream

func NewPushbackInputStream(conn net.Conn) *pushbackInputStream

func NewSemaphore

func NewSemaphore() *semaphore

func NewServerMultiplexer

func NewServerMultiplexer() *multiplexer

func NewSignalTunnel

func NewSignalTunnel(conn *Conn, interval int) *signalTunnel

func RSADecrypt

func RSADecrypt(src []byte, priv *rsa.PrivateKey) (plain []byte, err error)

single block decrypt

func RSAEncrypt

func RSAEncrypt(src []byte, pub *rsa.PublicKey) (enc []byte, err error)

single block encrypt OAEP: must be less than 86byte base on RSA1024-OAEP_sha1

func ReadFullByLen

func ReadFullByLen(len_inByte int, reader io.Reader) (buf []byte, err error)

read by the first segment indicated the following segment length len_inByte: first segment length in byte

func SafeClose

func SafeClose(conn net.Conn)

func ThrowErr

func ThrowErr(e interface{})

func ThrowIf

func ThrowIf(condition bool, e interface{})

Types

type Cipher

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

type CipherFactory

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

func NewCipherFactory

func NewCipherFactory(name string, secret []byte) *CipherFactory

func (*CipherFactory) NewCipher

func (c *CipherFactory) NewCipher(iv []byte) *Cipher

type Client

type Client struct {
	State int32 // -1:aborted 0:working 1:requesting token
	// contains filtered or unexported fields
}

func NewClient

func NewClient(d5p *D5Params, dhKeys *DHKeyPair) *Client

func (*Client) ClientServe

func (c *Client) ClientServe(conn net.Conn)

func (*Client) StartSigTun

func (c *Client) StartSigTun(again bool)

func (*Client) Stats

func (t *Client) Stats() string

type Conn

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

func NewConn

func NewConn(conn *net.TCPConn, cipher *Cipher) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) CloseRead

func (c *Conn) CloseRead()

func (*Conn) CloseWrite

func (c *Conn) CloseWrite()

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) SetSockOpt

func (c *Conn) SetSockOpt(disableDeadline, keepAlive, noDelay int8)

func (*Conn) Update

func (c *Conn) Update()

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type ConnPool

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

func NewConnPool

func NewConnPool() *ConnPool

func (*ConnPool) Len

func (h *ConnPool) Len() int

func (*ConnPool) Push

func (h *ConnPool) Push(x *Conn)

func (*ConnPool) Remove

func (h *ConnPool) Remove(c *Conn) bool

func (*ConnPool) Select

func (h *ConnPool) Select() *Conn

type D5ClientConf

type D5ClientConf struct {
	Listen     string `importable:":9009"`
	Verbose    int    `importable:"1"`
	ListenAddr *net.TCPAddr
	D5PList    []*D5Params
}

client

func Parse_d5cFile

func Parse_d5cFile(path string) *D5ClientConf

public for external

type D5Params

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

d5p

func NewD5Params

func NewD5Params(uri string) (*D5Params, error)

without sPub field

func (*D5Params) RemoteName

func (d *D5Params) RemoteName() string

type D5ServConf

type D5ServConf struct {
	Listen     string `importable:":9008"`
	AuthTable  string `importable:"file:///PATH/YOUR_AUTH_FILE_PATH"`
	Algo       string `importable:"AES128CFB"`
	ServerName string `importable:"SERVER_NAME"`
	Verbose    int    `importable:"1"`
	AuthSys    auth.AuthSys
	RSAKeys    *RSAKeyPair
	ListenAddr *net.TCPAddr
}

Server

func Parse_d5sFile

func Parse_d5sFile(path string) *D5ServConf

public for external

func (*D5ServConf) Export_d5p

func (d *D5ServConf) Export_d5p(user *auth.User) string

PEMed text

type DHKeyPair

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

func GenerateDHKeyPairs

func GenerateDHKeyPairs() *DHKeyPair

type FieldDescriptor

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

type ImportableFieldDesc

type ImportableFieldDesc map[string]*FieldDescriptor

type RSAKeyPair

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

func GenerateRSAKeyPair

func GenerateRSAKeyPair() *RSAKeyPair

type S5Step1

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

socks5 protocol step1 on client side

func (*S5Step1) Handshake

func (s *S5Step1) Handshake()

func (*S5Step1) HandshakeAck

func (s *S5Step1) HandshakeAck() bool

type Server

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

Server

func NewServer

func NewServer(d5s *D5ServConf, dhKeys *DHKeyPair) *Server

func (*Server) Stats

func (t *Server) Stats() string

func (*Server) TunnelServe

func (t *Server) TunnelServe(conn *net.TCPConn)

type Session

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

Session

func NewSession

func NewSession(tun *Conn, cf *CipherFactory, identity string) *Session

func (*Session) DataTunServe

func (t *Session) DataTunServe(fconn *Conn, buf []byte)

type SessionContainer

type SessionContainer map[string]*Session

type SessionMgr

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

SessionMgr

func NewSessionMgr

func NewSessionMgr() *SessionMgr

type TSPriority

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

Jump to

Keyboard shortcuts

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