tunnel

package
v0.0.0-...-7f29b95 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2014 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B_TRUE  byte = 1
	B_FALSE byte = 0

	PROTO_MAGIC   = 'P'
	PROTO_VERSION = 1

	PACKET_NEW_CONN   = 1
	PACKET_PROXY      = 2
	PACKET_CLOSE_CONN = 3

	PROTO_ADDR_IP     byte = 1
	PROTO_ADDR_DOMAIN byte = 2

	REUSE_SUCCESS                    = 0
	REUSE_FAIL_HMAC_FAIL             = 1
	REUSE_FAIL_SYS_ERR               = 2
	REUSE_FAIL_START_CIPHER_EXCHANGE = 0x10
)

Variables

This section is empty.

Functions

func CheckMAC

func CheckMAC(message, messageMAC, key []byte) bool

func GenerateRSAKey

func GenerateRSAKey(bits int, path string) (*rsa.PrivateKey, error)

func LoadRSAPrivateKey

func LoadRSAPrivateKey(path string) (*rsa.PrivateKey, error)

func LoadRSAPublicKey

func LoadRSAPublicKey(path string) (*rsa.PublicKey, error)

func LoadYamlConfig

func LoadYamlConfig(path string, obj interface{}) error

func MakeCryptoKeyIV

func MakeCryptoKeyIV(password []byte, key_size, iv_size int) ([]byte, []byte)

func ReadN2

func ReadN2(bs []byte, offset int) uint16

func ReadN4

func ReadN4(bs []byte, offset int) uint32

func WriteN2

func WriteN2(bs []byte, offset int, n uint16)

func WriteN4

func WriteN4(bs []byte, offset int, n uint32)

Types

type AESCipherMaker

type AESCipherMaker struct{}

func (*AESCipherMaker) NewStreamCipher

func (m *AESCipherMaker) NewStreamCipher(key, iv []byte) (cipher.Stream, cipher.Stream, error)

type CipherConfig

type CipherConfig struct {
	Name    string
	KeySize int
	IVSize  int
	// contains filtered or unexported fields
}

func GetCipherConfig

func GetCipherConfig(name string) *CipherConfig

func (*CipherConfig) NewCipher

func (ctx *CipherConfig) NewCipher(key, iv []byte) (cipher.Stream, cipher.Stream, error)

type CipherContext

type CipherContext struct {
	P         *big.Int
	G         int
	XY        *big.Int
	EF        *big.Int
	Key       *big.Int
	CryptoKey []byte // fixed size key, for cipher
	IV        []byte
}

func MakeCipherContext

func MakeCipherContext(p *big.Int, g int) *CipherContext

func NewCipherContext

func NewCipherContext(group int) (*CipherContext, error)

func (*CipherContext) CalcKey

func (ctx *CipherContext) CalcKey(ef *big.Int)

func (*CipherContext) MakeCryptoKeyIV

func (ctx *CipherContext) MakeCryptoKeyIV(key_size, iv_size int) ([]byte, []byte)

func (*CipherContext) MakeE

func (ctx *CipherContext) MakeE() (*big.Int, error)

func (*CipherContext) MakeEF

func (ctx *CipherContext) MakeEF(minval int64) (*big.Int, error)

func (*CipherContext) MakeF

func (ctx *CipherContext) MakeF() (*big.Int, error)

func (*CipherContext) MakeSessionId

func (ctx *CipherContext) MakeSessionId() (SessionId, error)

type CipherExchangeInit

type CipherExchangeInit struct {
	PublickKey []byte
	P          []byte
	G          uint8
	F          []byte
	Signature  []byte
}

type Client

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

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

func (*Client) Close

func (cli *Client) Close()

func (*Client) DoDomainProxy

func (cli *Client) DoDomainProxy(domain string, port int, rw io.ReadWriteCloser)

func (*Client) DoIPProxy

func (cli *Client) DoIPProxy(addr []byte, port int, rw io.ReadWriteCloser)

func (*Client) Init

func (cli *Client) Init() error

type ClientConfig

type ClientConfig struct {
	ServerAddr      string
	SocksListenAddr string
	RedirListenAddr string
	DNSListenAddr   string
	DNSListenOnTCP  bool
	DNSRemoteAddr   string

	GlobalEncryptMethod   string
	GlobalEncryptPassword string
	LinkEncryptMethods    []string
	ServerPublicKeyPath   string

	Username string
	Password string
}

func LoadClientConfig

func LoadClientConfig(path string) (*ClientConfig, error)

type ClientProxy

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

func NewClientProxy

func NewClientProxy(session *Session, pipe *StreamPipe) *ClientProxy

func (*ClientProxy) DoProxy

func (cp *ClientProxy) DoProxy()

type ClientTunnel

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

func NewClientTunnel

func NewClientTunnel(cli *Client) *ClientTunnel

func (*ClientTunnel) Init

func (ct *ClientTunnel) Init() error

type ConnManager

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

func NewConnManager

func NewConnManager(write_ch chan []byte) *ConnManager

func (*ConnManager) CloseAllConns

func (cm *ConnManager) CloseAllConns()

func (*ConnManager) CloseConn

func (cm *ConnManager) CloseConn(conn_id uint32)

func (*ConnManager) DoProxy

func (cm *ConnManager) DoProxy(conn_type byte, addr []byte, port int, rw io.ReadWriteCloser)

func (*ConnManager) WriteToLocalConn

func (cm *ConnManager) WriteToLocalConn(conn_id uint32, data []byte)

type DESCipherMaker

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

func (*DESCipherMaker) NewStreamCipher

func (m *DESCipherMaker) NewStreamCipher(key, iv []byte) (cipher.Stream, cipher.Stream, error)

type GlobalCipherConfig

type GlobalCipherConfig struct {
	Config *CipherConfig
	Key    []byte
	IV     []byte
}

func LoadGlobalCipherConfig

func LoadGlobalCipherConfig(name string, passwd []byte) (*GlobalCipherConfig, error)

func (*GlobalCipherConfig) NewCipher

func (cfg *GlobalCipherConfig) NewCipher() (cipher.Stream, cipher.Stream, error)

type LoginRequest

type LoginRequest struct {
	Magic         uint8
	ClientVersion uint8
	Username      string
	Password      string
}

type LoginResponse

type LoginResponse struct {
	Magic         uint8
	ServerVersion uint8
	LoginOk       bool
	SessionId     string
}

type RC4CipherMaker

type RC4CipherMaker struct{}

func (*RC4CipherMaker) NewStreamCipher

func (m *RC4CipherMaker) NewStreamCipher(key, iv []byte) (cipher.Stream, cipher.Stream, error)

type ReuseSession

type ReuseSession struct {
	SessionId string
	RandMsg   []byte
	HMACData  []byte
}

type Server

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

func NewServer

func NewServer(config *ServerConfig) (*Server, error)

func (*Server) Run

func (ser *Server) Run()

type ServerConfig

type ServerConfig struct {
	ListenAddr            string
	GlobalEncryptMethod   string
	GlobalEncryptPassword string
	LinkEncryptMethods    []string

	UserConfigPath string
	KeyPath        string
}

func LoadServerConfig

func LoadServerConfig(path string) (*ServerConfig, error)

type Session

type Session struct {
	Id           SessionId
	Username     string
	CipherCtx    *CipherContext
	CipherConfig *CipherConfig
}

type SessionId

type SessionId string

func SessionIdFromBytes

func SessionIdFromBytes(bs []byte) SessionId

func (SessionId) Bytes

func (sid SessionId) Bytes() ([]byte, error)

type SessionManager

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

func NewSessionManager

func NewSessionManager() *SessionManager

func (*SessionManager) DelSession

func (mgr *SessionManager) DelSession(sid SessionId)

func (*SessionManager) GetSession

func (mgr *SessionManager) GetSession(sid SessionId) *Session

func (*SessionManager) NewSession

func (mgr *SessionManager) NewSession(ctx *CipherContext) (*Session, error)

type SockChan

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

type StreamPipe

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

func NewStreamPipe

func NewStreamPipe(rw io.ReadWriteCloser) *StreamPipe

func (*StreamPipe) Close

func (pipe *StreamPipe) Close() error

func (*StreamPipe) Read

func (pipe *StreamPipe) Read(bs []byte) (int, error)

func (*StreamPipe) SwitchCipher

func (pipe *StreamPipe) SwitchCipher(enc, dec cipher.Stream)

func (*StreamPipe) Write

func (pipe *StreamPipe) Write(bs []byte) (int, error)

type UserConfig

type UserConfig struct {
	Password string
}

type UserConfigs

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

func GetUserConfigs

func GetUserConfigs(path string) (*UserConfigs, error)

func (*UserConfigs) Get

func (cfgs *UserConfigs) Get(user string) *UserConfig

func (*UserConfigs) Reload

func (cfgs *UserConfigs) Reload() error

Jump to

Keyboard shortcuts

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