diff options
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r-- | auto_tests/onion_test.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 329d7371..44ea9c7d 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -75,22 +75,24 @@ void print_client_id(uint8_t *client_id, uint32_t length) | |||
75 | #endif | 75 | #endif |
76 | static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; | 76 | static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; |
77 | static int handled_test_3; | 77 | static int handled_test_3; |
78 | static uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; | 78 | static uint8_t test_3_pub_key[CRYPTO_PUBLIC_KEY_SIZE]; |
79 | static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; | 79 | static uint8_t test_3_ping_id[CRYPTO_SHA256_SIZE]; |
80 | static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 80 | static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
81 | { | 81 | { |
82 | Onion *onion = (Onion *)object; | 82 | Onion *onion = (Onion *)object; |
83 | 83 | ||
84 | if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES + | 84 | if (length != (1 + CRYPTO_NONCE_SIZE + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + CRYPTO_SHA256_SIZE + |
85 | crypto_box_MACBYTES)) { | 85 | CRYPTO_MAC_SIZE)) { |
86 | return 1; | 86 | return 1; |
87 | } | 87 | } |
88 | 88 | ||
89 | uint8_t plain[1 + crypto_hash_sha256_BYTES]; | 89 | uint8_t plain[1 + CRYPTO_SHA256_SIZE]; |
90 | //print_client_id(packet, length); | 90 | #if 0 |
91 | print_client_id(packet, length); | ||
92 | #endif | ||
91 | int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | 93 | int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, |
92 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, | 94 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, |
93 | 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); | 95 | 1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain); |
94 | 96 | ||
95 | if (len == -1) { | 97 | if (len == -1) { |
96 | return 1; | 98 | return 1; |
@@ -101,31 +103,33 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
101 | return 1; | 103 | return 1; |
102 | } | 104 | } |
103 | 105 | ||
104 | memcpy(test_3_ping_id, plain + 1, crypto_hash_sha256_BYTES); | 106 | memcpy(test_3_ping_id, plain + 1, CRYPTO_SHA256_SIZE); |
105 | //print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); | 107 | #if 0 |
108 | print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); | ||
109 | #endif | ||
106 | handled_test_3 = 1; | 110 | handled_test_3 = 1; |
107 | return 0; | 111 | return 0; |
108 | } | 112 | } |
109 | 113 | ||
110 | static uint8_t nonce[crypto_box_NONCEBYTES]; | 114 | static uint8_t nonce[CRYPTO_NONCE_SIZE]; |
111 | static int handled_test_4; | 115 | static int handled_test_4; |
112 | static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 116 | static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
113 | { | 117 | { |
114 | Onion *onion = (Onion *)object; | 118 | Onion *onion = (Onion *)object; |
115 | 119 | ||
116 | if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") + | 120 | if (length != (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + sizeof("Install gentoo") + |
117 | crypto_box_MACBYTES)) { | 121 | CRYPTO_MAC_SIZE)) { |
118 | return 1; | 122 | return 1; |
119 | } | 123 | } |
120 | 124 | ||
121 | uint8_t plain[sizeof("Install gentoo")] = {0}; | 125 | uint8_t plain[sizeof("Install gentoo")] = {0}; |
122 | 126 | ||
123 | if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) { | 127 | if (memcmp(nonce, packet + 1, CRYPTO_NONCE_SIZE) != 0) { |
124 | return 1; | 128 | return 1; |
125 | } | 129 | } |
126 | 130 | ||
127 | int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1, | 131 | int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion->dht->self_secret_key, packet + 1, |
128 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); | 132 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain); |
129 | 133 | ||
130 | if (len == -1) { | 134 | if (len == -1) { |
131 | return 1; | 135 | return 1; |
@@ -151,12 +155,12 @@ START_TEST(test_basic) | |||
151 | 155 | ||
152 | IP_Port on1 = {ip, onion1->net->port}; | 156 | IP_Port on1 = {ip, onion1->net->port}; |
153 | Node_format n1; | 157 | Node_format n1; |
154 | memcpy(n1.public_key, onion1->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 158 | memcpy(n1.public_key, onion1->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
155 | n1.ip_port = on1; | 159 | n1.ip_port = on1; |
156 | 160 | ||
157 | IP_Port on2 = {ip, onion2->net->port}; | 161 | IP_Port on2 = {ip, onion2->net->port}; |
158 | Node_format n2; | 162 | Node_format n2; |
159 | memcpy(n2.public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 163 | memcpy(n2.public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
160 | n2.ip_port = on2; | 164 | n2.ip_port = on2; |
161 | 165 | ||
162 | Node_format nodes[4]; | 166 | Node_format nodes[4]; |
@@ -190,10 +194,10 @@ START_TEST(test_basic) | |||
190 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1); | 194 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1); |
191 | ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); | 195 | ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); |
192 | uint8_t zeroes[64] = {0}; | 196 | uint8_t zeroes[64] = {0}; |
193 | randombytes(sb_data, sizeof(sb_data)); | 197 | random_bytes(sb_data, sizeof(sb_data)); |
194 | uint64_t s; | 198 | uint64_t s; |
195 | memcpy(&s, sb_data, sizeof(uint64_t)); | 199 | memcpy(&s, sb_data, sizeof(uint64_t)); |
196 | memcpy(test_3_pub_key, nodes[3].public_key, crypto_box_PUBLICKEYBYTES); | 200 | memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
197 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, | 201 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, |
198 | onion1->dht->self_secret_key, | 202 | onion1->dht->self_secret_key, |
199 | zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s); | 203 | zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s); |
@@ -206,16 +210,16 @@ START_TEST(test_basic) | |||
206 | c_sleep(50); | 210 | c_sleep(50); |
207 | } | 211 | } |
208 | 212 | ||
209 | randombytes(sb_data, sizeof(sb_data)); | 213 | random_bytes(sb_data, sizeof(sb_data)); |
210 | memcpy(&s, sb_data, sizeof(uint64_t)); | 214 | memcpy(&s, sb_data, sizeof(uint64_t)); |
211 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 215 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
212 | onion2_a->entries[1].time = unix_time(); | 216 | onion2_a->entries[1].time = unix_time(); |
213 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); | 217 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); |
214 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, | 218 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, |
215 | test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s); | 219 | test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s); |
216 | 220 | ||
217 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key, | 221 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key, |
218 | crypto_box_PUBLICKEYBYTES) != 0) { | 222 | CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
219 | do_onion(onion1); | 223 | do_onion(onion1); |
220 | do_onion(onion2); | 224 | do_onion(onion2); |
221 | c_sleep(50); | 225 | c_sleep(50); |
@@ -340,8 +344,8 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | |||
340 | } | 344 | } |
341 | 345 | ||
342 | static bool first, last; | 346 | static bool first, last; |
343 | static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; | 347 | static uint8_t first_dht_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
344 | static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; | 348 | static uint8_t last_dht_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
345 | 349 | ||
346 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) | 350 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) |
347 | { | 351 | { |
@@ -355,7 +359,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub | |||
355 | if (NUM_FIRST == number && !first) { | 359 | if (NUM_FIRST == number && !first) { |
356 | first = 1; | 360 | first = 1; |
357 | 361 | ||
358 | if (memcmp(dht_public_key, last_dht_pk, crypto_box_PUBLICKEYBYTES) != 0) { | 362 | if (memcmp(dht_public_key, last_dht_pk, CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
359 | ck_abort_msg("Error wrong dht key."); | 363 | ck_abort_msg("Error wrong dht key."); |
360 | } | 364 | } |
361 | 365 | ||
@@ -365,7 +369,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub | |||
365 | if (NUM_LAST == number && !last) { | 369 | if (NUM_LAST == number && !last) { |
366 | last = 1; | 370 | last = 1; |
367 | 371 | ||
368 | if (memcmp(dht_public_key, first_dht_pk, crypto_box_PUBLICKEYBYTES) != 0) { | 372 | if (memcmp(dht_public_key, first_dht_pk, CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
369 | ck_abort_msg("Error wrong dht key."); | 373 | ck_abort_msg("Error wrong dht key."); |
370 | } | 374 | } |
371 | 375 | ||
@@ -422,8 +426,8 @@ START_TEST(test_announce) | |||
422 | c_sleep(50); | 426 | c_sleep(50); |
423 | } | 427 | } |
424 | 428 | ||
425 | memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 429 | memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
426 | memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 430 | memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
427 | 431 | ||
428 | printf("adding friend\n"); | 432 | printf("adding friend\n"); |
429 | int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, onions[NUM_LAST]->onion_c->c->self_public_key); | 433 | int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, onions[NUM_LAST]->onion_c->c->self_public_key); |