mirror of https://github.com/v2ray/v2ray-core
handle AEAD cipher
parent
713ebfb203
commit
80258c0542
|
@ -102,12 +102,17 @@ type Cipher interface {
|
||||||
IVSize() int
|
IVSize() int
|
||||||
NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)
|
NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)
|
||||||
NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)
|
NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)
|
||||||
|
IsAEAD() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type AesCfb struct {
|
type AesCfb struct {
|
||||||
KeyBytes int
|
KeyBytes int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*AesCfb) IsAEAD() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (v *AesCfb) KeySize() int {
|
func (v *AesCfb) KeySize() int {
|
||||||
return v.KeyBytes
|
return v.KeyBytes
|
||||||
}
|
}
|
||||||
|
@ -132,6 +137,10 @@ type AEADCipher struct {
|
||||||
AEADAuthCreator func(key []byte) cipher.AEAD
|
AEADAuthCreator func(key []byte) cipher.AEAD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*AEADCipher) IsAEAD() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (c *AEADCipher) KeySize() int {
|
func (c *AEADCipher) KeySize() int {
|
||||||
return c.KeyBytes
|
return c.KeyBytes
|
||||||
}
|
}
|
||||||
|
@ -170,6 +179,10 @@ type ChaCha20 struct {
|
||||||
IVBytes int
|
IVBytes int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*ChaCha20) IsAEAD() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (v *ChaCha20) KeySize() int {
|
func (v *ChaCha20) KeySize() int {
|
||||||
return 32
|
return 32
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
||||||
request.Option.Set(RequestOptionOneTimeAuth)
|
request.Option.Set(RequestOptionOneTimeAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.Option.Has(RequestOptionOneTimeAuth) && account.OneTimeAuth == Account_Disabled {
|
if request.Option.Has(RequestOptionOneTimeAuth) && (account.OneTimeAuth == Account_Disabled || account.Cipher.IsAEAD()) {
|
||||||
return nil, nil, newError("rejecting connection with OTA enabled, while server disables OTA")
|
return nil, nil, newError("rejecting connection with OTA enabled, while server disables OTA")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +136,12 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
||||||
}
|
}
|
||||||
account := rawAccount.(*ShadowsocksAccount)
|
account := rawAccount.(*ShadowsocksAccount)
|
||||||
|
|
||||||
|
if account.Cipher.IsAEAD() {
|
||||||
|
request.Option.Clear(RequestOptionOneTimeAuth)
|
||||||
|
}
|
||||||
|
|
||||||
iv := make([]byte, account.Cipher.IVSize())
|
iv := make([]byte, account.Cipher.IVSize())
|
||||||
rand.Read(iv)
|
common.Must2(rand.Read(iv))
|
||||||
_, err = writer.Write(iv)
|
_, err = writer.Write(iv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to write IV")
|
return nil, newError("failed to write IV")
|
||||||
|
|
Loading…
Reference in New Issue