vmess

package
v0.0.0-...-c6b16a5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptBasicFormat byte = 0 // 不加密传输
	OptChunkStream byte = 1 // 分块传输,每个分块使用如下Security方法加密

)

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
)

CMD types

View Source
const (
	AtypIP4    byte = 1
	AtypDomain byte = 2
	AtypIP6    byte = 3
)

Atyp

View Source
const Name = "vmess"

Variables

This section is empty.

Functions

func AEADReader

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

AEADReader returns a aead reader

func AEADWriter

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

AEADWriter returns a aead 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 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 NewVmessClient

func NewVmessClient(ctx context.Context, url *url.URL) (proxy.Client, error)

func NewVmessServer

func NewVmessServer(ctx context.Context, url *url.URL) (proxy.Server, error)

func ParseAddr

func ParseAddr(s string) (byte, []byte, uint16, error)

ParseAddr parses the address in string

func StrToUUID

func StrToUUID(s string) (uuid [16]byte, err error)

StrToUUID converts string to uuid

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 {
	// contains filtered or unexported fields
}

Client is a vmess client

func (*Client) Addr

func (c *Client) Addr() string

func (*Client) Handshake

func (c *Client) Handshake(underlay net.Conn, target string) (proxy.StreamConn, error)

func (*Client) Name

func (c *Client) Name() string

func (*Client) Pack

func (c *Client) Pack(underlay net.Conn) (proxy.PacketConn, error)

type ClientConn

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

ClientConn is a connection to vmess server

func (*ClientConn) Auth

func (c *ClientConn) Auth() error

Auth send auth info: HMAC("md5", UUID, UTC)

func (*ClientConn) Close

func (c *ClientConn) Close() error

func (*ClientConn) DecodeRespHeader

func (c *ClientConn) DecodeRespHeader() error

DecodeRespHeader decodes response header.

func (*ClientConn) Read

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

func (*ClientConn) Request

func (c *ClientConn) Request() error

Request sends request to server.

func (*ClientConn) Write

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

type Server

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

func (*Server) Addr

func (s *Server) Addr() string

func (*Server) Handshake

func (s *Server) Handshake(underlay net.Conn) (proxy.StreamConn, *proxy.TargetAddr, error)

func (*Server) Name

func (s *Server) Name() string

func (*Server) Pack

func (s *Server) Pack(underlay net.Conn) (proxy.PacketConn, error)

type ServerConn

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

ServerConn wrapper a net.Conn with vmess protocol

func (*ServerConn) Close

func (c *ServerConn) Close() error

func (*ServerConn) Read

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

func (*ServerConn) Write

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

type SessionId

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

type User

type User struct {
	*user.Meter
	UUID [16]byte

	// VMess协议会使用用户的UUID生成AlterId个新的UUID,随机的使用不同的UUID进行传输这个用户的流量
	// https://www.v2fly.org/config/protocols/vmess.html
	AlterId int
	UUIDs   [][16]byte
	// AES-128-CFB加密算法的Key,用于指令部分的加密
	// https://www.v2fly.org/developer/protocols/vmess.html#%E6%8C%87%E4%BB%A4%E9%83%A8%E5%88%86
	CmdKey [16]byte
}

VMess user

func NewUser

func NewUser(ctx context.Context, uuidStr, alterIdStr string) (*User, error)

type UserAtTime

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

type UserManager

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

VMess user manager

func NewUserManager

func NewUserManager(ctx context.Context, uuidStr, alterId string) *UserManager

Create a user manager with init user uuid and its alter id

func (*UserManager) AddUser

func (um *UserManager) AddUser(hash string, more ...string) error

添加用户后,平均30秒会刷新

func (*UserManager) AuthUser

func (um *UserManager) AuthUser(hash string) (bool, user.User)

func (*UserManager) CheckAuth

func (um *UserManager) CheckAuth(auth [16]byte) (*User, int64, error)

处理VMess请求的认证信息

func (*UserManager) CheckSession

func (um *UserManager) CheckSession(auth, uuid, reqBodyKey, reqBodyIV [16]byte) (*SessionId, error)

从VMess请求的指令部分中提取出reqBodyKey和reqBodyIV,来判断某个UUID是否已经发送过同样的值

func (*UserManager) DelUser

func (um *UserManager) DelUser(hash string) error

func (*UserManager) ListUsers

func (um *UserManager) ListUsers() []user.User

func (*UserManager) Refresh

func (um *UserManager) Refresh()

Refresh

Jump to

Keyboard shortcuts

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