vmess

package
v0.0.0-...-5f1f6bc Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KDFSaltConstAuthIDEncryptionKey             = "AES Auth ID Encryption"
	KDFSaltConstAEADRespHeaderLenKey            = "AEAD Resp Header Len Key"
	KDFSaltConstAEADRespHeaderLenIV             = "AEAD Resp Header Len IV"
	KDFSaltConstAEADRespHeaderPayloadKey        = "AEAD Resp Header Key"
	KDFSaltConstAEADRespHeaderPayloadIV         = "AEAD Resp Header IV"
	KDFSaltConstVMessAEADKDF                    = "VMess AEAD KDF"
	KDFSaltConstVMessHeaderPayloadAEADKey       = "VMess Header AEAD Key"
	KDFSaltConstVMessHeaderPayloadAEADIV        = "VMess Header AEAD Nonce"
	KDFSaltConstVMessHeaderPayloadLengthAEADKey = "VMess Header AEAD Key_Length"
	KDFSaltConstVMessHeaderPayloadLengthAEADIV  = "VMess Header AEAD Nonce_Length"
)
View Source
const (
	OptionChunkStream        = 1
	OptionChunkLengthMasking = 4
	OptionGlobalPadding      = 8
)
View Source
const (
	MaxChunkSize = 1 << 14
	MaxUDPSize   = 1 << 11
)
View Source
const (
	IDBytesLen = 16
)
View Source
const SeqPacketMagicAddress = "sp.packet-addr.v2fly.arpa"

Variables

View Source
var (
	ErrInvalidMetadata = fmt.Errorf("invalid metadata")
)
View Source
var (
	NewCipherMapper = map[Cipher]func(key []byte) (cipher.AEAD, error){
		CipherC20P1305:  NewC20P1305,
		CipherAES128GCM: NewAesGcm,
	}
)

Functions

func AuthEAuthID

func AuthEAuthID(blk cipher.Block, eAuthID []byte, doubleCuckoo *ReplayFilter, startTimestamp int64) error

func ContainOption

func ContainOption(options byte, option byte) bool

func DefaultIDHash

func DefaultIDHash(key []byte) hash.Hash

func EncryptReqHeaderFromPool

func EncryptReqHeaderFromPool(instruction []byte, cmdKey []byte) ([]byte, error)

func ExtractPacketAddr

func ExtractPacketAddr(src []byte) (protocol.MetadataType, netip.AddrPort, error)

func GenerateChacha20Poly1305KeyFromPool

func GenerateChacha20Poly1305KeyFromPool(b []byte) []byte

GenerateChacha20Poly1305Key generates a 32-byte key from a given 16-byte array.

func KDF

func KDF(key []byte, path ...[]byte) []byte

func MetadataTypeToByte

func MetadataTypeToByte(typ protocol.MetadataType) byte

func NetworkToByte

func NetworkToByte(network string) byte

func NewAesGcm

func NewAesGcm(key []byte) (cipher.AEAD, error)

func NewC20P1305

func NewC20P1305(key []byte) (cipher.AEAD, error)

func NewDialer

func NewDialer(nextDialer netproxy.Dialer, header protocol.Header) (netproxy.Dialer, error)

func NewDialerFactory

func NewDialerFactory(proto protocol.Protocol) func(nextDialer netproxy.Dialer, header protocol.Header) (netproxy.Dialer, error)

func PacketAddrLength

func PacketAddrLength(typ protocol.MetadataType) int

func ParseMetadataType

func ParseMetadataType(t byte) protocol.MetadataType

func ParseNetwork

func ParseNetwork(n byte) string

func ParsePacketAddrType

func ParsePacketAddrType(t byte) protocol.MetadataType

func PutEAuthID

func PutEAuthID(dst []byte, cmdKey []byte) []byte

func PutPacketAddr

func PutPacketAddr(src []byte, addr *net.UDPAddr) error

func ReqInstructionDataFromPool

func ReqInstructionDataFromPool(metadata Metadata) []byte

func RespHeaderFromPool

func RespHeaderFromPool(V byte) []byte

func UDPAddrToPacketAddrLength

func UDPAddrToPacketAddrLength(addr *net.UDPAddr) int

Types

type BytesGenerator

type BytesGenerator func() []byte

func GenerateChunkNonce

func GenerateChunkNonce(nonce []byte, size uint32) BytesGenerator

type ChunkSizeDecoder

type ChunkSizeDecoder interface {
	SizeBytes() int32
	Decode([]byte) (uint16, error)
}

ChunkSizeDecoder is a utility class to decode size value from bytes.

type ChunkSizeEncoder

type ChunkSizeEncoder interface {
	SizeBytes() int32
	Encode(uint16, []byte) []byte
}

ChunkSizeEncoder is a utility class to encode size value into bytes.

type Cipher

type Cipher string
const (
	CipherC20P1305  Cipher = "chacha20-poly1305"
	CipherAES128GCM Cipher = "aes-128-gcm"
)

func ParseCipherFromSecurity

func ParseCipherFromSecurity(security byte) (Cipher, error)

func (Cipher) ToSecurity

func (c Cipher) ToSecurity() byte

type Conn

type Conn struct {
	netproxy.Conn

	NewAEAD func(key []byte) (cipher.AEAD, error)
	// contains filtered or unexported fields
}

func NewConn

func NewConn(conn netproxy.Conn, metadata Metadata, dialTgt string, cmdKey []byte) (c *Conn, err error)

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) EncryptRespHeaderFromPool

func (c *Conn) EncryptRespHeaderFromPool(header []byte) (b []byte, err error)

func (*Conn) InitContext

func (c *Conn) InitContext(instructionData []byte) error

func (*Conn) Metadata

func (c *Conn) Metadata() Metadata

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

func (*Conn) ReadFrom

func (c *Conn) ReadFrom(p []byte) (n int, addr netip.AddrPort, err error)

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

func (*Conn) WriteReqHeader

func (c *Conn) WriteReqHeader() (err error)

func (*Conn) WriteTo

func (c *Conn) WriteTo(p []byte, addr string) (n int, err error)

type Dialer

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

func (*Dialer) Dial

func (d *Dialer) Dial(network string, addr string) (c netproxy.Conn, err error)

func (*Dialer) DialTcp

func (d *Dialer) DialTcp(addr string) (c netproxy.Conn, err error)

func (*Dialer) DialUdp

func (d *Dialer) DialUdp(addr string) (c netproxy.PacketConn, err error)

type ID

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

The ID of en entity, in the form of a UUID.

func NewAlterIDs

func NewAlterIDs(primary *ID, alterIDCount uint16) []*ID

func NewID

func NewID(uuid uuid.UUID) *ID

NewID returns an ID with given UUID.

func (*ID) Bytes

func (id *ID) Bytes() []byte

func (*ID) CmdKey

func (id *ID) CmdKey() []byte

func (*ID) Equals

func (id *ID) Equals(another *ID) bool

Equals returns true if this ID equals to the other one.

func (*ID) String

func (id *ID) String() string

func (*ID) UUID

func (id *ID) UUID() uuid.UUID

type IDHash

type IDHash func(key []byte) hash.Hash

type Metadata

type Metadata struct {
	protocol.Metadata

	Network string
	// contains filtered or unexported fields
}

func NewServerMetadata

func NewServerMetadata(cmdKey, eAuthID []byte) *Metadata

func (*Metadata) AddrLen

func (m *Metadata) AddrLen() int

func (*Metadata) CompleteFromInstructionData

func (m *Metadata) CompleteFromInstructionData(instructionData []byte) (err error)

func (*Metadata) IsPacketAddr

func (m *Metadata) IsPacketAddr() bool

func (*Metadata) PutAddr

func (m *Metadata) PutAddr(dst []byte) (n int)

type PaddingLengthGenerator

type PaddingLengthGenerator interface {
	MaxPaddingLen() uint16
	NextPaddingLen() uint16
}

type PlainChunkSizeParser

type PlainChunkSizeParser struct{}

func (PlainChunkSizeParser) Decode

func (PlainChunkSizeParser) Decode(b []byte) (uint16, error)

func (PlainChunkSizeParser) Encode

func (PlainChunkSizeParser) Encode(size uint16, b []byte) []byte

func (PlainChunkSizeParser) SizeBytes

func (PlainChunkSizeParser) SizeBytes() int32

type PlainPaddingGenerator

type PlainPaddingGenerator struct {
	PaddingLengthGenerator
}

func (PlainPaddingGenerator) MaxPaddingLen

func (PlainPaddingGenerator) MaxPaddingLen() uint16

func (PlainPaddingGenerator) NextPaddingLen

func (PlainPaddingGenerator) NextPaddingLen() uint16

type ReplayFilter

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

ReplayFilter check for replay attacks.

func NewReplayFilter

func NewReplayFilter(interval int64) *ReplayFilter

NewReplayFilter create a new filter with specifying the expiration time interval in seconds.

func (*ReplayFilter) Check

func (filter *ReplayFilter) Check(sum []byte) bool

Check determine if there are duplicate records.

func (*ReplayFilter) Interval

func (filter *ReplayFilter) Interval() int64

Interval in second for expiration time for duplicate records.

type ShakeSizeParser

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

func NewShakeSizeParser

func NewShakeSizeParser(nonce []byte) *ShakeSizeParser

func (*ShakeSizeParser) Decode

func (s *ShakeSizeParser) Decode(b []byte) (uint16, error)

func (*ShakeSizeParser) Encode

func (s *ShakeSizeParser) Encode(size uint16, b []byte) []byte

func (*ShakeSizeParser) MaxPaddingLen

func (s *ShakeSizeParser) MaxPaddingLen() uint16

func (*ShakeSizeParser) NextPaddingLen

func (s *ShakeSizeParser) NextPaddingLen() uint16

func (*ShakeSizeParser) SizeBytes

func (*ShakeSizeParser) SizeBytes() int32

Jump to

Keyboard shortcuts

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