diff options
Diffstat (limited to 'auto_tests/TCP_test.c')
-rw-r--r-- | auto_tests/TCP_test.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index c09e336c..b4a5392a 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -123,7 +123,8 @@ START_TEST(test_basic) | |||
123 | memcpy(f_nonce_r, response_plain + CRYPTO_SHARED_KEY_SIZE, CRYPTO_NONCE_SIZE); | 123 | memcpy(f_nonce_r, response_plain + CRYPTO_SHARED_KEY_SIZE, CRYPTO_NONCE_SIZE); |
124 | 124 | ||
125 | // Building a request | 125 | // Building a request |
126 | uint8_t r_req_p[1 + CRYPTO_PUBLIC_KEY_SIZE] = {0}; | 126 | uint8_t r_req_p[1 + CRYPTO_PUBLIC_KEY_SIZE]; |
127 | r_req_p[0] = TCP_PACKET_ROUTING_REQUEST; | ||
127 | memcpy(r_req_p + 1, f_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 128 | memcpy(r_req_p + 1, f_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
128 | uint8_t r_req[2 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE]; | 129 | uint8_t r_req[2 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE]; |
129 | uint16_t size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE; | 130 | uint16_t size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE; |
@@ -163,7 +164,8 @@ START_TEST(test_basic) | |||
163 | ck_assert_msg(ret != -1, "Failed to decrypt the TCP server's response."); | 164 | ck_assert_msg(ret != -1, "Failed to decrypt the TCP server's response."); |
164 | increment_nonce(f_nonce_r); | 165 | increment_nonce(f_nonce_r); |
165 | 166 | ||
166 | ck_assert_msg(packet_resp_plain[0] == 1, "Server sent the wrong packet id: %u", packet_resp_plain[0]); | 167 | ck_assert_msg(packet_resp_plain[0] == TCP_PACKET_ROUTING_RESPONSE, "Server sent the wrong packet id: %u", |
168 | packet_resp_plain[0]); | ||
167 | ck_assert_msg(packet_resp_plain[1] == 0, "Server did not refuse the connection."); | 169 | ck_assert_msg(packet_resp_plain[1] == 0, "Server did not refuse the connection."); |
168 | ck_assert_msg(public_key_cmp(packet_resp_plain + 2, f_public_key) == 0, "Server sent the wrong public key."); | 170 | ck_assert_msg(public_key_cmp(packet_resp_plain + 2, f_public_key) == 0, "Server sent the wrong public key."); |
169 | 171 | ||
@@ -288,7 +290,7 @@ START_TEST(test_some) | |||
288 | struct sec_TCP_con *con3 = new_TCP_con(tcp_s, mono_time); | 290 | struct sec_TCP_con *con3 = new_TCP_con(tcp_s, mono_time); |
289 | 291 | ||
290 | uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE]; | 292 | uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE]; |
291 | requ_p[0] = 0; | 293 | requ_p[0] = TCP_PACKET_ROUTING_REQUEST; |
292 | 294 | ||
293 | // Sending wrong public keys to test server response. | 295 | // Sending wrong public keys to test server response. |
294 | memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE); | 296 | memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE); |
@@ -302,14 +304,14 @@ START_TEST(test_some) | |||
302 | uint8_t data[2048]; | 304 | uint8_t data[2048]; |
303 | int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE); | 305 | int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE); |
304 | ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len); | 306 | ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len); |
305 | ck_assert_msg(data[0] == 1, "Wrong response packet id of %d.", data[0]); | 307 | ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]); |
306 | ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key."); | 308 | ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key."); |
307 | ck_assert_msg(public_key_cmp(data + 2, con3->public_key) == 0, "Key in response packet wrong."); | 309 | ck_assert_msg(public_key_cmp(data + 2, con3->public_key) == 0, "Key in response packet wrong."); |
308 | 310 | ||
309 | // Connection 3 | 311 | // Connection 3 |
310 | len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE); | 312 | len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE); |
311 | ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len); | 313 | ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len); |
312 | ck_assert_msg(data[0] == 1, "Wrong response packet id of %d.", data[0]); | 314 | ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]); |
313 | ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key."); | 315 | ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key."); |
314 | ck_assert_msg(public_key_cmp(data + 2, con1->public_key) == 0, "Key in response packet wrong."); | 316 | ck_assert_msg(public_key_cmp(data + 2, con1->public_key) == 0, "Key in response packet wrong."); |
315 | 317 | ||
@@ -323,11 +325,11 @@ START_TEST(test_some) | |||
323 | 325 | ||
324 | len = read_packet_sec_TCP(con1, data, 2 + 2 + CRYPTO_MAC_SIZE); | 326 | len = read_packet_sec_TCP(con1, data, 2 + 2 + CRYPTO_MAC_SIZE); |
325 | ck_assert_msg(len == 2, "wrong len %d", len); | 327 | ck_assert_msg(len == 2, "wrong len %d", len); |
326 | ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]); | 328 | ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]); |
327 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); | 329 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); |
328 | len = read_packet_sec_TCP(con3, data, 2 + 2 + CRYPTO_MAC_SIZE); | 330 | len = read_packet_sec_TCP(con3, data, 2 + 2 + CRYPTO_MAC_SIZE); |
329 | ck_assert_msg(len == 2, "wrong len %d", len); | 331 | ck_assert_msg(len == 2, "wrong len %d", len); |
330 | ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]); | 332 | ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]); |
331 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); | 333 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); |
332 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); | 334 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
333 | ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len); | 335 | ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len); |
@@ -358,14 +360,14 @@ START_TEST(test_some) | |||
358 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 360 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
359 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 361 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
360 | 362 | ||
361 | uint8_t ping_packet[1 + sizeof(uint64_t)] = {4, 8, 6, 9, 67}; | 363 | uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67}; |
362 | write_packet_TCP_secure_connection(con1, ping_packet, sizeof(ping_packet)); | 364 | write_packet_TCP_secure_connection(con1, ping_packet, sizeof(ping_packet)); |
363 | 365 | ||
364 | do_TCP_server_delay(tcp_s, mono_time, 50); | 366 | do_TCP_server_delay(tcp_s, mono_time, 50); |
365 | 367 | ||
366 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE); | 368 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE); |
367 | ck_assert_msg(len == sizeof(ping_packet), "wrong len %d", len); | 369 | ck_assert_msg(len == sizeof(ping_packet), "wrong len %d", len); |
368 | ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]); | 370 | ck_assert_msg(data[0] == TCP_PACKET_PONG, "wrong packet id %u", data[0]); |
369 | ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data"); | 371 | ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data"); |
370 | 372 | ||
371 | // Kill off the connections | 373 | // Kill off the connections |