cipherstream

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxPayloadSize is the maximum size of payload, set to 16KB.
	MaxPayloadSize     = 1<<14 - 1
	MaxCipherRelaySize = MaxPayloadSize + MaxPayloadSize/2
)
View Source
const (
	MethodAes256GCM        = "aes-256-gcm"
	MethodChaCha20Poly1305 = "chacha20-poly1305"
)
View Source
const (
	Http2HeaderLen = 9
	PaddingSize    = 64
	MaxPaddingSize = 255
	MinPaddingSize = 64
)
View Source
const (
	FlagTCP uint8 = 1 << iota
	FlagUDP
	FlagICMP
	FlagPad
	FlagNeedACK
	FlagFIN
	FlagACK
	FlagDNS
)
View Source
const FlagDefault uint8 = 0

Variables

View Source
var (
	ErrFINRSTStream = errors.New("receive FIN_RST_STREAM frame")
	ErrACKRSTStream = errors.New("receive ACK_RST_STREAM frame")
	ErrTimeout      = errors.New("net: io timeout error")
	ErrPayloadSize  = errors.New("payload size is invalid")
	ErrPingHook     = errors.New("ping hook error")
)

Functions

func New

func New(stream net.Conn, password, method string, frameType FrameType, flags ...uint8) (net.Conn, error)

Types

type AEADCipher

type AEADCipher interface {
	Encrypt(plaintext []byte) (ciphertext []byte, err error)
	Decrypt(ciphertext []byte) (plaintext []byte, err error)
	NonceSize() int
	Overhead() int
}

func NewAes256GCM

func NewAes256GCM(password []byte) (AEADCipher, error)

NewAes256GCM creates a aes-gcm AEAD instance

func NewChaCha20Poly1305

func NewChaCha20Poly1305(password []byte) (AEADCipher, error)

NewChaCha20Poly1305 creates a chacha20-poly1305 AEAD instance

type AEADCipherImpl

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

func (*AEADCipherImpl) Decrypt

func (aci *AEADCipherImpl) Decrypt(ciphertext []byte) (plaintext []byte, err error)

Decrypt decrypts data using 256-bit AEAD. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation.

func (*AEADCipherImpl) Encrypt

func (aci *AEADCipherImpl) Encrypt(plaintext []byte) (ciphertext []byte, err error)

Encrypt encrypts data using 256-bit AEAD. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation.

func (*AEADCipherImpl) NonceSize

func (aci *AEADCipherImpl) NonceSize() int

NonceSize return underlying aead nonce size

func (*AEADCipherImpl) Overhead

func (aci *AEADCipherImpl) Overhead() int

Overhead return underlying aead overhead size

type CipherStream

type CipherStream struct {
	net.Conn
	AEADCipher
	// contains filtered or unexported fields
}

func (*CipherStream) Close added in v2.3.0

func (cs *CipherStream) Close() error

func (*CipherStream) CloseWrite added in v2.1.0

func (cs *CipherStream) CloseWrite() error

func (*CipherStream) MarkConnUnusable added in v2.4.1

func (cs *CipherStream) MarkConnUnusable() bool

func (*CipherStream) Read

func (cs *CipherStream) Read(b []byte) (int, error)

func (*CipherStream) ReadFrame added in v2.3.0

func (cs *CipherStream) ReadFrame() (*Frame, error)

func (*CipherStream) ReadFrom

func (cs *CipherStream) ReadFrom(r io.Reader) (n int64, err error)

func (*CipherStream) Release

func (cs *CipherStream) Release()

func (*CipherStream) Write

func (cs *CipherStream) Write(b []byte) (int, error)

func (*CipherStream) WriteFrame added in v2.3.0

func (cs *CipherStream) WriteFrame(f *Frame) error

func (*CipherStream) WritePing

func (cs *CipherStream) WritePing(b []byte, flag uint8) error

func (*CipherStream) WriteRST

func (cs *CipherStream) WriteRST(flag uint8) error

type Frame added in v2.3.0

type Frame struct {
	*Header
	*Payload
	// contains filtered or unexported fields
}

func NewFrame added in v2.3.0

func NewFrame(ft FrameType, payload []byte, flag uint8, cipher AEADCipher) *Frame

func (*Frame) EncodeWithCipher added in v2.3.0

func (f *Frame) EncodeWithCipher(buf []byte) ([]byte, error)

func (*Frame) Release added in v2.3.0

func (f *Frame) Release()

type FrameIter added in v2.3.0

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

func NewFrameIter added in v2.3.0

func NewFrameIter(r io.Reader, cipher AEADCipher) *FrameIter

func (*FrameIter) Error added in v2.3.0

func (fi *FrameIter) Error() error

func (*FrameIter) Next added in v2.3.0

func (fi *FrameIter) Next() *Frame

func (*FrameIter) Release added in v2.3.0

func (fi *FrameIter) Release()

type FrameType added in v2.3.0

type FrameType uint8
const (
	FrameTypeData    FrameType = 0x0
	FrameTypeRST     FrameType = 0x3
	FrameTypePing    FrameType = 0x6
	FrameTypeUnknown FrameType = 0xff
)

func ParseFrameTypeFrom added in v2.3.0

func ParseFrameTypeFrom(i uint8) FrameType

func (FrameType) String added in v2.3.0

func (ft FrameType) String() string

func (FrameType) ToUint8 added in v2.3.0

func (ft FrameType) ToUint8() uint8
type Header struct {
	// contains filtered or unexported fields
}

func (*Header) FrameType added in v2.3.0

func (h *Header) FrameType() FrameType

func (*Header) HasPad added in v2.3.0

func (h *Header) HasPad() bool

HasPad returns true if http2 header frame has pad field, panic if header's length not equals Http2HeaderLen

func (*Header) IsDNSProto added in v2.4.0

func (h *Header) IsDNSProto() bool

func (*Header) IsDataFrame added in v2.3.0

func (h *Header) IsDataFrame() bool

func (*Header) IsNeedACK added in v2.3.0

func (h *Header) IsNeedACK() bool

func (*Header) IsPingFrame added in v2.3.0

func (h *Header) IsPingFrame() bool

func (*Header) IsRSTACKFrame added in v2.3.0

func (h *Header) IsRSTACKFrame() bool

func (*Header) IsRSTFINFrame added in v2.3.0

func (h *Header) IsRSTFINFrame() bool

func (*Header) IsTCPProto added in v2.3.0

func (h *Header) IsTCPProto() bool

func (*Header) IsUDPProto added in v2.3.0

func (h *Header) IsUDPProto() bool

func (*Header) PayloadLen added in v2.3.0

func (h *Header) PayloadLen() int

PayloadLen returns payload length in http2 header frame, panic if header's length not equals Http2HeaderLen

type Payload added in v2.3.0

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

func (*Payload) FramePayload added in v2.3.0

func (p *Payload) FramePayload() []byte

func (*Payload) Pad added in v2.3.0

func (p *Payload) Pad() []byte

func (*Payload) PadSize added in v2.3.0

func (p *Payload) PadSize() byte

func (*Payload) RawDataPayload added in v2.3.0

func (p *Payload) RawDataPayload() []byte

Jump to

Keyboard shortcuts

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