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 | |
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')
-rw-r--r-- | testing/DHT_test.c | 46 | ||||
-rw-r--r-- | testing/Messenger_test.c | 13 |
2 files changed, 46 insertions, 13 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]; |
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 @@ | |||
7 | * If it recieves a message from a friend it replies back. | 7 | * If it recieves a message from a friend it replies back. |
8 | * | 8 | * |
9 | * | 9 | * |
10 | * 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 | 10 | * 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 |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * Command line arguments are the ip and port of a node (for bootstrapping). | 13 | * 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) | |||
77 | 77 | ||
78 | int main(int argc, char *argv[]) | 78 | int main(int argc, char *argv[]) |
79 | { | 79 | { |
80 | if (argc < 3) { | 80 | if (argc < 4) { |
81 | printf("usage %s ip port (of the DHT bootstrap node)\n", argv[0]); | 81 | printf("usage %s ip port public_key (of the DHT bootstrap node)\n", argv[0]); |
82 | exit(0); | 82 | exit(0); |
83 | } | 83 | } |
84 | initMessenger(); | 84 | initMessenger(); |
@@ -96,14 +96,17 @@ int main(int argc, char *argv[]) | |||
96 | 96 | ||
97 | char temp_id[128]; | 97 | char temp_id[128]; |
98 | printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); | 98 | printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); |
99 | scanf("%s", temp_id); | 99 | if(scanf("%s", temp_id) != 1) |
100 | { | ||
101 | return 1; | ||
102 | } | ||
100 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 103 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
101 | 104 | ||
102 | perror("Initialization"); | 105 | perror("Initialization"); |
103 | IP_Port bootstrap_ip_port; | 106 | IP_Port bootstrap_ip_port; |
104 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 107 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
105 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); | 108 | bootstrap_ip_port.ip.i = inet_addr(argv[1]); |
106 | DHT_bootstrap(bootstrap_ip_port); | 109 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
107 | 110 | ||
108 | while(1) | 111 | while(1) |
109 | { | 112 | { |