2023-07-25 11:53:09 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
* Copyright © 2016-2018 The TokTok team.
|
|
|
|
* Copyright © 2013 Tox project.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the announce part of docs/Prevent_Tracking.txt
|
|
|
|
*/
|
|
|
|
#include "onion_announce.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "DHT.h"
|
|
|
|
#include "LAN_discovery.h"
|
Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272
b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.
git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
2024-03-07 23:12:55 +01:00
|
|
|
#include "attributes.h"
|
2023-07-25 11:53:09 +02:00
|
|
|
#include "ccompat.h"
|
2024-01-09 16:39:05 +01:00
|
|
|
#include "crypto_core.h"
|
|
|
|
#include "logger.h"
|
|
|
|
#include "mem.h"
|
2023-07-25 11:53:09 +02:00
|
|
|
#include "mono_time.h"
|
2024-01-09 16:39:05 +01:00
|
|
|
#include "network.h"
|
|
|
|
#include "onion.h"
|
2023-07-25 11:53:09 +02:00
|
|
|
#include "shared_key_cache.h"
|
2024-12-19 16:27:40 +01:00
|
|
|
#include "sort.h"
|
2024-01-09 16:39:05 +01:00
|
|
|
#include "timed_auth.h"
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
#define PING_ID_TIMEOUT ONION_ANNOUNCE_TIMEOUT
|
|
|
|
|
|
|
|
#define ANNOUNCE_REQUEST_MIN_SIZE_RECV (ONION_ANNOUNCE_REQUEST_MIN_SIZE + ONION_RETURN_3)
|
|
|
|
#define ANNOUNCE_REQUEST_MAX_SIZE_RECV (ONION_ANNOUNCE_REQUEST_MAX_SIZE + ONION_RETURN_3)
|
|
|
|
|
|
|
|
/* TODO(Jfreegman): DEPRECATE */
|
|
|
|
#define ANNOUNCE_REQUEST_SIZE_RECV (ONION_ANNOUNCE_REQUEST_SIZE + ONION_RETURN_3)
|
|
|
|
|
|
|
|
#define DATA_REQUEST_MIN_SIZE ONION_DATA_REQUEST_MIN_SIZE
|
|
|
|
#define DATA_REQUEST_MIN_SIZE_RECV (DATA_REQUEST_MIN_SIZE + ONION_RETURN_3)
|
|
|
|
|
|
|
|
#define ONION_MINIMAL_SIZE (ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE * 2 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH)
|
|
|
|
|
|
|
|
/* Settings for the shared key cache */
|
|
|
|
#define MAX_KEYS_PER_SLOT 4
|
|
|
|
#define KEYS_TIMEOUT 600
|
|
|
|
|
|
|
|
static_assert(ONION_PING_ID_SIZE == CRYPTO_PUBLIC_KEY_SIZE,
|
|
|
|
"announce response packets assume that ONION_PING_ID_SIZE is equal to CRYPTO_PUBLIC_KEY_SIZE");
|
|
|
|
|
|
|
|
typedef struct Onion_Announce_Entry {
|
|
|
|
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
|
|
|
IP_Port ret_ip_port;
|
|
|
|
uint8_t ret[ONION_RETURN_3];
|
|
|
|
uint8_t data_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
|
|
|
uint64_t announce_time;
|
|
|
|
} Onion_Announce_Entry;
|
|
|
|
|
|
|
|
struct Onion_Announce {
|
|
|
|
const Logger *log;
|
|
|
|
const Mono_Time *mono_time;
|
|
|
|
const Random *rng;
|
2023-10-10 19:37:39 +02:00
|
|
|
const Memory *mem;
|
2023-07-25 11:53:09 +02:00
|
|
|
DHT *dht;
|
|
|
|
Networking_Core *net;
|
|
|
|
Onion_Announce_Entry entries[ONION_ANNOUNCE_MAX_ENTRIES];
|
|
|
|
uint8_t hmac_key[CRYPTO_HMAC_KEY_SIZE];
|
|
|
|
|
|
|
|
Shared_Key_Cache *shared_keys_recv;
|
|
|
|
|
|
|
|
uint16_t extra_data_max_size;
|
|
|
|
pack_extra_data_cb *extra_data_callback;
|
|
|
|
void *extra_data_object;
|
|
|
|
};
|
|
|
|
|
|
|
|
void onion_announce_extra_data_callback(Onion_Announce *onion_a, uint16_t extra_data_max_size,
|
|
|
|
pack_extra_data_cb *extra_data_callback, void *extra_data_object)
|
|
|
|
{
|
|
|
|
onion_a->extra_data_max_size = extra_data_max_size;
|
|
|
|
onion_a->extra_data_callback = extra_data_callback;
|
|
|
|
onion_a->extra_data_object = extra_data_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *onion_announce_entry_public_key(Onion_Announce *onion_a, uint32_t entry)
|
|
|
|
{
|
|
|
|
return onion_a->entries[entry].public_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onion_announce_entry_set_time(Onion_Announce *onion_a, uint32_t entry, uint64_t announce_time)
|
|
|
|
{
|
|
|
|
onion_a->entries[entry].announce_time = announce_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Create an onion announce request packet in packet of max_packet_length.
|
|
|
|
*
|
|
|
|
* Recommended value for max_packet_length is ONION_ANNOUNCE_REQUEST_MIN_SIZE.
|
|
|
|
*
|
|
|
|
* dest_client_id is the public key of the node the packet will be sent to.
|
|
|
|
* public_key and secret_key is the kepair which will be used to encrypt the request.
|
|
|
|
* ping_id is the ping id that will be sent in the request.
|
|
|
|
* client_id is the client id of the node we are searching for.
|
|
|
|
* data_public_key is the public key we want others to encrypt their data packets with.
|
|
|
|
* sendback_data is the data of ONION_ANNOUNCE_SENDBACK_DATA_LENGTH length that we expect to
|
|
|
|
* receive back in the response.
|
|
|
|
*
|
|
|
|
* return -1 on failure.
|
|
|
|
* return packet length on success.
|
|
|
|
*/
|
2024-12-19 16:27:40 +01:00
|
|
|
int create_announce_request(const Memory *mem, const Random *rng, uint8_t *packet, uint16_t max_packet_length, const uint8_t *dest_client_id,
|
2023-07-25 11:53:09 +02:00
|
|
|
const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id,
|
|
|
|
const uint8_t *data_public_key, uint64_t sendback_data)
|
|
|
|
{
|
|
|
|
if (max_packet_length < ONION_ANNOUNCE_REQUEST_MIN_SIZE) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t plain[ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE +
|
|
|
|
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
|
|
|
|
memcpy(plain, ping_id, ONION_PING_ID_SIZE);
|
|
|
|
memcpy(plain + ONION_PING_ID_SIZE, client_id, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
memcpy(plain + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE, data_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
memcpy(plain + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE, &sendback_data,
|
|
|
|
sizeof(sendback_data));
|
|
|
|
|
|
|
|
packet[0] = NET_PACKET_ANNOUNCE_REQUEST_OLD;
|
|
|
|
random_nonce(rng, packet + 1);
|
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
const int len = encrypt_data(mem, dest_client_id, secret_key, packet + 1, plain, sizeof(plain),
|
2023-07-25 11:53:09 +02:00
|
|
|
packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
|
|
|
|
if ((uint32_t)len + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE != ONION_ANNOUNCE_REQUEST_MIN_SIZE) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(packet + 1 + CRYPTO_NONCE_SIZE, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
|
|
|
|
return ONION_ANNOUNCE_REQUEST_MIN_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Create an onion data request packet in packet of max_packet_length.
|
|
|
|
*
|
|
|
|
* Recommended value for max_packet_length is ONION_ANNOUNCE_REQUEST_SIZE.
|
|
|
|
*
|
|
|
|
* public_key is the real public key of the node which we want to send the data of length length to.
|
|
|
|
* encrypt_public_key is the public key used to encrypt the data packet.
|
|
|
|
*
|
|
|
|
* nonce is the nonce to encrypt this packet with
|
|
|
|
*
|
|
|
|
* return -1 on failure.
|
|
|
|
* return 0 on success.
|
|
|
|
*/
|
2024-12-19 16:27:40 +01:00
|
|
|
int create_data_request(const Memory *mem, const Random *rng, uint8_t *packet, uint16_t max_packet_length, const uint8_t *public_key,
|
2023-07-25 11:53:09 +02:00
|
|
|
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length)
|
|
|
|
{
|
|
|
|
if (DATA_REQUEST_MIN_SIZE + length > max_packet_length) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DATA_REQUEST_MIN_SIZE + length > ONION_MAX_DATA_SIZE) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
packet[0] = NET_PACKET_ONION_DATA_REQUEST;
|
|
|
|
memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE);
|
|
|
|
|
|
|
|
uint8_t random_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
|
|
|
uint8_t random_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
|
|
|
crypto_new_keypair(rng, random_public_key, random_secret_key);
|
|
|
|
|
|
|
|
memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, random_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
const int len = encrypt_data(mem, encrypt_public_key, random_secret_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length,
|
2023-07-25 11:53:09 +02:00
|
|
|
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
|
|
|
|
if (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + len != DATA_REQUEST_MIN_SIZE +
|
|
|
|
length) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DATA_REQUEST_MIN_SIZE + length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Create and send an onion announce request packet.
|
|
|
|
*
|
|
|
|
* path is the path the request will take before it is sent to dest.
|
|
|
|
*
|
|
|
|
* public_key and secret_key is the kepair which will be used to encrypt the request.
|
|
|
|
* ping_id is the ping id that will be sent in the request.
|
|
|
|
* client_id is the client id of the node we are searching for.
|
|
|
|
* data_public_key is the public key we want others to encrypt their data packets with.
|
|
|
|
* sendback_data is the data of ONION_ANNOUNCE_SENDBACK_DATA_LENGTH length that we expect to
|
|
|
|
* receive back in the response.
|
|
|
|
*
|
|
|
|
* return -1 on failure.
|
|
|
|
* return 0 on success.
|
|
|
|
*/
|
2023-12-24 12:21:34 +01:00
|
|
|
int send_announce_request(
|
2024-12-19 16:27:40 +01:00
|
|
|
const Logger *log, const Memory *mem, const Networking_Core *net, const Random *rng,
|
Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272
b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.
git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
2024-03-07 23:12:55 +01:00
|
|
|
const Onion_Path *path, const Node_format *dest,
|
|
|
|
const uint8_t *public_key, const uint8_t *secret_key,
|
|
|
|
const uint8_t *ping_id, const uint8_t *client_id,
|
|
|
|
const uint8_t *data_public_key, uint64_t sendback_data)
|
2023-07-25 11:53:09 +02:00
|
|
|
{
|
|
|
|
uint8_t request[ONION_ANNOUNCE_REQUEST_MIN_SIZE];
|
2024-12-19 16:27:40 +01:00
|
|
|
int len = create_announce_request(mem, rng, request, sizeof(request), dest->public_key, public_key, secret_key, ping_id,
|
2023-07-25 11:53:09 +02:00
|
|
|
client_id, data_public_key, sendback_data);
|
|
|
|
|
|
|
|
if (len != sizeof(request)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t packet[ONION_MAX_PACKET_SIZE];
|
2024-12-19 16:27:40 +01:00
|
|
|
len = create_onion_packet(mem, rng, packet, sizeof(packet), path, &dest->ip_port, request, sizeof(request));
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (len == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendpacket(net, &path->ip_port1, packet, len) != len) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Create and send an onion data request packet.
|
|
|
|
*
|
|
|
|
* path is the path the request will take before it is sent to dest.
|
|
|
|
* (if dest knows the person with the public_key they should
|
|
|
|
* send the packet to that person in the form of a response)
|
|
|
|
*
|
|
|
|
* public_key is the real public key of the node which we want to send the data of length length to.
|
|
|
|
* encrypt_public_key is the public key used to encrypt the data packet.
|
|
|
|
*
|
|
|
|
* nonce is the nonce to encrypt this packet with
|
|
|
|
*
|
|
|
|
* The maximum length of data is MAX_DATA_REQUEST_SIZE.
|
|
|
|
*
|
|
|
|
* return -1 on failure.
|
|
|
|
* return 0 on success.
|
|
|
|
*/
|
2023-12-24 12:21:34 +01:00
|
|
|
int send_data_request(
|
2024-12-19 16:27:40 +01:00
|
|
|
const Logger *log, const Memory *mem, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest,
|
Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272
b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.
git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
2024-03-07 23:12:55 +01:00
|
|
|
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce,
|
|
|
|
const uint8_t *data, uint16_t length)
|
2023-07-25 11:53:09 +02:00
|
|
|
{
|
|
|
|
uint8_t request[ONION_MAX_DATA_SIZE];
|
2024-12-19 16:27:40 +01:00
|
|
|
int len = create_data_request(mem, rng, request, sizeof(request), public_key, encrypt_public_key, nonce, data, length);
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (len == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t packet[ONION_MAX_PACKET_SIZE];
|
2024-12-19 16:27:40 +01:00
|
|
|
len = create_onion_packet(mem, rng, packet, sizeof(packet), path, dest, request, len);
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (len == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendpacket(net, &path->ip_port1, packet, len) != len) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief check if public key is in entries list
|
|
|
|
*
|
|
|
|
* return -1 if no
|
|
|
|
* return position in list if yes
|
|
|
|
*/
|
|
|
|
non_null()
|
|
|
|
static int in_entries(const Onion_Announce *onion_a, const uint8_t *public_key)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < ONION_ANNOUNCE_MAX_ENTRIES; ++i) {
|
|
|
|
if (!mono_time_is_timeout(onion_a->mono_time, onion_a->entries[i].announce_time, ONION_ANNOUNCE_TIMEOUT)
|
|
|
|
&& pk_equal(onion_a->entries[i].public_key, public_key)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
typedef struct Onion_Announce_Entry_Cmp {
|
|
|
|
const Memory *mem;
|
2023-07-25 11:53:09 +02:00
|
|
|
const Mono_Time *mono_time;
|
2024-12-19 16:27:40 +01:00
|
|
|
const uint8_t *comp_public_key;
|
|
|
|
} Onion_Announce_Entry_Cmp;
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
non_null()
|
2024-12-19 16:27:40 +01:00
|
|
|
static int onion_announce_entry_cmp(const Onion_Announce_Entry_Cmp *cmp, const Onion_Announce_Entry *entry1, const Onion_Announce_Entry *entry2)
|
2023-07-25 11:53:09 +02:00
|
|
|
{
|
2024-12-19 16:27:40 +01:00
|
|
|
const bool t1 = mono_time_is_timeout(cmp->mono_time, entry1->announce_time, ONION_ANNOUNCE_TIMEOUT);
|
|
|
|
const bool t2 = mono_time_is_timeout(cmp->mono_time, entry2->announce_time, ONION_ANNOUNCE_TIMEOUT);
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (t1 && t2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
const int closest = id_closest(cmp->comp_public_key, entry1->public_key, entry2->public_key);
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (closest == 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closest == 2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
2024-12-19 16:27:40 +01:00
|
|
|
static bool onion_announce_entry_less_handler(const void *object, const void *a, const void *b)
|
2023-07-25 11:53:09 +02:00
|
|
|
{
|
2024-12-19 16:27:40 +01:00
|
|
|
const Onion_Announce_Entry_Cmp *cmp = (const Onion_Announce_Entry_Cmp *)object;
|
|
|
|
const Onion_Announce_Entry *entry1 = (const Onion_Announce_Entry *)a;
|
|
|
|
const Onion_Announce_Entry *entry2 = (const Onion_Announce_Entry *)b;
|
2023-07-25 11:53:09 +02:00
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
return onion_announce_entry_cmp(cmp, entry1, entry2) < 0;
|
|
|
|
}
|
2023-07-25 11:53:09 +02:00
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
non_null()
|
|
|
|
static const void *onion_announce_entry_get_handler(const void *arr, uint32_t index)
|
|
|
|
{
|
|
|
|
const Onion_Announce_Entry *entries = (const Onion_Announce_Entry *)arr;
|
|
|
|
return &entries[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static void onion_announce_entry_set_handler(void *arr, uint32_t index, const void *val)
|
|
|
|
{
|
|
|
|
Onion_Announce_Entry *entries = (Onion_Announce_Entry *)arr;
|
|
|
|
const Onion_Announce_Entry *entry = (const Onion_Announce_Entry *)val;
|
|
|
|
entries[index] = *entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static void *onion_announce_entry_subarr_handler(void *arr, uint32_t index, uint32_t size)
|
|
|
|
{
|
|
|
|
Onion_Announce_Entry *entries = (Onion_Announce_Entry *)arr;
|
|
|
|
return &entries[index];
|
|
|
|
}
|
2023-07-25 11:53:09 +02:00
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
non_null()
|
|
|
|
static void *onion_announce_entry_alloc_handler(const void *object, uint32_t size)
|
|
|
|
{
|
|
|
|
const Onion_Announce_Entry_Cmp *cmp = (const Onion_Announce_Entry_Cmp *)object;
|
|
|
|
Onion_Announce_Entry *tmp = (Onion_Announce_Entry *)mem_valloc(cmp->mem, size, sizeof(Onion_Announce_Entry));
|
2023-07-25 11:53:09 +02:00
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
if (tmp == nullptr) {
|
|
|
|
return nullptr;
|
2023-07-25 11:53:09 +02:00
|
|
|
}
|
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static void onion_announce_entry_delete_handler(const void *object, void *arr, uint32_t size)
|
|
|
|
{
|
|
|
|
const Onion_Announce_Entry_Cmp *cmp = (const Onion_Announce_Entry_Cmp *)object;
|
|
|
|
mem_delete(cmp->mem, arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Sort_Funcs onion_announce_entry_cmp_funcs = {
|
|
|
|
onion_announce_entry_less_handler,
|
|
|
|
onion_announce_entry_get_handler,
|
|
|
|
onion_announce_entry_set_handler,
|
|
|
|
onion_announce_entry_subarr_handler,
|
|
|
|
onion_announce_entry_alloc_handler,
|
|
|
|
onion_announce_entry_delete_handler,
|
|
|
|
};
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static void sort_onion_announce_list(const Memory *mem, const Mono_Time *mono_time,
|
|
|
|
Onion_Announce_Entry *list, unsigned int length,
|
|
|
|
const uint8_t *comp_public_key)
|
|
|
|
{
|
|
|
|
// Pass comp_public_key to sort with each Onion_Announce_Entry entry, so the
|
|
|
|
// comparison function can use it as the base of comparison.
|
|
|
|
const Onion_Announce_Entry_Cmp cmp = {
|
|
|
|
mem,
|
|
|
|
mono_time,
|
|
|
|
comp_public_key,
|
|
|
|
};
|
|
|
|
|
|
|
|
merge_sort(list, length, &cmp, &onion_announce_entry_cmp_funcs);
|
2023-07-25 11:53:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief add entry to entries list
|
|
|
|
*
|
|
|
|
* return -1 if failure
|
|
|
|
* return position if added
|
|
|
|
*/
|
|
|
|
non_null()
|
|
|
|
static int add_to_entries(Onion_Announce *onion_a, const IP_Port *ret_ip_port, const uint8_t *public_key,
|
|
|
|
const uint8_t *data_public_key, const uint8_t *ret)
|
|
|
|
{
|
|
|
|
int pos = in_entries(onion_a, public_key);
|
|
|
|
|
|
|
|
if (pos == -1) {
|
|
|
|
for (unsigned i = 0; i < ONION_ANNOUNCE_MAX_ENTRIES; ++i) {
|
|
|
|
if (mono_time_is_timeout(onion_a->mono_time, onion_a->entries[i].announce_time, ONION_ANNOUNCE_TIMEOUT)) {
|
|
|
|
pos = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos == -1) {
|
|
|
|
if (id_closest(dht_get_self_public_key(onion_a->dht), public_key, onion_a->entries[0].public_key) == 1) {
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(onion_a->entries[pos].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
onion_a->entries[pos].ret_ip_port = *ret_ip_port;
|
|
|
|
memcpy(onion_a->entries[pos].ret, ret, ONION_RETURN_3);
|
|
|
|
memcpy(onion_a->entries[pos].data_public_key, data_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
onion_a->entries[pos].announce_time = mono_time_get(onion_a->mono_time);
|
|
|
|
|
2023-10-10 19:37:39 +02:00
|
|
|
sort_onion_announce_list(onion_a->mem, onion_a->mono_time,
|
|
|
|
onion_a->entries, ONION_ANNOUNCE_MAX_ENTRIES,
|
2023-07-25 11:53:09 +02:00
|
|
|
dht_get_self_public_key(onion_a->dht));
|
|
|
|
return in_entries(onion_a, public_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static void make_announce_payload_helper(const Onion_Announce *onion_a, const uint8_t *ping_id,
|
|
|
|
uint8_t *response, int index, const uint8_t *packet_public_key, const uint8_t *data_public_key)
|
|
|
|
{
|
|
|
|
if (index < 0) {
|
|
|
|
response[0] = 0;
|
|
|
|
memcpy(response + 1, ping_id, ONION_PING_ID_SIZE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pk_equal(onion_a->entries[index].public_key, packet_public_key)) {
|
|
|
|
if (!pk_equal(onion_a->entries[index].data_public_key, data_public_key)) {
|
|
|
|
response[0] = 0;
|
|
|
|
memcpy(response + 1, ping_id, ONION_PING_ID_SIZE);
|
|
|
|
} else {
|
|
|
|
response[0] = 2;
|
|
|
|
memcpy(response + 1, ping_id, ONION_PING_ID_SIZE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
response[0] = 1;
|
|
|
|
memcpy(response + 1, onion_a->entries[index].data_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Handle an onion announce request, possibly with extra data for group chats.
|
|
|
|
*
|
|
|
|
* @param onion_a The announce object.
|
|
|
|
* @param source Requester IP/Port.
|
|
|
|
* @param packet Encrypted incoming packet.
|
|
|
|
* @param length Length of incoming packet.
|
|
|
|
* @param response_packet_id Packet ID to use for the onion announce response.
|
|
|
|
* @param plain_size Expected size of the decrypted packet. This function returns an error if the
|
|
|
|
* actual decrypted size is not exactly equal to this number.
|
|
|
|
* @param want_node_count If true, the packed nodes in the response are preceded by the number of
|
|
|
|
* nodes sent in the packet. This is necessary if you want to send extra data after the nodes.
|
|
|
|
* @param max_extra_size Amount of memory to allocate in the outgoing packet to be filled by the
|
|
|
|
* extra data callback.
|
|
|
|
* @param pack_extra_data_callback Callback that may write extra data into the packet.
|
|
|
|
*
|
|
|
|
* @retval 1 on failure.
|
|
|
|
* @retval 0 on success.
|
|
|
|
*/
|
|
|
|
non_null(1, 2, 3) nullable(9)
|
|
|
|
static int handle_announce_request_common(
|
|
|
|
Onion_Announce *onion_a, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
|
|
|
uint8_t response_packet_id, uint16_t plain_size, bool want_node_count, uint16_t max_extra_size,
|
|
|
|
pack_extra_data_cb *pack_extra_data_callback)
|
|
|
|
{
|
|
|
|
const uint8_t *packet_public_key = packet + 1 + CRYPTO_NONCE_SIZE;
|
|
|
|
const uint8_t *shared_key = shared_key_cache_lookup(onion_a->shared_keys_recv, packet_public_key);
|
|
|
|
|
|
|
|
if (shared_key == nullptr) {
|
|
|
|
/* Error looking up/deriving the shared key */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-10-10 19:37:39 +02:00
|
|
|
uint8_t *plain = (uint8_t *)mem_balloc(onion_a->mem, plain_size);
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (plain == nullptr) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-12-19 16:27:40 +01:00
|
|
|
const int decrypted_len = decrypt_data_symmetric(onion_a->mem, shared_key, packet + 1,
|
2023-07-25 11:53:09 +02:00
|
|
|
packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, plain_size + CRYPTO_MAC_SIZE, plain);
|
|
|
|
|
|
|
|
if ((uint32_t)decrypted_len != plain_size) {
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint16_t ping_id_data_len = CRYPTO_PUBLIC_KEY_SIZE + sizeof(*source);
|
|
|
|
uint8_t ping_id_data[CRYPTO_PUBLIC_KEY_SIZE + sizeof(*source)];
|
|
|
|
memcpy(ping_id_data, packet_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
|
|
memcpy(ping_id_data + CRYPTO_PUBLIC_KEY_SIZE, source, sizeof(*source));
|
|
|
|
|
|
|
|
const uint8_t *data_public_key = plain + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE;
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (check_timed_auth(onion_a->mono_time, PING_ID_TIMEOUT, onion_a->hmac_key,
|
|
|
|
ping_id_data, ping_id_data_len, plain)) {
|
|
|
|
index = add_to_entries(onion_a, source, packet_public_key, data_public_key,
|
|
|
|
packet + (length - ONION_RETURN_3));
|
|
|
|
} else {
|
|
|
|
index = in_entries(onion_a, plain + ONION_PING_ID_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Respond with a announce response packet */
|
|
|
|
Node_format nodes_list[MAX_SENT_NODES];
|
|
|
|
const unsigned int num_nodes =
|
|
|
|
get_close_nodes(onion_a->dht, plain + ONION_PING_ID_SIZE, nodes_list, net_family_unspec(), ip_is_lan(&source->ip), false);
|
|
|
|
|
|
|
|
assert(num_nodes <= UINT8_MAX);
|
|
|
|
|
|
|
|
uint8_t nonce[CRYPTO_NONCE_SIZE];
|
|
|
|
random_nonce(onion_a->rng, nonce);
|
|
|
|
|
|
|
|
const uint16_t nodes_offset = 1 + ONION_PING_ID_SIZE + (want_node_count ? 1 : 0);
|
|
|
|
const uint16_t response_size = nodes_offset
|
|
|
|
+ MAX_SENT_NODES * PACKED_NODE_SIZE_IP6
|
|
|
|
+ max_extra_size;
|
2023-10-10 19:37:39 +02:00
|
|
|
uint8_t *response = (uint8_t *)mem_balloc(onion_a->mem, response_size);
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (response == nullptr) {
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t ping_id[TIMED_AUTH_SIZE];
|
|
|
|
generate_timed_auth(onion_a->mono_time, PING_ID_TIMEOUT, onion_a->hmac_key,
|
|
|
|
ping_id_data, ping_id_data_len, ping_id);
|
|
|
|
|
|
|
|
make_announce_payload_helper(onion_a, ping_id, response, index, packet_public_key, data_public_key);
|
|
|
|
|
|
|
|
int nodes_length = 0;
|
|
|
|
|
|
|
|
if (num_nodes != 0) {
|
|
|
|
nodes_length = pack_nodes(onion_a->log, response + nodes_offset, sizeof(nodes_list), nodes_list,
|
|
|
|
(uint16_t)num_nodes);
|
|
|
|
|
|
|
|
if (nodes_length <= 0) {
|
|
|
|
LOGGER_WARNING(onion_a->log, "Failed to pack nodes");
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, response);
|
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t offset = nodes_offset + nodes_length;
|
|
|
|
|
|
|
|
if (want_node_count) {
|
|
|
|
response[1 + ONION_PING_ID_SIZE] = (uint8_t)num_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int extra_size = pack_extra_data_callback == nullptr ? 0
|
|
|
|
: pack_extra_data_callback(onion_a->extra_data_object,
|
|
|
|
onion_a->log, onion_a->mono_time, num_nodes,
|
|
|
|
plain + ONION_MINIMAL_SIZE, length - ANNOUNCE_REQUEST_MIN_SIZE_RECV,
|
|
|
|
response, response_size, offset);
|
|
|
|
|
|
|
|
if (extra_size == -1) {
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, response);
|
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += extra_size;
|
|
|
|
|
|
|
|
uint8_t data[ONION_ANNOUNCE_RESPONSE_MAX_SIZE];
|
2024-12-19 16:27:40 +01:00
|
|
|
const int len = encrypt_data_symmetric(onion_a->mem, shared_key, nonce, response, offset,
|
2023-07-25 11:53:09 +02:00
|
|
|
data + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE);
|
|
|
|
|
|
|
|
if (len != offset + CRYPTO_MAC_SIZE) {
|
|
|
|
LOGGER_ERROR(onion_a->log, "Failed to encrypt announce response");
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, response);
|
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data[0] = response_packet_id;
|
|
|
|
memcpy(data + 1, plain + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
|
|
|
|
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH);
|
|
|
|
memcpy(data + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, nonce, CRYPTO_NONCE_SIZE);
|
|
|
|
|
2023-12-24 12:21:34 +01:00
|
|
|
if (send_onion_response(onion_a->log, onion_a->net, source, data,
|
2023-07-25 11:53:09 +02:00
|
|
|
1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE + len,
|
|
|
|
packet + (length - ONION_RETURN_3)) == -1) {
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, response);
|
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, response);
|
|
|
|
mem_delete(onion_a->mem, plain);
|
2023-07-25 11:53:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static int handle_gca_announce_request(Onion_Announce *onion_a, const IP_Port *source, const uint8_t *packet,
|
|
|
|
uint16_t length)
|
|
|
|
{
|
|
|
|
if (length > ANNOUNCE_REQUEST_MAX_SIZE_RECV || length <= ANNOUNCE_REQUEST_MIN_SIZE_RECV) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onion_a->extra_data_callback == nullptr) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle_announce_request_common(onion_a, source, packet, length, NET_PACKET_ANNOUNCE_RESPONSE,
|
|
|
|
ONION_MINIMAL_SIZE + length - ANNOUNCE_REQUEST_MIN_SIZE_RECV,
|
|
|
|
true, onion_a->extra_data_max_size, onion_a->extra_data_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null(1, 2, 3) nullable(5)
|
|
|
|
static int handle_announce_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
Onion_Announce *onion_a = (Onion_Announce *)object;
|
|
|
|
|
|
|
|
if (length != ANNOUNCE_REQUEST_MIN_SIZE_RECV) {
|
|
|
|
return handle_gca_announce_request(onion_a, source, packet, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle_announce_request_common(onion_a, source, packet, length, NET_PACKET_ANNOUNCE_RESPONSE,
|
|
|
|
ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE * 2 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
|
|
|
true, 0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO(Jfreegman): DEPRECATE */
|
|
|
|
non_null(1, 2, 3) nullable(5)
|
|
|
|
static int handle_announce_request_old(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
Onion_Announce *onion_a = (Onion_Announce *)object;
|
|
|
|
|
|
|
|
if (length != ANNOUNCE_REQUEST_SIZE_RECV) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle_announce_request_common(onion_a, source, packet, length, NET_PACKET_ANNOUNCE_RESPONSE_OLD,
|
|
|
|
ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE * 2 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
|
|
|
false, 0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
non_null()
|
|
|
|
static int handle_data_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
const Onion_Announce *onion_a = (const Onion_Announce *)object;
|
|
|
|
|
|
|
|
if (length <= DATA_REQUEST_MIN_SIZE_RECV) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length > ONION_MAX_PACKET_SIZE) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int index = in_entries(onion_a, packet + 1);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272
b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.
git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
2024-03-07 23:12:55 +01:00
|
|
|
const uint16_t data_size = length - (CRYPTO_PUBLIC_KEY_SIZE + ONION_RETURN_3);
|
|
|
|
VLA(uint8_t, data, data_size);
|
2023-07-25 11:53:09 +02:00
|
|
|
data[0] = NET_PACKET_ONION_DATA_RESPONSE;
|
|
|
|
memcpy(data + 1, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length - (1 + CRYPTO_PUBLIC_KEY_SIZE + ONION_RETURN_3));
|
|
|
|
|
Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272
b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.
git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
2024-03-07 23:12:55 +01:00
|
|
|
if (send_onion_response(onion_a->log, onion_a->net, &onion_a->entries[index].ret_ip_port, data, data_size,
|
2023-07-25 11:53:09 +02:00
|
|
|
onion_a->entries[index].ret) == -1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-10 19:37:39 +02:00
|
|
|
Onion_Announce *new_onion_announce(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht)
|
2023-07-25 11:53:09 +02:00
|
|
|
{
|
|
|
|
if (dht == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-10-10 19:37:39 +02:00
|
|
|
Onion_Announce *onion_a = (Onion_Announce *)mem_alloc(mem, sizeof(Onion_Announce));
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
if (onion_a == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
onion_a->log = log;
|
|
|
|
onion_a->rng = rng;
|
2023-10-10 19:37:39 +02:00
|
|
|
onion_a->mem = mem;
|
2023-07-25 11:53:09 +02:00
|
|
|
onion_a->mono_time = mono_time;
|
|
|
|
onion_a->dht = dht;
|
|
|
|
onion_a->net = dht_get_net(dht);
|
|
|
|
onion_a->extra_data_max_size = 0;
|
|
|
|
onion_a->extra_data_callback = nullptr;
|
|
|
|
onion_a->extra_data_object = nullptr;
|
|
|
|
new_hmac_key(rng, onion_a->hmac_key);
|
|
|
|
|
2023-12-24 12:21:34 +01:00
|
|
|
onion_a->shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht_get_self_secret_key(dht), KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
2023-07-25 11:53:09 +02:00
|
|
|
if (onion_a->shared_keys_recv == nullptr) {
|
2023-12-27 12:37:22 +01:00
|
|
|
// cppcheck-suppress mismatchAllocDealloc
|
2023-07-25 11:53:09 +02:00
|
|
|
kill_onion_announce(onion_a);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_announce_request, onion_a);
|
|
|
|
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST_OLD, &handle_announce_request_old, onion_a);
|
|
|
|
networking_registerhandler(onion_a->net, NET_PACKET_ONION_DATA_REQUEST, &handle_data_request, onion_a);
|
|
|
|
|
|
|
|
return onion_a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void kill_onion_announce(Onion_Announce *onion_a)
|
|
|
|
{
|
|
|
|
if (onion_a == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, nullptr, nullptr);
|
|
|
|
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST_OLD, nullptr, nullptr);
|
|
|
|
networking_registerhandler(onion_a->net, NET_PACKET_ONION_DATA_REQUEST, nullptr, nullptr);
|
|
|
|
|
|
|
|
crypto_memzero(onion_a->hmac_key, CRYPTO_HMAC_KEY_SIZE);
|
|
|
|
shared_key_cache_free(onion_a->shared_keys_recv);
|
|
|
|
|
2023-10-10 19:37:39 +02:00
|
|
|
mem_delete(onion_a->mem, onion_a);
|
2023-07-25 11:53:09 +02:00
|
|
|
}
|