diff options
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r-- | auto_tests/onion_test.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 70bea4a1..234e8aa5 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -65,6 +65,7 @@ void print_client_id(uint8_t *client_id, uint32_t length) | |||
65 | printf("\n"); | 65 | printf("\n"); |
66 | } | 66 | } |
67 | */ | 67 | */ |
68 | uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; | ||
68 | static int handled_test_3; | 69 | static int handled_test_3; |
69 | uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; | 70 | uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; |
70 | uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; | 71 | uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; |
@@ -72,16 +73,22 @@ static int handle_test_3(void *object, IP_Port source, uint8_t *packet, uint32_t | |||
72 | { | 73 | { |
73 | Onion *onion = object; | 74 | Onion *onion = object; |
74 | 75 | ||
75 | if (length != (1 + crypto_box_NONCEBYTES + crypto_hash_sha256_BYTES + crypto_box_MACBYTES)) | 76 | if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_hash_sha256_BYTES + |
77 | crypto_box_MACBYTES)) | ||
76 | return 1; | 78 | return 1; |
77 | 79 | ||
80 | uint8_t plain[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_hash_sha256_BYTES]; | ||
78 | //print_client_id(packet, length); | 81 | //print_client_id(packet, length); |
79 | int len = decrypt_data(test_3_pub_key, onion->dht->c->self_secret_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES, | 82 | int len = decrypt_data(test_3_pub_key, onion->dht->c->self_secret_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES, |
80 | crypto_hash_sha256_BYTES + crypto_box_MACBYTES, test_3_ping_id); | 83 | ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); |
81 | 84 | ||
82 | if (len == -1) | 85 | if (len == -1) |
83 | return 1; | 86 | return 1; |
84 | 87 | ||
88 | if (memcmp(plain, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) | ||
89 | return 1; | ||
90 | |||
91 | memcpy(test_3_ping_id, plain + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, crypto_hash_sha256_BYTES); | ||
85 | //print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); | 92 | //print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); |
86 | handled_test_3 = 1; | 93 | handled_test_3 = 1; |
87 | return 0; | 94 | return 0; |
@@ -157,9 +164,10 @@ START_TEST(test_basic) | |||
157 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1); | 164 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1); |
158 | ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); | 165 | ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); |
159 | uint8_t zeroes[64] = {0}; | 166 | uint8_t zeroes[64] = {0}; |
167 | randombytes(sb_data, sizeof(sb_data)); | ||
160 | memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES); | 168 | memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES); |
161 | ret = send_announce_request(onion1->dht, nodes, onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, | 169 | ret = send_announce_request(onion1->dht, nodes, onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, |
162 | zeroes, onion1->dht->c->self_public_key); | 170 | zeroes, onion1->dht->c->self_public_key, sb_data); |
163 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); | 171 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); |
164 | handled_test_3 = 0; | 172 | handled_test_3 = 0; |
165 | 173 | ||
@@ -168,11 +176,12 @@ START_TEST(test_basic) | |||
168 | do_onion(onion2); | 176 | do_onion(onion2); |
169 | } | 177 | } |
170 | 178 | ||
179 | randombytes(sb_data, sizeof(sb_data)); | ||
171 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 180 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); |
172 | onion2_a->entries[1].time = unix_time(); | 181 | onion2_a->entries[1].time = unix_time(); |
173 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); | 182 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); |
174 | send_announce_request(onion1->dht, nodes, onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, | 183 | send_announce_request(onion1->dht, nodes, onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, |
175 | test_3_ping_id, onion1->dht->c->self_public_key); | 184 | test_3_ping_id, onion1->dht->c->self_public_key, sb_data); |
176 | 185 | ||
177 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->c->self_public_key, | 186 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->c->self_public_key, |
178 | crypto_box_PUBLICKEYBYTES) != 0) { | 187 | crypto_box_PUBLICKEYBYTES) != 0) { |