diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-12 16:27:19 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-12 16:27:19 -0400 |
commit | 79aa715514e7d587695ce0182fdf97537d9d9b85 (patch) | |
tree | 213a0566099fadd3b49f9e11cbb4c70053999360 /testing/DHT_test.c | |
parent | e830861a9d96f4a8e8ea203e24cfe431f7960c04 (diff) |
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)
Diffstat (limited to 'testing/DHT_test.c')
-rw-r--r-- | testing/DHT_test.c | 46 |
1 files changed, 38 insertions, 8 deletions
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 @@ | |||
3 | * | 3 | * |
4 | * Compile with: gcc -O2 -Wall -o test ../core/network.c DHT_test.c | 4 | * Compile with: gcc -O2 -Wall -o test ../core/network.c DHT_test.c |
5 | * | 5 | * |
6 | * 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 | 6 | * Command line arguments are the ip, port and public key of a node. |
7 | * EX: ./test 127.0.0.1 33445 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef | 7 | * EX: ./test 127.0.0.1 33445 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
8 | * | ||
9 | * The test will then ask you for the id (in hex format) of the friend you wish to add | ||
8 | */ | 10 | */ |
9 | #include "../core/network.h" | 11 | //#include "../core/network.h" |
10 | #include "../core/DHT.c" | 12 | #include "../core/DHT.c" |
11 | 13 | ||
12 | #include <string.h> | 14 | #include <string.h> |
@@ -94,15 +96,44 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | |||
94 | printf("\n--------------------END-----------------------------\n\n\n"); | 96 | printf("\n--------------------END-----------------------------\n\n\n"); |
95 | } | 97 | } |
96 | 98 | ||
99 | //horrible function from one of my first C programs. | ||
100 | //only here because I was too lazy to write a proper one. | ||
101 | unsigned char * hex_string_to_bin(char hex_string[]) | ||
102 | { | ||
103 | unsigned char * val = malloc(strlen(hex_string)); | ||
104 | char * pos = hex_string; | ||
105 | int i=0; | ||
106 | while(i < strlen(hex_string)) | ||
107 | { | ||
108 | sscanf(pos,"%2hhx",&val[i]); | ||
109 | pos+=2; | ||
110 | i++; | ||
111 | } | ||
112 | return val; | ||
113 | } | ||
114 | |||
97 | int main(int argc, char *argv[]) | 115 | int main(int argc, char *argv[]) |
98 | { | 116 | { |
99 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); | 117 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); |
100 | 118 | ||
101 | if (argc < 4) { | 119 | if (argc < 4) { |
102 | printf("usage %s ip port client_id(of friend to find ip_port of)\n", argv[0]); | 120 | printf("usage %s ip port public_key\n", argv[0]); |
103 | exit(0); | 121 | exit(0); |
104 | } | 122 | } |
105 | DHT_addfriend((uint8_t *)argv[3]); | 123 | new_keys(); |
124 | printf("OUR ID: "); | ||
125 | uint32_t i; | ||
126 | for(i = 0; i < 32; i++) | ||
127 | { | ||
128 | if(self_public_key[i] < 16) | ||
129 | printf("0"); | ||
130 | printf("%hhX",self_public_key[i]); | ||
131 | } | ||
132 | |||
133 | char temp_id[128]; | ||
134 | printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); | ||
135 | scanf("%s", temp_id); | ||
136 | DHT_addfriend(hex_string_to_bin(temp_id)); | ||
106 | 137 | ||
107 | //initialize networking | 138 | //initialize networking |
108 | //bind to ip 0.0.0.0:PORT | 139 | //bind to ip 0.0.0.0:PORT |
@@ -110,8 +141,7 @@ int main(int argc, char *argv[]) | |||
110 | ip.i = 0; | 141 | ip.i = 0; |
111 | init_networking(ip, PORT); | 142 | init_networking(ip, PORT); |
112 | 143 | ||
113 | int randdomnum = random_int(); | 144 | |
114 | memcpy(self_client_id, &randdomnum, 4); | ||
115 | 145 | ||
116 | 146 | ||
117 | perror("Initialization"); | 147 | perror("Initialization"); |
@@ -122,7 +152,7 @@ int main(int argc, char *argv[]) | |||
122 | //bootstrap_ip_port.ip.c[2] = 0; | 152 | //bootstrap_ip_port.ip.c[2] = 0; |
123 | //bootstrap_ip_port.ip.c[3] = 1; | 153 | //bootstrap_ip_port.ip.c[3] = 1; |
124 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | 154 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); |
125 | DHT_bootstrap(bootstrap_ip_port); | 155 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
126 | 156 | ||
127 | IP_Port ip_port; | 157 | IP_Port ip_port; |
128 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 158 | uint8_t data[MAX_UDP_PACKET_SIZE]; |