From 2ce891748d3b379232ad09b45159a82d1571fe28 Mon Sep 17 00:00:00 2001 From: Logan007 Date: Tue, 16 Jun 2020 23:46:52 +0545 Subject: [PATCH] new communities have no header encryption --- sn.c | 11 ++++++++++- sn_utils.c | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sn.c b/sn.c index 8c01a7b..60549e3 100644 --- a/sn.c +++ b/sn.c @@ -19,6 +19,7 @@ /* Supernode for n2n-2.x */ #include "n2n.h" +#include "header_encryption.h" #ifdef WIN32 #include @@ -435,13 +436,14 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) { */ static int process_udp(n2n_sn_t * sss, const struct sockaddr_in * sender_sock, - const uint8_t * udp_buf, + uint8_t * udp_buf, size_t udp_size, time_t now) { n2n_common_t cmn; /* common fields in the packet header */ size_t rem; size_t idx; + int8_t he = HEADER_ENCRYPTION_UNKNOWN; size_t msg_type; uint8_t from_supernode; macstr_t mac_buf; @@ -453,6 +455,10 @@ static int process_udp(n2n_sn_t * sss, udp_size, intoa(ntohl(sender_sock->sin_addr.s_addr), buf, sizeof(buf)), ntohs(sender_sock->sin_port)); + he = packet_header_decrypt_if_required (udp_buf, udp_size, sss->communities); + if (he < 0) + return -1; /* something wrong during packet decryption */ + /* Use decode_common() to determine the kind of packet then process it: * * REGISTER_SUPER adds an edge and generate a return REGISTER_SUPER_ACK @@ -622,6 +628,9 @@ static int process_udp(n2n_sn_t * sss, if(comm) { strncpy(comm->community, (char*)cmn.community, N2N_COMMUNITY_SIZE-1); comm->community[N2N_COMMUNITY_SIZE-1] = '\0'; + /* new communities introduced by REGISTERs could not have had encrypted header */ + comm->header_encryption = HEADER_ENCRYPTION_NONE; + HASH_ADD_STR(sss->communities, community, comm); traceEvent(TRACE_INFO, "New community: %s", comm->community); diff --git a/sn_utils.c b/sn_utils.c index b38e045..51742f7 100644 --- a/sn_utils.c +++ b/sn_utils.c @@ -394,7 +394,7 @@ static int process_udp(n2n_sn_t *sss, he = packet_header_decrypt_if_required (udp_buf, udp_size, sss->communities); if (he < 0) - return -1; /* something wrong with packet decryption */ + return -1; /* something wrong during packet decryption */ /* Use decode_common() to determine the kind of packet then process it: * @@ -577,6 +577,9 @@ static int process_udp(n2n_sn_t *sss, { strncpy(comm->community, (char *)cmn.community, N2N_COMMUNITY_SIZE - 1); comm->community[N2N_COMMUNITY_SIZE - 1] = '\0'; + /* new communities introduced by REGISTERs could not have had encrypted header */ + comm->header_encryption = HEADER_ENCRYPTION_NONE; + HASH_ADD_STR(sss->communities, community, comm); traceEvent(TRACE_INFO, "New community: %s", comm->community);