From 233f079a9479279d2aab68f4accb139ee87ad664 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 7 May 2018 22:27:03 +0200 Subject: Rewrite timers and related state machines --- noise-protocol.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'noise-protocol.go') diff --git a/noise-protocol.go b/noise-protocol.go index 35e95ef..3abbe4b 100644 --- a/noise-protocol.go +++ b/noise-protocol.go @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 * - * Copyright (C) 2017-2018 Jason A. Donenfeld . All Rights Reserved. + * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ package main @@ -488,7 +488,7 @@ func (device *Device) ConsumeMessageResponse(msg *MessageResponse) *Peer { /* Derives a new key-pair from the current handshake state * */ -func (peer *Peer) NewKeyPair() *KeyPair { +func (peer *Peer) NewKeypair() *Keypair { device := peer.device handshake := &peer.handshake handshake.mutex.Lock() @@ -528,7 +528,7 @@ func (peer *Peer) NewKeyPair() *KeyPair { // create AEAD instances - keyPair := new(KeyPair) + keyPair := new(Keypair) keyPair.send, _ = chacha20poly1305.New(sendKey[:]) keyPair.receive, _ = chacha20poly1305.New(recvKey[:]) @@ -559,24 +559,27 @@ func (peer *Peer) NewKeyPair() *KeyPair { kp := &peer.keyPairs kp.mutex.Lock() - if isInitiator { - if kp.previous != nil { - device.DeleteKeyPair(kp.previous) - kp.previous = nil - } + peer.timersSessionDerived() + + previous := kp.previous + next := kp.next + current := kp.current - if kp.next != nil { - kp.previous = kp.next - kp.next = keyPair + if isInitiator { + if next != nil { + kp.next = nil + kp.previous = next + device.DeleteKeypair(current) } else { - kp.previous = kp.current - kp.current = keyPair - peer.event.newKeyPair.Fire() + kp.previous = current } - + device.DeleteKeypair(previous) + kp.current = keyPair } else { kp.next = keyPair + device.DeleteKeypair(next) kp.previous = nil + device.DeleteKeypair(previous) } kp.mutex.Unlock() -- cgit v1.2.3