Documentation ¶
Index ¶
- Constants
- Variables
- func DPipe(conn1, conn2 SSConn, buf12, buf21 *SSBuffer, res chan error)
- func DeriveKey(key []byte, pass []byte)
- func DetectHTTP(buf *SSBuffer) bool
- func DetectRedir(tconn SSConn) bool
- func DetectSocks4(buf *SSBuffer) bool
- func DetectSocks5(buf *SSBuffer) bool
- func FDAttain()
- func FDGetCur() int
- func FDRelease()
- func FDSetMax(max int)
- func HTTPPipeBody(in SSConn, buf *SSBuffer, out SSConn, header HTTPHeader, res chan error)
- func HTTPReadLine(tconn SSConn, buf *SSBuffer, i_offset int) (line string, offset int, err error)
- func HTTPWrite400(conn SSConn) error
- func HTTPWrite502(conn SSConn) error
- func HTTPWriteHeader(conn SSConn, header HTTPHeader) (err error)
- func IsAuthError(err error) bool
- func IsIPv6(host string) bool
- func NewAuthError(message string) error
- func NewError(message string) error
- func NewKeyDeriver(pass []byte) io.Reader
- func ParseAddress(buf []byte) (addr string, n int, err error)
- func Pipe(reader, writer SSConn, buf *SSBuffer, res chan error)
- func UnwrapAddr(addr string) (host string, port uint16, err error)
- func WrapAddr(host string, port uint16) string
- type AEADCipherFactory
- type AEADConn
- type CipherFactory
- type CipherInfo
- type ClientContext
- func (ctx *ClientContext) DialServer() (conn SSConn, err error)
- func (ctx *ClientContext) HandleConnection(conn net.Conn)
- func (ctx *ClientContext) HandleHTTP(tconn SSConn, buf *SSBuffer) (err error)
- func (ctx *ClientContext) HandleRedir(tconn SSConn, buf *SSBuffer) (err error)
- func (ctx *ClientContext) HandleSocks4(tconn SSConn, buf *SSBuffer) (err error)
- func (ctx *ClientContext) HandleSocks5(tconn SSConn, buf *SSBuffer) (err error)
- func (ctx *ClientContext) Run()
- func (ctx *ClientContext) Stop()
- func (ctx *ClientContext) Wait() (err error)
- type Config
- type DelayInitConn
- type HTTPConnCtx
- type HTTPConnectionManager
- type HTTPHeader
- func (header *HTTPHeader) ContentLength() (int64, error)
- func (header *HTTPHeader) KeepAlive() bool
- func (header *HTTPHeader) Method() (string, error)
- func (header *HTTPHeader) Status() (int, error)
- func (header *HTTPHeader) URL() (string, error)
- func (header *HTTPHeader) URLHost() (string, error)
- func (header *HTTPHeader) URLRel() (string, error)
- func (header *HTTPHeader) Version() int
- type HTTPHeaderField
- type KeyDeriver
- type NewAEADCipherFunc
- type NewCipherFactoryFunc
- type Nonce
- type PlainConn
- type SBFSaltFilter
- type SSBuffer
- type SSConn
- type SSError
- type SaltFilter
- type ServerContext
- type ServerManager
- type SyncSaltFilter
Constants ¶
const DEFAULT_BUF_SIZE = 3072
const HKDF_INFO = "ss-subkey"
const HTTP_CONTENT_CHUNKED = -2
const HTTP_CONTENT_EOF = -1
const LEN_SIZE = 2
const MAX_BUF_SIZE = 32768
const MAX_READ_SIZE = 2048
const MAX_WRITE_CHUNK_SIZE = 2048
const SO_ORIGINAL_DST = 80
Variables ¶
var Ciphers = map[string]*CipherInfo{}
var ERR_AUTH_FAIL = NewAuthError("Authentication failure")
var ERR_BUF_SIZE_EXCEED = NewError("Maximum buffer size exceeded")
var ERR_DUP_SALT = NewAuthError("Duplicated salt (maybe replay attack)")
var ERR_HTTP_HOST_TOO_LONG = NewError("HTTP host too long")
var ERR_HTTP_INVALID_HEADER = NewError("Invalid HTTP header")
var ERR_HTTP_MANAGER_DEAD = NewError("HTTP manager is dead")
var ERR_INVALID_ADDR = NewError("Invalid address")
var ERR_INVALID_ADDR_TYPE = NewError("Invalid address type")
var ERR_INVALID_CHUNK_SIZE = NewError("Invalid chunk size")
var ERR_MAX_CHUNK_SIZE_EXCEED = NewError("Maximum chunk size exceeded")
var ERR_SERVER_NOT_EXIST = NewError("Server does not exist")
var ERR_SOCKS4_COMMAND_NOT_SUPPORTED = NewError("Unsupported socks4 command")
var ERR_SOCKS4_INVALID_PROTOCOL = NewError("Invalid socks4 protocol")
var ERR_SOCKS5_COMMAND_NOT_SUPPORTED = NewError("Unsupported socks5 command")
var ERR_SOCKS5_INVALID_PROTOCOL = NewError("Invalid socks5 protocol")
var ERR_SOCKS5_NO_VALID_AUTH = NewError("Socks5 request requires auth")
var ERR_UNIMPLEMENTED = NewError("Unimplemented")
Functions ¶
func DetectHTTP ¶
DetectHTTP detects whether the buffer contains valid HTTP proxy request.
Protocol definition: RFC 7230 5.3.2, RFC 7231 4.3.6 https://www.ietf.org/rfc/rfc7230.txt https://www.ietf.org/rfc/rfc7231.txt
func DetectRedir ¶
func DetectSocks4 ¶
DetectSocks4 detects whether the buffer contains a valid socks4(a) request.
Protocol definition: https://www.openssh.com/txt/socks4.protocol https://www.openssh.com/txt/socks4a.protocol
func DetectSocks5 ¶
DetectSocks5 detects whether the buffer contains valid socks5 request.
Protocol definition: RFC 1928 https://www.ietf.org/rfc/rfc1928.txt
func HTTPPipeBody ¶
func HTTPPipeBody(in SSConn, buf *SSBuffer, out SSConn, header HTTPHeader, res chan error)
func HTTPReadLine ¶
func HTTPWrite400 ¶
func HTTPWrite502 ¶
func HTTPWriteHeader ¶
func HTTPWriteHeader(conn SSConn, header HTTPHeader) (err error)
func IsAuthError ¶
func IsIPv6 ¶
IsIPv6 checks whether an address is IPv6. It does not guarantee that the address is valid, so you should only check it on an IP address or a hostname.
func NewAuthError ¶
func NewKeyDeriver ¶
NewKeyDeriver creates a new KeyDeriver.
func ParseAddress ¶
ParseAddress parses an address buffer into string. It returns resulting address, length of bytes required, and error if exists. You must check that len(buf) >= n, otherwise addr is not a valid address.
Types ¶
type AEADCipherFactory ¶
type AEADCipherFactory struct {
// contains filtered or unexported fields
}
AEADCipherFactory implements CipherFactory with AEAD ciphers.
Specification: https://shadowsocks.org/en/spec/AEAD-Ciphers.html
func (*AEADCipherFactory) Wrap ¶
func (a *AEADCipherFactory) Wrap(c PlainConn) SSConn
type AEADConn ¶
type AEADConn struct {
// contains filtered or unexported fields
}
AEADCipherConn implements SSConn with given AEAD cipher.
func (*AEADConn) RemoteAddr ¶
type CipherFactory ¶
CipherFactory is a factory that wraps PlainConn into encrypted connections.
func NewAEADCipherFactory ¶
func NewAEADCipherFactory(newCipher NewAEADCipherFunc, keySize, saltSize int, key []byte) CipherFactory
type CipherInfo ¶
type CipherInfo struct {
// contains filtered or unexported fields
}
type ClientContext ¶
type ClientContext struct {
// contains filtered or unexported fields
}
ClientContext represents an instance of client. It listens on a local port, and is configured to connect certain server address using specified encryption. It accepts several protocols, e.g. HTTP proxy, socks4(a), socks5. The combinition should be able to be configured in the future.
func NewClientContext ¶
func NewClientContext(config Config) (ctx ClientContext, err error)
NewClientContext creates a new client context.
func (*ClientContext) DialServer ¶
func (ctx *ClientContext) DialServer() (conn SSConn, err error)
func (*ClientContext) HandleConnection ¶
func (ctx *ClientContext) HandleConnection(conn net.Conn)
HandleConnection handles client connections, checking input buffer, and dispatch connections to different protocol handler.
func (*ClientContext) HandleHTTP ¶
func (ctx *ClientContext) HandleHTTP(tconn SSConn, buf *SSBuffer) (err error)
HandleHTTP handles a HTTP/1.0 or HTTP/1.1 proxy connection.
func (*ClientContext) HandleRedir ¶
func (ctx *ClientContext) HandleRedir(tconn SSConn, buf *SSBuffer) (err error)
func (*ClientContext) HandleSocks4 ¶
func (ctx *ClientContext) HandleSocks4(tconn SSConn, buf *SSBuffer) (err error)
HandleSocks4 handles a socks4(a) connection.
func (*ClientContext) HandleSocks5 ¶
func (ctx *ClientContext) HandleSocks5(tconn SSConn, buf *SSBuffer) (err error)
HandleSocks5 handles a socks5 connection.
func (*ClientContext) Run ¶
func (ctx *ClientContext) Run()
Run runs a client. Usually this should be run in a goroutine.
func (*ClientContext) Stop ¶
func (ctx *ClientContext) Stop()
Stop stops the client running goroutine.
func (*ClientContext) Wait ¶
func (ctx *ClientContext) Wait() (err error)
Wait waits the client to stop and return its error
type Config ¶
type Config struct { // Server listening address ServerHost string // Server listening port ServerPort uint16 // Local listening address (Client only) LocalHost string // Local listening port (Client only) LocalPort uint16 // Encryption method Method string // Key generator KeyDeriver io.Reader // TCP keepalive timeout Timeout time.Duration // Connect IPv4 address only (Server only) ConnectV4Only bool // New connection timeout (Server only) ConnectTimeout time.Duration }
func DefaultConfig ¶
func DefaultConfig() Config
type DelayInitConn ¶
type DelayInitConn struct {
// contains filtered or unexported fields
}
func NewDelayInitConn ¶
func NewDelayInitConn(conn SSConn, initBuf []byte) *DelayInitConn
func (*DelayInitConn) Alive ¶
func (c *DelayInitConn) Alive() bool
func (*DelayInitConn) Close ¶
func (c *DelayInitConn) Close() error
func (*DelayInitConn) RemoteAddr ¶
func (c *DelayInitConn) RemoteAddr() string
func (*DelayInitConn) SSRead ¶
func (c *DelayInitConn) SSRead(buf *SSBuffer) error
func (*DelayInitConn) SSWrite ¶
func (c *DelayInitConn) SSWrite(buf *SSBuffer) error
type HTTPConnCtx ¶
type HTTPConnCtx struct {
// contains filtered or unexported fields
}
type HTTPConnectionManager ¶
type HTTPConnectionManager struct {
// contains filtered or unexported fields
}
func NewHTTPConnectionManager ¶
func NewHTTPConnectionManager(ctx *ClientContext) (m *HTTPConnectionManager)
func (*HTTPConnectionManager) Delete ¶
func (m *HTTPConnectionManager) Delete()
func (*HTTPConnectionManager) Get ¶
func (m *HTTPConnectionManager) Get(addr string) (hctx *HTTPConnCtx, err error)
func (*HTTPConnectionManager) Release ¶
func (m *HTTPConnectionManager) Release(hctx *HTTPConnCtx)
type HTTPHeader ¶
type HTTPHeader struct {
// contains filtered or unexported fields
}
func HTTPParseHeader ¶
func HTTPParseHeader(tconn SSConn, buf *SSBuffer, req bool) (header HTTPHeader, err error)
func (*HTTPHeader) ContentLength ¶
func (header *HTTPHeader) ContentLength() (int64, error)
func (*HTTPHeader) KeepAlive ¶
func (header *HTTPHeader) KeepAlive() bool
func (*HTTPHeader) Method ¶
func (header *HTTPHeader) Method() (string, error)
func (*HTTPHeader) Status ¶
func (header *HTTPHeader) Status() (int, error)
func (*HTTPHeader) URL ¶
func (header *HTTPHeader) URL() (string, error)
func (*HTTPHeader) URLHost ¶
func (header *HTTPHeader) URLHost() (string, error)
func (*HTTPHeader) URLRel ¶
func (header *HTTPHeader) URLRel() (string, error)
func (*HTTPHeader) Version ¶
func (header *HTTPHeader) Version() int
type HTTPHeaderField ¶
type HTTPHeaderField struct {
// contains filtered or unexported fields
}
type KeyDeriver ¶
type KeyDeriver struct {
// contains filtered or unexported fields
}
KeyDeriver is a context of key deriving.
type NewCipherFactoryFunc ¶
type NewCipherFactoryFunc func([]byte) CipherFactory
type SBFSaltFilter ¶
type SBFSaltFilter struct{}
func (*SBFSaltFilter) Add ¶
func (f *SBFSaltFilter) Add(salt []byte)
func (*SBFSaltFilter) Clean ¶
func (f *SBFSaltFilter) Clean()
func (*SBFSaltFilter) Contains ¶
func (f *SBFSaltFilter) Contains(salt []byte) bool
type SSBuffer ¶
type SSBuffer struct {
// contains filtered or unexported fields
}
SSBuffer contains a buffer, currently a simple []byte. The content is to be sent. The capacity of the slice will be reused when reading.
type SSConn ¶
type SSConn interface { // SSRead reads some data into buffer. The size is uncertain. // Data is appended to the buffer. SSRead(*SSBuffer) error // SSWrite writes the data to the connection. It should write // the whole buffer and reset the buffer, otherwise it will // report an error. SSWrite(*SSBuffer) error // Close closes the connection. Close() error // Alive checks whether the connection is alive. Alive() bool // RemoteAddr returns the address of remote endpoint // note this should not used to Dial. It is currently // used for debugging. RemoteAddr() string }
SSConn represents a Shadowsocks accepted connection (maybe).
type SaltFilter ¶
type ServerContext ¶
type ServerContext struct {
// contains filtered or unexported fields
}
ServerContext represents an instance of Shadowsocks server which listens on a single port and accept a single kind of encryption.
func NewServerContext ¶
func NewServerContext(config Config) (ctx ServerContext, err error)
NewServerContext creates a new instance of ServerContext with specified arguments.
func (*ServerContext) HandleConnection ¶
func (ctx *ServerContext) HandleConnection(conn net.Conn)
HandleConnection handles a newly accepted connection with configured ciphers.
func (*ServerContext) Run ¶
func (ctx *ServerContext) Run()
Run runs the server, normally running in a new goroutine.
func (*ServerContext) Wait ¶
func (ctx *ServerContext) Wait() (err error)
Wait waits the server to stop and return its error.
type ServerManager ¶
type ServerManager struct {
// contains filtered or unexported fields
}
func NewServerManager ¶
func NewServerManager() ServerManager
func (*ServerManager) Add ¶
func (m *ServerManager) Add(config Config) (err error)
func (*ServerManager) Listen ¶
func (m *ServerManager) Listen(addr string) (err error)
type SyncSaltFilter ¶
type SyncSaltFilter struct { SaltFilter // contains filtered or unexported fields }
func WrapSyncSaltFilter ¶
func WrapSyncSaltFilter(f SaltFilter) (s *SyncSaltFilter)
func (*SyncSaltFilter) Add ¶
func (f *SyncSaltFilter) Add(salt []byte)
func (*SyncSaltFilter) Clean ¶
func (f *SyncSaltFilter) Clean()
func (*SyncSaltFilter) Contains ¶
func (f *SyncSaltFilter) Contains(salt []byte) bool
Source Files ¶
- client.go
- client_http.go
- client_http_connmgr.go
- client_http_util.go
- client_redir.go
- client_redir_getsockopt.go
- client_socks4a.go
- client_socks5.go
- config.go
- const.go
- crypto.go
- crypto_aead.go
- crypto_aead_aesgcm.go
- crypto_aead_chacha20poly1305.go
- delayinit_conn.go
- errors.go
- fdtracker.go
- salt_filter.go
- salt_filter_stable_bloom.go
- server.go
- server_manager.go
- stream.go
- util.go