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

[WIP] - Contacts, etc. #2242

Open
wants to merge 376 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
376 commits
Select commit Hold shift + click to select a range
baabfab
fetch RID result handler logic
dr7ana Nov 28, 2023
9bb8558
housekeeping pre-trust model
dr7ana Nov 29, 2023
e1a5d93
move from vectors to unordered_sets
dr7ana Nov 29, 2023
483b79a
pull yourself up by your bootstraps sonny
dr7ana Nov 30, 2023
e02ddd6
trust model
dr7ana Dec 1, 2023
63a57d5
trust model fetch fails
dr7ana Dec 4, 2023
ec88706
testnet prep
dr7ana Dec 4, 2023
44696b1
trust model edge case handling
dr7ana Dec 5, 2023
32e55b0
testnet prep
dr7ana Dec 6, 2023
66ad28a
Local router mode
dr7ana Dec 6, 2023
267a698
libquic vbump
dr7ana Dec 7, 2023
6a32148
address parsing
dr7ana Dec 7, 2023
aeb0798
TELL ME WHEN IT WORKS
dr7ana Dec 8, 2023
686c7e0
testnet: don't give oxend and error when testing is disabled
jagerman Dec 8, 2023
03976d8
Squashed misc testnet fixes
dr7ana Dec 8, 2023
e43833a
Update logging in daemon.cpp
jagerman Dec 8, 2023
6231b49
Remove release motto
jagerman Dec 8, 2023
72276e3
Update libquic
jagerman Dec 8, 2023
ed87b73
Bump libquic
jagerman Dec 8, 2023
be61373
Remove duplicate connection closing method
jagerman Dec 8, 2023
950ebfe
Update libquic
jagerman Dec 9, 2023
4b426f5
Crit logging
dr7ana Dec 11, 2023
c4f0a70
Bootstrap seed
dr7ana Dec 11, 2023
4c3f7dc
kick
dr7ana Dec 11, 2023
0b7997e
kick
dr7ana Dec 11, 2023
2405d36
libquic vbump
dr7ana Dec 11, 2023
7568b71
kick
dr7ana Dec 11, 2023
9c92c30
try queueing
dr7ana Dec 11, 2023
3d9e3ae
kiiiiiick
dr7ana Dec 11, 2023
384cb7a
dont bomb with bootstrap reqs
dr7ana Dec 11, 2023
ba6c8ee
REVERT ME: debug incoming dict data
jagerman Dec 11, 2023
dab6e90
Fix version encoding
jagerman Dec 11, 2023
aabd413
D
dr7ana Dec 11, 2023
eb62185
RemoteRC: `explicit` single-argument constructors
jagerman Dec 11, 2023
4328212
shoot
dr7ana Dec 11, 2023
329acaf
Revert me: debug print the msg/sig/signer
jagerman Dec 11, 2023
ff3a495
Fix pubkey parsing to be read as bytes
jagerman Dec 11, 2023
3161683
Revert me: fix double-hex in debug output
jagerman Dec 11, 2023
b8c8a2c
log
dr7ana Dec 11, 2023
97fe3c6
send localrc, receive as remoterc
dr7ana Dec 11, 2023
cd96497
print but better
dr7ana Dec 11, 2023
0cf5805
DRY duplicated code in RCRemote
jagerman Dec 11, 2023
96c93c9
Bump libquic
jagerman Dec 11, 2023
f00137a
Bump libquic for message move/copy fixes
jagerman Dec 11, 2023
0e88839
who cares
dr7ana Dec 11, 2023
4c25124
libquic vbump
dr7ana Dec 12, 2023
1e1f4dd
come on already work already
dr7ana Dec 12, 2023
90a530a
whatever
dr7ana Dec 12, 2023
6505c7b
Replace GetBestNetIF with quic::Address version
jagerman Dec 12, 2023
d6cc702
Bump libquic for register_command fix
jagerman Dec 12, 2023
8bdfb20
wrap dat
dr7ana Dec 12, 2023
fcbfc19
update seeds before returning no
dr7ana Dec 12, 2023
cb39f64
Fix std::set move semantics
jagerman Dec 12, 2023
8f99ead
doofus
dr7ana Dec 12, 2023
30ea679
better!
dr7ana Dec 12, 2023
a591d44
libquic vbump
dr7ana Dec 13, 2023
dbad0d5
Fixed pending message queue weirdness
dr7ana Dec 13, 2023
9f0766f
Big fix!
dr7ana Dec 13, 2023
bf6e705
libquic vbump
dr7ana Dec 13, 2023
42da1b0
bootstrap tweaking
dr7ana Dec 13, 2023
5ab40a7
libquic vbump
dr7ana Dec 13, 2023
1364e4c
actually have rid in command registration
dr7ana Dec 13, 2023
caa7b7a
libquic vbump
dr7ana Dec 14, 2023
cc97fe1
Added connection keepalive
dr7ana Dec 15, 2023
89975a0
gossip fetch and response handling implemented
dr7ana Dec 15, 2023
7f143bb
full mesh proto implementation
dr7ana Dec 15, 2023
4d56c97
Revert me: print out the failed bootstrap response
jagerman Dec 15, 2023
7b8c8fd
booyakasha
dr7ana Dec 15, 2023
4251172
libquic/oxenc vbumps
dr7ana Dec 15, 2023
22879b6
rc parsing
dr7ana Dec 15, 2023
75e3127
btreq destructor
dr7ana Dec 15, 2023
4ce0385
loop call
dr7ana Dec 15, 2023
86f2906
Get rid of IterDir
jagerman Dec 15, 2023
961763d
lets see which gets rejected
dr7ana Dec 15, 2023
687d655
Add `exact` argument to get_n_random_rcs
jagerman Dec 15, 2023
ae38dc7
gossip storage, logs
dr7ana Dec 16, 2023
0e73605
libquic vbump (stream redux, reauth updates, alpns->ustring)
dr7ana Dec 18, 2023
3e9d5a9
ALPN verification
dr7ana Dec 18, 2023
9cc0536
re-abstraction for client connections
dr7ana Dec 19, 2023
1cbec98
address parsing of deprecated opts
dr7ana Dec 19, 2023
6171846
zero cost exception handling my ass
dr7ana Dec 20, 2023
38c1008
gossip new RC's on bfetch
dr7ana Dec 20, 2023
6bb65cc
Fix SETCAP disabling
jagerman Dec 20, 2023
9153ba3
okay now lets try clients
dr7ana Dec 20, 2023
9b37b5b
client testing
dr7ana Dec 20, 2023
8e9dce1
do not gossip client RCs!
dr7ana Dec 20, 2023
c0b6277
HAPPY NEW YEAR
dr7ana Dec 20, 2023
674edab
No fetch only throw
dr7ana Dec 21, 2023
95fe45e
Deprecate pending_msg_que in favor of libquic internal stream buffers
dr7ana Jan 7, 2024
2c12f06
libquic vbump
dr7ana Jan 16, 2024
fb19e14
squash: kick testnet
dr7ana Jan 16, 2024
9cc3efc
a soothing renomenclatura
dr7ana Jan 17, 2024
6073377
libquic vbump
dr7ana Jan 19, 2024
261fc6b
REVERT: verbose close logging
dr7ana Jan 19, 2024
12381c8
libquic vbump
dr7ana Jan 22, 2024
7970ad2
Simul-defer connections
dr7ana Jan 22, 2024
722b03b
libquic bump
dr7ana Jan 29, 2024
861d573
Clear application map connection entry earlier
dr7ana Jan 31, 2024
5f8e1ad
formatting
dr7ana Feb 1, 2024
fbd1935
nodedb one-liner
dr7ana Feb 1, 2024
0fe8c6f
remove a few calls to bootstrap fallback
dr7ana Feb 1, 2024
27f09f0
log crit
dr7ana Feb 1, 2024
62002c3
Loop call fixes, libquic bump to latest fixes
dr7ana Feb 1, 2024
a79a5d2
bump libquic after merging pr#100
dr7ana Feb 2, 2024
b15f3e7
commented out decaf20 log changes
dr7ana Feb 2, 2024
2d3e68a
log
dr7ana Feb 2, 2024
b733415
formatting
dr7ana Feb 2, 2024
cba6cd8
asserts
dr7ana Feb 2, 2024
5004fbc
libquic testing out verbose bparser stuff
dr7ana Feb 2, 2024
ac6255c
Squashed commits for merge errors afer fixing client-refactor:
dr7ana Jan 17, 2024
25f13c9
deprecated byte_t (twas a dumb typedef anyways)
dr7ana Feb 5, 2024
b1f0f37
ToString is no longer camelcase because why would it be???
dr7ana Feb 5, 2024
e495637
deprecated old types from config
dr7ana Feb 6, 2024
76f720e
bump libquic for updated exposed ranges
dr7ana Feb 7, 2024
53552ad
deprecated net/ip_address and path/path_context
dr7ana Feb 7, 2024
f541d0b
bump libquic to expose ev loop
dr7ana Feb 7, 2024
800c62b
event loop swap
dr7ana Feb 12, 2024
0d7b973
link_manager generates static_secret for quic ep
dr7ana Feb 12, 2024
e6d4814
deprecation nation
dr7ana Feb 12, 2024
28194aa
libquic bump
dr7ana Feb 13, 2024
b7b9398
compiling, not linking
dr7ana Feb 13, 2024
8cc152a
C++ version, clang-format
dr7ana Feb 14, 2024
44e7c1b
libquic bump
dr7ana Feb 25, 2024
bf2f367
bye bye bencode baby bye byeeee
dr7ana Mar 17, 2024
d0af37a
fully deprecated old logging
dr7ana Mar 17, 2024
bb5f1b3
libquic bump
dr7ana Mar 17, 2024
a8c6673
ip packet checksums for ipv4/6, udp/tcp
dr7ana Mar 17, 2024
d8f9702
templated remoteaddress object
dr7ana Mar 18, 2024
d0203b3
config parsing cleaned up for owned ranges and addresses
dr7ana Mar 18, 2024
b037c04
compile fixes (except for consteval fmt::format oddities
dr7ana Mar 18, 2024
0301bc8
re-separated address classes
dr7ana Mar 19, 2024
abb16b1
Putting new objects to use
dr7ana Mar 22, 2024
6a20b3d
libquic c++20/ev-loop/ip bump
dr7ana Mar 27, 2024
aae23c1
Restructuring, session initiation
dr7ana Mar 25, 2024
bbbc433
Transposed address types
dr7ana Apr 2, 2024
0eaf854
Design review meeting
dr7ana Apr 2, 2024
b7918df
libquic vbump
dr7ana Apr 3, 2024
b06473d
Segmented path-build
dr7ana Apr 3, 2024
8262f04
Removed outer hash for path messages
dr7ana Apr 3, 2024
ecd7744
DRY'ed out symmetric encryption logic in path-build and path-controls
dr7ana Apr 4, 2024
cbaa175
Symmetric encryption
dr7ana Apr 8, 2024
597927a
Session init
dr7ana Apr 8, 2024
a1a3254
Router prefiguring, ons resolve
dr7ana Apr 9, 2024
ee961cf
libquic vbump
dr7ana Apr 9, 2024
791155d
Make it reachable
dr7ana Apr 9, 2024
078d0df
Prefiguring, deprecation
dr7ana Apr 9, 2024
9e6a334
Buffer methods
dr7ana Apr 10, 2024
d9cee71
TCP listener laid out
dr7ana Apr 10, 2024
6e5d841
Netif and quic Tunnel reduction
dr7ana Apr 12, 2024
849c645
libquic vbump
dr7ana Apr 17, 2024
fee6cd6
So much
dr7ana Apr 18, 2024
afe20e8
Session initation, authentication
dr7ana Apr 19, 2024
8938c06
TCP client code hooked up
dr7ana Apr 19, 2024
5b9ad10
TCP tunnel differentiated inbound/outbound
dr7ana Apr 22, 2024
8a45350
Client session refactor, datagram pipelining
dr7ana Apr 22, 2024
4ef9754
Dep bump + misc
dr7ana May 17, 2024
ce16778
IPRange iterator
dr7ana May 28, 2024
4979f9a
TUN/Session IP routing negotiation
dr7ana May 29, 2024
f755d26
TUN ip packet re-writing; deps bump
dr7ana Jun 2, 2024
6a7e973
CI fixes and architecture changes; bt serialize path object fix; deps…
dr7ana Jun 3, 2024
d455a36
testing something on CI
dr7ana Jun 4, 2024
5f61469
libquic bump -> dr7ana/repeater
dr7ana Jun 5, 2024
fcf62fb
it's... alive!?
dr7ana Jun 13, 2024
52ceb26
libquic bump
dr7ana Jun 18, 2024
c15b3b1
tick logic handling
dr7ana Jun 19, 2024
dfa0e52
Aggregated bugfix commits and logging fixes
dr7ana Jul 3, 2024
9e300d2
libquic -> dr7ana/primary_net_closure branch
dr7ana Aug 16, 2024
ec2dbd3
ipv6 config disabled, tun interface solid on ipv4
dr7ana Aug 23, 2024
5b48abc
kick testnet buddy
dr7ana Aug 23, 2024
ab30bf2
so much better!
dr7ana Aug 28, 2024
b794430
Misc (squash)
dr7ana Aug 28, 2024
ca7fc07
kick
dr7ana Aug 30, 2024
35e05b3
issue fixed, force clearing nodedb
dr7ana Sep 3, 2024
036fbe2
better netif
dr7ana Sep 3, 2024
c155db3
libevent 2.2 for watchers
dr7ana Sep 4, 2024
8a381c8
more netif
dr7ana Sep 4, 2024
104ba6d
testing this out
dr7ana Sep 9, 2024
ea6d62c
libquic -> dr7ana/0rtt, etc
dr7ana Sep 12, 2024
e3d80ea
updated, may kill testnet but yolo
dr7ana Sep 13, 2024
fe9d229
yay clients connecting
dr7ana Sep 16, 2024
fe717b9
yay path building
dr7ana Sep 16, 2024
ec32167
squash, but more the zucchini type
dr7ana Sep 17, 2024
5b522e6
maybe a little green beans too
dr7ana Sep 18, 2024
c874387
any beets on the side?
dr7ana Sep 19, 2024
8495517
whatsup paths
dr7ana Sep 24, 2024
3103194
Better linux fd poller
dr7ana Sep 25, 2024
b636e35
contact library, re-org
dr7ana Oct 2, 2024
d09655a
libquic bump
dr7ana Oct 10, 2024
5d7ba88
oxend rpc ping -> ticker
dr7ana Oct 21, 2024
d3e3e3d
(WIP, squash) contact library, re-org
dr7ana Oct 2, 2024
1359ee3
ExitConfig struct added, backcompat, etc
dr7ana Oct 3, 2024
a5ccc9c
squash
dr7ana Oct 10, 2024
da157f5
oxenc vbump -> dr7ana/chartype-fix for const_spans
dr7ana Oct 14, 2024
827ff5b
clientcontact logic (squash)
dr7ana Oct 21, 2024
d236b46
who? never heard of em
dr7ana Oct 22, 2024
1b14e79
squash; kick le net
dr7ana Oct 24, 2024
0805844
testnet kick
dr7ana Oct 24, 2024
de4843c
Refactored path message serialization
dr7ana Oct 25, 2024
f8d625b
path control serialization, smaller overall payload
dr7ana Oct 28, 2024
bf02987
path control handling
dr7ana Oct 28, 2024
1c630f9
path message addressing to the right rxid
dr7ana Oct 29, 2024
85642fa
HopID changes, control message serialization, etc
dr7ana Oct 30, 2024
d0ef3e8
alas, hop unification!
dr7ana Oct 31, 2024
ff8069f
path request handling made same as other requests
dr7ana Nov 4, 2024
39fa366
Moved remaining path-requests to improved quic handler
dr7ana Nov 5, 2024
6f182b7
more efficient transit hop population, path etc
dr7ana Nov 5, 2024
b01ef9a
Request handling, debugged hop-selection issues, strict-connect pinne…
dr7ana Nov 5, 2024
80885fd
fix make_scalar, call-safe, de-serialization error, etc
dr7ana Nov 7, 2024
7562253
path-mapping, storage, and fetching
dr7ana Nov 7, 2024
48601ed
client config
dr7ana Nov 10, 2024
78ce7bd
request handling for sessions
dr7ana Nov 12, 2024
17a2ec8
who actually even knows (squash)
dr7ana Nov 14, 2024
19460a4
squash again
dr7ana Nov 14, 2024
acc6bf1
squash
dr7ana Nov 18, 2024
a165528
squash again whatever
dr7ana Nov 19, 2024
a1fc8b5
yeehaw
dr7ana Nov 19, 2024
e09df7d
libquic bump dr7ana/0rtt
dr7ana Dec 5, 2024
a3ae897
Fix dangling view in addr/port parsing
jagerman Dec 5, 2024
3e1089a
0rtt bump for stateless reset lifetimes, nodedb prune against whitelist
dr7ana Dec 5, 2024
6d54176
datagramIO
dr7ana Dec 7, 2024
d8d794d
datagramio tweaking
dr7ana Dec 9, 2024
2db462d
client data message routing
dr7ana Dec 11, 2024
73c06de
libquic bump for ip range/net types
dr7ana Dec 11, 2024
b1711f3
squash
dr7ana Dec 13, 2024
74a64bb
squash
dr7ana Dec 15, 2024
208eed6
big reorg, more commits to come
dr7ana Jan 13, 2025
f603ecb
dropme: once oxenc constexpr is merged
dr7ana Jan 13, 2025
2033d6b
squash
dr7ana Jan 14, 2025
1b3a405
new session tags, many:1 on paths, etc
dr7ana Jan 16, 2025
b3ca8c0
testing dgram split on testnet
dr7ana Jan 16, 2025
05d1b87
squash
dr7ana Jan 23, 2025
ec77c68
big squash, more like a zucchini (cli11 -> latest)
dr7ana Jan 26, 2025
d32d15d
rpc, client, etc
dr7ana Jan 30, 2025
62f65d8
better path handling, etc, its working working
dr7ana Feb 6, 2025
444230d
close session RPC, finessing internal path mapping, daemon cmake
dr7ana Feb 10, 2025
68d8c4c
switch it up
dr7ana Feb 11, 2025
4e5f22c
more path-switch and session info updating logic
dr7ana Feb 12, 2025
7d53a4e
rpc tweak, close logic
dr7ana Feb 12, 2025
021116a
switch vs close
dr7ana Feb 12, 2025
38fd87f
tweak session close logic to properly notify handler
dr7ana Feb 13, 2025
64604c6
session unmapping, more succinct logging in b32z and so on
dr7ana Feb 13, 2025
4df3e42
rotation is so dry
dr7ana Feb 18, 2025
4d9d97d
More efficient internals RE path rotation/sessions/clientcontacts
dr7ana Feb 19, 2025
30868b5
fixed static build, dropped unnecessary latest libevent external, oth…
dr7ana Feb 20, 2025
188f30a
ci rework
dr7ana Feb 20, 2025
d4e0d57
rotation and path switching are coordinated with publishing
dr7ana Feb 21, 2025
9458dd3
WIP: relay sessions almost complete
dr7ana Feb 23, 2025
c2a74a2
batch-gossip
dr7ana Feb 24, 2025
2520731
relay sessions heirarchically implemented
dr7ana Feb 24, 2025
b3345be
relay sesh anyone?
dr7ana Feb 24, 2025
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
Prev Previous commit
Next Next commit
clientcontact logic (squash)
- unorganized amalgamation of cc logic
- session-related logic still local
dr7ana committed Oct 21, 2024
commit 827ff5bc9a5a4d59a5d385e566eb2f0d43a5e733
1 change: 0 additions & 1 deletion llarp/address/address.hpp
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ namespace llarp
std::string name() const { return _pubkey.to_string(); }

std::string to_string() const { return name().append(_tld); }

static constexpr bool to_string_formattable{true};
};

96 changes: 69 additions & 27 deletions llarp/contact/client_contact.cpp
Original file line number Diff line number Diff line change
@@ -5,29 +5,32 @@ namespace llarp
static auto logcat = log::Cat("client-intro");

ClientContact::ClientContact(
Ed25519Hash pk,
Ed25519PrivateData private_data,
PubKey pk,
const std::unordered_set<dns::SRVData>& srvs,
uint16_t proto_flags,
std::optional<net::ExitPolicy> policy)
: derived_privatekey{std::move(pk)},
: derived_privatekey{std::move(private_data)},
pubkey{std::move(pk)},
SRVs{srvs.begin(), srvs.end()},
protos{proto_flags},
exit_policy{std::move(policy)}
{}

ClientContact::ClientContact(std::string_view buf)
ClientContact::ClientContact(std::string&& buf)
{
bt_decode(buf);
bt_decode(oxenc::bt_dict_consumer{std::move(buf)});
}

ClientContact ClientContact::generate(
Ed25519Hash&& pk,
Ed25519PrivateData&& private_data,
PubKey&& pk,
const std::unordered_set<dns::SRVData>& srvs,
uint16_t proto_flags,
std::optional<net::ExitPolicy> policy)
{
log::info(logcat, "Generating new ClientContact...");
return ClientContact{std::move(pk), srvs, proto_flags, std::move(policy)};
return ClientContact{std::move(private_data), std::move(pk), srvs, proto_flags, std::move(policy)};
}

void ClientContact::handle_updated_field(intro_set iset)
@@ -57,10 +60,10 @@ namespace llarp

void ClientContact::bt_encode(std::vector<unsigned char>& buf) const
{
bt_encode(oxenc::bt_dict_producer{reinterpret_cast<char*>(buf.data()), buf.size()});
buf.resize(bt_encode(oxenc::bt_dict_producer{reinterpret_cast<char*>(buf.data()), buf.size()}));
}

void ClientContact::bt_encode(oxenc::bt_dict_producer&& btdp) const
size_t ClientContact::bt_encode(oxenc::bt_dict_producer&& btdp) const
{
btdp.append("a", pubkey.to_view());

@@ -82,21 +85,23 @@ namespace llarp
for (auto& s : SRVs)
s.bt_encode(sublist.append_dict());
}
}

void ClientContact::bt_decode(std::string_view buf)
{
try
{
bt_decode(oxenc::bt_dict_consumer{buf});
}
catch (const std::exception& e)
{
log::critical(logcat, "ClientContact deserialization failed: {}", e.what());
throw;
}
return btdp.view().size();
}

// void ClientContact::bt_decode(std::string_view buf)
// {
// try
// {
// bt_decode(oxenc::bt_dict_consumer{buf});
// }
// catch (const std::exception& e)
// {
// log::critical(logcat, "ClientContact deserialization failed: {}", e.what());
// throw;
// }
// }

void ClientContact::bt_decode(oxenc::bt_dict_consumer&& btdc)
{
pubkey.from_string(btdc.require<std::string_view>("a"));
@@ -117,7 +122,6 @@ namespace llarp

protos = btdc.require<uint16_t>("p");

// ditto as above
if (btdc.skip_until("s"))
{
auto sublist = btdc.consume_list_consumer();
@@ -133,20 +137,37 @@ namespace llarp
return intros.rbegin()->is_expired(now);
}

EncryptedClientContact ClientContact::encrypt_and_sign()
EncryptedClientContact ClientContact::encrypt_and_sign() const
{
EncryptedClientContact enc{};

try
{
enc.blinded_pubkey = derived_privatekey.to_pubkey();
bt_encode(enc.encrypted);

if (not crypto::xchacha20(enc.encrypted.data(), enc.encrypted.size(), pubkey.data(), enc.nonce.data()))
throw std::runtime_error{"Failed to encrypt ClientContact bt-payload!"};

enc.signed_at = llarp::time_now_ms();

oxenc::bt_dict_producer btdp;
enc.bt_encode(btdp);

auto view = btdp.view_for_signing<unsigned char>();

if (not crypto::sign(enc.sig, derived_privatekey, view.data(), view.size()))
throw std::runtime_error{"Failed to sign EncryptedClientContact payload!"};

btdp.append("~", enc.sig.to_view());

enc._bt_payload = std::move(btdp).str();
}
catch (const std::exception& e)
{
log::warning(logcat, "Exception encrypting and signing client contact: {}", e.what());
throw;
}


return enc;
}
@@ -157,12 +178,12 @@ namespace llarp
return EncryptedClientContact{buf};
}

EncryptedClientContact::EncryptedClientContact(std::string_view buf)
EncryptedClientContact::EncryptedClientContact(std::string_view buf) : _bt_payload{buf}
{
bt_decode(oxenc::bt_dict_consumer{buf});
bt_decode(oxenc::bt_dict_consumer{_bt_payload});
}

void EncryptedClientContact::bt_encode(oxenc::bt_dict_producer&& btdp) const
void EncryptedClientContact::bt_encode(oxenc::bt_dict_producer& btdp) const
{
btdp.append("i", blinded_pubkey.to_view());
btdp.append("n", nonce.to_view());
@@ -193,6 +214,27 @@ namespace llarp
}
}

std::optional<ClientContact> EncryptedClientContact::decrypt(const PubKey& root)
{
std::optional<ClientContact> cc = std::nullopt;
std::string payload{_bt_payload};

if (crypto::xchacha20(
reinterpret_cast<unsigned char*>(payload.data()), payload.size(), root.data(), nonce.data()))
{
log::debug(logcat, "EncryptedClientContact decrypted successfully...");
cc = ClientContact{std::move(payload)};
}

return cc;
}

bool EncryptedClientContact::verify() const
{
return crypto::verify(
blinded_pubkey, reinterpret_cast<const unsigned char*>(_bt_payload.data()), _bt_payload.size(), sig);
}

bool EncryptedClientContact::is_expired(std::chrono::milliseconds now) const
{
return now >= signed_at + path::DEFAULT_LIFETIME;
61 changes: 44 additions & 17 deletions llarp/contact/client_contact.hpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

#include <llarp/constants/version.hpp>
#include <llarp/crypto/crypto.hpp>
#include <llarp/dht/key.hpp>
#include <llarp/dns/srv_data.hpp>
#include <llarp/net/net.hpp>
#include <llarp/net/traffic_policy.hpp>
@@ -46,41 +47,61 @@ namespace llarp
TCP2QUIC = 1 << 5,
};

/** TODO:
- LocalCC
- holds the derived Ed25519PrivateData
- RemoteCC:

*/

/** ClientContact
On the wire we encode the data as a dict containing:
- "" : the CC format version, which must be == ClientContact::VERSION to be parsed successfully
- "a" : public key of the remote client instance
- "e" : (optional) exit policy containing sublists of accepted protocols and routed IP ranges
- "i" : list of client introductions corresponding to the different pivots through which paths can be built
to the client instance
- "p" : supported protocols indicating the traffic accepted by the client instance; this indicates if the
client is embedded and therefore requires a tunneled connection. Serialized as a bitwise flag of
above protocol_flag enums
- "s" : SRV records for lokinet DNS lookup
- "s" : (optional) SRV records for lokinet DNS lookup
*/
struct ClientContact
{
friend struct EncryptedClientContact;
friend class handlers::SessionEndpoint;

inline static constexpr uint8_t CC_VERSION{0};
inline static constexpr size_t MAX_CC_SIZE{4096};

~ClientContact() = default;

protected:
ClientContact() = default;
ClientContact(std::string_view buf);
ClientContact(std::string&& buf);

ClientContact(
Ed25519Hash pk,
Ed25519PrivateData private_data,
PubKey pk,
const std::unordered_set<dns::SRVData>& srvs,
uint16_t proto_flags,
std::optional<net::ExitPolicy> policy = std::nullopt);

/** Parameters:
- `private_data` : derived private subkey data
- `pubkey` : master identity key pubkey
- `srvs` : SRV records (optional, can be empty)
- `proto_flags` : client-supported protocols
- `policy` : exit-related traffic policy (optional)
*/
static ClientContact generate(
Ed25519Hash&& pk,
Ed25519PrivateData&& private_data,
PubKey&& pubkey,
const std::unordered_set<dns::SRVData>& srvs,
uint16_t proto_flags,
std::optional<net::ExitPolicy> policy = std::nullopt);

EncryptedClientContact encrypt_and_sign();
EncryptedClientContact encrypt_and_sign() const;

template <typename... Opt>
void regenerate(intro_set iset, Opt&&... args)
@@ -95,9 +116,7 @@ namespace llarp
_regenerate();
}

~ClientContact() = default;

Ed25519Hash derived_privatekey;
Ed25519PrivateData derived_privatekey;

PubKey pubkey;

@@ -114,7 +133,7 @@ namespace llarp

void bt_encode(std::vector<unsigned char>& buf) const;

void bt_encode(oxenc::bt_dict_producer&& btdp) const;
size_t bt_encode(oxenc::bt_dict_producer&& btdp) const;

// Throws like a MF (for now)
void bt_decode(std::string_view buf);
@@ -135,38 +154,46 @@ namespace llarp
};

/** EncryptedClientContact
"i" blinded local routerID
"i" blinded local PubKey (routerID)
"n" nounce
"t" signing time
"x" encrypted payload
"~" signature
"~" signature (signed with blinded derived scalar `b`)
*/
struct EncryptedClientContact
{
friend struct dht::CCNode;
friend struct ClientContact;

protected:
EncryptedClientContact() : nonce{SymmNonce::make_random()}, encrypted(ClientContact::MAX_CC_SIZE) {}

static EncryptedClientContact construct();

static EncryptedClientContact deserialize(std::string_view buf);

// protected:
protected:
explicit EncryptedClientContact(std::string_view buf);

PubKey blinded_pubkey;
SymmNonce nonce;
std::chrono::milliseconds signed_at{0s};
std::vector<unsigned char> encrypted;
Signature sig;
Signature sig{};

void bt_encode(oxenc::bt_dict_producer&& btdp) const;
std::string _bt_payload;

// Does not encode signature, meant to be called prior to signing
void bt_encode(oxenc::bt_dict_producer& btdp) const;

void bt_decode(oxenc::bt_dict_consumer&& btdc);

public:
dht::Key_t key() const { return dht::Key_t{blinded_pubkey.data()}; }

std::optional<ClientContact> decrypt(const PubKey& root);

std::string_view bt_payload() const { return _bt_payload; }

bool verify() const;

bool is_expired(std::chrono::milliseconds now = time_now_ms()) const;
};
} // namespace llarp
37 changes: 21 additions & 16 deletions llarp/contact/contactdb.cpp
Original file line number Diff line number Diff line change
@@ -10,28 +10,28 @@ namespace llarp
_introset_nodes = std::make_unique<dht::Bucket<dht::ISNode>>(_local_key, llarp::randint);
}

// std::optional<ClientContact> ContactDB::get_decrypted_cc(RouterID remote) const
// {
// std::optional<ClientContact> ret = std::nullopt;
std::optional<ClientContact> ContactDB::get_decrypted_cc(RouterID remote) const
{
std::optional<ClientContact> ret = std::nullopt;

// (void)remote;
// // TESTNET: TODO: finish this after implementing CC encrypt/decrypt
if (auto enc = get_encrypted_cc(dht::Key_t::derive_from_rid(remote)))
ret = enc->decrypt(remote);

// return ret;
// }
return ret;
}

// std::optional<EncryptedClientContact> ContactDB::get_encrypted_cc(const dht::Key_t& key) const
// {
// std::optional<EncryptedClientContact> enc = std::nullopt;
std::optional<EncryptedClientContact> ContactDB::get_encrypted_cc(const dht::Key_t& key) const
{
std::optional<EncryptedClientContact> enc = std::nullopt;

// auto& clientcontacts = _cc_nodes->nodes;
auto& clientcontacts = _cc_nodes->nodes;

// if (auto itr = clientcontacts.find(key);
// itr != clientcontacts.end() && not itr->second.client_contact.is_expired())
// enc = itr->second.client_contact;
if (auto itr = clientcontacts.find(key);
itr != clientcontacts.end() && not itr->second.client_contact.is_expired())
enc = itr->second.client_contact;

// return enc;
// }
return enc;
}

std::optional<service::IntroSetOld> ContactDB::get_decrypted_introset(RouterID remote) const
{
@@ -67,4 +67,9 @@ namespace llarp
_introset_nodes->put_node(std::move(enc));
}

void ContactDB::put_cc(EncryptedClientContact enc)
{
_cc_nodes->put_node(enc);
}

} // namespace llarp
Loading