obfs

package
v0.0.0-...-d00ae73 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	MAX_INT  = (1 << 64) - 1
	MOV_MASK = (1 << (64 - 23)) - 1
)
View Source
const (
	NETWORK_MTU      = 1500
	TCP_MSS          = 1460
	BUF_SIZE         = 32 * 1024
	UDP_MAX_BUF_SIZE = 65536
	DEFAULT_HEAD_LEN = 30
)

Variables

View Source
var (
	DEFAULT_VERSION       = []byte{0x03, 0x03}
	DEFAULT_OVERHEAD      = 5
	DEFAULT_MAX_TIME_DIFF = 60 * 60 * 24
)

golang dont support declare constant array so we use variable to replace it

View Source
var USER_AGENT = []string{
	"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0",
	"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/44.0",
	"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
	"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36",
	"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0",
	"Mozilla/5.0 (compatible; WOW64; MSIE 10.0; Windows NT 6.2)",
	"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
	"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)",
	"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
	"Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/BuildID) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36",
	"Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
	"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
}

Functions

func MustHexDecode

func MustHexDecode(data string) []byte

Types

type AuthAes128Sha1

type AuthAes128Sha1 struct {
	*AuthBase
	*ObfsAuthChainData
	HashFunc      func() hash.Hash
	RecvBuf       []byte
	UnitLen       int
	RawTrans      bool
	HasRecvHeader bool
	HasSentHeader bool
	ClientID      int
	ConnectionID  int
	MaxTimeDif    int
	Salt          []byte
	ExtraWaitSize int
	PackID        int
	RecvID        int
	UserID        []byte
	UserKey       []byte
	LastRndLen    int
}

func (*AuthAes128Sha1) ClientPostDecrypt

func (a *AuthAes128Sha1) ClientPostDecrypt(buf []byte) (result []byte, err error)

func (*AuthAes128Sha1) ClientPreEncrypt

func (a *AuthAes128Sha1) ClientPreEncrypt(buf []byte) (result []byte, err error)

func (*AuthAes128Sha1) ClientUDPPostDecrypt

func (a *AuthAes128Sha1) ClientUDPPostDecrypt(buf []byte) ([]byte, error)

func (*AuthAes128Sha1) ClientUDPPreEncrypt

func (a *AuthAes128Sha1) ClientUDPPreEncrypt(buf []byte) ([]byte, error)

func (*AuthAes128Sha1) ServerPostDecrypt

func (a *AuthAes128Sha1) ServerPostDecrypt(buf []byte) (result []byte, sendback bool, err error)

func (*AuthAes128Sha1) ServerPreEncrypt

func (a *AuthAes128Sha1) ServerPreEncrypt(buf []byte) ([]byte, error)

func (*AuthAes128Sha1) ServerUDPPostDecrypt

func (a *AuthAes128Sha1) ServerUDPPostDecrypt(buf []byte) ([]byte, string, error)

func (*AuthAes128Sha1) ServerUDPPreEncrypt

func (a *AuthAes128Sha1) ServerUDPPreEncrypt(buf, uid []byte) ([]byte, error)

func (*AuthAes128Sha1) SetServerInfo

func (a *AuthAes128Sha1) SetServerInfo(s ServerInfo)

type AuthBase

type AuthBase struct {
	Plain
	Method             string
	NoCompatibleMethod string
	Overhead           int
	RawTrans           bool
}

---------------------------- AuthBase ----------------------------

func NewAuthBase

func NewAuthBase(method string) (*AuthBase, error)

func (*AuthBase) GetOverhead

func (authBase *AuthBase) GetOverhead(direction bool) int

func (*AuthBase) NotMatchReturn

func (authBase *AuthBase) NotMatchReturn(buf []byte) ([]byte, bool)

type AuthChainA

type AuthChainA struct {
	*AuthBase
	RecvBuf        []byte
	UnintLen       int
	HasSentHeader  bool
	HasRecvHeader  bool
	ClientID       int
	ConnectionID   int
	MaxTimeDif     int
	Salt           []byte
	PackID         int
	RecvID         int
	UserID         []byte
	UserIDNum      int
	UserKey        []byte
	ClientOverhead int
	LastClientHash []byte
	LastServerHash []byte
	RandomClient   *XorShift128Plus
	RandomServer   *XorShift128Plus
	Encryptor      *ciphers.Encryptor
}

----------------------------------AuthChainA----------------------------------

Example
server := GetAuth()
testData, _ := hex.DecodeString("1f1f645b1c61777508c444705f7ac909ce549d8859f4959996b9b817cfccf89560c0716f3e7ec8ad809fea1785b0f2ae162789d30cec6a589cb71d75a796584d4e085b15189bee7f1daff841d802a70e36dc9a541937c38cbf2cb8252fc06f5f2a374bd12454316d7265921e84d8e662749a1fa93198dc3cc946a9aafe0b30b2c013a5eaa2bf9b9e74aee69d7996b62e9e3302e87cefe9137c0d4572e50944e1c6a7856549bf1ef4b10ee1b2c370420c53e9e7e78f975d022257236da092e424c96746d88d28b764ddc45d4f1b061b94424cc02b4d6b4a8ce0f97d30235a4dfa0fb1acd51ade9fe78be6991c5c2d6caad8028cf7a0660ca3cf0f805c42b4c59ad1628813df92866b9007000fc017b4995e087aa35e0d77a6b2e7d934672b37a925cca50ed9ff715aab68a9b812afa93228bf54e0ded51d989bdd9aa86a52a05a9283e955dd34f81af06d43650a43651ebdd5e36c9b42697f636d1275b2d61389a62c3cafed92e532316ce4d3d2e913c81d6f225192da176cfa007307f11b605918240c5d3ebed516f3c1ea657e6c6337f1bd1cb34e01d34660f592408cf50b936f9beec5409f8718ac4e3f833bb400cb01ceec7d67fa34b7971167f56dc8d335d9865d11e52d78c773a99ce2755fa10d537556252cc0604640bb63d98140edfa2def15d316e183dab62e393aa7a3b885a2eb25e0d2476b6a008c1987772898ad4777b75a36b22a8c52ebb248cf9db6916ad622e3bd049c0b1acf8610d5f1ce94e8b47df03e2168b11d067916ce6465501f4844fc5c8cec9e95455703c1330ce62045fd3ff0ef6d3107a7c7d5c01ff3f48dae7582a1c80779c36a433f24d919d4b1528e7cac85790df311c4231907e5989f11053603d53952b7d8ef815ac831a3a4e37e467327b50042f087a3bce89f347b98e9cdbf7f395b00d43d384455ae8fbcc98ddebbddaac8a0f4e784916ee12c4abd2a7fc3f792d39b242b57c67ebe22867c92460bbe15450eca27aa1c8a0df86522e050bda1f8a3d80352f5e4017d8b1e06e0df6d0f230b4aefdb7d7ab517725d347582c766963a7f30759f9194ba431decf37f422c2716ac4dfcf3cb1785243012a095b3c3276329a3f12effd50a2696eb79ceec8b245a7605b84b76e0f9ac1eeb1694e723285cc16ba613f8407905090aa0088b1b18e16abb6cc6ce22f8cb8a6858546cbe18eb277df693be995e3b2a61a4278820cba983e64b9397444edc239ee5bd06bb69d370383cb13f5d23cca1b078996a91550e74578b2215c2aeaf5a6a00267f878d58860fbc415ce3b9239f93ad97acfb9d49e3eca3a5b9832b773224ab54ba60af74e098465fbee992f4639cb6dcd43b648441ae89dc8039b9d72a8af09ca33f2d5b3056e4d193ae8488092b95573ac84e49542b63c75ca9e982109b56b7f1850974f5b7ad0eb3fe9e856e6513801608fdc9cc125fc35cc23faf17c265ff05f18676659bef8082fcc6b78fd07d83b765f0b11333af84498d27675fd3e6de77d8b1fe3c630fe36f538535adc8f6cbf8ae3e6671b81b59fb14830d5d72e008d41e032f8aefc3f3a588a7e47f86ad479912d11a4b96d840a316837b082a2bd50f8322ebee431c1bd20f2ddbe9b8f59d749c8da29f90d4f28314e9fea064292e049cbb6d7e7d3aa389c6343af69710f4a3be10913c21a10c2922564f6d1a66be2366a95697515b4bf2291e427aa46eb81c5aa4e71022d3aaab458d556b13dd632ec6a2bf311b4a085fd91210415c7c0ce3b0e03de498bd41a0b046efcf91b8654370b302b509acc995a3c99a700fdb50d9eed0260d62a8568c837f10d06865cd7ddcbf57ca3f2c3beac7137c5a6d22aba73fcfbd03b16b6a4407026b46e7c1cad47c1064cfac076c")
result, sendback, err := server.ServerPostDecrypt(testData)
if err != nil {
	fmt.Print(err)
	return
}
fmt.Printf("sendback: %v,result: %s\n", sendback, result)
Output:

func (*AuthChainA) ClientPostDecrypt

func (a *AuthChainA) ClientPostDecrypt(buf []byte) (result []byte, err error)

func (*AuthChainA) ClientPreEncrypt

func (a *AuthChainA) ClientPreEncrypt(buf []byte) (result []byte, err error)

func (*AuthChainA) ClientUDPPostDecrypt

func (a *AuthChainA) ClientUDPPostDecrypt(buf []byte) ([]byte, error)

func (*AuthChainA) ClientUDPPreEncrypt

func (a *AuthChainA) ClientUDPPreEncrypt(buf []byte) ([]byte, error)

func (*AuthChainA) Dispose

func (a *AuthChainA) Dispose()

func (*AuthChainA) GetOverhead

func (a *AuthChainA) GetOverhead(direction bool) int

func (*AuthChainA) ServerPostDecrypt

func (a *AuthChainA) ServerPostDecrypt(buf []byte) (result []byte, sendback bool, err error)

func (*AuthChainA) ServerPreEncrypt

func (a *AuthChainA) ServerPreEncrypt(buf []byte) (result []byte, err error)

func (*AuthChainA) ServerUDPPostDecrypt

func (a *AuthChainA) ServerUDPPostDecrypt(buf []byte) ([]byte, string, error)

func (*AuthChainA) ServerUDPPreEncrypt

func (a *AuthChainA) ServerUDPPreEncrypt(buf, uid []byte) ([]byte, error)

func (*AuthChainA) SetServerInfo

func (a *AuthChainA) SetServerInfo(s ServerInfo)

type ClientQueue

type ClientQueue struct {
	Front      int
	Back       int
	Alloc      *sync.Map
	Enable     bool
	LastUpdate time.Time
	Ref        int
}

func NewClientQueue

func NewClientQueue(beginID int) *ClientQueue

func (*ClientQueue) AddRef

func (c *ClientQueue) AddRef()

func (*ClientQueue) DelRef

func (c *ClientQueue) DelRef()

func (*ClientQueue) Insert

func (c *ClientQueue) Insert(connectionID int) bool

func (*ClientQueue) IsActive

func (c *ClientQueue) IsActive() bool

func (*ClientQueue) ReEnable

func (c *ClientQueue) ReEnable(connectionID int)

func (*ClientQueue) Update

func (c *ClientQueue) Update()

type HashNewFunc

type HashNewFunc func() hash.Hash

type HttpSimple

type HttpSimple struct {
	Plain
	// contains filtered or unexported fields
}

func (*HttpSimple) ClientDecode

func (h *HttpSimple) ClientDecode(buf []byte) ([]byte, bool, error)

func (*HttpSimple) ClientEncode

func (h *HttpSimple) ClientEncode(buf []byte) ([]byte, error)

func (*HttpSimple) ServerDecode

func (h *HttpSimple) ServerDecode(buf []byte) ([]byte, bool, bool, error)

func (*HttpSimple) ServerEncode

func (h *HttpSimple) ServerEncode(buf []byte) ([]byte, error)

type ObfsAuthChainData

type ObfsAuthChainData struct {
	Name          string
	UserID        map[string]*cache.LRU
	LocalClientId []byte
	ConnectionID  int
	MaxClient     int
	MaxBuffer     int
}

func NewObfsAuthChainData

func NewObfsAuthChainData(name string) *ObfsAuthChainData

func (*ObfsAuthChainData) AuthData

func (o *ObfsAuthChainData) AuthData() []byte

func (*ObfsAuthChainData) GetClientID

func (o *ObfsAuthChainData) GetClientID() []byte

func (*ObfsAuthChainData) GetConnectionID

func (o *ObfsAuthChainData) GetConnectionID() int

func (*ObfsAuthChainData) Insert

func (o *ObfsAuthChainData) Insert(userID []byte, clientID, connectionID int) bool

func (*ObfsAuthChainData) Remove

func (o *ObfsAuthChainData) Remove(userID string, clientID int)

func (*ObfsAuthChainData) SetClientID

func (o *ObfsAuthChainData) SetClientID(clientID []byte)

func (*ObfsAuthChainData) SetConnectionID

func (o *ObfsAuthChainData) SetConnectionID(connectionID int)

func (*ObfsAuthChainData) SetMaxClient

func (o *ObfsAuthChainData) SetMaxClient(maxClient int)

func (*ObfsAuthChainData) Update

func (o *ObfsAuthChainData) Update(userID []byte, clientID, connectionID int)

type ObfsAuthData

type ObfsAuthData struct {
	ServerInfo
	ClientData *cache.Cache
	ClientID   []byte
	StartTime  int
	TicketBuf  map[string][]byte
}

func NewObfsAuthData

func NewObfsAuthData() *ObfsAuthData

type ObfsTLS

type ObfsTLS struct {
	Plain
	*ObfsAuthData
	HandshakeStatus int
	SendBuffer      []byte
	RecvBuffer      []byte
	ClientID        []byte
	MaxTimeDiff     int
	TLSVersion      []byte
	Overhead        int
}

func (*ObfsTLS) ClientDecode

func (otls *ObfsTLS) ClientDecode(buf []byte) ([]byte, bool, error)

ClientDecode buffer_to_recv, is_need_to_encode_and_send_back

func (*ObfsTLS) ClientEncode

func (otls *ObfsTLS) ClientEncode(buf []byte) ([]byte, error)

func (*ObfsTLS) ClientPreEncrypt

func (otls *ObfsTLS) ClientPreEncrypt(buf []byte) ([]byte, error)

func (*ObfsTLS) DecodeErrorReturn

func (otls *ObfsTLS) DecodeErrorReturn(buf []byte) ([]byte, bool, bool, error)

func (*ObfsTLS) GetOverhead

func (otls *ObfsTLS) GetOverhead(direction bool) int

func (*ObfsTLS) GetServerInfo

func (otls *ObfsTLS) GetServerInfo() ServerInfo

func (*ObfsTLS) ServerDecode

func (otls *ObfsTLS) ServerDecode(buf []byte) ([]byte, bool, bool, error)

ServerDecode return buffer_to_recv, is_need_decrypt, is_need_to_encode_and_send_back

func (*ObfsTLS) ServerEncode

func (otls *ObfsTLS) ServerEncode(buf []byte) ([]byte, error)

func (*ObfsTLS) SetServerInfo

func (otls *ObfsTLS) SetServerInfo(s ServerInfo)

type Plain

type Plain interface {
	InitData() []byte
	GetMethod() string
	SetMethod(method string)
	GetOverhead(direction bool) int
	GetServerInfo() ServerInfo
	SetServerInfo(s ServerInfo)
	ClientPreEncrypt(buf []byte) ([]byte, error)
	ClientEncode(buf []byte) ([]byte, error)
	ClientDecode(buf []byte) ([]byte, bool, error)
	ClientPostDecrypt(buf []byte) ([]byte, error)
	ServerPreEncrypt(buf []byte) ([]byte, error)
	ServerEncode(buf []byte) ([]byte, error)
	// ServerDecode return buffer_to_recv, is_need_decrypt, is_need_to_encode_and_send_back
	ServerDecode(buf []byte) ([]byte, bool, bool, error)
	ServerPostDecrypt(buf []byte) ([]byte, bool, error)
	ClientUDPPreEncrypt(buf []byte) ([]byte, error)
	ClientUDPPostDecrypt(buf []byte) ([]byte, error)
	ServerUDPPreEncrypt(buf, uid []byte) ([]byte, error)
	ServerUDPPostDecrypt(buf []byte) ([]byte, string, error)
	Dispose()
	GetHeadSize(buf []byte, defaultValue int) int
}

Plain interface

func AuthAes128Md5Factory

func AuthAes128Md5Factory(method string) (Plain, error)

func AuthAes128Sha1Factory

func AuthAes128Sha1Factory(method string) (Plain, error)

func GetObfs

func GetObfs(method string) (Plain, error)
Example
GetObfs("obfs")
Output:

func NewAuthAes128Sha1

func NewAuthAes128Sha1(method string, handle func() hash.Hash) (Plain, error)

func NewAuthChainA

func NewAuthChainA(method string) (Plain, error)

func NewHttpSimple

func NewHttpSimple(method string) (Plain, error)

func NewObfsTLS

func NewObfsTLS(method string) (Plain, error)

func NewPlain

func NewPlain(method string) (Plain, error)

NewPlain construct a new plain and initliza default value

type PlainFactory

type PlainFactory func(string) (Plain, error)

type ServerInfo

type ServerInfo interface {
	GetHost() string
	SetHost(host string)
	GetPort() int
	SetPort(port int)
	GetClient() net.IP
	SetClient(client net.IP)
	GetClientPort() int
	SetClientPort(port int)
	GetProtocolParam() string
	SetProtocolParam(protocolParam string)
	GetObfsParam() string
	SetObfsParam(obfsParam string)
	SetIv(iv []byte)
	GetIv() []byte
	SetRecvIv(iv []byte)
	GetRecvIv() []byte
	SetKeyStr(key string)
	GetKeyStr() string
	SetKey(key []byte)
	GetKey() []byte
	SetHeadLen(len int)
	GetHeadLen() int
	SetTCPMss(mss int)
	GetTCPMss() int
	SetBufferSize(size int)
	GetBufferSize() int
	SetOverhead(size int)
	GetOverhead() int
	GetUsers() map[string]string
	SetUsers(users map[string]string)
	UpdateUser(uid []byte)
	SetUpdateUserFunc(func(uid []byte))
}

func NewServerInfo

func NewServerInfo() ServerInfo

InitServerInfo init ServerInfo default value

type XorShift128Plus

type XorShift128Plus struct {
	V0 uint64
	V1 uint64
}
Example
a := NewXorShift128Plus()
a.InitFromBin(bytes.Repeat([]byte{byte(0x01)}, 16))
fmt.Println(a)
a = NewXorShift128Plus()
a.InitFromBinLen(bytes.Repeat([]byte{byte(0x01)}, 16), 2)
fmt.Println(a)
fmt.Printf("%v\n", a.Next())

a = NewXorShift128Plus()
a.InitFromBinLen(MustHexDecode("1c61777508c444705f7ec9092de53b7e"), 5)
fmt.Printf("%v\n", a.Next())
Output:

&{72340172838076673 72340172838076673}
&{11655686789823302041 3472380973156407715}
5864189510468454840

func NewXorShift128Plus

func NewXorShift128Plus() *XorShift128Plus

func (*XorShift128Plus) InitFromBin

func (xs1p *XorShift128Plus) InitFromBin(bin []byte)

func (*XorShift128Plus) InitFromBinLen

func (xs1p *XorShift128Plus) InitFromBinLen(bin []byte, length int)

func (*XorShift128Plus) Next

func (xs1p *XorShift128Plus) Next() uint64

Jump to

Keyboard shortcuts

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