From ae492d1b359918d20fda817e31675f126c7a7837 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 17 Oct 2019 15:43:06 +0200 Subject: device: recheck counters while holding write lock --- device/noise-protocol.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/device/noise-protocol.go b/device/noise-protocol.go index dd75cc3..88c6aae 100644 --- a/device/noise-protocol.go +++ b/device/noise-protocol.go @@ -315,8 +315,13 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer { handshake.chainKey = chainKey handshake.remoteIndex = msg.Sender handshake.remoteEphemeral = msg.Ephemeral - handshake.lastTimestamp = timestamp - handshake.lastInitiationConsumption = time.Now() + if timestamp.After(handshake.lastTimestamp) { + handshake.lastTimestamp = timestamp + } + now := time.Now() + if now.After(handshake.lastInitiationConsumption) { + handshake.lastInitiationConsumption = now + } handshake.state = HandshakeInitiationConsumed handshake.mutex.Unlock() -- cgit v1.2.3