From 87427a7ec866c7f8fb829fa07340b3a9b2d7f66f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 19 Oct 2016 01:08:08 +0200 Subject: timers: always delay handshakes for responder With the prior behavior, when sending a packet, we checked to see if it was about time to start a new handshake, and if we were past a certain time, we started it. For the responder, we made that time a bit further in the future than for the initiator, to prevent the thundering herd problem of them both starting at the same time. However, this was flawed. If both parties stopped communicating after 2.2 minutes, and then one party decided to initiate a TCP connection before the 3 minute mark, the currently open session would be used. However, because it was after the 2.2 minute mark, both peers would try to initiate a handshake upon sending their first packet. The errant flow was as follows: 1. Peer A sends SYN. 2. Peer A sees that his key is getting old and initiates new handshake. 3. Peer B receives SYN and sends ACK. 4. Peer B sees that his key is getting old and initiates new handshake. Since these events happened after the 2.2 minute mark, there's no delay between handshake initiations, and problems begin. The new behavior is changed to: 1. Peer A sends SYN. 2. Peer A sees that his key is getting old and initiates new handshake. 3. Peer B receives SYN and sends ACK. 4. Peer B sees that his key is getting old and schedules a delayed handshake for 12.5 seconds in the future. 5. Peer B receives handshake initiation and cancels scheduled handshake. --- src/timers.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/timers.h') diff --git a/src/timers.h b/src/timers.h index b6f80fd..349bdab 100644 --- a/src/timers.h +++ b/src/timers.h @@ -13,7 +13,9 @@ void timers_data_sent(struct wireguard_peer *peer); void timers_data_received(struct wireguard_peer *peer); void timers_any_authenticated_packet_received(struct wireguard_peer *peer); void timers_handshake_initiated(struct wireguard_peer *peer); +void timers_handshake_received(struct wireguard_peer *peer); void timers_handshake_complete(struct wireguard_peer *peer); +void timers_delay_handshake(struct wireguard_peer *peer, unsigned int delay); void timers_ephemeral_key_created(struct wireguard_peer *peer); void timers_any_authenticated_packet_traversal(struct wireguard_peer *peer); -- cgit v1.2.3-59-g8ed1b