From 7b252be29921513abbd726c51de028873f0f2f9a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 24 Jan 2014 21:20:32 -0500 Subject: Set last_noreplay to zero when friend goes offline. --- toxcore/onion_client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'toxcore/onion_client.c') diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index f0f8fa70..97ef3b84 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -703,9 +703,11 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on return -1; onion_c->friends_list[friend_num].is_online = is_online; - /* Should we reset the no_replay when the other goes offline? + + /* This should prevent some clock related issues */ if (!is_online) - onion_c->friends_list[friend_num].last_noreplay = 0; */ + onion_c->friends_list[friend_num].last_noreplay = 0; + return 0; } -- cgit v1.2.3 From 0d53abebcdea36adc509ee46e2bfdacea41ac5e4 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 25 Jan 2014 13:33:39 -0500 Subject: Fixed possible anonimity leak with the onion routing. --- toxcore/onion.c | 2 +- toxcore/onion_announce.c | 4 ++-- toxcore/onion_client.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'toxcore/onion_client.c') diff --git a/toxcore/onion.c b/toxcore/onion.c index b4d2a364..961f5bd5 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -55,7 +55,7 @@ int send_onion_packet(DHT *dht, Node_format *nodes, uint8_t *data, uint32_t leng memcpy(step1 + sizeof(IP_Port), data, length); uint8_t nonce[crypto_box_NONCEBYTES]; - new_nonce(nonce); + random_nonce(nonce); uint8_t random_public_key[crypto_box_PUBLICKEYBYTES]; uint8_t random_secret_key[crypto_box_SECRETKEYBYTES]; crypto_box_keypair(random_public_key, random_secret_key); diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 8150974b..2ca53896 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -61,7 +61,7 @@ int send_announce_request(DHT *dht, Node_format *nodes, uint8_t *public_key, uin ONION_ANNOUNCE_SENDBACK_DATA_LENGTH); uint8_t packet[ANNOUNCE_REQUEST_SIZE]; packet[0] = NET_PACKET_ANNOUNCE_REQUEST; - new_nonce(packet + 1); + random_nonce(packet + 1); int len = encrypt_data(nodes[3].client_id, secret_key, packet + 1, plain, sizeof(plain), packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES); @@ -253,7 +253,7 @@ static int handle_announce_request(void *object, IP_Port source, uint8_t *packet to_net_family(&nodes_list[i].ip_port.ip); uint8_t nonce[crypto_box_NONCEBYTES]; - new_nonce(nonce); + random_nonce(nonce); uint8_t pl[1 + ONION_PING_ID_SIZE + sizeof(nodes_list)]; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 97ef3b84..a85a07a2 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -50,7 +50,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, uint8_t *public_key { uint8_t plain[sizeof(uint32_t) + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)]; uint64_t time = unix_time(); - new_nonce(sendback); + random_nonce(sendback); memcpy(plain, &num, sizeof(uint32_t)); memcpy(plain + sizeof(uint32_t), &time, sizeof(uint64_t)); memcpy(plain + sizeof(uint32_t) + sizeof(uint64_t), public_key, crypto_box_PUBLICKEYBYTES); @@ -420,7 +420,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32 return -1; uint8_t nonce[crypto_box_NONCEBYTES]; - new_nonce(nonce); + random_nonce(nonce); uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; memcpy(packet, onion_c->dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); -- cgit v1.2.3 From 1505d489f43c649cd7263fdbeffae25d218fbde5 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 30 Jan 2014 14:23:19 -0500 Subject: Fixed bug with client_ping_nodes() not pinging any nodes. --- toxcore/onion_client.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'toxcore/onion_client.c') diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index a85a07a2..337bc296 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -183,13 +183,19 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry); int index = -1; + uint32_t i; - if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) - || id_closest(reference_id, list_nodes[0].client_id, public_key) == 2) { - index = 0; - } + for (i = 0; i < MAX_ONION_CLIENTS; ++i) { + if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT) + || id_closest(reference_id, list_nodes[i].client_id, public_key) == 2) { + index = i; - uint32_t i; + if (i != 0) + break; + } else { + break; + } + } for (i = 0; i < MAX_ONION_CLIENTS; ++i) { if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { @@ -255,8 +261,9 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n } } - if (j == MAX_ONION_CLIENTS) + if (j == MAX_ONION_CLIENTS) { client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL); + } } } @@ -306,7 +313,10 @@ static int handle_announce_response(void *object, IP_Port source, uint8_t *packe if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1) return 1; - if (client_ping_nodes(onion_c, num, (Node_format *)plain + 1 + ONION_PING_ID_SIZE, num_nodes, source) == -1) + Node_format nodes[MAX_SENT_NODES]; + memcpy(nodes, plain + 1 + ONION_PING_ID_SIZE, num_nodes * sizeof(Node_format)); + + if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) return 1; return 0; -- cgit v1.2.3 From a377c7fbf4344ba5359bc1fafafde415f50b4749 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 31 Jan 2014 18:05:49 -0500 Subject: Improved onion connection by a bit. --- toxcore/onion_client.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'toxcore/onion_client.c') diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 337bc296..7cba27a9 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -766,24 +766,26 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) } } - if (count < MAX_ONION_CLIENTS / 2) { - Node_format nodes_list[MAX_SENT_NODES]; - uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, - rand() % 2 ? AF_INET : AF_INET6, 1, 0); - - for (i = 0; i < num_nodes; ++i) - client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); - } + if (count != MAX_ONION_CLIENTS) { + if (count < rand() % MAX_ONION_CLIENTS) { + Node_format nodes_list[MAX_SENT_NODES]; + uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list, + rand() % 2 ? AF_INET : AF_INET6, 1, 0); + + for (i = 0; i < num_nodes; ++i) + client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); + } - /* send packets to friend telling them our fake DHT id. */ - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) - onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); + /* send packets to friend telling them our fake DHT id. */ + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) + onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) - onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) + onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); + } } } /* Function to call when onion data packet with contents beginning with byte is received. */ @@ -820,13 +822,15 @@ static void do_announce(Onion_Client *onion_c) } } - if (count < MAX_ONION_CLIENTS / 2) { - Node_format nodes_list[MAX_SENT_NODES]; - uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, - rand() % 2 ? AF_INET : AF_INET6, 1, 0); + if (count != MAX_ONION_CLIENTS) { + if (count < rand() % MAX_ONION_CLIENTS) { + Node_format nodes_list[MAX_SENT_NODES]; + uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->dht->c->self_public_key, nodes_list, + rand() % 2 ? AF_INET : AF_INET6, 1, 0); - for (i = 0; i < num_nodes; ++i) - client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0); + for (i = 0; i < num_nodes; ++i) + client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0); + } } } -- cgit v1.2.3 From d5c005f02462b996c067d7ed4f1ef71bbd4e5dd2 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 31 Jan 2014 20:25:46 -0500 Subject: Fixed error in last commit. The tests actually work. --- toxcore/onion_client.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'toxcore/onion_client.c') diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 7cba27a9..93697c28 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -775,17 +775,17 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) for (i = 0; i < num_nodes; ++i) client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0); } + } + /* send packets to friend telling them our fake DHT id. */ + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) + onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); - /* send packets to friend telling them our fake DHT id. */ - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_onion_sent, ONION_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 0) >= 1) - onion_c->friends_list[friendnum].last_fakeid_onion_sent = unix_time(); + if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) + if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) + onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); - if (is_timeout(onion_c->friends_list[friendnum].last_fakeid_dht_sent, DHT_FAKEID_INTERVAL)) - if (send_fakeid_announce(onion_c, friendnum, 1) >= 1) - onion_c->friends_list[friendnum].last_fakeid_dht_sent = unix_time(); - } } } /* Function to call when onion data packet with contents beginning with byte is received. */ -- cgit v1.2.3