diff options
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 92727a8c..cfa1bc34 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -254,30 +254,31 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t * | |||
254 | * | 254 | * |
255 | * return -1 if not valid request. | 255 | * return -1 if not valid request. |
256 | */ | 256 | */ |
257 | static int handle_request(Net_Crypto *c, uint8_t *public_key, uint8_t *data, uint8_t *request_id, uint8_t *packet, | 257 | int handle_request(uint8_t *self_public_key, uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, |
258 | uint16_t length) | 258 | uint8_t *request_id, uint8_t *packet, uint16_t length) |
259 | { | 259 | { |
260 | |||
261 | if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING && | 260 | if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING && |
262 | length <= MAX_DATA_SIZE + ENCRYPTION_PADDING && | 261 | length <= MAX_DATA_SIZE) { |
263 | memcmp(packet + 1, c->self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { | 262 | if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
264 | memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); | 263 | memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); |
265 | uint8_t nonce[crypto_box_NONCEBYTES]; | 264 | uint8_t nonce[crypto_box_NONCEBYTES]; |
266 | uint8_t temp[MAX_DATA_SIZE]; | 265 | uint8_t temp[MAX_DATA_SIZE]; |
267 | memcpy(nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2, crypto_box_NONCEBYTES); | 266 | memcpy(nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2, crypto_box_NONCEBYTES); |
268 | int len1 = decrypt_data(public_key, c->self_secret_key, nonce, | 267 | int len1 = decrypt_data(public_key, self_secret_key, nonce, |
269 | packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES, | 268 | packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES, |
270 | length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), temp); | 269 | length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), temp); |
271 | 270 | ||
272 | if (len1 == -1 || len1 == 0) | 271 | if (len1 == -1 || len1 == 0) |
273 | return -1; | 272 | return -1; |
274 | 273 | ||
275 | request_id[0] = temp[0]; | 274 | request_id[0] = temp[0]; |
276 | --len1; | 275 | --len1; |
277 | memcpy(data, temp + 1, len1); | 276 | memcpy(data, temp + 1, len1); |
278 | return len1; | 277 | return len1; |
279 | } else | 278 | } |
280 | return -1; | 279 | } |
280 | |||
281 | return -1; | ||
281 | } | 282 | } |
282 | 283 | ||
283 | void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object) | 284 | void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object) |
@@ -299,7 +300,7 @@ static int cryptopacket_handle(void *object, IP_Port source, uint8_t *packet, ui | |||
299 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 300 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
300 | uint8_t data[MAX_DATA_SIZE]; | 301 | uint8_t data[MAX_DATA_SIZE]; |
301 | uint8_t number; | 302 | uint8_t number; |
302 | int len = handle_request(dht->c, public_key, data, &number, packet, length); | 303 | int len = handle_request(dht->c->self_public_key, dht->c->self_secret_key, public_key, data, &number, packet, length); |
303 | 304 | ||
304 | if (len == -1 || len == 0) | 305 | if (len == -1 || len == 0) |
305 | return 1; | 306 | return 1; |