From 4f0cfe26bf5445fc06a59a6db47cb2fa3158b87b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 31 Mar 2012 21:18:07 +0200 Subject: Trigger handshake when unexpected data is received from a floating peer --- src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c') diff --git a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c index a7a635c..32c459a 100644 --- a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c +++ b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c @@ -561,8 +561,13 @@ static void protocol_handshake_handle(fastd_context *ctx, fastd_peer *peer, cons } if (peer->protocol_state->initiating_handshake->peer_config != peer_config) { - pr_debug(ctx, "received handshake response with wrong sender key from %P", peer); - return; + if (peer->protocol_state->initiating_handshake->peer_config) { + pr_debug(ctx, "received handshake response with wrong sender key from %P", peer); + return; + } + else { + peer->protocol_state->initiating_handshake->peer_config = peer_config; + } } if (memcmp(peer->protocol_state->initiating_handshake->public_key.p, handshake->records[RECORD_RECEIPIENT_HANDSHAKE_KEY].data, PUBLICKEYBYTES) != 0) { @@ -606,14 +611,21 @@ static void protocol_handshake_handle(fastd_context *ctx, fastd_peer *peer, cons } static void protocol_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer) { - if (!fastd_peer_is_established(peer)) + if (!fastd_peer_is_established(peer)) { + pr_debug(ctx, "received unexpected packet from %P", peer); + + if (fastd_peer_is_temporary(peer)) { + pr_debug(ctx, "sending handshake to temporary peer %P", peer); + fastd_task_schedule_handshake(ctx, peer, 0); + } + goto end; + } if (buffer.len < NONCEBYTES) goto end; if (!peer->protocol_state || !is_session_valid(ctx, &peer->protocol_state->session)) { - pr_debug(ctx, "received unexpected packet from %P", peer); goto end; } @@ -644,7 +656,7 @@ static void protocol_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buf if (!is_nonce_valid(nonce, session->receive_nonce)) { pr_debug(ctx, "received packet with invalid nonce from %P", peer); - + fastd_buffer_free(recv_buffer); goto end; } -- cgit v1.2.3