mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Putting the sendback outside the encrypted part of the response.
It's more useful this way.
This commit is contained in:
parent
0fd8e49c38
commit
ea7d1a726d
|
@ -77,18 +77,20 @@ static int handle_test_3(void *object, IP_Port source, uint8_t *packet, uint32_t
|
||||||
crypto_box_MACBYTES))
|
crypto_box_MACBYTES))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
uint8_t plain[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_hash_sha256_BYTES];
|
uint8_t plain[crypto_hash_sha256_BYTES];
|
||||||
//print_client_id(packet, length);
|
//print_client_id(packet, length);
|
||||||
int len = decrypt_data(test_3_pub_key, onion->dht->c->self_secret_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES,
|
int len = decrypt_data(test_3_pub_key, onion->dht->c->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
||||||
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain);
|
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES,
|
||||||
|
crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain);
|
||||||
|
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (memcmp(plain, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0)
|
|
||||||
|
if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
memcpy(test_3_ping_id, plain + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, crypto_hash_sha256_BYTES);
|
memcpy(test_3_ping_id, plain, crypto_hash_sha256_BYTES);
|
||||||
//print_client_id(test_3_ping_id, sizeof(test_3_ping_id));
|
//print_client_id(test_3_ping_id, sizeof(test_3_ping_id));
|
||||||
handled_test_3 = 1;
|
handled_test_3 = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -110,8 +110,8 @@ encrypted with that temporary private key and the nonce and the real public key
|
||||||
|
|
||||||
Data sent to us:
|
Data sent to us:
|
||||||
announce response packet:
|
announce response packet:
|
||||||
[uint8_t packet id (132)][nonce]
|
[uint8_t packet id (132)][data to send back in response(fixed size)][nonce]
|
||||||
encrypted with the DHT private key of Node D, the public key in the request and the nonce:[[data to send back in response(fixed size)][(32 bytes) ping_id][Node_Format * (maximum of 8)]]
|
encrypted with the DHT private key of Node D, the public key in the request and the nonce:[[(32 bytes) ping_id][Node_Format * (maximum of 8)]]
|
||||||
(if the ping id is zero, it means the information to reach the client id we are searching for is stored on this node)
|
(if the ping id is zero, it means the information to reach the client id we are searching for is stored on this node)
|
||||||
|
|
||||||
data to route response packet:
|
data to route response packet:
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#define ANNOUNCE_REQUEST_SIZE (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_MACBYTES)
|
#define ANNOUNCE_REQUEST_SIZE (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_MACBYTES)
|
||||||
#define ANNOUNCE_REQUEST_SIZE_RECV (ANNOUNCE_REQUEST_SIZE + ONION_RETURN_3)
|
#define ANNOUNCE_REQUEST_SIZE_RECV (ANNOUNCE_REQUEST_SIZE + ONION_RETURN_3)
|
||||||
#define ANNOUNCE_RESPONSE_MIN_SIZE (1 + crypto_box_NONCEBYTES + ONION_PING_ID_SIZE + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_MACBYTES)
|
#define ANNOUNCE_RESPONSE_MIN_SIZE (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES + ONION_PING_ID_SIZE + crypto_box_MACBYTES)
|
||||||
#define ANNOUNCE_RESPONSE_MAX_SIZE (ANNOUNCE_RESPONSE_MIN_SIZE + sizeof(Node_format)*MAX_SENT_NODES)
|
#define ANNOUNCE_RESPONSE_MAX_SIZE (ANNOUNCE_RESPONSE_MIN_SIZE + sizeof(Node_format)*MAX_SENT_NODES)
|
||||||
|
|
||||||
#define DATA_REQUEST_MIN_SIZE (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
|
#define DATA_REQUEST_MIN_SIZE (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
|
||||||
|
@ -242,29 +242,28 @@ static int handle_announce_request(void *object, IP_Port source, uint8_t *packet
|
||||||
uint8_t nonce[crypto_box_NONCEBYTES];
|
uint8_t nonce[crypto_box_NONCEBYTES];
|
||||||
new_nonce(nonce);
|
new_nonce(nonce);
|
||||||
|
|
||||||
uint8_t pl[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + ONION_PING_ID_SIZE + sizeof(nodes_list)] = {0};
|
uint8_t pl[ONION_PING_ID_SIZE + sizeof(nodes_list)] = {0};
|
||||||
|
|
||||||
|
|
||||||
memcpy(pl, plain + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH);
|
|
||||||
|
|
||||||
if (!stored) {
|
if (!stored) {
|
||||||
memcpy(pl + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, ping_id2, ONION_PING_ID_SIZE);
|
memcpy(pl, ping_id2, ONION_PING_ID_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pl + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + ONION_PING_ID_SIZE, nodes_list, num_nodes * sizeof(Node_format));
|
memcpy(pl + ONION_PING_ID_SIZE, nodes_list, num_nodes * sizeof(Node_format));
|
||||||
|
|
||||||
uint8_t data[ANNOUNCE_RESPONSE_MAX_SIZE];
|
uint8_t data[ANNOUNCE_RESPONSE_MAX_SIZE];
|
||||||
len = encrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion_a->dht->self_secret_key, nonce, pl,
|
len = encrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion_a->dht->self_secret_key, nonce, pl, ONION_PING_ID_SIZE + num_nodes * sizeof(Node_format), data + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES);
|
||||||
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + ONION_PING_ID_SIZE + num_nodes * sizeof(Node_format),
|
|
||||||
data + 1 + crypto_box_NONCEBYTES);
|
|
||||||
|
|
||||||
if ((uint32_t)len != ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + ONION_PING_ID_SIZE + num_nodes * sizeof(
|
if ((uint32_t)len != ONION_PING_ID_SIZE + num_nodes * sizeof(Node_format) + crypto_box_MACBYTES)
|
||||||
Node_format) + crypto_box_MACBYTES)
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
data[0] = NET_PACKET_ANNOUNCE_RESPONSE;
|
data[0] = NET_PACKET_ANNOUNCE_RESPONSE;
|
||||||
memcpy(data + 1, nonce, crypto_box_NONCEBYTES);
|
memcpy(data + 1, plain + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH);
|
||||||
|
memcpy(data + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, nonce, crypto_box_NONCEBYTES);
|
||||||
|
|
||||||
if (send_onion_response(onion_a->net, source, data, 1 + crypto_box_NONCEBYTES + len,
|
if (send_onion_response(onion_a->net, source, data,
|
||||||
|
1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES + len,
|
||||||
packet + (ANNOUNCE_REQUEST_SIZE_RECV - ONION_RETURN_3)) == -1)
|
packet + (ANNOUNCE_REQUEST_SIZE_RECV - ONION_RETURN_3)) == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user