vmess

package module
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: GPL-2.0 Imports: 35 Imported by: 0

README

sing-vmess

Some confusing protocol.

Features

100% compatible with v2ray-core.

  • Stream length chunk with padding and masking
  • AEAD length chunk with padding
  • Stream chunk
  • AEAD chunk
  • Legacy client
  • AEAD client
  • Legacy server
  • AEAD server

Extra features:

  • Mux server
  • XUDP client
  • VLESS client

Documentation

Index

Constants

View Source
const (
	Version              = 1
	ReadChunkSize        = 16384
	WriteChunkSize       = 15000
	CacheDurationSeconds = 120
	MaxPaddingSize       = 64
	MaxFrontHeadroom     = 2 + CipherOverhead
	MaxRearHeadroom      = CipherOverhead*2 + MaxPaddingSize
)
View Source
const (
	SecurityTypeLegacy           = 1
	SecurityTypeAuto             = 2
	SecurityTypeAes128Gcm        = 3
	SecurityTypeChacha20Poly1305 = 4
	SecurityTypeNone             = 5
	SecurityTypeZero             = 6
)
View Source
const (
	CommandTCP = 1
	CommandUDP = 2
	CommandMux = 3
)
View Source
const (
	RequestOptionChunkStream         = 1
	RequestOptionConnectionReuse     = 2
	RequestOptionChunkMasking        = 4
	RequestOptionGlobalPadding       = 8
	RequestOptionAuthenticatedLength = 16
)
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 (
	StatusNew       = 1
	StatusKeep      = 2
	StatusEnd       = 3
	StatusKeepAlive = 4
	OptionData      = 1
	OptionError     = 2
	NetworkTCP      = 1
	NetworkUDP      = 2
)
View Source
const (
	CipherOverhead = 16
)

Variables

View Source
var (
	ErrUnsupportedSecurityType = E.New("vmess: unsupported security type")
	ErrInvalidChecksum         = E.New("vmess: invalid chunk checksum")
)
View Source
var (
	ErrBadHeader    = E.New("bad header")
	ErrBadTimestamp = E.New("bad timestamp")
	ErrReplay       = E.New("replayed request")
	ErrBadRequest   = E.New("bad request")
	ErrBadVersion   = E.New("bad version")
)
View Source
var ErrBadLengthChunk = E.New("bad length chunk")
View Source
var MuxDestination = M.Socksaddr{
	Fqdn: "v1.mux.cool",
	Port: 666,
}

Functions

func AlterId

func AlterId(user uuid.UUID) uuid.UUID

func AuthID

func AuthID(key [16]byte, time time.Time, buffer *buf.Buffer)

func AutoSecurityType

func AutoSecurityType() byte

func CreateReader

func CreateReader(upstream io.Reader, streamReader io.Reader, requestKey []byte, requestNonce []byte, key []byte, nonce []byte, security byte, option byte) io.Reader

func CreateWriter

func CreateWriter(upstream io.Writer, streamWriter io.Writer, requestKey []byte, requestNonce []byte, key []byte, nonce []byte, security byte, option byte) io.Writer

func GenerateChacha20Poly1305Key

func GenerateChacha20Poly1305Key(b []byte) []byte

func HandleMuxConnection

func HandleMuxConnection(ctx context.Context, conn net.Conn, handler Handler) error

func KDF

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

func Key

func Key(user uuid.UUID) (key [16]byte)

Types

type AEADChunkReader

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

func NewAEADChunkReader

func NewAEADChunkReader(upstream io.Reader, cipher cipher.AEAD, nonce []byte, globalPadding sha3.ShakeHash) *AEADChunkReader

func NewAes128GcmChunkReader

func NewAes128GcmChunkReader(upstream io.Reader, key []byte, nonce []byte, globalPadding sha3.ShakeHash) *AEADChunkReader

func NewChacha20Poly1305ChunkReader

func NewChacha20Poly1305ChunkReader(upstream io.Reader, key []byte, nonce []byte, globalPadding sha3.ShakeHash) *AEADChunkReader

func (*AEADChunkReader) Read

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

func (*AEADChunkReader) Upstream

func (r *AEADChunkReader) Upstream() any

type AEADChunkWriter

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

func NewAEADChunkWriter

func NewAEADChunkWriter(upstream io.Writer, cipher cipher.AEAD, nonce []byte, globalPadding sha3.ShakeHash) *AEADChunkWriter

func NewAes128GcmChunkWriter

func NewAes128GcmChunkWriter(upstream io.Writer, key []byte, nonce []byte, globalPadding sha3.ShakeHash) *AEADChunkWriter

func NewChacha20Poly1305ChunkWriter

func NewChacha20Poly1305ChunkWriter(upstream io.Writer, key []byte, nonce []byte, globalPadding sha3.ShakeHash) *AEADChunkWriter

func (*AEADChunkWriter) FrontHeadroom

func (w *AEADChunkWriter) FrontHeadroom() int

func (*AEADChunkWriter) RearHeadroom

func (w *AEADChunkWriter) RearHeadroom() int

func (*AEADChunkWriter) Upstream

func (w *AEADChunkWriter) Upstream() any

func (*AEADChunkWriter) Write

func (w *AEADChunkWriter) Write(p []byte) (n int, err error)

func (*AEADChunkWriter) WriteBuffer

func (w *AEADChunkWriter) WriteBuffer(buffer *buf.Buffer) error

type AEADReader

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

func NewAEADReader

func NewAEADReader(upstream io.Reader, cipher cipher.AEAD, nonce []byte) *AEADReader

func NewAes128GcmReader

func NewAes128GcmReader(upstream io.Reader, key []byte, nonce []byte) *AEADReader

func NewChacha20Poly1305Reader

func NewChacha20Poly1305Reader(upstream io.Reader, key []byte, nonce []byte) *AEADReader

func (*AEADReader) Read

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

func (*AEADReader) ReadBuffer

func (r *AEADReader) ReadBuffer(buffer *buf.Buffer) error

func (*AEADReader) Upstream

func (r *AEADReader) Upstream() any

type AEADWriter

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

func NewAEADWriter

func NewAEADWriter(upstream io.Writer, cipher cipher.AEAD, nonce []byte) *AEADWriter

func NewAes128GcmWriter

func NewAes128GcmWriter(upstream io.Writer, key []byte, nonce []byte) *AEADWriter

func NewChacha20Poly1305Writer

func NewChacha20Poly1305Writer(upstream io.Writer, key []byte, nonce []byte) *AEADWriter

func (*AEADWriter) RearHeadroom

func (w *AEADWriter) RearHeadroom() int

func (*AEADWriter) Upstream

func (w *AEADWriter) Upstream() any

func (*AEADWriter) Write

func (w *AEADWriter) Write(p []byte) (n int, err error)

func (*AEADWriter) WriteBuffer

func (w *AEADWriter) WriteBuffer(buffer *buf.Buffer) error

type Client

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

func NewClient

func NewClient(userId string, security string, alterId int, options ...ClientOption) (*Client, error)

func (*Client) DialConn

func (c *Client) DialConn(upstream net.Conn, destination M.Socksaddr) (N.ExtendedConn, error)

func (*Client) DialEarlyConn

func (c *Client) DialEarlyConn(upstream net.Conn, destination M.Socksaddr) N.ExtendedConn

func (*Client) DialEarlyPacketConn

func (c *Client) DialEarlyPacketConn(upstream net.Conn, destination M.Socksaddr) PacketConn

func (*Client) DialEarlyXUDPPacketConn

func (c *Client) DialEarlyXUDPPacketConn(upstream net.Conn, destination M.Socksaddr) PacketConn

func (*Client) DialPacketConn

func (c *Client) DialPacketConn(upstream net.Conn, destination M.Socksaddr) (PacketConn, error)

func (*Client) DialXUDPPacketConn

func (c *Client) DialXUDPPacketConn(upstream net.Conn, destination M.Socksaddr) (PacketConn, error)

type ClientOption

type ClientOption func(*Client)

func ClientWithAuthenticatedLength

func ClientWithAuthenticatedLength() ClientOption

func ClientWithGlobalPadding

func ClientWithGlobalPadding() ClientOption

func ClientWithTimeFunc

func ClientWithTimeFunc(timeFunc TimeFunc) ClientOption

type Handler

type Handler interface {
	N.TCPConnectionHandler
	N.UDPConnectionHandler
	E.Handler
}

type MuxConnWrapper

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

func NewMuxConnWrapper

func NewMuxConnWrapper(conn net.Conn, destination M.Socksaddr) *MuxConnWrapper

func (*MuxConnWrapper) FrontHeadroom

func (c *MuxConnWrapper) FrontHeadroom() int

func (*MuxConnWrapper) Read

func (c *MuxConnWrapper) Read(p []byte) (n int, err error)

func (*MuxConnWrapper) ReadBuffer

func (c *MuxConnWrapper) ReadBuffer(buffer *buf.Buffer) error

func (*MuxConnWrapper) Upstream

func (c *MuxConnWrapper) Upstream() any

func (*MuxConnWrapper) Write

func (c *MuxConnWrapper) Write(p []byte) (n int, err error)

func (*MuxConnWrapper) WriteBuffer

func (c *MuxConnWrapper) WriteBuffer(buffer *buf.Buffer) error

type PacketConn

type PacketConn interface {
	net.Conn
	N.NetPacketConn
}

type Service

type Service[U comparable] struct {
	// contains filtered or unexported fields
}

func NewService

func NewService[U comparable](handler Handler, options ...ServiceOption) *Service[U]

func (*Service[U]) Close

func (s *Service[U]) Close() error

func (*Service[U]) NewConnection

func (s *Service[U]) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error

func (*Service[U]) Start

func (s *Service[U]) Start() error

func (*Service[U]) UpdateUsers

func (s *Service[U]) UpdateUsers(userList []U, userIdList []string, alterIdList []int) error

type ServiceOption

type ServiceOption func(service *Service[string])

func ServiceWithDisableHeaderProtection

func ServiceWithDisableHeaderProtection() ServiceOption

func ServiceWithTimeFunc

func ServiceWithTimeFunc(timeFunc TimeFunc) ServiceOption

type StreamChecksumReader

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

func NewStreamChecksumReader

func NewStreamChecksumReader(reader io.Reader) *StreamChecksumReader

func (*StreamChecksumReader) Read

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

func (*StreamChecksumReader) ReadBuffer

func (r *StreamChecksumReader) ReadBuffer(buffer *buf.Buffer) error

func (*StreamChecksumReader) Upstream

func (r *StreamChecksumReader) Upstream() any

type StreamChecksumWriter

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

func NewStreamChecksumWriter

func NewStreamChecksumWriter(upstream *StreamChunkWriter) *StreamChecksumWriter

func (*StreamChecksumWriter) FrontHeadroom

func (w *StreamChecksumWriter) FrontHeadroom() int

func (*StreamChecksumWriter) Upstream

func (w *StreamChecksumWriter) Upstream() any

func (*StreamChecksumWriter) Write

func (w *StreamChecksumWriter) Write(p []byte) (n int, err error)

func (*StreamChecksumWriter) WriteBuffer

func (w *StreamChecksumWriter) WriteBuffer(buffer *buf.Buffer) error

type StreamChunkReader

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

func NewStreamChunkReader

func NewStreamChunkReader(upstream io.Reader, chunkMasking sha3.ShakeHash, globalPadding sha3.ShakeHash) *StreamChunkReader

func (*StreamChunkReader) Read

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

func (*StreamChunkReader) Upstream

func (r *StreamChunkReader) Upstream() any

type StreamChunkWriter

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

func NewStreamChunkWriter

func NewStreamChunkWriter(upstream io.Writer, chunkMasking sha3.ShakeHash, globalPadding sha3.ShakeHash) *StreamChunkWriter

func (*StreamChunkWriter) FrontHeadroom

func (w *StreamChunkWriter) FrontHeadroom() int

func (*StreamChunkWriter) RearHeadroom

func (w *StreamChunkWriter) RearHeadroom() int

func (*StreamChunkWriter) Upstream

func (w *StreamChunkWriter) Upstream() any

func (*StreamChunkWriter) Write

func (w *StreamChunkWriter) Write(p []byte) (n int, err error)

func (*StreamChunkWriter) WriteBuffer

func (w *StreamChunkWriter) WriteBuffer(buffer *buf.Buffer) error

func (*StreamChunkWriter) WriteWithChecksum

func (w *StreamChunkWriter) WriteWithChecksum(checksum uint32, p []byte) (n int, err error)

type StreamReader

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

func NewStreamReader

func NewStreamReader(upstream io.Reader, key []byte, iv []byte) *StreamReader

func (*StreamReader) Read

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

func (*StreamReader) ReadBuffer

func (r *StreamReader) ReadBuffer(buffer *buf.Buffer) error

func (*StreamReader) Upstream

func (r *StreamReader) Upstream() any

type StreamWriter

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

func NewStreamWriter

func NewStreamWriter(upstream io.Writer, key []byte, iv []byte) *StreamWriter

func (*StreamWriter) Upstream

func (w *StreamWriter) Upstream() any

func (*StreamWriter) Write

func (w *StreamWriter) Write(p []byte) (n int, err error)

func (*StreamWriter) WriteBuffer

func (w *StreamWriter) WriteBuffer(buffer *buf.Buffer) error

type TimeFunc

type TimeFunc = func() time.Time

type XUDPConn

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

func NewXUDPConn

func NewXUDPConn(conn net.Conn, destination M.Socksaddr) *XUDPConn

func (*XUDPConn) FrontHeadroom

func (c *XUDPConn) FrontHeadroom() int

func (*XUDPConn) NeedAdditionalReadDeadline

func (c *XUDPConn) NeedAdditionalReadDeadline() bool

func (*XUDPConn) NeedHandshake

func (c *XUDPConn) NeedHandshake() bool

func (*XUDPConn) Read

func (c *XUDPConn) Read(p []byte) (n int, err error)

func (*XUDPConn) ReadFrom

func (c *XUDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

func (*XUDPConn) ReadPacket

func (c *XUDPConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error)

func (*XUDPConn) Upstream

func (c *XUDPConn) Upstream() any

func (*XUDPConn) Write

func (c *XUDPConn) Write(p []byte) (n int, err error)

func (*XUDPConn) WritePacket

func (c *XUDPConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error

func (*XUDPConn) WriteTo

func (c *XUDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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