mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
移除非aead的代码
This commit is contained in:
@@ -129,20 +129,11 @@ func (c *Client) commonHandshake(underlay net.Conn, firstPayload []byte, target
|
||||
utils.PutBytes(randBytes)
|
||||
conn.reqRespV = randBytes[32]
|
||||
|
||||
//non-aead
|
||||
//conn.respBodyIV = md5.Sum(conn.reqBodyIV[:])
|
||||
//conn.respBodyKey = md5.Sum(conn.reqBodyKey[:])
|
||||
|
||||
bodyKey := sha256.Sum256(conn.reqBodyKey[:])
|
||||
bodyIV := sha256.Sum256(conn.reqBodyIV[:])
|
||||
copy(conn.respBodyKey[:], bodyKey[:16])
|
||||
copy(conn.respBodyIV[:], bodyIV[:16])
|
||||
|
||||
// Auth
|
||||
//err := conn.non_aead_auth()
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
var err error
|
||||
|
||||
// Request
|
||||
@@ -223,11 +214,11 @@ func (c *ClientConn) handshake(cmd byte) error {
|
||||
defer utils.PutBuf(buf)
|
||||
|
||||
// Request
|
||||
buf.WriteByte(1) // Ver
|
||||
buf.Write(c.reqBodyIV[:]) // IV
|
||||
buf.Write(c.reqBodyKey[:]) // Key
|
||||
buf.WriteByte(c.reqRespV) // V
|
||||
buf.WriteByte(c.opt) // Opt
|
||||
buf.WriteByte(1) // Ver
|
||||
buf.Write(c.reqBodyIV[:])
|
||||
buf.Write(c.reqBodyKey[:])
|
||||
buf.WriteByte(c.reqRespV)
|
||||
buf.WriteByte(c.opt)
|
||||
|
||||
// pLen and Sec
|
||||
paddingLen := rand.Intn(16)
|
||||
@@ -238,13 +229,13 @@ func (c *ClientConn) handshake(cmd byte) error {
|
||||
buf.WriteByte(cmd)
|
||||
|
||||
// target
|
||||
err := binary.Write(buf, binary.BigEndian, c.port) // port
|
||||
err := binary.Write(buf, binary.BigEndian, c.port)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf.WriteByte(c.atyp) // atyp
|
||||
buf.Write(c.addr) // addr
|
||||
buf.WriteByte(c.atyp)
|
||||
buf.Write(c.addr)
|
||||
|
||||
// padding
|
||||
if paddingLen > 0 {
|
||||
@@ -254,7 +245,6 @@ func (c *ClientConn) handshake(cmd byte) error {
|
||||
utils.PutBytes(padding)
|
||||
}
|
||||
|
||||
// F
|
||||
fnv1a := fnv.New32a()
|
||||
_, err = fnv1a.Write(buf.Bytes())
|
||||
if err != nil {
|
||||
@@ -262,19 +252,6 @@ func (c *ClientConn) handshake(cmd byte) error {
|
||||
}
|
||||
buf.Write(fnv1a.Sum(nil))
|
||||
|
||||
// log.Printf("Request Send %v", buf.Bytes())
|
||||
/*
|
||||
//non-aead procedure
|
||||
|
||||
block, err := aes.NewCipher(GetKey(c.user))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stream := cipher.NewCFBEncrypter(block, TimestampHash(time.Now().UTC().Unix()))
|
||||
stream.XORKeyStream(buf.Bytes(), buf.Bytes())
|
||||
*/
|
||||
|
||||
var fixedLengthCmdKey [16]byte
|
||||
copy(fixedLengthCmdKey[:], GetKey(c.user))
|
||||
vmessout := sealVMessAEADHeader(fixedLengthCmdKey, buf.Bytes(), time.Now())
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package vmess
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/e1732a364fed/v2ray_simple/utils"
|
||||
)
|
||||
|
||||
//Deprecated: send non_aead_auth info: HMAC("md5", UUID, UTC)
|
||||
func (c *ClientConn) non_aead_auth() error {
|
||||
ts := utils.GetBytes(8)
|
||||
defer utils.PutBytes(ts)
|
||||
|
||||
binary.BigEndian.PutUint64(ts, uint64(time.Now().UTC().Unix()))
|
||||
|
||||
h := hmac.New(md5.New, c.user.IdentityBytes())
|
||||
h.Write(ts)
|
||||
|
||||
_, err := c.Conn.Write(h.Sum(nil))
|
||||
return err
|
||||
}
|
||||
|
||||
//Deprecated: non_aead is depreated
|
||||
func (c *ClientConn) non_aead_decodeRespHeader() error {
|
||||
block, err := aes.NewCipher(c.respBodyKey[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stream := cipher.NewCFBDecrypter(block, c.respBodyIV[:])
|
||||
|
||||
b := utils.GetBytes(4)
|
||||
defer utils.PutBytes(b)
|
||||
|
||||
_, err = io.ReadFull(c.Conn, b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stream.XORKeyStream(b, b)
|
||||
|
||||
if b[0] != c.reqRespV {
|
||||
return errors.New("unexpected response header")
|
||||
}
|
||||
|
||||
if b[2] != 0 {
|
||||
return errors.New("dynamic port is not supported now")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user