From 1bb59bad98c1218dfa2e5108c34644c954e1688a Mon Sep 17 00:00:00 2001 From: Evgeny Date: Fri, 6 Feb 2026 22:21:21 +0300 Subject: [PATCH] Fix: Isolate test configs and add key validation retry --- src/secure_channel.c | 17 ++++++++++++++--- test_etcp_100_packets_client.conf | 15 +++++++++++++++ test_etcp_100_packets_server.conf | 10 ++++++++++ test_etcp_simple_traffic_client.conf | 15 +++++++++++++++ test_etcp_simple_traffic_server.conf | 10 ++++++++++ test_etcp_two_instances_client.conf | 15 +++++++++++++++ test_etcp_two_instances_server.conf | 10 ++++++++++ test_pkt_normalizer_etcp_client.conf | 15 +++++++++++++++ test_pkt_normalizer_etcp_server.conf | 10 ++++++++++ tests/test_client.conf | 2 +- tests/test_etcp_100_packets.c | 4 ++-- tests/test_etcp_100_packets_client.conf | 15 +++++++++++++++ tests/test_etcp_100_packets_server.conf | 10 ++++++++++ tests/test_etcp_simple_traffic.c | 9 +++++++-- tests/test_etcp_simple_traffic_client.conf | 15 +++++++++++++++ tests/test_etcp_simple_traffic_server.conf | 10 ++++++++++ tests/test_etcp_two_instances.c | 4 ++-- tests/test_etcp_two_instances_client.conf | 15 +++++++++++++++ tests/test_etcp_two_instances_server.conf | 10 ++++++++++ tests/test_pkt_normalizer_etcp.c | 4 ++-- tests/test_pkt_normalizer_etcp_client.conf | 15 +++++++++++++++ tests/test_pkt_normalizer_etcp_server.conf | 10 ++++++++++ tests/test_server.conf | 7 ++++++- 23 files changed, 234 insertions(+), 13 deletions(-) create mode 100644 test_etcp_100_packets_client.conf create mode 100644 test_etcp_100_packets_server.conf create mode 100644 test_etcp_simple_traffic_client.conf create mode 100644 test_etcp_simple_traffic_server.conf create mode 100644 test_etcp_two_instances_client.conf create mode 100644 test_etcp_two_instances_server.conf create mode 100644 test_pkt_normalizer_etcp_client.conf create mode 100644 test_pkt_normalizer_etcp_server.conf create mode 100644 tests/test_etcp_100_packets_client.conf create mode 100644 tests/test_etcp_100_packets_server.conf create mode 100644 tests/test_etcp_simple_traffic_client.conf create mode 100644 tests/test_etcp_simple_traffic_server.conf create mode 100644 tests/test_etcp_two_instances_client.conf create mode 100644 tests/test_etcp_two_instances_server.conf create mode 100644 tests/test_pkt_normalizer_etcp_client.conf create mode 100644 tests/test_pkt_normalizer_etcp_server.conf diff --git a/src/secure_channel.c b/src/secure_channel.c index f40a830e..eb80b485 100644 --- a/src/secure_channel.c +++ b/src/secure_channel.c @@ -527,10 +527,21 @@ sc_status_t sc_generate_keypair(struct SC_MYKEYS *pk) /* Set custom RNG function */ uECC_set_rng(sc_rng); - if (!uECC_make_key(pk->public_key, pk->private_key, curve)) { - return SC_ERR_CRYPTO; + /* Try to generate valid key pair (max 10 attempts) */ + for (int attempt = 0; attempt < 10; attempt++) { + if (!uECC_make_key(pk->public_key, pk->private_key, curve)) { + continue; + } + /* Validate generated public key immediately */ + if (sc_validate_key(pk->public_key) == 0) { + DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_generate_keypair: generated valid keypair on attempt %d", attempt + 1); + return SC_OK; + } + DEBUG_WARN(DEBUG_CATEGORY_CRYPTO, "sc_generate_keypair: generated invalid key on attempt %d, retrying...", attempt + 1); } - return SC_OK; + + DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_generate_keypair: failed to generate valid keypair after 10 attempts"); + return SC_ERR_CRYPTO; } sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key, const char *private_key) { diff --git a/test_etcp_100_packets_client.conf b/test_etcp_100_packets_client.conf new file mode 100644 index 00000000..c0d5c085 --- /dev/null +++ b/test_etcp_100_packets_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9022 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9021 diff --git a/test_etcp_100_packets_server.conf b/test_etcp_100_packets_server.conf new file mode 100644 index 00000000..6f66187c --- /dev/null +++ b/test_etcp_100_packets_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9021 +type=public diff --git a/test_etcp_simple_traffic_client.conf b/test_etcp_simple_traffic_client.conf new file mode 100644 index 00000000..18ada253 --- /dev/null +++ b/test_etcp_simple_traffic_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9002 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9001 diff --git a/test_etcp_simple_traffic_server.conf b/test_etcp_simple_traffic_server.conf new file mode 100644 index 00000000..943bb59b --- /dev/null +++ b/test_etcp_simple_traffic_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9001 +type=public diff --git a/test_etcp_two_instances_client.conf b/test_etcp_two_instances_client.conf new file mode 100644 index 00000000..abdfaf27 --- /dev/null +++ b/test_etcp_two_instances_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9012 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9011 diff --git a/test_etcp_two_instances_server.conf b/test_etcp_two_instances_server.conf new file mode 100644 index 00000000..8dd922b7 --- /dev/null +++ b/test_etcp_two_instances_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9011 +type=public diff --git a/test_pkt_normalizer_etcp_client.conf b/test_pkt_normalizer_etcp_client.conf new file mode 100644 index 00000000..ffd17add --- /dev/null +++ b/test_pkt_normalizer_etcp_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9032 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9031 diff --git a/test_pkt_normalizer_etcp_server.conf b/test_pkt_normalizer_etcp_server.conf new file mode 100644 index 00000000..91d3d9a0 --- /dev/null +++ b/test_pkt_normalizer_etcp_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9031 +type=public diff --git a/tests/test_client.conf b/tests/test_client.conf index 068bf703..18ada253 100644 --- a/tests/test_client.conf +++ b/tests/test_client.conf @@ -12,4 +12,4 @@ type=public [client: test_client] keepalive=1 peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 -link=test:127.0.0.1:9001 \ No newline at end of file +link=test:127.0.0.1:9001 diff --git a/tests/test_etcp_100_packets.c b/tests/test_etcp_100_packets.c index 6fd36081..d3c6945c 100644 --- a/tests/test_etcp_100_packets.c +++ b/tests/test_etcp_100_packets.c @@ -309,7 +309,7 @@ int main() { printf("Creating server...\n"); ua = uasync_create(); - server_instance = utun_instance_create(ua, "test_server.conf"); + server_instance = utun_instance_create(ua, "test_etcp_100_packets_server.conf"); if (!server_instance || init_connections(server_instance) < 0) { printf("Failed to create server\n"); return 1; @@ -317,7 +317,7 @@ int main() { printf("✅ Server ready\n\n"); printf("Creating client...\n"); - client_instance = utun_instance_create(ua, "test_client.conf"); + client_instance = utun_instance_create(ua, "test_etcp_100_packets_client.conf"); if (!client_instance || init_connections(client_instance) < 0) { printf("Failed to create client\n"); return 1; diff --git a/tests/test_etcp_100_packets_client.conf b/tests/test_etcp_100_packets_client.conf new file mode 100644 index 00000000..c0d5c085 --- /dev/null +++ b/tests/test_etcp_100_packets_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9022 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9021 diff --git a/tests/test_etcp_100_packets_server.conf b/tests/test_etcp_100_packets_server.conf new file mode 100644 index 00000000..6f66187c --- /dev/null +++ b/tests/test_etcp_100_packets_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9021 +type=public diff --git a/tests/test_etcp_simple_traffic.c b/tests/test_etcp_simple_traffic.c index da5443dc..10582cfe 100644 --- a/tests/test_etcp_simple_traffic.c +++ b/tests/test_etcp_simple_traffic.c @@ -287,7 +287,7 @@ int main() { // Create server instance printf("Creating server instance...\n"); ua = uasync_create(); - server_instance = utun_instance_create(ua, "test_server.conf"); + server_instance = utun_instance_create(ua, "test_etcp_simple_traffic_server.conf"); if (!server_instance) { printf("Failed to create server instance\n"); return 1; @@ -315,7 +315,7 @@ int main() { // Create client instance printf("Creating client instance...\n"); - client_instance = utun_instance_create(ua, "test_client.conf"); + client_instance = utun_instance_create(ua, "test_etcp_simple_traffic_client.conf"); if (!client_instance) { printf("Failed to create client instance\n"); utun_instance_destroy(server_instance); @@ -407,6 +407,11 @@ int main() { check_packet_received(); } + // If packet was received via direct check, mark test as completed + if (packet_received && !test_completed) { + test_completed = 1; + } + // Quick exit if packet received if (test_completed == 1) { printf("[TEST] Packet received, exiting early after %d ms\n", elapsed); diff --git a/tests/test_etcp_simple_traffic_client.conf b/tests/test_etcp_simple_traffic_client.conf new file mode 100644 index 00000000..18ada253 --- /dev/null +++ b/tests/test_etcp_simple_traffic_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9002 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9001 diff --git a/tests/test_etcp_simple_traffic_server.conf b/tests/test_etcp_simple_traffic_server.conf new file mode 100644 index 00000000..943bb59b --- /dev/null +++ b/tests/test_etcp_simple_traffic_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9001 +type=public diff --git a/tests/test_etcp_two_instances.c b/tests/test_etcp_two_instances.c index 5cfe589a..eb8e521c 100644 --- a/tests/test_etcp_two_instances.c +++ b/tests/test_etcp_two_instances.c @@ -131,7 +131,7 @@ int main() { // Create server instance DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Creating server instance..."); ua = uasync_create(); - server_instance = utun_instance_create(ua, "test_server.conf"); + server_instance = utun_instance_create(ua, "test_etcp_two_instances_server.conf"); if (!server_instance) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to create server instance"); return 1; @@ -166,7 +166,7 @@ int main() { // Create client instance DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Creating client instance..."); - client_instance = utun_instance_create(ua, "test_client.conf"); + client_instance = utun_instance_create(ua, "test_etcp_two_instances_client.conf"); if (!client_instance) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to create client instance"); utun_instance_destroy(server_instance); diff --git a/tests/test_etcp_two_instances_client.conf b/tests/test_etcp_two_instances_client.conf new file mode 100644 index 00000000..abdfaf27 --- /dev/null +++ b/tests/test_etcp_two_instances_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9012 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9011 diff --git a/tests/test_etcp_two_instances_server.conf b/tests/test_etcp_two_instances_server.conf new file mode 100644 index 00000000..8dd922b7 --- /dev/null +++ b/tests/test_etcp_two_instances_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9011 +type=public diff --git a/tests/test_pkt_normalizer_etcp.c b/tests/test_pkt_normalizer_etcp.c index 06b04f06..6ae6f403 100644 --- a/tests/test_pkt_normalizer_etcp.c +++ b/tests/test_pkt_normalizer_etcp.c @@ -440,7 +440,7 @@ int main() { printf("Creating server...\n"); ua = uasync_create(); - server_instance = utun_instance_create(ua, "test_server.conf"); + server_instance = utun_instance_create(ua, "test_pkt_normalizer_etcp_server.conf"); if (!server_instance || init_connections(server_instance) < 0) { printf("Failed to create server\n"); return 1; @@ -448,7 +448,7 @@ int main() { printf("Server created, waiting for connection...\n\n"); printf("Creating client...\n"); - client_instance = utun_instance_create(ua, "test_client.conf"); + client_instance = utun_instance_create(ua, "test_pkt_normalizer_etcp_client.conf"); if (!client_instance || init_connections(client_instance) < 0) { printf("Failed to create client\n"); return 1; diff --git a/tests/test_pkt_normalizer_etcp_client.conf b/tests/test_pkt_normalizer_etcp_client.conf new file mode 100644 index 00000000..ffd17add --- /dev/null +++ b/tests/test_pkt_normalizer_etcp_client.conf @@ -0,0 +1,15 @@ +[global] +my_node_id=0x2222222222222222 +my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2 +my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +tun_ip=10.99.0.2/24 +tun_ifname=tun98 + +[server: test] +addr=127.0.0.1:9032 +type=public + +[client: test_client] +keepalive=1 +peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +link=test:127.0.0.1:9031 diff --git a/tests/test_pkt_normalizer_etcp_server.conf b/tests/test_pkt_normalizer_etcp_server.conf new file mode 100644 index 00000000..91d3d9a0 --- /dev/null +++ b/tests/test_pkt_normalizer_etcp_server.conf @@ -0,0 +1,10 @@ +[global] +my_node_id=0x1111111111111111 +my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb +my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9 +tun_ip=10.99.0.1/24 +tun_ifname=tun99 + +[server: test] +addr=127.0.0.1:9031 +type=public diff --git a/tests/test_server.conf b/tests/test_server.conf index f1e42943..f58740c5 100644 --- a/tests/test_server.conf +++ b/tests/test_server.conf @@ -5,6 +5,11 @@ my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c6 tun_ip=10.99.0.1/24 tun_ifname=tun99 -[server: test] +[server: test] addr=127.0.0.1:9001 type=public + +[client: test_client] +keepalive=1 +peer_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71 +link=test:127.0.0.1:9002