mirror of https://github.com/v2ray/v2ray-core
parent
09b601528b
commit
81c9968188
|
@ -28,3 +28,11 @@ func NewAesStreamMethod(key []byte, iv []byte, f func(cipher.Block, []byte) ciph
|
||||||
func NewAesCTRStream(key []byte, iv []byte) cipher.Stream {
|
func NewAesCTRStream(key []byte, iv []byte) cipher.Stream {
|
||||||
return NewAesStreamMethod(key, iv, cipher.NewCTR)
|
return NewAesStreamMethod(key, iv, cipher.NewCTR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAesGcm(key []byte) cipher.AEAD {
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
common.Must(err)
|
||||||
|
aead, err := cipher.NewGCM(block)
|
||||||
|
common.Must(err)
|
||||||
|
return aead
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
|
||||||
"crypto/cipher"
|
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
|
@ -105,10 +103,8 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
|
||||||
common.Must(buffer.AppendSupplier(serial.WriteHash(fnv1a)))
|
common.Must(buffer.AppendSupplier(serial.WriteHash(fnv1a)))
|
||||||
}
|
}
|
||||||
|
|
||||||
timestampHash := md5.New()
|
iv := md5.Sum(hashTimestamp(timestamp))
|
||||||
common.Must2(timestampHash.Write(hashTimestamp(timestamp)))
|
aesStream := crypto.NewAesEncryptionStream(account.ID.CmdKey(), iv[:])
|
||||||
iv := timestampHash.Sum(nil)
|
|
||||||
aesStream := crypto.NewAesEncryptionStream(account.ID.CmdKey(), iv)
|
|
||||||
aesStream.XORKeyStream(buffer.Bytes(), buffer.Bytes())
|
aesStream.XORKeyStream(buffer.Bytes(), buffer.Bytes())
|
||||||
common.Must2(writer.Write(buffer.Bytes()))
|
common.Must2(writer.Write(buffer.Bytes()))
|
||||||
return nil
|
return nil
|
||||||
|
@ -153,9 +149,7 @@ func (c *ClientSession) EncodeRequestBody(request *protocol.RequestHeader, write
|
||||||
|
|
||||||
return &buf.SequentialWriter{Writer: cryptionWriter}
|
return &buf.SequentialWriter{Writer: cryptionWriter}
|
||||||
case protocol.SecurityType_AES128_GCM:
|
case protocol.SecurityType_AES128_GCM:
|
||||||
block, _ := aes.NewCipher(c.requestBodyKey[:])
|
aead := crypto.NewAesGcm(c.requestBodyKey[:])
|
||||||
aead, _ := cipher.NewGCM(block)
|
|
||||||
|
|
||||||
auth := &crypto.AEADAuthenticator{
|
auth := &crypto.AEADAuthenticator{
|
||||||
AEAD: aead,
|
AEAD: aead,
|
||||||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||||
|
@ -163,7 +157,8 @@ func (c *ClientSession) EncodeRequestBody(request *protocol.RequestHeader, write
|
||||||
}
|
}
|
||||||
return crypto.NewAuthenticationWriter(auth, sizeParser, writer, request.Command.TransferType(), padding)
|
return crypto.NewAuthenticationWriter(auth, sizeParser, writer, request.Command.TransferType(), padding)
|
||||||
case protocol.SecurityType_CHACHA20_POLY1305:
|
case protocol.SecurityType_CHACHA20_POLY1305:
|
||||||
aead, _ := chacha20poly1305.New(GenerateChacha20Poly1305Key(c.requestBodyKey[:]))
|
aead, err := chacha20poly1305.New(GenerateChacha20Poly1305Key(c.requestBodyKey[:]))
|
||||||
|
common.Must(err)
|
||||||
|
|
||||||
auth := &crypto.AEADAuthenticator{
|
auth := &crypto.AEADAuthenticator{
|
||||||
AEAD: aead,
|
AEAD: aead,
|
||||||
|
@ -250,8 +245,7 @@ func (c *ClientSession) DecodeResponseBody(request *protocol.RequestHeader, read
|
||||||
|
|
||||||
return buf.NewReader(c.responseReader)
|
return buf.NewReader(c.responseReader)
|
||||||
case protocol.SecurityType_AES128_GCM:
|
case protocol.SecurityType_AES128_GCM:
|
||||||
block, _ := aes.NewCipher(c.responseBodyKey[:])
|
aead := crypto.NewAesGcm(c.responseBodyKey[:])
|
||||||
aead, _ := cipher.NewGCM(block)
|
|
||||||
|
|
||||||
auth := &crypto.AEADAuthenticator{
|
auth := &crypto.AEADAuthenticator{
|
||||||
AEAD: aead,
|
AEAD: aead,
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
|
||||||
"crypto/cipher"
|
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
@ -147,12 +145,10 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
||||||
return nil, newError("invalid user")
|
return nil, newError("invalid user")
|
||||||
}
|
}
|
||||||
|
|
||||||
timestampHash := md5.New()
|
iv := md5.Sum(hashTimestamp(timestamp))
|
||||||
common.Must2(timestampHash.Write(hashTimestamp(timestamp)))
|
|
||||||
iv := timestampHash.Sum(nil)
|
|
||||||
vmessAccount := user.Account.(*vmess.InternalAccount)
|
vmessAccount := user.Account.(*vmess.InternalAccount)
|
||||||
|
|
||||||
aesStream := crypto.NewAesDecryptionStream(vmessAccount.ID.CmdKey(), iv)
|
aesStream := crypto.NewAesDecryptionStream(vmessAccount.ID.CmdKey(), iv[:])
|
||||||
decryptor := crypto.NewCryptionReader(aesStream, reader)
|
decryptor := crypto.NewCryptionReader(aesStream, reader)
|
||||||
|
|
||||||
if err := buffer.Reset(buf.ReadFullFrom(decryptor, 38)); err != nil {
|
if err := buffer.Reset(buf.ReadFullFrom(decryptor, 38)); err != nil {
|
||||||
|
@ -263,8 +259,7 @@ func (s *ServerSession) DecodeRequestBody(request *protocol.RequestHeader, reade
|
||||||
|
|
||||||
return buf.NewReader(cryptionReader)
|
return buf.NewReader(cryptionReader)
|
||||||
case protocol.SecurityType_AES128_GCM:
|
case protocol.SecurityType_AES128_GCM:
|
||||||
block, _ := aes.NewCipher(s.requestBodyKey[:])
|
aead := crypto.NewAesGcm(s.requestBodyKey[:])
|
||||||
aead, _ := cipher.NewGCM(block)
|
|
||||||
|
|
||||||
auth := &crypto.AEADAuthenticator{
|
auth := &crypto.AEADAuthenticator{
|
||||||
AEAD: aead,
|
AEAD: aead,
|
||||||
|
@ -341,8 +336,7 @@ func (s *ServerSession) EncodeResponseBody(request *protocol.RequestHeader, writ
|
||||||
|
|
||||||
return &buf.SequentialWriter{Writer: s.responseWriter}
|
return &buf.SequentialWriter{Writer: s.responseWriter}
|
||||||
case protocol.SecurityType_AES128_GCM:
|
case protocol.SecurityType_AES128_GCM:
|
||||||
block, _ := aes.NewCipher(s.responseBodyKey[:])
|
aead := crypto.NewAesGcm(s.responseBodyKey[:])
|
||||||
aead, _ := cipher.NewGCM(block)
|
|
||||||
|
|
||||||
auth := &crypto.AEADAuthenticator{
|
auth := &crypto.AEADAuthenticator{
|
||||||
AEAD: aead,
|
AEAD: aead,
|
||||||
|
|
Loading…
Reference in New Issue