Store session secrets only on succesful decodeHandshakePacket

This commit is contained in:
kdeme 2020-10-01 12:07:43 +02:00 committed by zah
parent a10ee4cc42
commit 820a73f96f
1 changed files with 5 additions and 2 deletions

View File

@ -478,8 +478,6 @@ proc decodeHandshakePacket(c: var Codec, fromAddr: Address, srcId: NodeId,
ephKey, challenge.whoareyouData.idNonce) ephKey, challenge.whoareyouData.idNonce)
swap(secrets.readKey, secrets.writeKey) swap(secrets.readKey, secrets.writeKey)
c.sessions.store(srcId, fromAddr, secrets.readKey,
secrets.writeKey)
let pt = decryptGCM(secrets.readKey, nonce, ct, header) let pt = decryptGCM(secrets.readKey, nonce, ct, header)
if pt.isNone(): if pt.isNone():
@ -490,6 +488,11 @@ proc decodeHandshakePacket(c: var Codec, fromAddr: Address, srcId: NodeId,
let message = ? decodeMessage(pt.get()) let message = ? decodeMessage(pt.get())
# Only store the session secrets in case decryption was successful and also
# in case the message can get decoded.
c.sessions.store(srcId, fromAddr, secrets.readKey,
secrets.writeKey)
return ok(Packet(flag: Flag.HandshakeMessage, message: message, srcId: srcId, return ok(Packet(flag: Flag.HandshakeMessage, message: message, srcId: srcId,
node: newNode)) node: newNode))