|
|
@@ -61,6 +61,12 @@ func ReadTCPSession(user *protocol.MemoryUser, reader io.Reader) (*protocol.Requ
|
|
|
iv = append([]byte(nil), buffer.BytesTo(ivLen)...)
|
|
|
}
|
|
|
|
|
|
+ if ivError := account.CheckIV(iv); ivError != nil {
|
|
|
+ readSizeRemain -= int(buffer.Len())
|
|
|
+ DrainConnN(reader, readSizeRemain)
|
|
|
+ return nil, nil, newError("failed iv check").Base(ivError)
|
|
|
+ }
|
|
|
+
|
|
|
r, err := account.Cipher.NewDecryptionReader(account.Key, iv, reader)
|
|
|
if err != nil {
|
|
|
readSizeRemain -= int(buffer.Len())
|
|
|
@@ -111,6 +117,9 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
|
|
|
if account.Cipher.IVSize() > 0 {
|
|
|
iv = make([]byte, account.Cipher.IVSize())
|
|
|
common.Must2(rand.Read(iv))
|
|
|
+ if ivError := account.CheckIV(iv); ivError != nil {
|
|
|
+ return nil, newError("failed to mark outgoing iv").Base(ivError)
|
|
|
+ }
|
|
|
if err := buf.WriteAllBytes(writer, iv); err != nil {
|
|
|
return nil, newError("failed to write IV")
|
|
|
}
|
|
|
@@ -145,6 +154,10 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ivError := account.CheckIV(iv); ivError != nil {
|
|
|
+ return nil, newError("failed iv check").Base(ivError)
|
|
|
+ }
|
|
|
+
|
|
|
return account.Cipher.NewDecryptionReader(account.Key, iv, reader)
|
|
|
}
|
|
|
|
|
|
@@ -156,6 +169,9 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Wr
|
|
|
if account.Cipher.IVSize() > 0 {
|
|
|
iv = make([]byte, account.Cipher.IVSize())
|
|
|
common.Must2(rand.Read(iv))
|
|
|
+ if ivError := account.CheckIV(iv); ivError != nil {
|
|
|
+ return nil, newError("failed to mark outgoing iv").Base(ivError)
|
|
|
+ }
|
|
|
if err := buf.WriteAllBytes(writer, iv); err != nil {
|
|
|
return nil, newError("failed to write IV.").Base(err)
|
|
|
}
|