|
|
|
@ -41,7 +41,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|
|
|
|
ivLen := account.Cipher.IVSize()
|
|
|
|
|
var iv []byte
|
|
|
|
|
if ivLen > 0 {
|
|
|
|
|
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, int32(ivLen))); err != nil {
|
|
|
|
|
if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, ivLen)); err != nil {
|
|
|
|
|
return nil, nil, newError("failed to read IV").Base(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -227,7 +227,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buff
|
|
|
|
|
buffer := buf.New()
|
|
|
|
|
ivLen := account.Cipher.IVSize()
|
|
|
|
|
if ivLen > 0 {
|
|
|
|
|
common.Must(buffer.Reset(buf.ReadFullFrom(rand.Reader, int32(ivLen))))
|
|
|
|
|
common.Must(buffer.Reset(buf.ReadFullFrom(rand.Reader, ivLen)))
|
|
|
|
|
}
|
|
|
|
|
iv := buffer.Bytes()
|
|
|
|
|
|
|
|
|
@ -293,7 +293,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
|
|
|
|
|
|
|
|
|
|
authenticator := NewAuthenticator(HeaderKeyGenerator(account.Key, iv))
|
|
|
|
|
actualAuth := make([]byte, AuthSize)
|
|
|
|
|
authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth)
|
|
|
|
|
common.Must2(authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth))
|
|
|
|
|
if !bytes.Equal(actualAuth, authBytes) {
|
|
|
|
|
return nil, nil, newError("invalid OTA")
|
|
|
|
|
}
|
|
|
|
|