summaryrefslogtreecommitdiff
path: root/auto_tests/onion_test.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-05-20 00:27:02 +0200
committermannol <eniz_vukovic@hotmail.com>2014-05-20 00:27:02 +0200
commitc9f1c6882dbf986685e3a900dae516f06832393c (patch)
tree6529505163b9a0d4fd0cb6c4aac0a19c5a108fb1 /auto_tests/onion_test.c
parenta1f2a18ae4146ebea11fbd3f83df803b715813da (diff)
parentfc19327dccedf7950377856c3b09a13f2b0f5911 (diff)
Merge upstream fo real now?
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r--auto_tests/onion_test.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 2f244693..4489a894 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
@@ -176,26 +176,30 @@ START_TEST(test_basic)
176 ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); 176 ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing.");
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 uint64_t s;
180 memcpy(&s, sb_data, sizeof(uint64_t));
179 memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES); 181 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, 182 ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key,
181 onion1->dht->c->self_secret_key, 183 onion1->dht->self_secret_key,
182 zeroes, onion1->dht->c->self_public_key, onion1->dht->c->self_public_key, sb_data); 184 zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s);
183 ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); 185 ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet.");
184 handled_test_3 = 0; 186 handled_test_3 = 0;
185 187
186 while (handled_test_3 == 0) { 188 while (handled_test_3 == 0) {
187 do_onion(onion1); 189 do_onion(onion1);
188 do_onion(onion2); 190 do_onion(onion2);
191 c_sleep(50);
189 } 192 }
190 193
191 randombytes(sb_data, sizeof(sb_data)); 194 randombytes(sb_data, sizeof(sb_data));
195 memcpy(&s, sb_data, sizeof(uint64_t));
192 memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); 196 memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
193 onion2_a->entries[1].time = unix_time(); 197 onion2_a->entries[1].time = unix_time();
194 networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); 198 networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
195 send_announce_request(onion1->net, &path, nodes[3], onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, 199 send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key,
196 test_3_ping_id, onion1->dht->c->self_public_key, onion1->dht->c->self_public_key, sb_data); 200 test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s);
197 201
198 while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->c->self_public_key, 202 while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key,
199 crypto_box_PUBLICKEYBYTES) != 0) { 203 crypto_box_PUBLICKEYBYTES) != 0) {
200 do_onion(onion1); 204 do_onion(onion1);
201 do_onion(onion2); 205 do_onion(onion2);
@@ -203,12 +207,12 @@ START_TEST(test_basic)
203 } 207 }
204 208
205 c_sleep(1000); 209 c_sleep(1000);
206 Onion *onion3 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34569)))); 210 Onion *onion3 = new_onion(new_DHT(new_networking(ip, 34569)));
207 ck_assert_msg((onion3 != NULL), "Onion failed initializing."); 211 ck_assert_msg((onion3 != NULL), "Onion failed initializing.");
208 212
209 new_nonce(nonce); 213 new_nonce(nonce);
210 ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->c->self_public_key, 214 ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key,
211 onion1->dht->c->self_public_key, 215 onion1->dht->self_public_key,
212 nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); 216 nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo"));
213 ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); 217 ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet.");
214 handled_test_4 = 0; 218 handled_test_4 = 0;
@@ -233,10 +237,10 @@ Onions *new_onions(uint16_t port)
233 ip_init(&ip, 1); 237 ip_init(&ip, 1);
234 ip.ip6.uint8[15] = 1; 238 ip.ip6.uint8[15] = 1;
235 Onions *on = malloc(sizeof(Onions)); 239 Onions *on = malloc(sizeof(Onions));
236 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); 240 DHT *dht = new_DHT(new_networking(ip, port));
237 on->onion = new_onion(dht); 241 on->onion = new_onion(dht);
238 on->onion_a = new_onion_announce(dht); 242 on->onion_a = new_onion_announce(dht);
239 on->onion_c = new_onion_client(dht); 243 on->onion_c = new_onion_client(new_net_crypto(dht));
240 244
241 if (on->onion && on->onion_a && on->onion_c) 245 if (on->onion && on->onion_a && on->onion_c)
242 return on; 246 return on;
@@ -297,8 +301,8 @@ START_TEST(test_announce)
297 c_sleep(50); 301 c_sleep(50);
298 } 302 }
299 303
300 onion_addfriend(onions[7]->onion_c, onions[37]->onion->dht->c->self_public_key); 304 onion_addfriend(onions[7]->onion_c, onions[37]->onion_c->c->self_public_key);
301 int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion->dht->c->self_public_key); 305 int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion_c->c->self_public_key);
302 306
303 int ok = -1; 307 int ok = -1;
304 308