Feature: support vmess 'zero' security (#2513)

This commit is contained in:
bobo liu
2023-01-30 14:14:42 +08:00
committed by GitHub
parent 58732ee8b1
commit 81b1e9f931
4 changed files with 110 additions and 9 deletions

View File

@ -35,6 +35,7 @@ type Conn struct {
respBodyKey []byte
respV byte
security byte
option byte
isAead bool
received bool
@ -74,7 +75,7 @@ func (vc *Conn) sendRequest() error {
buf.Write(vc.reqBodyIV[:])
buf.Write(vc.reqBodyKey[:])
buf.WriteByte(vc.respV)
buf.WriteByte(OptionChunkStream)
buf.WriteByte(vc.option)
p := rand.Intn(16)
// P Sec Reserve Cmd
@ -206,6 +207,7 @@ func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security, isAead bool
copy(reqBodyIV[:], randBytes[:16])
copy(reqBodyKey[:], randBytes[16:32])
respV := randBytes[32]
option := OptionChunkStream
var (
respBodyKey []byte
@ -227,6 +229,16 @@ func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security, isAead bool
var writer io.Writer
var reader io.Reader
switch security {
case SecurityZero:
security = SecurityNone
if !dst.UDP {
reader = conn
writer = conn
option = 0
} else {
reader = newChunkReader(conn)
writer = newChunkWriter(conn)
}
case SecurityNone:
reader = newChunkReader(conn)
writer = newChunkWriter(conn)
@ -267,6 +279,7 @@ func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security, isAead bool
reader: reader,
writer: writer,
security: security,
option: option,
isAead: isAead,
}
if err := c.sendRequest(); err != nil {

View File

@ -26,15 +26,9 @@ const (
SecurityAES128GCM Security = 3
SecurityCHACHA20POLY1305 Security = 4
SecurityNone Security = 5
SecurityZero Security = 6
)
// CipherMapping return
var CipherMapping = map[string]byte{
"none": SecurityNone,
"aes-128-gcm": SecurityAES128GCM,
"chacha20-poly1305": SecurityCHACHA20POLY1305,
}
// Command types
const (
CommandTCP byte = 1
@ -95,6 +89,8 @@ func NewClient(config Config) (*Client, error) {
security = SecurityCHACHA20POLY1305
case "none":
security = SecurityNone
case "zero":
security = SecurityZero
case "auto":
security = SecurityCHACHA20POLY1305
if runtime.GOARCH == "amd64" || runtime.GOARCH == "s390x" || runtime.GOARCH == "arm64" {