diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-15 00:29:51 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-16 15:46:13 +0000 |
commit | 22db2b9fe581a35300b66126604d12e83c2eafb1 (patch) | |
tree | f0a4b46fd2453f917e89bf8034eafd5a5946d0f0 /toxcore/onion_client.c | |
parent | bc58c6ea2f68123abb12ccd09bb9f50bcb230e10 (diff) |
Make Net_Crypto a module-private type.
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 50373330..f7ff41bd 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -587,12 +587,13 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_ | |||
587 | int len; | 587 | int len; |
588 | 588 | ||
589 | if (num == 0) { | 589 | if (num == 0) { |
590 | len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->c->self_public_key, | 590 | len = create_announce_request(request, sizeof(request), dest_pubkey, nc_get_self_public_key(onion_c->c), |
591 | onion_c->c->self_secret_key, ping_id, onion_c->c->self_public_key, onion_c->temp_public_key, sendback); | 591 | nc_get_self_secret_key(onion_c->c), ping_id, nc_get_self_public_key(onion_c->c), |
592 | onion_c->temp_public_key, sendback); | ||
592 | } else { | 593 | } else { |
593 | len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->friends_list[num - 1].temp_public_key, | 594 | len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->friends_list[num - 1].temp_public_key, |
594 | onion_c->friends_list[num - 1].temp_secret_key, ping_id, onion_c->friends_list[num - 1].real_public_key, zero_ping_id, | 595 | onion_c->friends_list[num - 1].temp_secret_key, ping_id, |
595 | sendback); | 596 | onion_c->friends_list[num - 1].real_public_key, zero_ping_id, sendback); |
596 | } | 597 | } |
597 | 598 | ||
598 | if (len == -1) { | 599 | if (len == -1) { |
@@ -670,12 +671,12 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
670 | } | 671 | } |
671 | 672 | ||
672 | Onion_Node *list_nodes = NULL; | 673 | Onion_Node *list_nodes = NULL; |
673 | uint8_t *reference_id = NULL; | 674 | const uint8_t *reference_id = NULL; |
674 | unsigned int list_length; | 675 | unsigned int list_length; |
675 | 676 | ||
676 | if (num == 0) { | 677 | if (num == 0) { |
677 | list_nodes = onion_c->clients_announce_list; | 678 | list_nodes = onion_c->clients_announce_list; |
678 | reference_id = onion_c->c->self_public_key; | 679 | reference_id = nc_get_self_public_key(onion_c->c); |
679 | list_length = MAX_ONION_CLIENTS_ANNOUNCE; | 680 | list_length = MAX_ONION_CLIENTS_ANNOUNCE; |
680 | 681 | ||
681 | if (is_stored == 1 && public_key_cmp(pingid_or_key, onion_c->temp_public_key) != 0) { | 682 | if (is_stored == 1 && public_key_cmp(pingid_or_key, onion_c->temp_public_key) != 0) { |
@@ -772,7 +773,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for | |||
772 | } | 773 | } |
773 | 774 | ||
774 | Onion_Node *list_nodes = NULL; | 775 | Onion_Node *list_nodes = NULL; |
775 | uint8_t *reference_id = NULL; | 776 | const uint8_t *reference_id = NULL; |
776 | unsigned int list_length; | 777 | unsigned int list_length; |
777 | 778 | ||
778 | Last_Pinged *last_pinged = NULL; | 779 | Last_Pinged *last_pinged = NULL; |
@@ -780,7 +781,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for | |||
780 | 781 | ||
781 | if (num == 0) { | 782 | if (num == 0) { |
782 | list_nodes = onion_c->clients_announce_list; | 783 | list_nodes = onion_c->clients_announce_list; |
783 | reference_id = onion_c->c->self_public_key; | 784 | reference_id = nc_get_self_public_key(onion_c->c); |
784 | list_length = MAX_ONION_CLIENTS_ANNOUNCE; | 785 | list_length = MAX_ONION_CLIENTS_ANNOUNCE; |
785 | last_pinged = onion_c->last_pinged; | 786 | last_pinged = onion_c->last_pinged; |
786 | last_pinged_index = &onion_c->last_pinged_index; | 787 | last_pinged_index = &onion_c->last_pinged_index; |
@@ -847,7 +848,8 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t | |||
847 | int len = -1; | 848 | int len = -1; |
848 | 849 | ||
849 | if (num == 0) { | 850 | if (num == 0) { |
850 | len = decrypt_data(public_key, onion_c->c->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | 851 | len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c), |
852 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | ||
851 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, | 853 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, |
852 | length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain); | 854 | length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain); |
853 | } else { | 855 | } else { |
@@ -913,7 +915,8 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac | |||
913 | } | 915 | } |
914 | 916 | ||
915 | VLA(uint8_t, plain, SIZEOF_VLA(temp_plain) - DATA_IN_RESPONSE_MIN_SIZE); | 917 | VLA(uint8_t, plain, SIZEOF_VLA(temp_plain) - DATA_IN_RESPONSE_MIN_SIZE); |
916 | len = decrypt_data(temp_plain, onion_c->c->self_secret_key, packet + 1, temp_plain + CRYPTO_PUBLIC_KEY_SIZE, | 918 | len = decrypt_data(temp_plain, nc_get_self_secret_key(onion_c->c), |
919 | packet + 1, temp_plain + CRYPTO_PUBLIC_KEY_SIZE, | ||
917 | SIZEOF_VLA(temp_plain) - CRYPTO_PUBLIC_KEY_SIZE, plain); | 920 | SIZEOF_VLA(temp_plain) - CRYPTO_PUBLIC_KEY_SIZE, plain); |
918 | 921 | ||
919 | if ((uint32_t)len != SIZEOF_VLA(plain)) { | 922 | if ((uint32_t)len != SIZEOF_VLA(plain)) { |
@@ -1064,8 +1067,9 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, | |||
1064 | random_nonce(nonce); | 1067 | random_nonce(nonce); |
1065 | 1068 | ||
1066 | VLA(uint8_t, packet, DATA_IN_RESPONSE_MIN_SIZE + length); | 1069 | VLA(uint8_t, packet, DATA_IN_RESPONSE_MIN_SIZE + length); |
1067 | memcpy(packet, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 1070 | memcpy(packet, nc_get_self_public_key(onion_c->c), CRYPTO_PUBLIC_KEY_SIZE); |
1068 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, | 1071 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, |
1072 | nc_get_self_secret_key(onion_c->c), nonce, data, | ||
1069 | length, packet + CRYPTO_PUBLIC_KEY_SIZE); | 1073 | length, packet + CRYPTO_PUBLIC_KEY_SIZE); |
1070 | 1074 | ||
1071 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE != SIZEOF_VLA(packet)) { | 1075 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE != SIZEOF_VLA(packet)) { |
@@ -1118,9 +1122,10 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin | |||
1118 | random_nonce(nonce); | 1122 | random_nonce(nonce); |
1119 | 1123 | ||
1120 | VLA(uint8_t, temp, DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE + length); | 1124 | VLA(uint8_t, temp, DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE + length); |
1121 | memcpy(temp, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 1125 | memcpy(temp, nc_get_self_public_key(onion_c->c), CRYPTO_PUBLIC_KEY_SIZE); |
1122 | memcpy(temp + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); | 1126 | memcpy(temp + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); |
1123 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, | 1127 | int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, |
1128 | nc_get_self_secret_key(onion_c->c), nonce, data, | ||
1124 | length, temp + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); | 1129 | length, temp + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); |
1125 | 1130 | ||
1126 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE != SIZEOF_VLA(temp)) { | 1131 | if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE != SIZEOF_VLA(temp)) { |
@@ -1152,7 +1157,8 @@ static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_ | |||
1152 | } | 1157 | } |
1153 | 1158 | ||
1154 | uint8_t plain[DHTPK_DATA_MAX_LENGTH]; | 1159 | uint8_t plain[DHTPK_DATA_MAX_LENGTH]; |
1155 | int len = decrypt_data(packet, onion_c->c->self_secret_key, packet + CRYPTO_PUBLIC_KEY_SIZE, | 1160 | int len = decrypt_data(packet, nc_get_self_secret_key(onion_c->c), |
1161 | packet + CRYPTO_PUBLIC_KEY_SIZE, | ||
1156 | packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, | 1162 | packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, |
1157 | length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE), plain); | 1163 | length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE), plain); |
1158 | 1164 | ||
@@ -1819,11 +1825,11 @@ void do_onion_client(Onion_Client *onion_c) | |||
1819 | bool UDP_connected = DHT_non_lan_connected(onion_c->dht); | 1825 | bool UDP_connected = DHT_non_lan_connected(onion_c->dht); |
1820 | 1826 | ||
1821 | if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) { | 1827 | if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) { |
1822 | set_tcp_onion_status(onion_c->c->tcp_c, !UDP_connected); | 1828 | set_tcp_onion_status(nc_get_tcp_c(onion_c->c), !UDP_connected); |
1823 | } | 1829 | } |
1824 | 1830 | ||
1825 | onion_c->UDP_connected = UDP_connected | 1831 | onion_c->UDP_connected = UDP_connected |
1826 | || get_random_tcp_onion_conn_number(onion_c->c->tcp_c) == -1; /* Check if connected to any TCP relays. */ | 1832 | || get_random_tcp_onion_conn_number(nc_get_tcp_c(onion_c->c)) == -1; /* Check if connected to any TCP relays. */ |
1827 | 1833 | ||
1828 | if (onion_connection_status(onion_c)) { | 1834 | if (onion_connection_status(onion_c)) { |
1829 | for (i = 0; i < onion_c->num_friends; ++i) { | 1835 | for (i = 0; i < onion_c->num_friends; ++i) { |
@@ -1857,8 +1863,8 @@ Onion_Client *new_onion_client(Net_Crypto *c) | |||
1857 | return NULL; | 1863 | return NULL; |
1858 | } | 1864 | } |
1859 | 1865 | ||
1860 | onion_c->dht = c->dht; | 1866 | onion_c->dht = nc_get_dht(c); |
1861 | onion_c->net = c->dht->net; | 1867 | onion_c->net = onion_c->dht->net; |
1862 | onion_c->c = c; | 1868 | onion_c->c = c; |
1863 | new_symmetric_key(onion_c->secret_symmetric_key); | 1869 | new_symmetric_key(onion_c->secret_symmetric_key); |
1864 | crypto_new_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); | 1870 | crypto_new_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); |
@@ -1866,7 +1872,7 @@ Onion_Client *new_onion_client(Net_Crypto *c) | |||
1866 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); | 1872 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); |
1867 | oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, &handle_dhtpk_announce, onion_c); | 1873 | oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, &handle_dhtpk_announce, onion_c); |
1868 | cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, &handle_dht_dhtpk, onion_c); | 1874 | cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, &handle_dht_dhtpk, onion_c); |
1869 | set_onion_packet_tcp_connection_callback(onion_c->c->tcp_c, &handle_tcp_onion, onion_c); | 1875 | set_onion_packet_tcp_connection_callback(nc_get_tcp_c(onion_c->c), &handle_tcp_onion, onion_c); |
1870 | 1876 | ||
1871 | return onion_c; | 1877 | return onion_c; |
1872 | } | 1878 | } |
@@ -1883,7 +1889,7 @@ void kill_onion_client(Onion_Client *onion_c) | |||
1883 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); | 1889 | networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); |
1884 | oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL); | 1890 | oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL); |
1885 | cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, NULL, NULL); | 1891 | cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, NULL, NULL); |
1886 | set_onion_packet_tcp_connection_callback(onion_c->c->tcp_c, NULL, NULL); | 1892 | set_onion_packet_tcp_connection_callback(nc_get_tcp_c(onion_c->c), NULL, NULL); |
1887 | crypto_memzero(onion_c, sizeof(Onion_Client)); | 1893 | crypto_memzero(onion_c, sizeof(Onion_Client)); |
1888 | free(onion_c); | 1894 | free(onion_c); |
1889 | } | 1895 | } |