shadowsocks

package
v0.0.0-...-72c0b7d Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TestCipher = "chacha20-ietf-poly1305"

TestCipher is a preferred cipher to use in testing.

Variables

View Source
var ErrShortPacket = errors.New("short packet")

ErrShortPacket is identical to shadowaead.ErrShortPacket

Functions

func DecryptOnce

func DecryptOnce(cipher *Cipher, salt []byte, plainText, cipherText []byte) ([]byte, error)

DecryptOnce will decrypt the cipherText using the cipher and salt, appending the output to plainText.

func MakeTestPayload

func MakeTestPayload(size int) []byte

MakeTestPayload returns a slice of `size` arbitrary bytes.

func MakeTestSecrets

func MakeTestSecrets(n int) []string

MakeTestSecrets returns a slice of `n` test passwords. Not secure!

func Pack

func Pack(dst, plaintext []byte, cipher *Cipher) ([]byte, error)

Pack encrypts a Shadowsocks-UDP packet and returns a slice containing the encrypted packet. dst must be big enough to hold the encrypted packet. If plaintext and dst overlap but are not aligned for in-place encryption, this function will panic.

func SupportedCipherNames

func SupportedCipherNames() []string

SupportedCipherNames lists the names of the AEAD ciphers that are supported.

func Unpack

func Unpack(dst, pkt []byte, cipher *Cipher) ([]byte, error)

Unpack decrypts a Shadowsocks-UDP packet and returns a slice containing the decrypted payload or an error. If dst is present, it is used to store the plaintext, and must have enough capacity. If dst is nil, decryption proceeds in-place. This function is needed because shadowaead.Unpack() embeds its own replay detection, which we do not always want, especially on memory-constrained clients.

Types

type ChunkReader

type ChunkReader interface {
	// ReadChunk reads the next chunk and returns its payload.  The caller must
	// complete its use of the returned buffer before the next call.
	// The buffer is nil iff there is an error.  io.EOF indicates a close.
	ReadChunk() ([]byte, error)
}

ChunkReader is similar to io.Reader, except that it controls its own buffer granularity.

type Cipher

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

Cipher encapsulates a Shadowsocks AEAD spec and a secret

func NewCipher

func NewCipher(cipherName string, secretText string) (*Cipher, error)

NewCipher creates a Cipher given a cipher name and a secret

func (*Cipher) NewAEAD

func (c *Cipher) NewAEAD(salt []byte) (cipher.AEAD, error)

NewAEAD creates the AEAD for this cipher

func (*Cipher) SaltSize

func (c *Cipher) SaltSize() int

SaltSize is the size of the salt for this Cipher

func (*Cipher) TagSize

func (c *Cipher) TagSize() int

TagSize is the size of the AEAD tag for this Cipher

type Reader

type Reader interface {
	io.Reader
	io.WriterTo
}

Reader is an io.Reader that also implements io.WriterTo to allow for piping the data without extra allocations and copies.

func NewShadowsocksReader

func NewShadowsocksReader(reader io.Reader, ssCipher *Cipher) Reader

NewShadowsocksReader creates a Reader that decrypts the given Reader using the shadowsocks protocol with the given shadowsocks cipher.

type SaltGenerator

type SaltGenerator interface {
	// Returns a new salt
	GetSalt(salt []byte) error
}

SaltGenerator generates unique salts to use in Shadowsocks connections.

var RandomSaltGenerator SaltGenerator = randomSaltGenerator{}

RandomSaltGenerator is a basic SaltGenerator.

type Writer

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

Writer is an io.Writer that also implements io.ReaderFrom to allow for piping the data without extra allocations and copies. The LazyWrite and Flush methods allow a header to be added but delayed until the first write, for concatenation. All methods except Flush must be called from a single thread.

func NewShadowsocksWriter

func NewShadowsocksWriter(writer io.Writer, ssCipher *Cipher) *Writer

NewShadowsocksWriter creates a Writer that encrypts the given Writer using the shadowsocks protocol with the given shadowsocks cipher.

func (*Writer) Flush

func (sw *Writer) Flush() error

Flush sends the pending data, if any. This method is thread-safe.

func (*Writer) LazyWrite

func (sw *Writer) LazyWrite(p []byte) (int, error)

LazyWrite queues p to be written, but doesn't send it until Flush() is called, a non-lazy write is made, or the buffer is filled.

func (*Writer) ReadFrom

func (sw *Writer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements the io.ReaderFrom interface.

func (*Writer) SetSaltGenerator

func (sw *Writer) SetSaltGenerator(saltGenerator SaltGenerator)

SetSaltGenerator sets the salt generator to be used. Must be called before the first write.

func (*Writer) Write

func (sw *Writer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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