diff options
author | irungentoo <irungentoo@gmail.com> | 2014-01-19 09:44:33 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-01-19 09:44:33 -0500 |
commit | cdcb8b86007b6490557f1329f42c08732282c500 (patch) | |
tree | 8e41be5a50fd122ea557f11ec445c5fc234e91a6 | |
parent | 99ae23813b47cc5198a210c4ea8da54d8a817829 (diff) |
Added no_replay and added some things to the docs.
-rw-r--r-- | docs/Prevent_Tracking.txt | 8 | ||||
-rw-r--r-- | docs/updates/Crypto.md | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 21 | ||||
-rw-r--r-- | toxcore/onion_client.c | 30 | ||||
-rw-r--r-- | toxcore/onion_client.h | 2 | ||||
-rw-r--r-- | toxcore/util.c | 19 | ||||
-rw-r--r-- | toxcore/util.h | 2 |
7 files changed, 55 insertions, 29 deletions
diff --git a/docs/Prevent_Tracking.txt b/docs/Prevent_Tracking.txt index 5f7aaf1e..ab091999 100644 --- a/docs/Prevent_Tracking.txt +++ b/docs/Prevent_Tracking.txt | |||
@@ -145,3 +145,11 @@ encrypted with temp symmetric key of Node A: [IP_Port (of us)][data to send back | |||
145 | (sent from node A to us): | 145 | (sent from node A to us): |
146 | 146 | ||
147 | [data to send back] | 147 | [data to send back] |
148 | |||
149 | |||
150 | Data packets: | ||
151 | |||
152 | To tell our friend what our DHT public key is so that he can connect to us we send a data packet with id 156 and | ||
153 | the data being:[uint64_t (in network byte order) no_replay, the packet will only be accepted if this number is bigger than the last one recieved] | ||
154 | [our dht public key][Node_Format * (maximum of 8) nodes closest to us so that the friend can find us faster] | ||
155 | |||
diff --git a/docs/updates/Crypto.md b/docs/updates/Crypto.md index 6b489c3b..a6c701d3 100644 --- a/docs/updates/Crypto.md +++ b/docs/updates/Crypto.md | |||
@@ -20,7 +20,7 @@ case 1: Alice adds Bobs public key and bob waits for Alice to attempt to connect | |||
20 | case 2: Bob and Alice add their respective public keys to their friends list at the same time. | 20 | case 2: Bob and Alice add their respective public keys to their friends list at the same time. |
21 | 21 | ||
22 | case 1: | 22 | case 1: |
23 | Alice sends a crypto request packet to bob with the encrypted part containing the friends request like so: | 23 | Alice sends a onion data (see: Prevent_tracking.txt) packet to bob with the encrypted part containing the friends request like so: |
24 | ``` | 24 | ``` |
25 | [char with a value of 32][nospam number (4 bytes)][Message] | 25 | [char with a value of 32][nospam number (4 bytes)][Message] |
26 | ``` | 26 | ``` |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 2f270fb6..19246d7d 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -34,27 +34,6 @@ | |||
34 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 34 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
35 | 35 | ||
36 | 36 | ||
37 | void host_to_net(uint8_t *num, uint16_t numbytes) | ||
38 | { | ||
39 | union { | ||
40 | uint32_t i; | ||
41 | uint8_t c[4]; | ||
42 | } a; | ||
43 | a.i = 1; | ||
44 | |||
45 | if (a.c[0] == 1) { | ||
46 | uint32_t i; | ||
47 | uint8_t buff[numbytes]; | ||
48 | |||
49 | for (i = 0; i < numbytes; ++i) { | ||
50 | buff[i] = num[numbytes - i - 1]; | ||
51 | } | ||
52 | |||
53 | memcpy(num, buff, numbytes); | ||
54 | } | ||
55 | } | ||
56 | #define net_to_host(x, y) host_to_net(x, y) | ||
57 | |||
58 | static void set_friend_status(Messenger *m, int friendnumber, uint8_t status); | 37 | static void set_friend_status(Messenger *m, int friendnumber, uint8_t status); |
59 | static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); | 38 | static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); |
60 | 39 | ||
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 932ffad7..e50679e5 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -341,7 +341,7 @@ static int handle_data_response(void *object, IP_Port source, uint8_t *packet, u | |||
341 | } | 341 | } |
342 | 342 | ||
343 | #define FAKEID_DATA_ID 156 | 343 | #define FAKEID_DATA_ID 156 |
344 | #define FAKEID_DATA_MIN_LENGTH (1 + crypto_box_PUBLICKEYBYTES) | 344 | #define FAKEID_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) |
345 | #define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) | 345 | #define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) |
346 | static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t length) | 346 | static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t length) |
347 | { | 347 | { |
@@ -361,19 +361,29 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t | |||
361 | if (friend_num == -1) | 361 | if (friend_num == -1) |
362 | return 1; | 362 | return 1; |
363 | 363 | ||
364 | if (memcmp(data + 1, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) != 0) { | 364 | uint64_t no_replay; |
365 | net_to_host(data + 1, sizeof(no_replay)); | ||
366 | memcpy(&no_replay, data + 1, sizeof(uint64_t)); | ||
367 | |||
368 | if (no_replay <= onion_c->friends_list[friend_num].last_noreplay) | ||
369 | return 1; | ||
370 | |||
371 | onion_c->friends_list[friend_num].last_noreplay = no_replay; | ||
372 | |||
373 | if (memcmp(data + 1 + sizeof(uint64_t), onion_c->friends_list[friend_num].fake_client_id, | ||
374 | crypto_box_PUBLICKEYBYTES) != 0) { | ||
365 | DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id); | 375 | DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id); |
366 | 376 | ||
367 | if (DHT_addfriend(onion_c->dht, data + 1) == 1) { | 377 | if (DHT_addfriend(onion_c->dht, data + 1 + sizeof(uint64_t)) == 1) { |
368 | return 1; | 378 | return 1; |
369 | } | 379 | } |
370 | 380 | ||
371 | memcpy(onion_c->friends_list[friend_num].fake_client_id, data + 1, crypto_box_PUBLICKEYBYTES); | 381 | memcpy(onion_c->friends_list[friend_num].fake_client_id, data + 1 + sizeof(uint64_t), crypto_box_PUBLICKEYBYTES); |
372 | } | 382 | } |
373 | 383 | ||
374 | uint16_t num_nodes = (length - FAKEID_DATA_MIN_LENGTH) / sizeof(Node_format); | 384 | uint16_t num_nodes = (length - FAKEID_DATA_MIN_LENGTH) / sizeof(Node_format); |
375 | Node_format nodes[num_nodes]; | 385 | Node_format nodes[num_nodes]; |
376 | memcpy(nodes, data + 1 + crypto_box_PUBLICKEYBYTES, sizeof(nodes)); | 386 | memcpy(nodes, data + 1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES, sizeof(nodes)); |
377 | uint32_t i; | 387 | uint32_t i; |
378 | 388 | ||
379 | for (i = 0; i < num_nodes; ++i) { | 389 | for (i = 0; i < num_nodes; ++i) { |
@@ -439,7 +449,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32 | |||
439 | return good; | 449 | return good; |
440 | } | 450 | } |
441 | 451 | ||
442 | /* Send the packets to tell our friends | 452 | /* Send the packets to tell our friends what our DHT public key is. |
443 | * return the number of packets sent on success | 453 | * return the number of packets sent on success |
444 | * return -1 on failure. | 454 | * return -1 on failure. |
445 | */ | 455 | */ |
@@ -450,7 +460,10 @@ static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num) | |||
450 | 460 | ||
451 | uint8_t data[FAKEID_DATA_MAX_LENGTH]; | 461 | uint8_t data[FAKEID_DATA_MAX_LENGTH]; |
452 | data[0] = FAKEID_DATA_ID; | 462 | data[0] = FAKEID_DATA_ID; |
453 | memcpy(data + 1, onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 463 | uint64_t no_replay = unix_time(); |
464 | host_to_net((uint8_t *)&no_replay, sizeof(no_replay)); | ||
465 | memcpy(data + 1, &no_replay, sizeof(no_replay)); | ||
466 | memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
454 | Node_format nodes[MAX_SENT_NODES]; | 467 | Node_format nodes[MAX_SENT_NODES]; |
455 | uint16_t num_nodes = closelist_nodes(onion_c->dht, nodes, MAX_SENT_NODES); | 468 | uint16_t num_nodes = closelist_nodes(onion_c->dht, nodes, MAX_SENT_NODES); |
456 | memcpy(data + FAKEID_DATA_MIN_LENGTH, nodes, sizeof(Node_format) * num_nodes); | 469 | memcpy(data + FAKEID_DATA_MIN_LENGTH, nodes, sizeof(Node_format) * num_nodes); |
@@ -597,6 +610,9 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on | |||
597 | return -1; | 610 | return -1; |
598 | 611 | ||
599 | onion_c->friends_list[friend_num].is_online = is_online; | 612 | onion_c->friends_list[friend_num].is_online = is_online; |
613 | /* Should we reset the no_replay when the other goes offline? | ||
614 | if (!is_online) | ||
615 | onion_c->friends_list[friend_num].last_noreplay = 0; */ | ||
600 | return 0; | 616 | return 0; |
601 | } | 617 | } |
602 | 618 | ||
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 78587846..56adc9ee 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -53,6 +53,8 @@ typedef struct { | |||
53 | uint8_t temp_secret_key[crypto_box_SECRETKEYBYTES]; | 53 | uint8_t temp_secret_key[crypto_box_SECRETKEYBYTES]; |
54 | 54 | ||
55 | uint64_t last_fakeid_sent; | 55 | uint64_t last_fakeid_sent; |
56 | |||
57 | uint64_t last_noreplay; | ||
56 | } Onion_Friend; | 58 | } Onion_Friend; |
57 | 59 | ||
58 | typedef int (*oniondata_handler_callback)(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t len); | 60 | typedef int (*oniondata_handler_callback)(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t len); |
diff --git a/toxcore/util.c b/toxcore/util.c index 9af7262f..d56c446e 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -65,6 +65,25 @@ uint32_t id_copy(uint8_t *dest, uint8_t *src) | |||
65 | return CLIENT_ID_SIZE; | 65 | return CLIENT_ID_SIZE; |
66 | } | 66 | } |
67 | 67 | ||
68 | void host_to_net(uint8_t *num, uint16_t numbytes) | ||
69 | { | ||
70 | union { | ||
71 | uint32_t i; | ||
72 | uint8_t c[4]; | ||
73 | } a; | ||
74 | a.i = 1; | ||
75 | |||
76 | if (a.c[0] == 1) { | ||
77 | uint32_t i; | ||
78 | uint8_t buff[numbytes]; | ||
79 | |||
80 | for (i = 0; i < numbytes; ++i) { | ||
81 | buff[i] = num[numbytes - i - 1]; | ||
82 | } | ||
83 | |||
84 | memcpy(num, buff, numbytes); | ||
85 | } | ||
86 | } | ||
68 | 87 | ||
69 | /* state load/save */ | 88 | /* state load/save */ |
70 | int load_state(load_state_callback_func load_state_callback, void *outer, | 89 | int load_state(load_state_callback_func load_state_callback, void *outer, |
diff --git a/toxcore/util.h b/toxcore/util.h index f05a9821..ae364d52 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -37,6 +37,8 @@ int is_timeout(uint64_t timestamp, uint64_t timeout); | |||
37 | bool id_equal(uint8_t *dest, uint8_t *src); | 37 | bool id_equal(uint8_t *dest, uint8_t *src); |
38 | uint32_t id_copy(uint8_t *dest, uint8_t *src); /* return value is CLIENT_ID_SIZE */ | 38 | uint32_t id_copy(uint8_t *dest, uint8_t *src); /* return value is CLIENT_ID_SIZE */ |
39 | 39 | ||
40 | void host_to_net(uint8_t *num, uint16_t numbytes); | ||
41 | #define net_to_host(x, y) host_to_net(x, y) | ||
40 | 42 | ||
41 | /* state load/save */ | 43 | /* state load/save */ |
42 | typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type); | 44 | typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type); |