diff options
-rw-r--r-- | auto_tests/tox_test.c | 5 | ||||
-rw-r--r-- | docs/updates/DHT.md | 4 | ||||
-rw-r--r-- | toxcore/DHT.c | 21 |
3 files changed, 11 insertions, 19 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 133fbb2a..7f6443b7 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -578,7 +578,8 @@ START_TEST(test_many_group) | |||
578 | 578 | ||
579 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 579 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
580 | int num_peers = tox_group_number_peers(toxes[i], 0); | 580 | int num_peers = tox_group_number_peers(toxes[i], 0); |
581 | ck_assert_msg(num_peers == NUM_GROUP_TOX, "Bad number of group peers. expected: %u got: %i, tox %u", NUM_GROUP_TOX, num_peers, i); | 581 | ck_assert_msg(num_peers == NUM_GROUP_TOX, "Bad number of group peers. expected: %u got: %i, tox %u", NUM_GROUP_TOX, |
582 | num_peers, i); | ||
582 | } | 583 | } |
583 | 584 | ||
584 | printf("group connected\n"); | 585 | printf("group connected\n"); |
@@ -600,7 +601,7 @@ START_TEST(test_many_group) | |||
600 | } | 601 | } |
601 | 602 | ||
602 | ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages."); | 603 | ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages."); |
603 | 604 | ||
604 | for (k = NUM_GROUP_TOX; k != 0 ; --k) { | 605 | for (k = NUM_GROUP_TOX; k != 0 ; --k) { |
605 | tox_del_groupchat(toxes[k - 1], 0); | 606 | tox_del_groupchat(toxes[k - 1], 0); |
606 | 607 | ||
diff --git a/docs/updates/DHT.md b/docs/updates/DHT.md index 86fad3d1..26f60399 100644 --- a/docs/updates/DHT.md +++ b/docs/updates/DHT.md | |||
@@ -95,11 +95,11 @@ ping_id = a random integer, the response must contain the exact same number as t | |||
95 | Get nodes (Request): | 95 | Get nodes (Request): |
96 | Packet contents: | 96 | Packet contents: |
97 | ``` | 97 | ``` |
98 | [byte with value: 02][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[char array: requested_node_id (node_id of which we want the ip), length=32 bytes][Sendback data (must be sent back unmodified by in the response), length=1 to NODES_ENCRYPTED_MESSAGE_LENGTH bytes]] | 98 | [byte with value: 02][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[char array: requested_node_id (node_id of which we want the ip), length=32 bytes][Sendback data (must be sent back unmodified by in the response), length=8 bytes]] |
99 | ``` | 99 | ``` |
100 | Valid replies: a send_nodes packet | 100 | Valid replies: a send_nodes packet |
101 | 101 | ||
102 | Send_nodes (response (for all addresses)): | 102 | Send_nodes (response (for all addresses)): |
103 | ``` | 103 | ``` |
104 | [byte with value: 04][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[uint8_t number of nodes in this packet][Nodes in node format, length=?? * (number of nodes (maximum of 8 nodes)) bytes][Sendback data, length=1 to NODES_ENCRYPTED_MESSAGE_LENGTH bytes]] | 104 | [byte with value: 04][char array (client node_id), length=32 bytes][random 24 byte nonce][Encrypted with the nonce and private key of the sender:[uint8_t number of nodes in this packet][Nodes in node format, length=?? * (number of nodes (maximum of 8 nodes)) bytes][Sendback data, length=8 bytes]] |
105 | ``` | 105 | ``` |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 1e120746..203ffa4c 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -828,8 +828,6 @@ end: | |||
828 | return 0; | 828 | return 0; |
829 | } | 829 | } |
830 | 830 | ||
831 | #define NODES_ENCRYPTED_MESSAGE_LENGTH (crypto_box_NONCEBYTES + sizeof(uint64_t) + sizeof(Node_format) + sizeof(Node_format) + crypto_box_MACBYTES) | ||
832 | |||
833 | /* Send a getnodes request. | 831 | /* Send a getnodes request. |
834 | sendback_node is the node that it will send back the response to (set to NULL to disable this) */ | 832 | sendback_node is the node that it will send back the response to (set to NULL to disable this) */ |
835 | static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id, | 833 | static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id, |
@@ -896,7 +894,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
896 | if (id_equal(public_key, dht->self_public_key)) | 894 | if (id_equal(public_key, dht->self_public_key)) |
897 | return -1; | 895 | return -1; |
898 | 896 | ||
899 | if (length > NODES_ENCRYPTED_MESSAGE_LENGTH || length == 0) | 897 | if (length != sizeof(uint64_t)) |
900 | return -1; | 898 | return -1; |
901 | 899 | ||
902 | size_t Node_format_size = sizeof(Node_format); | 900 | size_t Node_format_size = sizeof(Node_format); |
@@ -940,36 +938,29 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
940 | 938 | ||
941 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 939 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length) |
942 | { | 940 | { |
943 | uint32_t cmp_len = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + crypto_box_MACBYTES; | 941 | if (length != (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES)) |
944 | |||
945 | if (length <= cmp_len) | ||
946 | return 1; | 942 | return 1; |
947 | 943 | ||
948 | if (length > cmp_len + NODES_ENCRYPTED_MESSAGE_LENGTH) | ||
949 | return 1; | ||
950 | |||
951 | uint16_t sendback_data_length = length - cmp_len; | ||
952 | |||
953 | DHT *dht = object; | 944 | DHT *dht = object; |
954 | 945 | ||
955 | /* Check if packet is from ourself. */ | 946 | /* Check if packet is from ourself. */ |
956 | if (id_equal(packet + 1, dht->self_public_key)) | 947 | if (id_equal(packet + 1, dht->self_public_key)) |
957 | return 1; | 948 | return 1; |
958 | 949 | ||
959 | uint8_t plain[CLIENT_ID_SIZE + sendback_data_length]; | 950 | uint8_t plain[CLIENT_ID_SIZE + sizeof(uint64_t)]; |
960 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 951 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
961 | 952 | ||
962 | DHT_get_shared_key_recv(dht, shared_key, packet + 1); | 953 | DHT_get_shared_key_recv(dht, shared_key, packet + 1); |
963 | int len = decrypt_data_symmetric( shared_key, | 954 | int len = decrypt_data_symmetric( shared_key, |
964 | packet + 1 + CLIENT_ID_SIZE, | 955 | packet + 1 + CLIENT_ID_SIZE, |
965 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 956 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
966 | CLIENT_ID_SIZE + sendback_data_length + crypto_box_MACBYTES, | 957 | CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES, |
967 | plain ); | 958 | plain ); |
968 | 959 | ||
969 | if (len != CLIENT_ID_SIZE + sendback_data_length) | 960 | if (len != CLIENT_ID_SIZE + sizeof(uint64_t)) |
970 | return 1; | 961 | return 1; |
971 | 962 | ||
972 | sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sendback_data_length, shared_key); | 963 | sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sizeof(uint64_t), shared_key); |
973 | 964 | ||
974 | add_to_ping(dht->ping, packet + 1, source); | 965 | add_to_ping(dht->ping, packet + 1, source); |
975 | 966 | ||