summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/handshake.c11
-rw-r--r--src/handshake.h1
-rw-r--r--src/protocol_ec25519_fhmqvc.c15
3 files changed, 14 insertions, 13 deletions
diff --git a/src/handshake.c b/src/handshake.c
index dedb482..28abfc2 100644
--- a/src/handshake.c
+++ b/src/handshake.c
@@ -334,6 +334,9 @@ static inline const fastd_method_t* get_method(fastd_context_t *ctx, const fastd
}
void fastd_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, fastd_buffer_t buffer) {
+ char *peer_version = NULL;
+ const fastd_method_t *method = NULL;
+
fastd_handshake_t handshake = parse_tlvs(&buffer);
if (!handshake.tlv_data) {
@@ -351,7 +354,12 @@ void fastd_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fa
if (!check_records(ctx, sock, local_addr, remote_addr, peer, &handshake))
goto end_free;
- const fastd_method_t *method = get_method(ctx, &handshake);
+ if (!ctx->conf->secure_handshakes || handshake.type > 1) {
+ method = get_method(ctx, &handshake);
+
+ if (handshake.records[RECORD_VERSION_NAME].data)
+ handshake.peer_version = peer_version = strndup((const char*)handshake.records[RECORD_VERSION_NAME].data, handshake.records[RECORD_VERSION_NAME].length);
+ }
if (handshake.type > 1 && !method) {
send_error(ctx, sock, local_addr, remote_addr, peer, &handshake, REPLY_UNACCEPTABLE_VALUE, RECORD_METHOD_NAME);
@@ -361,5 +369,6 @@ void fastd_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fa
ctx->conf->protocol->handshake_handle(ctx, sock, local_addr, remote_addr, peer, &handshake, method);
end_free:
+ free(peer_version);
fastd_buffer_free(buffer);
}
diff --git a/src/handshake.h b/src/handshake.h
index ea4ec73..0faccba 100644
--- a/src/handshake.h
+++ b/src/handshake.h
@@ -71,6 +71,7 @@ typedef struct fastd_handshake_record {
struct fastd_handshake {
uint8_t type;
+ const char *peer_version;
fastd_handshake_record_t records[RECORD_MAX];
uint16_t tlv_len;
void *tlv_data;
diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c
index ce429dc..b7b5162 100644
--- a/src/protocol_ec25519_fhmqvc.c
+++ b/src/protocol_ec25519_fhmqvc.c
@@ -670,7 +670,6 @@ static inline keypair_t* get_handshake_keypair(handshake_key_t *handshake_key, u
}
static void protocol_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, const fastd_handshake_t *handshake, const fastd_method_t *method) {
- char *peer_version_name = NULL;
bool temporary_added = false;
maintenance(ctx);
@@ -740,11 +739,7 @@ static void protocol_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock
return;
}
- if (handshake->records[RECORD_VERSION_NAME].data)
- peer_version_name = strndup((const char*)handshake->records[RECORD_VERSION_NAME].data, handshake->records[RECORD_VERSION_NAME].length);
-
- pr_verbose(ctx, "received handshake from %P[%I] using fastd %s", peer, remote_addr, peer_version_name);
- free(peer_version_name);
+ pr_verbose(ctx, "received handshake from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
peer->last_handshake_response = ctx->now;
peer->last_handshake_response_address = *remote_addr;
@@ -785,17 +780,13 @@ static void protocol_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock
switch (handshake->type) {
case 2:
- if (handshake->records[RECORD_VERSION_NAME].data)
- peer_version_name = strndup((const char*)handshake->records[RECORD_VERSION_NAME].data, handshake->records[RECORD_VERSION_NAME].length);
-
- pr_verbose(ctx, "received handshake response from %P[%I] using fastd %s", peer, remote_addr, peer_version_name);
- free(peer_version_name);
+ pr_verbose(ctx, "received handshake response from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
finish_handshake(ctx, sock, local_addr, remote_addr, peer, handshake_key, &peer_handshake_key, handshake, method);
break;
case 3:
- pr_debug(ctx, "received handshake finish from %P[%I]", peer, remote_addr);
+ pr_debug(ctx, "received handshake finish from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: "");
handle_finish_handshake(ctx, sock, local_addr, remote_addr, peer, handshake_key, &peer_handshake_key, handshake, method);
break;