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 {