vmess

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package vmess implements vmess for proxy.Client and proxy.Server.

from github.com/Dreamacro/clash/tree/master/transport/vmess/

本作不支持alterid!=0 的情况. 即 仅支持 使用 aead 方式 进行认证. 即不支持 "MD5 认证信息"

标准: https://www.v2fly.org/developer/protocols/vmess.html

aead:

https://github.com/v2fly/v2fly-github-io/issues/20

Implementation Details

vmess 协议是一个很老旧的协议,有很多向前兼容的代码,很多地方都已经废弃了. 我们这里只支持最新的aead.

我们所实现的vmess 服务端 力求简单、最新,不求兼容所有老旧客户端。

Share URL

v2fly只有一个草案 https://github.com/v2fly/v2fly-github-io/issues/26

似乎v2fly社区对于这个URL标准的制定并不注重,而且看起来这个草案也不太美观

而xray社区的则美观得多,见 https://github.com/XTLS/Xray-core/discussions/716

Index

Constants

View Source
const (
	OptBasicFormat byte = 0 // 基本格式
	OptChunkStream byte = 1 // 标准格式,实际的请求数据被分割为若干个小块

	OptChunkMasking byte = 4

	OptGlobalPadding byte = 0x08
)

Request Options

View Source
const (
	SecurityAES128GCM        byte = 3
	SecurityChacha20Poly1305 byte = 4
	SecurityNone             byte = 5
)

Security types

View Source
const (
	CmdTCP byte = 1
	CmdUDP byte = 2

	CMDMux_VS byte = 4 //新定义的值,用于使用我们vs的mux方式
)

v2ray CMD types

View Source
const Name = "vmess"
View Source
const Security_confStr string = "vmess_security"

Variables

View Source
var ErrAuthID_timeBeyondGap = utils.ErrInErr{ErrDesc: fmt.Sprintf("vmess: time gap more than %d second", authID_timeMaxSecondGap), ErrDetail: utils.ErrInvalidData}
View Source
var ErrReplayAttack = errors.New("vmess: we are under replay attack! ")
View Source
var ErrReplaySessionAttack = utils.ErrInErr{ErrDesc: "vmess: duplicated session id, we are under replay attack! ", ErrDetail: ErrReplayAttack}

Functions

func AEADReader

func AEADReader(r io.Reader, aead cipher.AEAD, iv []byte, shakeParser *ShakeSizeParser) io.Reader

func AEADWriter

func AEADWriter(w io.Writer, aead cipher.AEAD, iv []byte, shakeParser *ShakeSizeParser) io.Writer

func ChunkedReader

func ChunkedReader(r io.Reader) io.Reader

ChunkedReader returns a chunked reader

func ChunkedWriter

func ChunkedWriter(w io.Writer) io.Writer

ChunkedWriter returns a chunked writer

func GetEncryptAlgo added in v1.2.4

func GetEncryptAlgo(dc *proxy.DialConf) (result string)

func GetKey

func GetKey(uuid [16]byte) []byte

GetKey returns the key of AES-128-CFB encrypter Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))

func TimestampHash

func TimestampHash(unixSec int64) []byte

TimestampHash returns the iv of AES-128-CFB encrypter IV:MD5(X + X + X + X),X = []byte(timestamp.now) (8 bytes, Big Endian)

Types

type Client

type Client struct {
	proxy.Base
	utils.V2rayUser
	// contains filtered or unexported fields
}

func (*Client) EstablishUDPChannel

func (c *Client) EstablishUDPChannel(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (netLayer.MsgConn, error)

func (*Client) GetCreator added in v1.2.4

func (*Client) GetCreator() proxy.ClientCreator

func (*Client) Handshake

func (c *Client) Handshake(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (io.ReadWriteCloser, error)

func (*Client) HasInnerMux added in v1.2.5

func (c *Client) HasInnerMux() (int, string)

func (*Client) Name

func (c *Client) Name() string

type ClientConn

type ClientConn struct {
	net.Conn

	utils.V2rayUser

	RM sync.Mutex //用于mux,因为可能同一时间多个写入发生
	WM sync.Mutex
	// contains filtered or unexported fields
}

ClientConn is a connection to vmess server

func (*ClientConn) CloseConnWithRaddr

func (c *ClientConn) CloseConnWithRaddr(_ netLayer.Addr) error

func (*ClientConn) Fullcone

func (c *ClientConn) Fullcone() bool

return false; vmess 标准 是不支持 fullcone的,和vless v0相同

func (*ClientConn) Read

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

func (*ClientConn) ReadMsg added in v1.2.5

func (c *ClientConn) ReadMsg() (bs []byte, target netLayer.Addr, err error)

func (*ClientConn) Write

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

func (*ClientConn) WriteMsg added in v1.2.5

func (c *ClientConn) WriteMsg(b []byte, _ netLayer.Addr) error

type ClientCreator

type ClientCreator struct{ proxy.CreatorCommonStruct }

func (ClientCreator) NewClient

func (ClientCreator) NewClient(dc *proxy.DialConf) (proxy.Client, error)

func (ClientCreator) URLToDialConf added in v1.2.4

func (ClientCreator) URLToDialConf(url *url.URL, dc *proxy.DialConf, format int) (*proxy.DialConf, error)

type PaddingLengthGenerator

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

type Server

type Server struct {
	proxy.Base

	*utils.MultiUserMap
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) Handshake

func (s *Server) Handshake(underlay net.Conn) (tcpConn net.Conn, msgConn netLayer.MsgConn, targetAddr netLayer.Addr, returnErr error)

func (*Server) HasInnerMux added in v1.2.5

func (*Server) HasInnerMux() (int, string)

func (*Server) Name

func (s *Server) Name() string

func (*Server) Stop

func (s *Server) Stop()

type ServerConn

type ServerConn struct {
	net.Conn

	utils.V2rayUser
	// contains filtered or unexported fields
}

func (*ServerConn) CloseConnWithRaddr

func (c *ServerConn) CloseConnWithRaddr(_ netLayer.Addr) error

func (*ServerConn) Fullcone

func (c *ServerConn) Fullcone() bool

func (*ServerConn) IsMux added in v1.2.5

func (s *ServerConn) IsMux() bool

实现 proxy.MuxMarker

func (*ServerConn) Read

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

func (*ServerConn) ReadMsg added in v1.2.5

func (c *ServerConn) ReadMsg() (bs []byte, target netLayer.Addr, err error)

func (*ServerConn) Write

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

func (*ServerConn) WriteMsg added in v1.2.5

func (c *ServerConn) WriteMsg(b []byte, _ netLayer.Addr) error

type ServerCreator

type ServerCreator struct{ proxy.CreatorCommonStruct }

func (ServerCreator) NewServer

func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error)

func (ServerCreator) URLToListenConf added in v1.2.4

func (ServerCreator) URLToListenConf(url *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error)

type ShakeSizeParser

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

func NewShakeSizeParser

func NewShakeSizeParser(nonce []byte, shouldPad bool) *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) 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