Skip to content

Retyped the libSession wrapper code in preparation of the 1.3.0 changes #21

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

Merged
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
10 changes: 0 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ jobs:
uses: microsoft/[email protected]
if: runner.os == 'Windows'

# Note: we will be able to get rid of this once the whole tree of submodules has the latest version of oxen-logging
# We'd need oxen-libquic to be updated to have the commit `bc7167f90e71643b43c2ea9cf7d1fefa5045f8d4`, but we don't want to
# update libquic that late.
# We will soon, though :tm:
- name: Apply patches
if: runner.os == 'Windows'
shell: bash
run: |
yarn naughty-patch

- name: generate fake src/version.h so we can try to build
shell: bash
run: yarn update_version
Expand Down
2 changes: 1 addition & 1 deletion libsession-util
Submodule libsession-util updated 94 files
+1 −1 .drone.jsonnet
+1 −1 CMakeLists.txt
+2 −2 external/CMakeLists.txt
+1 −1 external/oxen-libquic
+38 −19 include/session/blinding.hpp
+12 −9 include/session/config.hpp
+1 −5 include/session/config/base.h
+54 −44 include/session/config/base.hpp
+22 −14 include/session/config/community.hpp
+3 −1 include/session/config/contacts.hpp
+13 −7 include/session/config/convo_info_volatile.hpp
+21 −7 include/session/config/encrypt.hpp
+5 −5 include/session/config/groups/info.hpp
+50 −37 include/session/config/groups/keys.hpp
+3 −3 include/session/config/groups/members.hpp
+9 −6 include/session/config/profile_pic.hpp
+9 −3 include/session/config/protos.hpp
+13 −8 include/session/config/user_groups.hpp
+5 −3 include/session/config/user_profile.hpp
+4 −2 include/session/curve25519.hpp
+10 −4 include/session/ed25519.hpp
+1 −0 include/session/fields.hpp
+6 −1 include/session/hash.hpp
+81 −75 include/session/multi_encrypt.hpp
+1 −1 include/session/network.h
+10 −9 include/session/network.hpp
+4 −3 include/session/onionreq/builder.hpp
+16 −6 include/session/onionreq/hop_encryption.hpp
+8 −2 include/session/onionreq/key_types.hpp
+9 −9 include/session/onionreq/parser.hpp
+1 −1 include/session/onionreq/response_parser.hpp
+1 −1 include/session/random.hpp
+53 −33 include/session/session_encrypt.hpp
+2 −9 include/session/types.hpp
+81 −50 include/session/util.hpp
+9 −7 include/session/xed25519.hpp
+12 −0 src/CMakeLists.txt
+86 −50 src/blinding.cpp
+45 −41 src/config.cpp
+60 −50 src/config/base.cpp
+12 −10 src/config/community.cpp
+5 −5 src/config/contacts.cpp
+14 −12 src/config/convo_info_volatile.cpp
+26 −19 src/config/encrypt.cpp
+8 −6 src/config/groups/info.cpp
+143 −122 src/config/groups/keys.cpp
+5 −5 src/config/groups/members.cpp
+16 −11 src/config/internal.cpp
+16 −10 src/config/internal.hpp
+22 −14 src/config/protos.cpp
+28 −25 src/config/user_groups.cpp
+8 −5 src/config/user_profile.cpp
+6 −4 src/curve25519.cpp
+18 −9 src/ed25519.cpp
+7 −7 src/hash.cpp
+71 −61 src/multi_encrypt.cpp
+39 −25 src/network.cpp
+25 −21 src/onionreq/builder.cpp
+29 −22 src/onionreq/hop_encryption.cpp
+1 −1 src/onionreq/key_types.cpp
+11 −8 src/onionreq/parser.cpp
+9 −8 src/onionreq/response_parser.cpp
+2 −2 src/random.cpp
+117 −91 src/session_encrypt.cpp
+15 −15 src/xed25519.cpp
+2 −2 tests/catch2_bt_format.hpp
+1 −1 tests/static_bundle.cpp
+28 −20 tests/swarm-auth-test.cpp
+53 −49 tests/test_blinding.cpp
+2 −1 tests/test_bt_merge.cpp
+18 −14 tests/test_bugs.cpp
+9 −9 tests/test_compression.cpp
+5 −5 tests/test_config_contacts.cpp
+6 −5 tests/test_config_convo_info_volatile.cpp
+19 −17 tests/test_config_user_groups.cpp
+12 −10 tests/test_config_userprofile.cpp
+68 −71 tests/test_configdata.cpp
+4 −4 tests/test_curve25519.cpp
+11 −11 tests/test_ed25519.cpp
+3 −3 tests/test_encrypt.cpp
+17 −16 tests/test_group_info.cpp
+52 −46 tests/test_group_keys.cpp
+6 −6 tests/test_group_members.cpp
+22 −21 tests/test_hash.cpp
+8 −18 tests/test_logging.cpp
+116 −110 tests/test_multi_encrypt.cpp
+23 −13 tests/test_network.cpp
+10 −17 tests/test_onionreq.cpp
+3 −3 tests/test_proto.cpp
+126 −111 tests/test_session_encrypt.cpp
+19 −27 tests/test_xed25519.cpp
+10 −31 tests/utils.hpp
+1 −1 utils/ci/drone-format-verify.sh
+1 −1 utils/format.sh
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"update_version": "sh update_version.sh",
"clean": "rimraf .cache build",
"install": "cmake-js compile --runtime=electron --runtime-version=34.2.0 --CDSUBMODULE_CHECK=OFF --CDLOCAL_MIRROR=https://oxen.rocks/deps --CDENABLE_ONIONREQ=OFF --CDWITH_TESTS=OFF",
"naughty-patch": "git apply patches/oxen-libquic.patch",
"prepare_release": "sh prepare_release.sh"
},
"devDependencies": {
Expand Down
16 changes: 0 additions & 16 deletions patches/oxen-libquic.patch

This file was deleted.

2 changes: 0 additions & 2 deletions prepare_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ rm -f ./libsession_util_nodejs*.tar.gz
python -m venv .venv
. .venv/bin/activate
pip install git-archive-all
# see .github/workflows/test.yml for more info
yarn naughty-patch || true
PACKAGE_VERSION=$(node -p "require('./package.json').version")
yarn update_version
echo "PACKAGE_VERSION: $PACKAGE_VERSION"
Expand Down
2 changes: 1 addition & 1 deletion src/base_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Napi::Value ConfigBaseImpl::merge(const Napi::CallbackInfo& info) {
assertIsArray(info[0]);
Napi::Array asArray = info[0].As<Napi::Array>();

std::vector<std::pair<std::string, ustring_view>> conf_strs;
std::vector<std::pair<std::string, std::span<const unsigned char>>> conf_strs;
conf_strs.reserve(asArray.Length());

for (uint32_t i = 0; i < asArray.Length(); i++) {
Expand Down
7 changes: 3 additions & 4 deletions src/base_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cassert>
#include <memory>
#include <span>
#include <stdexcept>
#include <unordered_set>

Expand All @@ -13,8 +14,6 @@
#include "session/types.hpp"
#include "utilities.hpp"

using ustring_view = std::basic_string_view<unsigned char>;

namespace session::nodeapi {

class ConfigBaseImpl;
Expand Down Expand Up @@ -95,9 +94,9 @@ class ConfigBaseImpl {
// we should get secret key as first arg and optional dumped as second argument
assertIsUInt8Array(info[0], "base construct");
assertIsUInt8ArrayOrNull(info[1]);
ustring_view secretKey = toCppBufferView(info[0], class_name + ".new");
std::span<const unsigned char> secretKey = toCppBufferView(info[0], class_name + ".new");

std::optional<ustring_view> dump;
std::optional<std::span<const unsigned char>> dump;
auto second = info[1];
if (!second.IsEmpty() && !second.IsNull() && !second.IsUndefined())
dump = toCppBufferView(second, class_name + ".new");
Expand Down
4 changes: 2 additions & 2 deletions src/blinding/blinding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <napi.h>

#include <algorithm>
#include <vector>

#include "../meta/meta_base_wrapper.hpp"
#include "../utilities.hpp"
Expand Down Expand Up @@ -58,8 +59,7 @@ class BlindingWrapper : public Napi::ObjectWrap<BlindingWrapper> {

auto keypair = session::blind_version_key_pair(ed25519_secret_key);
session::uc32 pk_arr = std::get<0>(keypair);
ustring blinded_pk = session::ustring(
session::to_unsigned_sv(std::string(pk_arr.begin(), pk_arr.end())));
std::vector<unsigned char> blinded_pk = session::to_vector(pk_arr);
std::string blinded_pk_hex;
blinded_pk_hex.reserve(66);
blinded_pk_hex += "07";
Expand Down
9 changes: 5 additions & 4 deletions src/groups/meta_group.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <napi.h>
#include <vector>

#include "session/config/groups/info.hpp"
#include "session/config/groups/keys.hpp"
Expand Down Expand Up @@ -32,12 +33,12 @@ class MetaGroup {
shared_ptr<config::groups::Info> info,
shared_ptr<config::groups::Members> members,
shared_ptr<config::groups::Keys> keys,
session::ustring edGroupPubKey,
std::optional<session::ustring> edGroupSecKey) :
info{info}, members{members}, keys{keys}, edGroupPubKey{oxenc::to_hex(edGroupPubKey)} {
std::vector<unsigned char> edGroupPubKey,
std::optional<std::vector<unsigned char>> edGroupSecKey) :
info{info}, members{members}, keys{keys}, edGroupPubKey{oxenc::to_hex(edGroupPubKey.begin(), edGroupPubKey.end())} {

if (edGroupSecKey.has_value()) {
this->edGroupSecKey = oxenc::to_hex(*edGroupSecKey);
this->edGroupSecKey = oxenc::to_hex(edGroupSecKey->begin(), edGroupSecKey->end());
} else {
this->edGroupSecKey = std::nullopt;
}
Expand Down
34 changes: 18 additions & 16 deletions src/groups/meta_group_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <napi.h>

#include <memory>
#include <span>
#include <vector>

#include "oxenc/bt_producer.h"
#include "session/types.hpp"
Expand Down Expand Up @@ -208,12 +210,12 @@ Napi::Value MetaGroupWrapper::metaDump(const Napi::CallbackInfo& info) {
oxenc::bt_dict_producer combined;

// NOTE: the keys have to be in ascii-sorted order:
combined.append("info", session::from_unsigned_sv(this->meta_group->info->dump()));
combined.append("keys", session::from_unsigned_sv(this->meta_group->keys->dump()));
combined.append("members", session::from_unsigned_sv(this->meta_group->members->dump()));
combined.append("info", session::to_string(this->meta_group->info->dump()));
combined.append("keys", session::to_string(this->meta_group->keys->dump()));
combined.append("members", session::to_string(this->meta_group->members->dump()));
auto to_dump = std::move(combined).str();

return session::ustring{to_unsigned_sv(to_dump)};
return session::to_vector(to_dump);
});
}

Expand All @@ -222,13 +224,13 @@ Napi::Value MetaGroupWrapper::metaMakeDump(const Napi::CallbackInfo& info) {
oxenc::bt_dict_producer combined;

// NOTE: the keys have to be in ascii-sorted order:
combined.append("info", session::from_unsigned_sv(this->meta_group->info->make_dump()));
combined.append("keys", session::from_unsigned_sv(this->meta_group->keys->make_dump()));
combined.append("info", session::to_string(this->meta_group->info->make_dump()));
combined.append("keys", session::to_string(this->meta_group->keys->make_dump()));
combined.append(
"members", session::from_unsigned_sv(this->meta_group->members->make_dump()));
"members", session::to_string(this->meta_group->members->make_dump()));
auto to_dump = std::move(combined).str();

return ustring{to_unsigned_sv(to_dump)};
return session::to_vector(to_dump);
});
}

Expand Down Expand Up @@ -326,7 +328,7 @@ Napi::Value MetaGroupWrapper::metaMerge(const Napi::CallbackInfo& info) {
assertIsArray(groupInfo);
auto asArr = groupInfo.As<Napi::Array>();

std::vector<std::pair<std::string, ustring_view>> conf_strs;
std::vector<std::pair<std::string, std::span<const unsigned char>>> conf_strs;
conf_strs.reserve(asArr.Length());

for (uint32_t i = 0; i < asArr.Length(); i++) {
Expand All @@ -353,7 +355,7 @@ Napi::Value MetaGroupWrapper::metaMerge(const Napi::CallbackInfo& info) {
assertIsArray(groupMember);
auto asArr = groupMember.As<Napi::Array>();

std::vector<std::pair<std::string, ustring_view>> conf_strs;
std::vector<std::pair<std::string, std::span<const unsigned char>>> conf_strs;
conf_strs.reserve(asArr.Length());

for (uint32_t i = 0; i < asArr.Length(); i++) {
Expand Down Expand Up @@ -790,7 +792,7 @@ Napi::Value MetaGroupWrapper::encryptMessages(const Napi::CallbackInfo& info) {

auto plaintextsJS = info[0].As<Napi::Array>();
uint32_t arrayLength = plaintextsJS.Length();
std::vector<session::ustring> encryptedMessages;
std::vector<std::vector<unsigned char>> encryptedMessages;
encryptedMessages.reserve(arrayLength);

for (uint32_t i = 0; i < plaintextsJS.Length(); i++) {
Expand Down Expand Up @@ -820,10 +822,10 @@ Napi::Value MetaGroupWrapper::makeSwarmSubAccount(const Napi::CallbackInfo& info
assertIsString(info[0]);

auto memberPk = toCppString(info[0], "makeSwarmSubAccount");
ustring subaccount = this->meta_group->keys->swarm_make_subaccount(memberPk);
std::vector<unsigned char> subaccount = this->meta_group->keys->swarm_make_subaccount(memberPk);

session::nodeapi::checkOrThrow(
subaccount.length() == 100, "expected subaccount to be 100 bytes long");
subaccount.size() == 100, "expected subaccount to be 100 bytes long");

return subaccount;
});
Expand All @@ -835,12 +837,12 @@ Napi::Value MetaGroupWrapper::swarmSubAccountToken(const Napi::CallbackInfo& inf
assertIsString(info[0]);

auto memberPk = toCppString(info[0], "swarmSubAccountToken");
ustring subaccount = this->meta_group->keys->swarm_subaccount_token(memberPk);
std::vector<unsigned char> subaccount = this->meta_group->keys->swarm_subaccount_token(memberPk);

session::nodeapi::checkOrThrow(
subaccount.length() == 36, "expected subaccount token to be 36 bytes long");
subaccount.size() == 36, "expected subaccount token to be 36 bytes long");

return oxenc::to_hex(subaccount);
return oxenc::to_hex(subaccount.begin(), subaccount.end());
});
}

Expand Down
20 changes: 11 additions & 9 deletions src/meta/meta_base_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <napi.h>
#include <vector>
#include <span>

#include "../base_config.hpp"
#include "../groups/meta_group.hpp"
Expand Down Expand Up @@ -56,33 +58,33 @@ class MetaBaseWrapper {
obj.Get("groupEd25519Pubkey"),
class_name + ":constructGroupWrapper.groupEd25519Pubkey");

std::optional<ustring> group_ed25519_secretkey = maybeNonemptyBuffer(
std::optional<std::vector<unsigned char>> group_ed25519_secretkey = maybeNonemptyBuffer(
obj.Get("groupEd25519Secretkey"),
class_name + ":constructGroupWrapper.groupEd25519Secretkey");

std::optional<ustring> dumped_meta = maybeNonemptyBuffer(
std::optional<std::vector<unsigned char>> dumped_meta = maybeNonemptyBuffer(
obj.Get("metaDumped"), class_name + ":constructGroupWrapper.metaDumped");

std::optional<ustring_view> dumped_info;
std::optional<ustring_view> dumped_members;
std::optional<ustring_view> dumped_keys;
std::optional<std::span<const unsigned char>> dumped_info;
std::optional<std::span<const unsigned char>> dumped_members;
std::optional<std::span<const unsigned char>> dumped_keys;

if (dumped_meta) {
auto dumped_meta_str = from_unsigned_sv(*dumped_meta);
auto dumped_meta_str = to_string(*dumped_meta);

oxenc::bt_dict_consumer combined{dumped_meta_str};
// NB: must read in ascii-sorted order:
if (!combined.skip_until("info"))
throw std::runtime_error{"info dump not found in combined dump!"};
dumped_info = session::to_unsigned_sv(combined.consume_string_view());
dumped_info = session::to_span(combined.consume_string_view());

if (!combined.skip_until("keys"))
throw std::runtime_error{"keys dump not found in combined dump!"};
dumped_keys = session::to_unsigned_sv(combined.consume_string_view());
dumped_keys = session::to_span(combined.consume_string_view());

if (!combined.skip_until("members"))
throw std::runtime_error{"members dump not found in combined dump!"};
dumped_members = session::to_unsigned_sv(combined.consume_string_view());
dumped_members = session::to_span(combined.consume_string_view());
}

// Note, we keep shared_ptr for those as the Keys one need a reference to Members and
Expand Down
12 changes: 7 additions & 5 deletions src/multi_encrypt/multi_encrypt.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <napi.h>
#include <span>
#include <vector>

#include <algorithm>

Expand Down Expand Up @@ -58,7 +60,7 @@ class MultiEncryptWrapper : public Napi::ObjectWrap<MultiEncryptWrapper> {
auto messagesJSValue = obj.Get("messages");
assertIsArray(messagesJSValue);
auto messagesJS = messagesJSValue.As<Napi::Array>();
std::vector<ustring> messages;
std::vector<std::vector<unsigned char>> messages;
messages.reserve(messagesJS.Length());
for (uint32_t i = 0; i < messagesJS.Length(); i++) {
auto itemValue = messagesJS.Get(i);
Expand All @@ -71,18 +73,18 @@ class MultiEncryptWrapper : public Napi::ObjectWrap<MultiEncryptWrapper> {
auto recipientsJSValue = obj.Get("recipients");
assertIsArray(recipientsJSValue);
auto recipientsJS = recipientsJSValue.As<Napi::Array>();
std::vector<ustring> recipients;
std::vector<std::vector<unsigned char>> recipients;
recipients.reserve(recipientsJS.Length());
for (uint32_t i = 0; i < recipientsJS.Length(); i++) {
auto itemValue = recipientsJS.Get(i);
assertIsUInt8Array(itemValue, "multiEncrypt.itemValue.recipient");
auto item = toCppBuffer(itemValue, "multiEncrypt.itemValue.recipient");
recipients.push_back(item);
}
ustring random_nonce = session::random::random(24);
std::vector<unsigned char> random_nonce = session::random::random(24);

std::vector<ustring_view> messages_sv(messages.begin(), messages.end());
std::vector<ustring_view> recipients_sv(recipients.begin(), recipients.end());
std::vector<std::span<const unsigned char>> messages_sv(messages.begin(), messages.end());
std::vector<std::span<const unsigned char>> recipients_sv(recipients.begin(), recipients.end());

// Note: this function needs the first 2 args to be vector of sv explicitly
return session::encrypt_for_multiple_simple(
Expand Down
3 changes: 2 additions & 1 deletion src/user_groups_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <iostream>
#include <optional>
#include <vector>

#include "base_config.hpp"
#include "community.hpp"
Expand Down Expand Up @@ -158,7 +159,7 @@ Napi::Value UserGroupsWrapper::buildFullUrlFromDetails(const Napi::CallbackInfo&
return wrapResult(env, [&]() {
auto [baseUrl, roomId, pubkeyHex] = getStringArgs<3>(info);

ustring pubkey_bytes;
std::vector<unsigned char> pubkey_bytes;
if (!oxenc::is_hex(pubkeyHex.begin(), pubkeyHex.end()))
throw std::invalid_argument{"community pubkey is not hex!"};
oxenc::from_hex(pubkeyHex.begin(), pubkeyHex.end(), std::back_inserter(pubkey_bytes));
Expand Down
Loading