Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friends implementation #42

Merged
merged 23 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ rust_static_library(
compile_data = [":migrations"],
deps = [
":db_bridge",
"@crate_index//:anyhow",
"@crate_index//:diesel",
"@crate_index//:diesel_migrations",
"@crate_index//:libsqlite3-sys",
Expand Down
10 changes: 9 additions & 1 deletion daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Set up VSCode rust-analyzer (very recommended!):
bazelisk run @rules_rust//tools/rust_analyzer:gen_rust_project
```

# Database changes
## Database changes

We want to create a migration!

Expand All @@ -25,3 +25,11 @@ and
```
./diesel-cli.sh migration redo
```

## Debugging

For debugging the Rust code, run

```
bazelisk test //... --test_env=RUST_BACKTRACE=1
```
19 changes: 10 additions & 9 deletions daemon/crypto/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,34 @@
#include "sodium.h"

// MAC bytes
constexpr size_t CRYPTO_ABYTES = crypto_aead_xchacha20poly1305_ietf_ABYTES;
constexpr int CRYPTO_ABYTES = crypto_aead_xchacha20poly1305_ietf_ABYTES;
// nonce bytes
constexpr size_t CRYPTO_NPUBBYTES =
crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
constexpr int CRYPTO_NPUBBYTES = crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
// the maximum size of a message such that it can be sent in a single message
// if the message is this size or shorter, it is guaranteed to be sent in a
// single round. 1+5 is for the uint32 ID, 1+MESSAGE_SIZE is for the header of
// the string, and 1 + 5 is for num_chunks and 1 + 5 is for
// chunks_start_sequence_number element. -1 at the end is for the padding which
// reserves one byte.
constexpr size_t GUARANTEED_SINGLE_MESSAGE_SIZE =
constexpr int GUARANTEED_SINGLE_MESSAGE_SIZE =
MESSAGE_SIZE - (1 + 5) -
(1 +
CEIL_DIV((sizeof MESSAGE_SIZE) * 8 - std::countl_zero(MESSAGE_SIZE), 8)) -
(1 + 5) - (1 + 5) - CRYPTO_ABYTES - 1 - CRYPTO_NPUBBYTES;

// we support up to 4 billion messages! that's a lot.
// (we use unsigned integers)
constexpr size_t ACKING_BYTES = 4;
constexpr int ACKING_BYTES = 4;
// the encryption takes a nonce + a mac
constexpr size_t ENCRYPTED_ACKING_BYTES =
constexpr int ENCRYPTED_ACKING_BYTES =
ACKING_BYTES + CRYPTO_ABYTES + CRYPTO_NPUBBYTES;
// the maximum number of friends!
constexpr size_t MAX_FRIENDS = MESSAGE_SIZE / ENCRYPTED_ACKING_BYTES;
constexpr int MAX_FRIENDS = MESSAGE_SIZE / ENCRYPTED_ACKING_BYTES;

constexpr size_t MAX_ASYNC_FRIEND_REQUESTS = 500;
constexpr size_t ASYNC_FRIEND_REQUEST_BATCH_SIZE = 1000;
constexpr int MAX_ASYNC_FRIEND_REQUESTS = 500;
constexpr int ASYNC_FRIEND_REQUEST_BATCH_SIZE = 1000;
// TODO: figure out a reasonable limit here...
constexpr int INVITATION_MESSAGE_MAX_PLAINTEXT_SIZE = 500;

// NOTE: whenever these default values are changed, please make a database
// migration in the shape of UPDATE config SET value = 'new_value' WHERE value =
Expand Down
3 changes: 3 additions & 0 deletions daemon/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ auto decrypt_async_friend_request_public_key_only(
// TODO: insert additional checks here
// read the allocation
// create the friend
// TODO: specifically, we need to verify that the public_id in the body
// corresponds to the public_id that the message was authenticated with
// otherwise, someone might impersonate the real receiver
return std::make_pair(split_plaintext[0], split_plaintext[1]);
}
} // namespace crypto
Loading