diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-07 22:27:03 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-10 16:08:03 +0200 |
commit | 233f079a9479279d2aab68f4accb139ee87ad664 (patch) | |
tree | 338dfb681ffafbb53b81d353aa5612866ff935f5 /noise-protocol.go | |
parent | 375dcbd4aefc8054700dcb072a5e74a9ed7e9d39 (diff) |
Rewrite timers and related state machines
Diffstat (limited to 'noise-protocol.go')
-rw-r--r-- | noise-protocol.go | 33 |
1 files changed, 18 insertions, 15 deletions
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 <Jason@zx2c4.com>. All Rights Reserved. + * Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. 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() |