From 79aa715514e7d587695ce0182fdf97537d9d9b85 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 12 Jul 2013 16:27:19 -0400 Subject: First part of DHT hardening done. Added crypto to the DHT communications. This defeats completely the first attack mentioned in docs/DHT_hardening. Also updated the build system to build the latest test (it links it with libsodium) --- testing/DHT_test.c | 46 ++++++++++++++++++++++++++++++++++++++-------- testing/Messenger_test.c | 13 ++++++++----- 2 files changed, 46 insertions(+), 13 deletions(-) (limited to 'testing') diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 38ca4992..083e4d4b 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -3,10 +3,12 @@ * * Compile with: gcc -O2 -Wall -o test ../core/network.c DHT_test.c * - * Command line arguments are the ip and port of a node and the client_id (32 bytes) of the friend you want to find the ip_port of - * EX: ./test 127.0.0.1 33445 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef + * Command line arguments are the ip, port and public key of a node. + * EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + * + * The test will then ask you for the id (in hex format) of the friend you wish to add */ -#include "../core/network.h" +//#include "../core/network.h" #include "../core/DHT.c" #include @@ -94,15 +96,44 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) printf("\n--------------------END-----------------------------\n\n\n"); } +//horrible function from one of my first C programs. +//only here because I was too lazy to write a proper one. +unsigned char * hex_string_to_bin(char hex_string[]) +{ + unsigned char * val = malloc(strlen(hex_string)); + char * pos = hex_string; + int i=0; + while(i < strlen(hex_string)) + { + sscanf(pos,"%2hhx",&val[i]); + pos+=2; + i++; + } + return val; +} + int main(int argc, char *argv[]) { //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); if (argc < 4) { - printf("usage %s ip port client_id(of friend to find ip_port of)\n", argv[0]); + printf("usage %s ip port public_key\n", argv[0]); exit(0); } - DHT_addfriend((uint8_t *)argv[3]); + new_keys(); + printf("OUR ID: "); + uint32_t i; + for(i = 0; i < 32; i++) + { + if(self_public_key[i] < 16) + printf("0"); + printf("%hhX",self_public_key[i]); + } + + char temp_id[128]; + printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); + scanf("%s", temp_id); + DHT_addfriend(hex_string_to_bin(temp_id)); //initialize networking //bind to ip 0.0.0.0:PORT @@ -110,8 +141,7 @@ int main(int argc, char *argv[]) ip.i = 0; init_networking(ip, PORT); - int randdomnum = random_int(); - memcpy(self_client_id, &randdomnum, 4); + perror("Initialization"); @@ -122,7 +152,7 @@ int main(int argc, char *argv[]) //bootstrap_ip_port.ip.c[2] = 0; //bootstrap_ip_port.ip.c[3] = 1; bootstrap_ip_port.ip.i = inet_addr(argv[1]); - DHT_bootstrap(bootstrap_ip_port); + DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); IP_Port ip_port; uint8_t data[MAX_UDP_PACKET_SIZE]; diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 6b0e56fc..c049aa18 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -7,7 +7,7 @@ * If it recieves a message from a friend it replies back. * * - * This is how I compile it: gcc -O2 -Wall -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/DHT.c ../core/Messenger.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/* Messenger_test.c + * This is how I compile it: gcc -O2 -Wall -D VANILLA_NACL -o test ../core/Lossless_UDP.c ../core/network.c ../core/net_crypto.c ../core/Messenger.c ../core/DHT.c ../nacl/build/${HOSTNAME%.*}/lib/amd64/{cpucycles.o,libnacl.a,randombytes.o} Messenger_test.c * * * Command line arguments are the ip and port of a node (for bootstrapping). @@ -77,8 +77,8 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) int main(int argc, char *argv[]) { - if (argc < 3) { - printf("usage %s ip port (of the DHT bootstrap node)\n", argv[0]); + if (argc < 4) { + printf("usage %s ip port public_key (of the DHT bootstrap node)\n", argv[0]); exit(0); } initMessenger(); @@ -96,14 +96,17 @@ int main(int argc, char *argv[]) char temp_id[128]; printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); - scanf("%s", temp_id); + if(scanf("%s", temp_id) != 1) + { + return 1; + } int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); perror("Initialization"); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); bootstrap_ip_port.ip.i = inet_addr(argv[1]); - DHT_bootstrap(bootstrap_ip_port); + DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); while(1) { -- cgit v1.2.3