diff options
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 59f6ee9a..63012ce6 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -1238,7 +1238,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons | |||
1238 | 1238 | ||
1239 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1239 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1240 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ | 1240 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ |
1241 | set_connection_dht_public_key(c, crypt_connection_id, dht_public_key, current_time_monotonic()); | 1241 | set_connection_dht_public_key(c, crypt_connection_id, dht_public_key); |
1242 | 1242 | ||
1243 | if (conn->dht_pk_callback) | 1243 | if (conn->dht_pk_callback) |
1244 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key); | 1244 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key); |
@@ -1477,7 +1477,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const | |||
1477 | if (create_send_handshake(c, crypt_connection_id, n_c.cookie, n_c.dht_public_key) == 0) { | 1477 | if (create_send_handshake(c, crypt_connection_id, n_c.cookie, n_c.dht_public_key) == 0) { |
1478 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1478 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1479 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ | 1479 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ |
1480 | set_connection_dht_public_key(c, crypt_connection_id, n_c.dht_public_key, current_time_monotonic()); | 1480 | set_connection_dht_public_key(c, crypt_connection_id, n_c.dht_public_key); |
1481 | 1481 | ||
1482 | if (conn->dht_pk_callback) | 1482 | if (conn->dht_pk_callback) |
1483 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, n_c.dht_public_key); | 1483 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, n_c.dht_public_key); |
@@ -1530,7 +1530,7 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c) | |||
1530 | 1530 | ||
1531 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1531 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1532 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ | 1532 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ |
1533 | set_connection_dht_public_key(c, crypt_connection_id, n_c->dht_public_key, current_time_monotonic()); | 1533 | set_connection_dht_public_key(c, crypt_connection_id, n_c->dht_public_key); |
1534 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; | 1534 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; |
1535 | conn->packets_left = CRYPTO_MIN_QUEUE_LENGTH; | 1535 | conn->packets_left = CRYPTO_MIN_QUEUE_LENGTH; |
1536 | crypto_connection_add_source(c, crypt_connection_id, n_c->source); | 1536 | crypto_connection_add_source(c, crypt_connection_id, n_c->source); |
@@ -1626,9 +1626,9 @@ static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id) | |||
1626 | /* Copy friends DHT public key into dht_key. | 1626 | /* Copy friends DHT public key into dht_key. |
1627 | * | 1627 | * |
1628 | * return 0 on failure (no key copied). | 1628 | * return 0 on failure (no key copied). |
1629 | * return timestamp on success (key copied). | 1629 | * return 1 on success (key copied). |
1630 | */ | 1630 | */ |
1631 | uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key) | 1631 | unsigned int get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key) |
1632 | { | 1632 | { |
1633 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1633 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1634 | 1634 | ||
@@ -1639,28 +1639,22 @@ uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, ui | |||
1639 | return 0; | 1639 | return 0; |
1640 | 1640 | ||
1641 | memcpy(dht_public_key, conn->dht_public_key, crypto_box_PUBLICKEYBYTES); | 1641 | memcpy(dht_public_key, conn->dht_public_key, crypto_box_PUBLICKEYBYTES); |
1642 | return conn->dht_public_key_timestamp; | 1642 | return 1; |
1643 | } | 1643 | } |
1644 | 1644 | ||
1645 | 1645 | ||
1646 | /* Set the DHT public key of the crypto connection. | 1646 | /* Set the DHT public key of the crypto connection. |
1647 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | ||
1648 | * the other peer. | ||
1649 | * | 1647 | * |
1650 | * return -1 on failure. | 1648 | * return -1 on failure. |
1651 | * return 0 on success. | 1649 | * return 0 on success. |
1652 | */ | 1650 | */ |
1653 | int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key, | 1651 | int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key) |
1654 | uint64_t timestamp) | ||
1655 | { | 1652 | { |
1656 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1653 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1657 | 1654 | ||
1658 | if (conn == 0) | 1655 | if (conn == 0) |
1659 | return -1; | 1656 | return -1; |
1660 | 1657 | ||
1661 | if (timestamp <= conn->dht_public_key_timestamp) | ||
1662 | return -1; | ||
1663 | |||
1664 | if (conn->dht_public_key_set == 1 && memcmp(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) | 1658 | if (conn->dht_public_key_set == 1 && memcmp(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) |
1665 | return -1; | 1659 | return -1; |
1666 | 1660 | ||
@@ -1670,7 +1664,6 @@ int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const | |||
1670 | 1664 | ||
1671 | memcpy(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES); | 1665 | memcpy(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES); |
1672 | conn->dht_public_key_set = 1; | 1666 | conn->dht_public_key_set = 1; |
1673 | conn->dht_public_key_timestamp = timestamp; | ||
1674 | 1667 | ||
1675 | if (conn->status == CRYPTO_CONN_COOKIE_REQUESTING) { | 1668 | if (conn->status == CRYPTO_CONN_COOKIE_REQUESTING) { |
1676 | conn->cookie_request_number = random_64b(); | 1669 | conn->cookie_request_number = random_64b(); |