Added no_replay and added some things to the docs.

This commit is contained in:
irungentoo 2014-01-19 09:44:33 -05:00
parent 99ae23813b
commit cdcb8b8600
7 changed files with 55 additions and 29 deletions

View File

@ -145,3 +145,11 @@ encrypted with temp symmetric key of Node A: [IP_Port (of us)][data to send back
(sent from node A to us): (sent from node A to us):
[data to send back] [data to send back]
Data packets:
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
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]
[our dht public key][Node_Format * (maximum of 8) nodes closest to us so that the friend can find us faster]

View File

@ -20,7 +20,7 @@ case 1: Alice adds Bobs public key and bob waits for Alice to attempt to connect
case 2: Bob and Alice add their respective public keys to their friends list at the same time. case 2: Bob and Alice add their respective public keys to their friends list at the same time.
case 1: case 1:
Alice sends a crypto request packet to bob with the encrypted part containing the friends request like so: Alice sends a onion data (see: Prevent_tracking.txt) packet to bob with the encrypted part containing the friends request like so:
``` ```
[char with a value of 32][nospam number (4 bytes)][Message] [char with a value of 32][nospam number (4 bytes)][Message]
``` ```

View File

@ -34,27 +34,6 @@
#define MIN(a,b) (((a)<(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b))
void host_to_net(uint8_t *num, uint16_t numbytes)
{
union {
uint32_t i;
uint8_t c[4];
} a;
a.i = 1;
if (a.c[0] == 1) {
uint32_t i;
uint8_t buff[numbytes];
for (i = 0; i < numbytes; ++i) {
buff[i] = num[numbytes - i - 1];
}
memcpy(num, buff, numbytes);
}
}
#define net_to_host(x, y) host_to_net(x, y)
static void set_friend_status(Messenger *m, int friendnumber, uint8_t status); static void set_friend_status(Messenger *m, int friendnumber, uint8_t status);
static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);

View File

@ -341,7 +341,7 @@ static int handle_data_response(void *object, IP_Port source, uint8_t *packet, u
} }
#define FAKEID_DATA_ID 156 #define FAKEID_DATA_ID 156
#define FAKEID_DATA_MIN_LENGTH (1 + crypto_box_PUBLICKEYBYTES) #define FAKEID_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES)
#define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) #define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES)
static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t length) static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t length)
{ {
@ -361,19 +361,29 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t
if (friend_num == -1) if (friend_num == -1)
return 1; return 1;
if (memcmp(data + 1, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) != 0) { uint64_t no_replay;
net_to_host(data + 1, sizeof(no_replay));
memcpy(&no_replay, data + 1, sizeof(uint64_t));
if (no_replay <= onion_c->friends_list[friend_num].last_noreplay)
return 1;
onion_c->friends_list[friend_num].last_noreplay = no_replay;
if (memcmp(data + 1 + sizeof(uint64_t), onion_c->friends_list[friend_num].fake_client_id,
crypto_box_PUBLICKEYBYTES) != 0) {
DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id); DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id);
if (DHT_addfriend(onion_c->dht, data + 1) == 1) { if (DHT_addfriend(onion_c->dht, data + 1 + sizeof(uint64_t)) == 1) {
return 1; return 1;
} }
memcpy(onion_c->friends_list[friend_num].fake_client_id, data + 1, crypto_box_PUBLICKEYBYTES); memcpy(onion_c->friends_list[friend_num].fake_client_id, data + 1 + sizeof(uint64_t), crypto_box_PUBLICKEYBYTES);
} }
uint16_t num_nodes = (length - FAKEID_DATA_MIN_LENGTH) / sizeof(Node_format); uint16_t num_nodes = (length - FAKEID_DATA_MIN_LENGTH) / sizeof(Node_format);
Node_format nodes[num_nodes]; Node_format nodes[num_nodes];
memcpy(nodes, data + 1 + crypto_box_PUBLICKEYBYTES, sizeof(nodes)); memcpy(nodes, data + 1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES, sizeof(nodes));
uint32_t i; uint32_t i;
for (i = 0; i < num_nodes; ++i) { 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
return good; return good;
} }
/* Send the packets to tell our friends /* Send the packets to tell our friends what our DHT public key is.
* return the number of packets sent on success * return the number of packets sent on success
* return -1 on failure. * return -1 on failure.
*/ */
@ -450,7 +460,10 @@ static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num)
uint8_t data[FAKEID_DATA_MAX_LENGTH]; uint8_t data[FAKEID_DATA_MAX_LENGTH];
data[0] = FAKEID_DATA_ID; data[0] = FAKEID_DATA_ID;
memcpy(data + 1, onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES); uint64_t no_replay = unix_time();
host_to_net((uint8_t *)&no_replay, sizeof(no_replay));
memcpy(data + 1, &no_replay, sizeof(no_replay));
memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
Node_format nodes[MAX_SENT_NODES]; Node_format nodes[MAX_SENT_NODES];
uint16_t num_nodes = closelist_nodes(onion_c->dht, nodes, MAX_SENT_NODES); uint16_t num_nodes = closelist_nodes(onion_c->dht, nodes, MAX_SENT_NODES);
memcpy(data + FAKEID_DATA_MIN_LENGTH, nodes, sizeof(Node_format) * num_nodes); 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
return -1; return -1;
onion_c->friends_list[friend_num].is_online = is_online; onion_c->friends_list[friend_num].is_online = is_online;
/* Should we reset the no_replay when the other goes offline?
if (!is_online)
onion_c->friends_list[friend_num].last_noreplay = 0; */
return 0; return 0;
} }

View File

@ -53,6 +53,8 @@ typedef struct {
uint8_t temp_secret_key[crypto_box_SECRETKEYBYTES]; uint8_t temp_secret_key[crypto_box_SECRETKEYBYTES];
uint64_t last_fakeid_sent; uint64_t last_fakeid_sent;
uint64_t last_noreplay;
} Onion_Friend; } Onion_Friend;
typedef int (*oniondata_handler_callback)(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t len); typedef int (*oniondata_handler_callback)(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t len);

View File

@ -65,6 +65,25 @@ uint32_t id_copy(uint8_t *dest, uint8_t *src)
return CLIENT_ID_SIZE; return CLIENT_ID_SIZE;
} }
void host_to_net(uint8_t *num, uint16_t numbytes)
{
union {
uint32_t i;
uint8_t c[4];
} a;
a.i = 1;
if (a.c[0] == 1) {
uint32_t i;
uint8_t buff[numbytes];
for (i = 0; i < numbytes; ++i) {
buff[i] = num[numbytes - i - 1];
}
memcpy(num, buff, numbytes);
}
}
/* state load/save */ /* state load/save */
int load_state(load_state_callback_func load_state_callback, void *outer, int load_state(load_state_callback_func load_state_callback, void *outer,

View File

@ -37,6 +37,8 @@ int is_timeout(uint64_t timestamp, uint64_t timeout);
bool id_equal(uint8_t *dest, uint8_t *src); bool id_equal(uint8_t *dest, uint8_t *src);
uint32_t id_copy(uint8_t *dest, uint8_t *src); /* return value is CLIENT_ID_SIZE */ uint32_t id_copy(uint8_t *dest, uint8_t *src); /* return value is CLIENT_ID_SIZE */
void host_to_net(uint8_t *num, uint16_t numbytes);
#define net_to_host(x, y) host_to_net(x, y)
/* state load/save */ /* state load/save */
typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type); typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type);