From 5ccd47dd17ab7ef6d8b4e57503b292482a09d723 Mon Sep 17 00:00:00 2001 From: evgeny Date: Fri, 23 Oct 2026 23:17:25 +0200 Subject: [PATCH] Bind incoming UDP INIT identity to the authenticated key --- src/transport_layer/etcp_connections.c | 6 ++++++ src/transport_layer/etcp_connections.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/transport_layer/etcp_connections.c b/src/transport_layer/etcp_connections.c index 5e5315b8..e41d22ab 100644 --- a/src/transport_layer/etcp_connections.c +++ b/src/transport_layer/etcp_connections.c @@ -2441,6 +2441,12 @@ static void etcp_process_packet(struct ETCP_SOCKET* e_sock, uint8_t* data, struct ETCP_INIT_REQUEST_PKT* req = (struct ETCP_INIT_REQUEST_PKT*)pkt->data; peer_id = wire_read64(req->node_id); + uint64_t authenticated_id = sc_derive_node_id_from_pubkey(sc.peer_public_key); + if (peer_id != authenticated_id) { + DEBUG_WARN(DEBUG_CATEGORY_ETCP, "INIT sender ID mismatch: claimed=%016llx authenticated=%016llx from=%s", + (unsigned long long)peer_id, (unsigned long long)authenticated_id, sockaddr_storage_to_str(&addr).str); + errorcode = 7; goto ec_fr; + } uint64_t reset_id = wire_read64(req->reset_id); uint16_t mtu = wire_read16(req->mtu); uint16_t src_port = wire_read16(req->src_port); diff --git a/src/transport_layer/etcp_connections.h b/src/transport_layer/etcp_connections.h index ccf08c1f..15c3c89b 100644 --- a/src/transport_layer/etcp_connections.h +++ b/src/transport_layer/etcp_connections.h @@ -94,7 +94,7 @@ static inline unsigned etcp_ack_section_size(uint8_t count) { // INIT внутри шифрованного тела, до padding: запрос — 67 байт, ответ — 64 байта. // Каждая сторона передаёт свою эпоху reset_id; смена известной эпохи подтверждается через etcp_session. -// INIT REQUEST: client → server. Проверить всё 67-байтовое тело до чтения полей и изменения транспорта; padding допустим. +// INIT REQUEST: client → server. До изменения транспорта проверить 67-байтовое тело и node_id по X25519-ключу; padding допустим. struct ETCP_INIT_REQUEST_PKT { uint8_t code; // 0: ETCP_INIT_REQUEST (0x02) или ETCP_INIT_REQUEST_NOINIT (0x04) uint8_t node_id[8]; // 1: sender node_id (big-endian)