summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-04-01 04:31:03 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-04-01 04:31:03 +0200
commitb5efe8ac07194d6e2447bef423292fa5909cf2fd (patch)
tree42a8f7c90b28c5b5d2e9d5cd0fb58858614bdef9
parent2d7472633ac356f1bc8f8122a1cc3b3226a95697 (diff)
downloadfastd-b5efe8ac07194d6e2447bef423292fa5909cf2fd.tar
fastd-b5efe8ac07194d6e2447bef423292fa5909cf2fd.zip
Retry in case of a handshake conflict
-rw-r--r--src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
index 8336db5..886a372 100644
--- a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
+++ b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
@@ -528,6 +528,16 @@ static inline const fastd_peer_config* match_sender_key(fastd_context *ctx, cons
return NULL;
}
+static void kill_handshakes(fastd_context *ctx, fastd_peer *peer) {
+ pr_debug(ctx, "there is a handshake conflict, retrying in a moment...");
+
+ free_handshake(peer->protocol_state->initiating_handshake);
+ peer->protocol_state->initiating_handshake = NULL;
+
+ free_handshake(peer->protocol_state->accepting_handshake);
+ peer->protocol_state->accepting_handshake = NULL;
+}
+
static void protocol_handshake_handle(fastd_context *ctx, fastd_peer *peer, const fastd_handshake *handshake) {
init_peer_state(ctx, peer);
@@ -566,6 +576,11 @@ static void protocol_handshake_handle(fastd_context *ctx, fastd_peer *peer, cons
switch(handshake->type) {
case 1:
+ if (peer->protocol_state->initiating_handshake) {
+ kill_handshakes(ctx, peer);
+ return;
+ }
+
new_handshake(ctx, peer, peer_config, false);
memcpy(peer->protocol_state->accepting_handshake->peer_key.p, handshake->records[RECORD_SENDER_HANDSHAKE_KEY].data, PUBLICKEYBYTES);
respond_handshake(ctx, peer, handshake);
@@ -593,6 +608,12 @@ static void protocol_handshake_handle(fastd_context *ctx, fastd_peer *peer, cons
}
pr_debug(ctx, "received handshake response from %P", peer);
+
+ if (peer->protocol_state->accepting_handshake) {
+ kill_handshakes(ctx, peer);
+ return;
+ }
+
memcpy(peer->protocol_state->initiating_handshake->peer_key.p, handshake->records[RECORD_SENDER_HANDSHAKE_KEY].data, PUBLICKEYBYTES);
finish_handshake(ctx, peer, handshake);
@@ -619,6 +640,13 @@ static void protocol_handshake_handle(fastd_context *ctx, fastd_peer *peer, cons
return;
}
+ pr_debug(ctx, "received handshake finish from %P", peer);
+
+ if (peer->protocol_state->initiating_handshake) {
+ kill_handshakes(ctx, peer);
+ return;
+ }
+
handle_finish_handshake(ctx, peer, handshake);
break;