shadowsocks

package
v3.18.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2018 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package shadowsocks provides compatible functionality to Shadowsocks.

Shadowsocks client and server are implemented as outbound and inbound respectively in V2Ray's term.

Shadowsocks OTA is fully supported. By default both client and server enable OTA, but it can be optionally disabled.

Supperted Ciphers: * AES-256-CFB * AES-128-CFB * Chacha20 * Chacha20-IEFT

R.I.P Shadowsocks

Index

Constants

View Source
const (
	Version                               = 1
	RequestOptionOneTimeAuth bitmask.Byte = 0x01
)
View Source
const (
	// AuthSize is the number of extra bytes for Shadowsocks OTA.
	AuthSize = 10
)

Variables

View Source
var Account_OneTimeAuth_name = map[int32]string{
	0: "Auto",
	1: "Disabled",
	2: "Enabled",
}
View Source
var Account_OneTimeAuth_value = map[string]int32{
	"Auto":     0,
	"Disabled": 1,
	"Enabled":  2,
}
View Source
var CipherType_name = map[int32]string{
	0: "UNKNOWN",
	1: "AES_128_CFB",
	2: "AES_256_CFB",
	3: "CHACHA20",
	4: "CHACHA20_IETF",
	5: "AES_128_GCM",
	6: "AES_256_GCM",
	7: "CHACHA20_POLY1305",
	8: "NONE",
}
View Source
var CipherType_value = map[string]int32{
	"UNKNOWN":           0,
	"AES_128_CFB":       1,
	"AES_256_CFB":       2,
	"CHACHA20":          3,
	"CHACHA20_IETF":     4,
	"AES_128_GCM":       5,
	"AES_256_GCM":       6,
	"CHACHA20_POLY1305": 7,
	"NONE":              8,
}

Functions

func ChunkKeyGenerator

func ChunkKeyGenerator(iv []byte) func() []byte

func DecodeUDPPacket

func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.RequestHeader, *buf.Buffer, error)

func EncodeUDPPacket

func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buffer, error)

func HeaderKeyGenerator

func HeaderKeyGenerator(key []byte, iv []byte) func() []byte

func ReadTCPResponse

func ReadTCPResponse(user *protocol.User, reader io.Reader) (buf.Reader, error)

func ReadTCPSession

func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHeader, buf.Reader, error)

ReadTCPSession reads a Shadowsocks TCP session from the given reader, returns its header and remaining parts.

func WriteTCPRequest

func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Writer, error)

WriteTCPRequest writes Shadowsocks request into the given writer, and returns a writer for body.

func WriteTCPResponse

func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Writer, error)

Types

type AEADCipher

type AEADCipher struct {
	KeyBytes        int32
	IVBytes         int32
	AEADAuthCreator func(key []byte) cipher.AEAD
}

func (*AEADCipher) DecodePacket

func (c *AEADCipher) DecodePacket(key []byte, b *buf.Buffer) error

func (*AEADCipher) EncodePacket

func (c *AEADCipher) EncodePacket(key []byte, b *buf.Buffer) error

func (*AEADCipher) IVSize

func (c *AEADCipher) IVSize() int32

func (*AEADCipher) IsAEAD

func (*AEADCipher) IsAEAD() bool

func (*AEADCipher) KeySize

func (c *AEADCipher) KeySize() int32

func (*AEADCipher) NewDecryptionReader

func (c *AEADCipher) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)

func (*AEADCipher) NewEncryptionWriter

func (c *AEADCipher) NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)

type Account

type Account struct {
	Password   string              `protobuf:"bytes,1,opt,name=password" json:"password,omitempty"`
	CipherType CipherType          `` /* 130-byte string literal not displayed */
	Ota        Account_OneTimeAuth `protobuf:"varint,3,opt,name=ota,enum=v2ray.core.proxy.shadowsocks.Account_OneTimeAuth" json:"ota,omitempty"`
}

func (*Account) AsAccount

func (a *Account) AsAccount() (protocol.Account, error)

AsAccount implements protocol.AsAccount.

func (*Account) Descriptor

func (*Account) Descriptor() ([]byte, []int)

func (*Account) GetCipherType

func (m *Account) GetCipherType() CipherType

func (*Account) GetOta

func (m *Account) GetOta() Account_OneTimeAuth

func (*Account) GetPassword

func (m *Account) GetPassword() string

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) Reset

func (m *Account) Reset()

func (*Account) String

func (m *Account) String() string

type Account_OneTimeAuth

type Account_OneTimeAuth int32
const (
	Account_Auto     Account_OneTimeAuth = 0
	Account_Disabled Account_OneTimeAuth = 1
	Account_Enabled  Account_OneTimeAuth = 2
)

func (Account_OneTimeAuth) EnumDescriptor

func (Account_OneTimeAuth) EnumDescriptor() ([]byte, []int)

func (Account_OneTimeAuth) String

func (x Account_OneTimeAuth) String() string

type AesCfb

type AesCfb struct {
	KeyBytes int32
}

AesCfb represents all AES-CFB ciphers.

func (*AesCfb) DecodePacket

func (v *AesCfb) DecodePacket(key []byte, b *buf.Buffer) error

func (*AesCfb) EncodePacket

func (v *AesCfb) EncodePacket(key []byte, b *buf.Buffer) error

func (*AesCfb) IVSize

func (v *AesCfb) IVSize() int32

func (*AesCfb) IsAEAD

func (*AesCfb) IsAEAD() bool

func (*AesCfb) KeySize

func (v *AesCfb) KeySize() int32

func (*AesCfb) NewDecryptionReader

func (v *AesCfb) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)

func (*AesCfb) NewEncryptionWriter

func (v *AesCfb) NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(keygen KeyGenerator) *Authenticator

func (*Authenticator) Authenticate

func (v *Authenticator) Authenticate(data []byte) buf.Supplier

type ChaCha20

type ChaCha20 struct {
	IVBytes int32
}

func (*ChaCha20) DecodePacket

func (v *ChaCha20) DecodePacket(key []byte, b *buf.Buffer) error

func (*ChaCha20) EncodePacket

func (v *ChaCha20) EncodePacket(key []byte, b *buf.Buffer) error

func (*ChaCha20) IVSize

func (v *ChaCha20) IVSize() int32

func (*ChaCha20) IsAEAD

func (*ChaCha20) IsAEAD() bool

func (*ChaCha20) KeySize

func (v *ChaCha20) KeySize() int32

func (*ChaCha20) NewDecryptionReader

func (v *ChaCha20) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)

func (*ChaCha20) NewEncryptionWriter

func (v *ChaCha20) NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)

type ChunkReader

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

func NewChunkReader

func NewChunkReader(reader io.Reader, auth *Authenticator) *ChunkReader

func (*ChunkReader) ReadMultiBuffer

func (v *ChunkReader) ReadMultiBuffer() (buf.MultiBuffer, error)

type ChunkWriter

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

func NewChunkWriter

func NewChunkWriter(writer io.Writer, auth *Authenticator) *ChunkWriter

func (*ChunkWriter) WriteMultiBuffer

func (w *ChunkWriter) WriteMultiBuffer(mb buf.MultiBuffer) error

WriteMultiBuffer implements buf.Writer.

type Cipher

type Cipher interface {
	KeySize() int32
	IVSize() int32
	NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)
	NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)
	IsAEAD() bool
	EncodePacket(key []byte, b *buf.Buffer) error
	DecodePacket(key []byte, b *buf.Buffer) error
}

Cipher is an interface for all Shadowsocks ciphers.

type CipherType

type CipherType int32
const (
	CipherType_UNKNOWN           CipherType = 0
	CipherType_AES_128_CFB       CipherType = 1
	CipherType_AES_256_CFB       CipherType = 2
	CipherType_CHACHA20          CipherType = 3
	CipherType_CHACHA20_IETF     CipherType = 4
	CipherType_AES_128_GCM       CipherType = 5
	CipherType_AES_256_GCM       CipherType = 6
	CipherType_CHACHA20_POLY1305 CipherType = 7
	CipherType_NONE              CipherType = 8
)

func (CipherType) EnumDescriptor

func (CipherType) EnumDescriptor() ([]byte, []int)

func (CipherType) String

func (x CipherType) String() string

type Client

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

Client is a inbound handler for Shadowsocks protocol

func NewClient

func NewClient(ctx context.Context, config *ClientConfig) (*Client, error)

NewClient create a new Shadowsocks client.

func (*Client) Process

func (c *Client) Process(ctx context.Context, link *core.Link, dialer proxy.Dialer) error

Process implements OutboundHandler.Process().

type ClientConfig

type ClientConfig struct {
	Server []*v2ray_core_common_protocol1.ServerEndpoint `protobuf:"bytes,1,rep,name=server" json:"server,omitempty"`
}

func (*ClientConfig) Descriptor

func (*ClientConfig) Descriptor() ([]byte, []int)

func (*ClientConfig) GetServer

func (*ClientConfig) ProtoMessage

func (*ClientConfig) ProtoMessage()

func (*ClientConfig) Reset

func (m *ClientConfig) Reset()

func (*ClientConfig) String

func (m *ClientConfig) String() string

type KeyGenerator

type KeyGenerator func() []byte

type MemoryAccount

type MemoryAccount struct {
	Cipher      Cipher
	Key         []byte
	OneTimeAuth Account_OneTimeAuth
}

MemoryAccount is an account type converted from Account.

func (*MemoryAccount) Equals

func (a *MemoryAccount) Equals(another protocol.Account) bool

Equals implements protocol.Account.Equals().

type NoneCipher

type NoneCipher struct{}

func (NoneCipher) DecodePacket

func (NoneCipher) DecodePacket(key []byte, b *buf.Buffer) error

func (NoneCipher) EncodePacket

func (NoneCipher) EncodePacket(key []byte, b *buf.Buffer) error

func (NoneCipher) IVSize

func (NoneCipher) IVSize() int32

func (NoneCipher) IsAEAD

func (NoneCipher) IsAEAD() bool

func (NoneCipher) KeySize

func (NoneCipher) KeySize() int32

func (NoneCipher) NewDecryptionReader

func (NoneCipher) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)

func (NoneCipher) NewEncryptionWriter

func (NoneCipher) NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)

type Server added in v1.12.9

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

func NewServer added in v1.12.9

func NewServer(ctx context.Context, config *ServerConfig) (*Server, error)

NewServer create a new Shadowsocks server.

func (*Server) Network

func (s *Server) Network() net.NetworkList

func (*Server) Process

func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher core.Dispatcher) error

type ServerConfig

type ServerConfig struct {
	// UdpEnabled specified whether or not to enable UDP for Shadowsocks.
	// Deprecated. Use 'network' field.
	UdpEnabled bool                             `protobuf:"varint,1,opt,name=udp_enabled,json=udpEnabled" json:"udp_enabled,omitempty"`
	User       *v2ray_core_common_protocol.User `protobuf:"bytes,2,opt,name=user" json:"user,omitempty"`
	Network    []v2ray_core_common_net.Network  `protobuf:"varint,3,rep,packed,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
}

func (*ServerConfig) Descriptor

func (*ServerConfig) Descriptor() ([]byte, []int)

func (*ServerConfig) GetNetwork

func (m *ServerConfig) GetNetwork() []v2ray_core_common_net.Network

func (*ServerConfig) GetUdpEnabled

func (m *ServerConfig) GetUdpEnabled() bool

func (*ServerConfig) GetUser

func (*ServerConfig) ProtoMessage

func (*ServerConfig) ProtoMessage()

func (*ServerConfig) Reset

func (m *ServerConfig) Reset()

func (*ServerConfig) String

func (m *ServerConfig) String() string

type UDPReader

type UDPReader struct {
	Reader io.Reader
	User   *protocol.User
}

func (*UDPReader) ReadMultiBuffer

func (v *UDPReader) ReadMultiBuffer() (buf.MultiBuffer, error)

type UDPWriter

type UDPWriter struct {
	Writer  io.Writer
	Request *protocol.RequestHeader
}

func (*UDPWriter) Write

func (w *UDPWriter) Write(payload []byte) (int, error)

Write implements io.Writer.

Jump to

Keyboard shortcuts

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