Skip to content

Commit

Permalink
Work around protobuf overhead
Browse files Browse the repository at this point in the history
- Accomodate protobuf overhead in tests on exact push values/lengths
- Remove some debugging
  • Loading branch information
jagerman committed Sep 6, 2023
1 parent 233f364 commit 00c235c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 0 additions & 2 deletions proto/protos.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "protos.hpp"

#include <iostream>

#include "SessionProtos.pb.h"
#include "WebSocketResources.pb.h"

Expand Down
4 changes: 2 additions & 2 deletions tests/test_config_contacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ TEST_CASE("Contacts", "[config][contacts]") {
CHECK(seqno == seqno2 + 1);
std::tie(seqno2, to_push2, obs2) = contacts2.push();
CHECK(seqno == seqno2);
CHECK(to_push == to_push2);
CHECK(printable(to_push) == printable(to_push2));
CHECK(as_set(obs) == make_set("fakehash3a"s, "fakehash3b"));
CHECK(as_set(obs2) == make_set("fakehash3a"s, "fakehash3b"));

Expand Down Expand Up @@ -414,7 +414,7 @@ TEST_CASE("huge contacts compression", "[config][compression][contacts]") {

auto [seqno, to_push, obs] = contacts.push();
CHECK(seqno == 1);
CHECK(to_push.size() == 46'112);
CHECK(to_push.size() == 46'112); // TODO: return to 46'080 once we remove protobuf wrapping
auto dump = contacts.dump();
// With tons of duplicate info the push should have been nicely compressible:
CHECK(dump.size() > 1'320'000);
Expand Down
20 changes: 13 additions & 7 deletions tests/test_config_userprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ TEST_CASE("user profile C API", "[config][user_profile][c]") {
// We don't need to push since we haven't changed anything, so this call is mainly just for
// testing:
config_push_data* to_push = config_push(conf);
constexpr auto PROTOBUF_OVERHEAD = 28; // To be removed once we no longer protobuf wrap this
constexpr auto PROTOBUF_DATA_OFFSET = 26;
REQUIRE(to_push);
CHECK(to_push->seqno == 0);
CHECK(to_push->config_len == 284);
CHECK(to_push->config_len == 256 + PROTOBUF_OVERHEAD);
const char* enc_domain = "UserProfile";
REQUIRE(config_encryption_domain(conf) == std::string_view{enc_domain});
size_t to_push_decr_size;
unsigned char* to_push_decrypted = config_decrypt(
to_push->config, to_push->config_len, ed_sk.data(), enc_domain, &to_push_decr_size);

// Get the de-protobufed pointer and length:
auto inner_data = to_push->config + PROTOBUF_DATA_OFFSET;
auto inner_len = to_push->config_len - PROTOBUF_OVERHEAD;

unsigned char* to_push_decrypted =
config_decrypt(inner_data, inner_len, ed_sk.data(), enc_domain, &to_push_decr_size);
REQUIRE(to_push_decrypted);
CHECK(to_push_decr_size == 216); // 256 - 40 overhead
CHECK(printable(to_push_decrypted, to_push_decr_size) ==
Expand Down Expand Up @@ -146,12 +153,11 @@ TEST_CASE("user profile C API", "[config][user_profile][c]") {
"056009a9ebf58d45d7d696b74e0c7ff0499c4d23204976f19561dc0dba6dc53a2497d28ce03498ea"
"49bf122762d7bc1d6d9c02f6d54f8384"_hexbytes;

CHECK(oxenc::to_hex(to_push->config, to_push->config + to_push->config_len) ==
to_hex(exp_push1_encrypted));
CHECK(oxenc::to_hex(inner_data, inner_data + inner_len) == to_hex(exp_push1_encrypted));

// Raw decryption doesn't unpad (i.e. the padding is part of the encrypted data)
to_push_decrypted = config_decrypt(
to_push->config, to_push->config_len, ed_sk.data(), enc_domain, &to_push_decr_size);
to_push_decrypted =
config_decrypt(inner_data, inner_len, ed_sk.data(), enc_domain, &to_push_decr_size);
CHECK(to_push_decr_size == 256 - 40);
CHECK(printable(to_push_decrypted, to_push_decr_size) ==
printable(ustring(256 - 40 - exp_push1_decrypted.size(), '\0') + exp_push1_decrypted));
Expand Down

0 comments on commit 00c235c

Please sign in to comment.