shadowsocks

package
v0.0.0-...-dbd5d84 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MPL-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Package shadowsocks provides compatible functionality to Shadowsocks.

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

R.I.P Shadowsocks

Index

Constants

View Source
const (
	Version = 1
)

Variables

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",
	}
	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,
	}
)

Enum value maps for CipherType.

View Source
var File_proxy_shadowsocks_config_proto protoreflect.FileDescriptor

Functions

func DecodeUDPPacket

func DecodeUDPPacket(validator *Validator, payload *buf.Buffer) (*protocol.RequestHeader, *buf.Buffer, error)

func DrainConnN

func DrainConnN(reader io.Reader, n int) error

func EncodeUDPPacket

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

func ReadTCPResponse

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

func ReadTCPSession

func ReadTCPSession(validator *Validator, 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,proto3" json:"password,omitempty"`
	CipherType CipherType `` /* 131-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Account) AsAccount

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

AsAccount implements protocol.AsAccount.

func (*Account) Descriptor deprecated

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

Deprecated: Use Account.ProtoReflect.Descriptor instead.

func (*Account) GetCipherType

func (x *Account) GetCipherType() CipherType

func (*Account) GetPassword

func (x *Account) GetPassword() string

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) ProtoReflect

func (x *Account) ProtoReflect() protoreflect.Message

func (*Account) Reset

func (x *Account) Reset()

func (*Account) String

func (x *Account) 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 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 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) Descriptor

func (CipherType) Descriptor() protoreflect.EnumDescriptor

func (CipherType) Enum

func (x CipherType) Enum() *CipherType

func (CipherType) EnumDescriptor deprecated

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

Deprecated: Use CipherType.Descriptor instead.

func (CipherType) Number

func (x CipherType) Number() protoreflect.EnumNumber

func (CipherType) String

func (x CipherType) String() string

func (CipherType) Type

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 *transport.Link, dialer internet.Dialer) error

Process implements OutboundHandler.Process().

type ClientConfig

type ClientConfig struct {
	Server []*protocol.ServerEndpoint `protobuf:"bytes,1,rep,name=server,proto3" json:"server,omitempty"`
	// contains filtered or unexported fields
}

func (*ClientConfig) Descriptor deprecated

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

Deprecated: Use ClientConfig.ProtoReflect.Descriptor instead.

func (*ClientConfig) GetServer

func (x *ClientConfig) GetServer() []*protocol.ServerEndpoint

func (*ClientConfig) ProtoMessage

func (*ClientConfig) ProtoMessage()

func (*ClientConfig) ProtoReflect

func (x *ClientConfig) ProtoReflect() protoreflect.Message

func (*ClientConfig) Reset

func (x *ClientConfig) Reset()

func (*ClientConfig) String

func (x *ClientConfig) String() string

type FullReader

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

func (*FullReader) Read

func (r *FullReader) Read(p []byte) (n int, err error)

type MemoryAccount

type MemoryAccount struct {
	Cipher Cipher
	Key    []byte
}

MemoryAccount is an account type converted from Account.

func (*MemoryAccount) Equals

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

Equals implements protocol.Account.Equals().

func (*MemoryAccount) GetCipherName

func (a *MemoryAccount) GetCipherName() string

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

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

func NewServer

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

NewServer create a new Shadowsocks server.

func (*Server) AddUser

func (s *Server) AddUser(ctx context.Context, u *protocol.MemoryUser) error

AddUser implements proxy.UserManager.AddUser().

func (*Server) Network

func (s *Server) Network() []net.Network

func (*Server) Process

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

func (*Server) RemoveUser

func (s *Server) RemoveUser(ctx context.Context, e string) error

RemoveUser implements proxy.UserManager.RemoveUser().

type ServerConfig

type ServerConfig struct {
	Users   []*protocol.User `protobuf:"bytes,1,rep,name=users,proto3" json:"users,omitempty"`
	Network []net.Network    `protobuf:"varint,2,rep,packed,name=network,proto3,enum=xray.common.net.Network" json:"network,omitempty"`
	// contains filtered or unexported fields
}

func (*ServerConfig) Descriptor deprecated

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

Deprecated: Use ServerConfig.ProtoReflect.Descriptor instead.

func (*ServerConfig) GetNetwork

func (x *ServerConfig) GetNetwork() []net.Network

func (*ServerConfig) GetUsers

func (x *ServerConfig) GetUsers() []*protocol.User

func (*ServerConfig) ProtoMessage

func (*ServerConfig) ProtoMessage()

func (*ServerConfig) ProtoReflect

func (x *ServerConfig) ProtoReflect() protoreflect.Message

func (*ServerConfig) Reset

func (x *ServerConfig) Reset()

func (*ServerConfig) String

func (x *ServerConfig) String() string

type UDPReader

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

func (*UDPReader) ReadMultiBuffer

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

type UDPWriter

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

func (*UDPWriter) WriteMultiBuffer

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

type Validator

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

Validator stores valid Shadowsocks users.

func (*Validator) Add

func (v *Validator) Add(u *protocol.MemoryUser) error

Add a Shadowsocks user, Email must be empty or unique.

func (*Validator) Count

func (v *Validator) Count() int

Count the number of Shadowsocks users

func (*Validator) Del

func (v *Validator) Del(e string) error

Del a Shadowsocks user with a non-empty Email.

func (*Validator) Get

func (v *Validator) Get(bs []byte, command protocol.RequestCommand) (u *protocol.MemoryUser, aead cipher.AEAD, ret []byte, ivLen int32, err error)

Get a Shadowsocks user and the user's cipher.

func (*Validator) GetOnlyUser

func (v *Validator) GetOnlyUser() (u *protocol.MemoryUser, ivLen int32)

Get the only user without authentication

Jump to

Keyboard shortcuts

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