From 4f789737512d53b4d870efd6cde09fe36cc5de8c Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 2 Jun 2023 21:24:49 +0200 Subject: [PATCH] Fixed race condition when timed-out link receives a late establishment proof a few milliseconds after it has timed out --- RNS/Link.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index eba7394..162f820 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -225,15 +225,18 @@ class Link: self.hash = self.link_id def handshake(self): - self.status = Link.HANDSHAKE - self.shared_key = self.prv.exchange(self.peer_pub) + if self.status == Link.PENDING and self.prv != None: + self.status = Link.HANDSHAKE + self.shared_key = self.prv.exchange(self.peer_pub) - self.derived_key = RNS.Cryptography.hkdf( - length=32, - derive_from=self.shared_key, - salt=self.get_salt(), - context=self.get_context(), - ) + self.derived_key = RNS.Cryptography.hkdf( + length=32, + derive_from=self.shared_key, + salt=self.get_salt(), + context=self.get_context(), + ) + else: + RNS.log("Handshake attempt on "+str(self)+" with invalid state "+str(self.status), RNS.LOG_ERROR) def prove(self):