diff options
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r-- | auto_tests/onion_test.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 08904218..fe764517 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -34,12 +34,14 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
34 | { | 34 | { |
35 | Onion *onion = object; | 35 | Onion *onion = object; |
36 | 36 | ||
37 | if (memcmp(packet, "Install Gentoo", sizeof("Install Gentoo")) != 0) | 37 | if (memcmp(packet, "Install Gentoo", sizeof("Install Gentoo")) != 0) { |
38 | return 1; | 38 | return 1; |
39 | } | ||
39 | 40 | ||
40 | if (send_onion_response(onion->net, source, (uint8_t *)"install gentoo", sizeof("install gentoo"), | 41 | if (send_onion_response(onion->net, source, (uint8_t *)"install gentoo", sizeof("install gentoo"), |
41 | packet + sizeof("Install Gentoo")) == -1) | 42 | packet + sizeof("Install Gentoo")) == -1) { |
42 | return 1; | 43 | return 1; |
44 | } | ||
43 | 45 | ||
44 | handled_test_1 = 1; | 46 | handled_test_1 = 1; |
45 | return 0; | 47 | return 0; |
@@ -48,11 +50,13 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
48 | static int handled_test_2; | 50 | static int handled_test_2; |
49 | static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 51 | static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
50 | { | 52 | { |
51 | if (length != sizeof("install Gentoo")) | 53 | if (length != sizeof("install Gentoo")) { |
52 | return 1; | 54 | return 1; |
55 | } | ||
53 | 56 | ||
54 | if (memcmp(packet, (uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) | 57 | if (memcmp(packet, (uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) { |
55 | return 1; | 58 | return 1; |
59 | } | ||
56 | 60 | ||
57 | handled_test_2 = 1; | 61 | handled_test_2 = 1; |
58 | return 0; | 62 | return 0; |
@@ -77,8 +81,9 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
77 | Onion *onion = object; | 81 | Onion *onion = object; |
78 | 82 | ||
79 | if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES + | 83 | if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES + |
80 | crypto_box_MACBYTES)) | 84 | crypto_box_MACBYTES)) { |
81 | return 1; | 85 | return 1; |
86 | } | ||
82 | 87 | ||
83 | uint8_t plain[1 + crypto_hash_sha256_BYTES]; | 88 | uint8_t plain[1 + crypto_hash_sha256_BYTES]; |
84 | //print_client_id(packet, length); | 89 | //print_client_id(packet, length); |
@@ -86,12 +91,14 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
86 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, | 91 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, |
87 | 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); | 92 | 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); |
88 | 93 | ||
89 | if (len == -1) | 94 | if (len == -1) { |
90 | return 1; | 95 | return 1; |
96 | } | ||
91 | 97 | ||
92 | 98 | ||
93 | if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) | 99 | if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) { |
94 | return 1; | 100 | return 1; |
101 | } | ||
95 | 102 | ||
96 | memcpy(test_3_ping_id, plain + 1, crypto_hash_sha256_BYTES); | 103 | memcpy(test_3_ping_id, plain + 1, crypto_hash_sha256_BYTES); |
97 | //print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); | 104 | //print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); |
@@ -105,22 +112,27 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui | |||
105 | { | 112 | { |
106 | Onion *onion = object; | 113 | Onion *onion = object; |
107 | 114 | ||
108 | if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") + crypto_box_MACBYTES)) | 115 | if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") + |
116 | crypto_box_MACBYTES)) { | ||
109 | return 1; | 117 | return 1; |
118 | } | ||
110 | 119 | ||
111 | uint8_t plain[sizeof("Install gentoo")] = {0}; | 120 | uint8_t plain[sizeof("Install gentoo")] = {0}; |
112 | 121 | ||
113 | if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) | 122 | if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) { |
114 | return 1; | 123 | return 1; |
124 | } | ||
115 | 125 | ||
116 | int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1, | 126 | int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1, |
117 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); | 127 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); |
118 | 128 | ||
119 | if (len == -1) | 129 | if (len == -1) { |
120 | return 1; | 130 | return 1; |
131 | } | ||
121 | 132 | ||
122 | if (memcmp(plain, "Install gentoo", sizeof("Install gentoo")) != 0) | 133 | if (memcmp(plain, "Install gentoo", sizeof("Install gentoo")) != 0) { |
123 | return 1; | 134 | return 1; |
135 | } | ||
124 | 136 | ||
125 | handled_test_4 = 1; | 137 | handled_test_4 = 1; |
126 | return 0; | 138 | return 0; |
@@ -278,8 +290,9 @@ Onions *new_onions(uint16_t port) | |||
278 | TCP_Proxy_Info inf = {{{0}}}; | 290 | TCP_Proxy_Info inf = {{{0}}}; |
279 | on->onion_c = new_onion_client(new_net_crypto(NULL, dht, &inf)); | 291 | on->onion_c = new_onion_client(new_net_crypto(NULL, dht, &inf)); |
280 | 292 | ||
281 | if (on->onion && on->onion_a && on->onion_c) | 293 | if (on->onion && on->onion_a && on->onion_c) { |
282 | return on; | 294 | return on; |
295 | } | ||
283 | 296 | ||
284 | return NULL; | 297 | return NULL; |
285 | } | 298 | } |