tunnel

package
v0.0.0-...-84ee60a Latest Latest
Warning

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

Go to latest
Published: May 9, 2015 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	D5                 = 0xd5
	IPV4               = byte(1)
	DOMAIN             = byte(3)
	IPV6               = byte(4)
	SOCKS5_VER         = byte(5)
	NULL               = ""
	DMLEN              = 384
	TT_TOKEN_OFFSET    = SzTk + 2
	GENERAL_SO_TIMEOUT = 10 * time.Second
	TUN_PARAMS_LEN     = 32
	TP_INTERVAL_OFS    = 4
)
View Source
const (
	GENERATE_TOKEN_NUM = 64
	SzTk               = sha1.Size
	CMD_HEADER_LEN     = 16
	CTL_PING           = byte(1)
	CTL_PONG           = byte(2)
	TOKEN_REQUEST      = byte(5)
	TOKEN_REPLY        = byte(6)
	CTL_PING_INTERVAL  = uint16(60) // time.Second
)
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"
)

Variables

View Source
var (
	VERSION uint32
	// 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")
	// 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")
	TRANS_SESSION        = exception.NewW("TT")
	HASH_INCONSISTENCE   = exception.NewW("Hash inconsistence")
	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 (
	UNSUPPORTED_CIPHER = exception.NewW("Unsupported cipher method")
)

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 GetConnIdentifier

func GetConnIdentifier(con net.Conn) string

func IsNotExist

func IsNotExist(file string) bool

func Pipe

func Pipe(dst, src net.Conn, sid int32, ctl *CtlThread)

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(id int, 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:token requesting
	// contains filtered or unexported fields
}

func NewClient

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

func (*Client) ClientServe

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

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 NewConnWithHash

func NewConnWithHash(conn *net.TCPConn) *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) FreeHash

func (c *Conn) FreeHash()

func (*Conn) RHashSum

func (c *Conn) RHashSum() []byte

func (*Conn) Read

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

func (*Conn) SetSockOpt

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

func (*Conn) WHashSum

func (c *Conn) WHashSum() []byte

func (*Conn) Write

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

type CtlCommandHandler

type CtlCommandHandler func(cmd byte, args []byte)

type CtlExitHandler

type CtlExitHandler func()

type CtlThread

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

func NewCtlThread

func NewCtlThread(conn *Conn, interval int) *CtlThread

type D5ClientConf

type D5ClientConf struct {
	Listen     string `importable:":9009"`
	Verbose    int    `importable:"2"`
	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) RemoteId

func (d *D5Params) RemoteId() string

func (*D5Params) RemoteIdFull

func (d *D5Params) RemoteIdFull() 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_INDENTIFIER"`
	Verbose    int    `importable:"2"`
	AlgoId     int
	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 S5Target

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

type Server

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

func NewServer

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

func (*Server) Stats

func (t *Server) Stats() string

func (*Server) TransServe

func (t *Server) TransServe(fconn *Conn, session *Session, buf []byte, sid int32)

func (*Server) TunnelServe

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

type Session

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

func NewSession

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

type SessionCtType

type SessionCtType map[string]*Session

type SessionMgr

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

func NewSessionMgr

func NewSessionMgr() *SessionMgr

Jump to

Keyboard shortcuts

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