Documentation
¶
Index ¶
- Constants
- func Base64Decode(password string) ([]byte, error)
- func GCMWithAES(key []byte) (cipher.AEAD, error)
- func Increment(b []byte)
- func UsersToEIHHash(users []UserConfig) map[EIHHash]string
- func XORBytes(a, b []byte) ([]byte, error)
- type ClientConfig
- type EIHHash
- type KeySizeError
- type MetaCipher
- type ServerConfig
- type SessionHash
- type ShadowCipher
- type TCPClient
- type TCPConfig
- type TCPConn
- type TCPConnCipher
- type TCPServer
- type UDPClient
- type UDPConfig
- type UDPConnCipher
- type UDPServer
- type UDPSession
- type UDPSessionManager
- type UserConfig
Constants ¶
const ( ROLE_UNKNOWN int = 0 ROLE_CLIENT int = 1 ROLE_SERVER int = 2 )
Variables ¶
This section is empty.
Functions ¶
func Base64Decode ¶
func Increment ¶
func Increment(b []byte)
increment little-endian encoded unsigned integer b. Wrap around on overflow.
func UsersToEIHHash ¶
func UsersToEIHHash(users []UserConfig) map[EIHHash]string
Types ¶
type ClientConfig ¶
type ClientConfig struct {
Cipher ShadowCipher
}
type KeySizeError ¶
type KeySizeError int
func (KeySizeError) Error ¶
func (e KeySizeError) Error() string
type MetaCipher ¶
type ServerConfig ¶
type ServerConfig struct {
Cipher ShadowCipher
Users []UserConfig
}
type SessionHash ¶
type SessionHash string
func SessionHashFromAddrPort ¶ added in v0.1.1
func SessionHashFromAddrPort(addr netip.AddrPort) SessionHash
func SessionHashFromSessionID ¶ added in v0.1.1
func SessionHashFromSessionID(id uint64) SessionHash
type ShadowCipher ¶
type ShadowCipher interface {
TCPConnCipher
UDPConnCipher
SaltSize() int
KeySize() int
NonceSize() int
TagSize() int
Encrypter(key, salt []byte) (cipher.AEAD, error)
Decrypter(key, salt []byte) (cipher.AEAD, error)
// Start from SIP023, the cipher can hold multiple keys for clients
// For server, user configuration should bind to implementation, ShadowCipher just save the main key
Keys() [][]byte
Key() []byte // return last key
FirstKey() []byte // return first key
}
type TCPClient ¶
type TCPClient struct {
// contains filtered or unexported fields
}
func NewTCPClient ¶
func NewTCPClient(config ClientConfig) TCPClient
type TCPConfig ¶
type TCPConfig struct {
Users []UserConfig
}
configurartions for shadowsocks TCP connections
type TCPServer ¶
type TCPServer struct {
// contains filtered or unexported fields
}
func NewTCPServer ¶
func NewTCPServer(config ServerConfig) TCPServer
func (*TCPServer) WrapConn ¶
This is a block function When some errors lead to unexpected closing of conn, the caller MUST act in a way that does not exhibit the amount of bytes consumed by the server. This defends against probes that send one byte at a time to detect how many bytes the server consumes before closing the connection.
type UDPClient ¶
type UDPClient struct {
// contains filtered or unexported fields
}
Clients create UDP relay sessions based on source address and port. When a client receives a packet from a new source address and port, it opens a new relay session, and subsequent packets from that source are sent over the same session.
func NewUDPClient ¶
func NewUDPClient(config ClientConfig, timeout int) UDPClient
type UDPConfig ¶
type UDPConfig struct {
Users []UserConfig
}
type UDPConnCipher ¶
type UDPConnCipher interface {
NewUDPSessionManager(timeout time.Duration, config UDPConfig, windowSize, role int) UDPSessionManager
}
type UDPServer ¶
type UDPServer struct {
// contains filtered or unexported fields
}
Servers manage UDP relay sessions by session ID. Each client session corresponds to one outgoing UDP socket on the server.
func NewUDPServer ¶
func NewUDPServer(config ServerConfig, timeout time.Duration) UDPServer
type UDPSession ¶
type UDPSession interface {
// Target returns the destination address for this session
Target() socks.Addr
ClientAddr() netip.AddrPort
// LastUsed returns when this session was last used
LastUsed() time.Time
// update LastUsed
Touch()
SessionID() uint64
// unique id for identifying session
Hash() SessionHash
}
UDPSession represents a single UDP relay session. This is used by protocol-specific managers internally.
type UDPSessionManager ¶
type UDPSessionManager interface {
// This function should complete following things:
// 1. Decrypt data and send to target
// 2. Validate session
ServerHandleInbound(encrypted []byte, clientAddr netip.AddrPort) (UDPSession, []byte, error)
// This function should return data from target, so it's maybe a block function.
ServerHandleOutbound(plaintext []byte, session UDPSession) ([]byte, error)
ClientHandleInbound(payload []byte, target socks.Addr, clientAddr netip.AddrPort) (UDPSession, []byte, error)
// This function should return data from target, so it's maybe a block function.
ClientHandleOutbound(encrypted []byte, session UDPSession) ([]byte, error)
}
UDPSessionManager is the interface that abstracts session management for different Shadowsocks protocols (AEAD vs SIP022). For server, the dataflow is: client encrypted data -> ServerHandleReceive -> target and plaintext -> target server target server -> plaintext -> ServerHandleOutbound -> encrypted data -> client For Client, the dataflow is: app -> plaintext -> ServerHandleReceive -> encrypted -> ss server ss server -> encrypted data -> ServerHandleOutbound -> plaintext -> app
type UserConfig ¶
func NewUserConfig ¶
func NewUserConfig(name, password string) UserConfig