mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
VMess AEAD based packet length
(cherry picked from commit 08221600082a79376bdc262f2ffec1a3129ae98d)
This commit is contained in:
parent
707efd6d12
commit
ff35118af5
8 changed files with 232 additions and 6 deletions
|
@ -171,6 +171,17 @@ func (c *ClientSession) EncodeRequestBody(request *protocol.RequestHeader, write
|
|||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
if request.Option.Has(protocol.RequestOptionAuthenticatedLength) {
|
||||
AuthenticatedLengthKey := vmessaead.KDF16(c.requestBodyKey[:], "auth_len")
|
||||
AuthenticatedLengthKeyAEAD := crypto.NewAesGcm(AuthenticatedLengthKey)
|
||||
|
||||
lengthAuth := &crypto.AEADAuthenticator{
|
||||
AEAD: AuthenticatedLengthKeyAEAD,
|
||||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
sizeParser = NewAEADSizeParser(lengthAuth)
|
||||
}
|
||||
return crypto.NewAuthenticationWriter(auth, sizeParser, writer, request.Command.TransferType(), padding)
|
||||
case protocol.SecurityType_CHACHA20_POLY1305:
|
||||
aead, err := chacha20poly1305.New(GenerateChacha20Poly1305Key(c.requestBodyKey[:]))
|
||||
|
@ -181,6 +192,18 @@ func (c *ClientSession) EncodeRequestBody(request *protocol.RequestHeader, write
|
|||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
if request.Option.Has(protocol.RequestOptionAuthenticatedLength) {
|
||||
AuthenticatedLengthKey := vmessaead.KDF16(c.requestBodyKey[:], "auth_len")
|
||||
AuthenticatedLengthKeyAEAD, err := chacha20poly1305.New(GenerateChacha20Poly1305Key(AuthenticatedLengthKey))
|
||||
common.Must(err)
|
||||
|
||||
lengthAuth := &crypto.AEADAuthenticator{
|
||||
AEAD: AuthenticatedLengthKeyAEAD,
|
||||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
sizeParser = NewAEADSizeParser(lengthAuth)
|
||||
}
|
||||
return crypto.NewAuthenticationWriter(auth, sizeParser, writer, request.Command.TransferType(), padding)
|
||||
default:
|
||||
panic("Unknown security type.")
|
||||
|
@ -312,6 +335,17 @@ func (c *ClientSession) DecodeResponseBody(request *protocol.RequestHeader, read
|
|||
NonceGenerator: GenerateChunkNonce(c.responseBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
if request.Option.Has(protocol.RequestOptionAuthenticatedLength) {
|
||||
AuthenticatedLengthKey := vmessaead.KDF16(c.requestBodyKey[:], "auth_len")
|
||||
AuthenticatedLengthKeyAEAD := crypto.NewAesGcm(AuthenticatedLengthKey)
|
||||
|
||||
lengthAuth := &crypto.AEADAuthenticator{
|
||||
AEAD: AuthenticatedLengthKeyAEAD,
|
||||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
sizeParser = NewAEADSizeParser(lengthAuth)
|
||||
}
|
||||
return crypto.NewAuthenticationReader(auth, sizeParser, reader, request.Command.TransferType(), padding)
|
||||
case protocol.SecurityType_CHACHA20_POLY1305:
|
||||
aead, _ := chacha20poly1305.New(GenerateChacha20Poly1305Key(c.responseBodyKey[:]))
|
||||
|
@ -321,6 +355,18 @@ func (c *ClientSession) DecodeResponseBody(request *protocol.RequestHeader, read
|
|||
NonceGenerator: GenerateChunkNonce(c.responseBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
if request.Option.Has(protocol.RequestOptionAuthenticatedLength) {
|
||||
AuthenticatedLengthKey := vmessaead.KDF16(c.requestBodyKey[:], "auth_len")
|
||||
AuthenticatedLengthKeyAEAD, err := chacha20poly1305.New(GenerateChacha20Poly1305Key(AuthenticatedLengthKey))
|
||||
common.Must(err)
|
||||
|
||||
lengthAuth := &crypto.AEADAuthenticator{
|
||||
AEAD: AuthenticatedLengthKeyAEAD,
|
||||
NonceGenerator: GenerateChunkNonce(c.requestBodyIV[:], uint32(aead.NonceSize())),
|
||||
AdditionalDataGenerator: crypto.GenerateEmptyBytes(),
|
||||
}
|
||||
sizeParser = NewAEADSizeParser(lengthAuth)
|
||||
}
|
||||
return crypto.NewAuthenticationReader(auth, sizeParser, reader, request.Command.TransferType(), padding)
|
||||
default:
|
||||
panic("Unknown security type.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue