]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: immediately rekey all peers after changing device private key
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 11 Jul 2019 15:36:36 +0000 (17:36 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 11 Jul 2019 15:37:35 +0000 (17:37 +0200)
Reported-by: Derrick Pallas <derrick@pallas.us>
device/device.go
device/peer.go

index a583fa9008058addd1f0ce4746e7f76c2d9decf1..ab5e4b08544ed7a1b85051f0da08c109be82d310 100644 (file)
@@ -207,6 +207,10 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
        device.staticIdentity.Lock()
        defer device.staticIdentity.Unlock()
 
+       if sk.Equals(device.staticIdentity.privateKey) {
+               return nil
+       }
+
        device.peers.Lock()
        defer device.peers.Unlock()
 
@@ -246,6 +250,8 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
 
                if isZero(handshake.precomputedStaticStatic[:]) {
                        unsafeRemovePeer(device, peer, key)
+               } else {
+                       peer.ExpireCurrentKeypairs()
                }
        }
 
index 4e7f2da21a49a3aca210c83d4937c6305c7f325b..256e4f55b7e7a63451d0a5b8ac7f6f13a4600e0d 100644 (file)
@@ -232,6 +232,25 @@ func (peer *Peer) ZeroAndFlushAll() {
        peer.FlushNonceQueue()
 }
 
+func (peer *Peer) ExpireCurrentKeypairs() {
+       handshake := &peer.handshake
+       handshake.mutex.Lock()
+       peer.device.indexTable.Delete(handshake.localIndex)
+       handshake.Clear()
+       handshake.mutex.Unlock()
+       peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
+
+       keypairs := &peer.keypairs
+       keypairs.Lock()
+       if keypairs.current != nil {
+               keypairs.current.sendNonce = RejectAfterMessages
+       }
+       if keypairs.next != nil {
+               keypairs.next.sendNonce = RejectAfterMessages
+       }
+       keypairs.Unlock()
+}
+
 func (peer *Peer) Stop() {
 
        // prevent simultaneous start/stop operations