diff options
-rw-r--r-- | auto_tests/onion_test.c | 34 | ||||
-rw-r--r-- | other/DHT_bootstrap.c | 23 | ||||
-rw-r--r-- | testing/DHT_test.c | 6 | ||||
-rw-r--r-- | toxcore/DHT.h | 4 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 3 | ||||
-rw-r--r-- | toxcore/onion_announce.c | 2 | ||||
-rw-r--r-- | toxcore/onion_client.c | 4 |
7 files changed, 35 insertions, 41 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index cd060b1f..b8145cc2 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -80,7 +80,7 @@ static int handle_test_3(void *object, IP_Port source, uint8_t *packet, uint32_t | |||
80 | 80 | ||
81 | uint8_t plain[1 + crypto_hash_sha256_BYTES]; | 81 | uint8_t plain[1 + crypto_hash_sha256_BYTES]; |
82 | //print_client_id(packet, length); | 82 | //print_client_id(packet, length); |
83 | int len = decrypt_data(test_3_pub_key, onion->dht->c->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | 83 | int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, |
84 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, | 84 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, |
85 | 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); | 85 | 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); |
86 | 86 | ||
@@ -111,7 +111,7 @@ static int handle_test_4(void *object, IP_Port source, uint8_t *packet, uint32_t | |||
111 | if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) | 111 | if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) |
112 | return 1; | 112 | return 1; |
113 | 113 | ||
114 | int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->c->self_secret_key, packet + 1, | 114 | int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1, |
115 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); | 115 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); |
116 | 116 | ||
117 | if (len == -1) | 117 | if (len == -1) |
@@ -129,8 +129,8 @@ START_TEST(test_basic) | |||
129 | IP ip; | 129 | IP ip; |
130 | ip_init(&ip, 1); | 130 | ip_init(&ip, 1); |
131 | ip.ip6.uint8[15] = 1; | 131 | ip.ip6.uint8[15] = 1; |
132 | Onion *onion1 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34567)))); | 132 | Onion *onion1 = new_onion(new_DHT(new_networking(ip, 34567))); |
133 | Onion *onion2 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34568)))); | 133 | Onion *onion2 = new_onion(new_DHT(new_networking(ip, 34568))); |
134 | ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing."); | 134 | ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing."); |
135 | networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2); | 135 | networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2); |
136 | 136 | ||
@@ -177,9 +177,9 @@ START_TEST(test_basic) | |||
177 | uint8_t zeroes[64] = {0}; | 177 | uint8_t zeroes[64] = {0}; |
178 | randombytes(sb_data, sizeof(sb_data)); | 178 | randombytes(sb_data, sizeof(sb_data)); |
179 | memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES); | 179 | memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES); |
180 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->c->self_public_key, | 180 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, |
181 | onion1->dht->c->self_secret_key, | 181 | onion1->dht->self_secret_key, |
182 | zeroes, onion1->dht->c->self_public_key, onion1->dht->c->self_public_key, sb_data); | 182 | zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, sb_data); |
183 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); | 183 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); |
184 | handled_test_3 = 0; | 184 | handled_test_3 = 0; |
185 | 185 | ||
@@ -193,10 +193,10 @@ START_TEST(test_basic) | |||
193 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 193 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); |
194 | onion2_a->entries[1].time = unix_time(); | 194 | onion2_a->entries[1].time = unix_time(); |
195 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); | 195 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); |
196 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, | 196 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, |
197 | test_3_ping_id, onion1->dht->c->self_public_key, onion1->dht->c->self_public_key, sb_data); | 197 | test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, sb_data); |
198 | 198 | ||
199 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->c->self_public_key, | 199 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key, |
200 | crypto_box_PUBLICKEYBYTES) != 0) { | 200 | crypto_box_PUBLICKEYBYTES) != 0) { |
201 | do_onion(onion1); | 201 | do_onion(onion1); |
202 | do_onion(onion2); | 202 | do_onion(onion2); |
@@ -204,12 +204,12 @@ START_TEST(test_basic) | |||
204 | } | 204 | } |
205 | 205 | ||
206 | c_sleep(1000); | 206 | c_sleep(1000); |
207 | Onion *onion3 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34569)))); | 207 | Onion *onion3 = new_onion(new_DHT(new_networking(ip, 34569))); |
208 | ck_assert_msg((onion3 != NULL), "Onion failed initializing."); | 208 | ck_assert_msg((onion3 != NULL), "Onion failed initializing."); |
209 | 209 | ||
210 | new_nonce(nonce); | 210 | new_nonce(nonce); |
211 | ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->c->self_public_key, | 211 | ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, |
212 | onion1->dht->c->self_public_key, | 212 | onion1->dht->self_public_key, |
213 | nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); | 213 | nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); |
214 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); | 214 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); |
215 | handled_test_4 = 0; | 215 | handled_test_4 = 0; |
@@ -234,10 +234,10 @@ Onions *new_onions(uint16_t port) | |||
234 | ip_init(&ip, 1); | 234 | ip_init(&ip, 1); |
235 | ip.ip6.uint8[15] = 1; | 235 | ip.ip6.uint8[15] = 1; |
236 | Onions *on = malloc(sizeof(Onions)); | 236 | Onions *on = malloc(sizeof(Onions)); |
237 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); | 237 | DHT *dht = new_DHT(new_networking(ip, port)); |
238 | on->onion = new_onion(dht); | 238 | on->onion = new_onion(dht); |
239 | on->onion_a = new_onion_announce(dht); | 239 | on->onion_a = new_onion_announce(dht); |
240 | on->onion_c = new_onion_client(dht); | 240 | on->onion_c = new_onion_client(new_net_crypto(dht)); |
241 | 241 | ||
242 | if (on->onion && on->onion_a && on->onion_c) | 242 | if (on->onion && on->onion_a && on->onion_c) |
243 | return on; | 243 | return on; |
@@ -298,8 +298,8 @@ START_TEST(test_announce) | |||
298 | c_sleep(50); | 298 | c_sleep(50); |
299 | } | 299 | } |
300 | 300 | ||
301 | onion_addfriend(onions[7]->onion_c, onions[37]->onion->dht->c->self_public_key); | 301 | onion_addfriend(onions[7]->onion_c, onions[37]->onion_c->c->self_public_key); |
302 | int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion->dht->c->self_public_key); | 302 | int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion_c->c->self_public_key); |
303 | 303 | ||
304 | int ok = -1; | 304 | int ok = -1; |
305 | 305 | ||
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 738c2a0c..462360c3 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -75,11 +75,12 @@ void manage_keys(DHT *dht) | |||
75 | exit(1); | 75 | exit(1); |
76 | } | 76 | } |
77 | 77 | ||
78 | load_keys(dht->c, keys); | 78 | memcpy(dht->self_public_key, keys, crypto_box_PUBLICKEYBYTES); |
79 | memcpy(dht->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); | ||
79 | printf("Keys loaded successfully.\n"); | 80 | printf("Keys loaded successfully.\n"); |
80 | } else { | 81 | } else { |
81 | new_keys(dht->c); | 82 | memcpy(keys, dht->self_public_key, crypto_box_PUBLICKEYBYTES); |
82 | save_keys(dht->c, keys); | 83 | memcpy(keys + crypto_box_PUBLICKEYBYTES, dht->self_secret_key, crypto_box_SECRETKEYBYTES); |
83 | keys_file = fopen("key", "w"); | 84 | keys_file = fopen("key", "w"); |
84 | 85 | ||
85 | if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { | 86 | if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { |
@@ -113,7 +114,7 @@ int main(int argc, char *argv[]) | |||
113 | IP ip; | 114 | IP ip; |
114 | ip_init(&ip, ipv6enabled); | 115 | ip_init(&ip, ipv6enabled); |
115 | 116 | ||
116 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); | 117 | DHT *dht = new_DHT(new_networking(ip, PORT)); |
117 | Onion *onion = new_onion(dht); | 118 | Onion *onion = new_onion(dht); |
118 | Onion_Announce *onion_a = new_onion_announce(dht); | 119 | Onion_Announce *onion_a = new_onion_announce(dht); |
119 | 120 | ||
@@ -129,9 +130,6 @@ int main(int argc, char *argv[]) | |||
129 | perror("Initialization"); | 130 | perror("Initialization"); |
130 | 131 | ||
131 | manage_keys(dht); | 132 | manage_keys(dht); |
132 | /* We want our DHT public key to be the same as our internal one since this is a bootstrap node */ | ||
133 | memcpy(dht->self_public_key, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
134 | memcpy(dht->self_secret_key, dht->c->self_secret_key, crypto_box_SECRETKEYBYTES); | ||
135 | printf("Public key: "); | 133 | printf("Public key: "); |
136 | uint32_t i; | 134 | uint32_t i; |
137 | 135 | ||
@@ -151,17 +149,14 @@ int main(int argc, char *argv[]) | |||
151 | file = fopen("PUBLIC_ID.txt", "w"); | 149 | file = fopen("PUBLIC_ID.txt", "w"); |
152 | 150 | ||
153 | for (i = 0; i < 32; i++) { | 151 | for (i = 0; i < 32; i++) { |
154 | if (dht->c->self_public_key[i] < 16) | 152 | printf("%02hhX", dht->self_public_key[i]); |
155 | printf("0"); | 153 | fprintf(file, "%02hhX", dht->self_public_key[i]); |
156 | |||
157 | printf("%hhX", dht->c->self_public_key[i]); | ||
158 | fprintf(file, "%hhX", dht->c->self_public_key[i]); | ||
159 | } | 154 | } |
160 | 155 | ||
161 | fclose(file); | 156 | fclose(file); |
162 | 157 | ||
163 | printf("\n"); | 158 | printf("\n"); |
164 | printf("Port: %u\n", ntohs(dht->c->lossless_udp->net->port)); | 159 | printf("Port: %u\n", ntohs(dht->net->port)); |
165 | 160 | ||
166 | if (argc > argvoffset + 3) { | 161 | if (argc > argvoffset + 3) { |
167 | printf("Trying to bootstrap into the network...\n"); | 162 | printf("Trying to bootstrap into the network...\n"); |
@@ -198,7 +193,7 @@ int main(int argc, char *argv[]) | |||
198 | #ifdef TCP_RELAY_ENABLED | 193 | #ifdef TCP_RELAY_ENABLED |
199 | do_TCP_server(tcp_s); | 194 | do_TCP_server(tcp_s); |
200 | #endif | 195 | #endif |
201 | networking_poll(dht->c->lossless_udp->net); | 196 | networking_poll(dht->net); |
202 | 197 | ||
203 | c_sleep(1); | 198 | c_sleep(1); |
204 | } | 199 | } |
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 3f8b58bd..2636ed02 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -187,9 +187,7 @@ int main(int argc, char *argv[]) | |||
187 | IP ip; | 187 | IP ip; |
188 | ip_init(&ip, ipv6enabled); | 188 | ip_init(&ip, ipv6enabled); |
189 | 189 | ||
190 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); | 190 | DHT *dht = new_DHT(new_networking(ip, PORT)); |
191 | |||
192 | new_keys(dht->c); | ||
193 | printf("OUR ID: "); | 191 | printf("OUR ID: "); |
194 | uint32_t i; | 192 | uint32_t i; |
195 | 193 | ||
@@ -245,7 +243,7 @@ int main(int argc, char *argv[]) | |||
245 | } | 243 | } |
246 | } | 244 | } |
247 | */ | 245 | */ |
248 | networking_poll(dht->c->lossless_udp->net); | 246 | networking_poll(dht->net); |
249 | 247 | ||
250 | print_clientlist(dht); | 248 | print_clientlist(dht); |
251 | print_friendlist(dht); | 249 | print_friendlist(dht); |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index c08b498c..c0731a3a 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -337,6 +337,10 @@ int route_packet(DHT *dht, uint8_t *client_id, uint8_t *packet, uint32_t length) | |||
337 | */ | 337 | */ |
338 | int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t length); | 338 | int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t length); |
339 | 339 | ||
340 | /* Function to handle crypto packets. | ||
341 | */ | ||
342 | void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_callback cb, void *object); | ||
343 | |||
340 | /* NAT PUNCHING FUNCTIONS */ | 344 | /* NAT PUNCHING FUNCTIONS */ |
341 | 345 | ||
342 | /* Puts all the different ips returned by the nodes for a friend_id into array ip_portlist. | 346 | /* Puts all the different ips returned by the nodes for a friend_id into array ip_portlist. |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index ef56b304..b2b9f4f5 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -87,9 +87,6 @@ uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id) | |||
87 | */ | 87 | */ |
88 | int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); | 88 | int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); |
89 | 89 | ||
90 | /* Function to call when request beginning with byte is received. */ | ||
91 | void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object); | ||
92 | |||
93 | /* Start a secure connection with other peer who has public_key and ip_port. | 90 | /* Start a secure connection with other peer who has public_key and ip_port. |
94 | * | 91 | * |
95 | * return -1 if failure. | 92 | * return -1 if failure. |
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 1e73aef9..abe72486 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c | |||
@@ -90,7 +90,7 @@ int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format de | |||
90 | int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *public_key, | 90 | int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *public_key, |
91 | uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length) | 91 | uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length) |
92 | { | 92 | { |
93 | if (DATA_REQUEST_MIN_SIZE + length > ONION_MAX_DATA_SIZE) | 93 | if ((unsigned int)DATA_REQUEST_MIN_SIZE + length > ONION_MAX_DATA_SIZE) |
94 | return -1; | 94 | return -1; |
95 | 95 | ||
96 | uint8_t packet[DATA_REQUEST_MIN_SIZE + length]; | 96 | uint8_t packet[DATA_REQUEST_MIN_SIZE + length]; |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 35fb4423..ee902d99 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -1007,7 +1007,7 @@ Onion_Client *new_onion_client(Net_Crypto *c) | |||
1007 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); | 1007 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); |
1008 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); | 1008 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); |
1009 | oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c); | 1009 | oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c); |
1010 | cryptopacket_registerhandler(onion_c->c, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c); | 1010 | cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c); |
1011 | 1011 | ||
1012 | return onion_c; | 1012 | return onion_c; |
1013 | } | 1013 | } |
@@ -1021,7 +1021,7 @@ void kill_onion_client(Onion_Client *onion_c) | |||
1021 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL); | 1021 | networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL); |
1022 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); | 1022 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); |
1023 | oniondata_registerhandler(onion_c, FAKEID_DATA_ID, NULL, NULL); | 1023 | oniondata_registerhandler(onion_c, FAKEID_DATA_ID, NULL, NULL); |
1024 | cryptopacket_registerhandler(onion_c->c, FAKEID_DATA_ID, NULL, NULL); | 1024 | cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, NULL, NULL); |
1025 | memset(onion_c, 0, sizeof(Onion_Client)); | 1025 | memset(onion_c, 0, sizeof(Onion_Client)); |
1026 | free(onion_c); | 1026 | free(onion_c); |
1027 | } | 1027 | } |