Commit graph

975 commits

Author SHA1 Message Date
Jason Rhinelander d79323a9f8 Bump version to 2.1.0
There is a fair bit of new stuff here, at least a minor version bump
seems in order.
2021-04-21 21:32:20 -03:00
Jason Rhinelander eb289c280e Add direction to xchacha20 shared key
This alters the derived key hash to reverse the pubkey order when
replying so that the same key in each direction is used, i.e. for a
message from client C to snode S the key is:

    H(cS || C || S)

before this commit, the would use an encryption key for return messages
of:

    H(sC || S || C)

and, while the client can still decrypt that, it means the client has
*two* derived keys to worry about.  With this change, server swap the
order so it puts itself *second*:

    H(sC || C || S)

which will yield the same shared key as the client derived for the
original message.
2021-04-21 21:31:39 -03:00
Jason Rhinelander 263b0ab219 Fix test suite 2021-04-21 21:30:51 -03:00
Jason Rhinelander cca44edcb8 Use longer omq onion req parameter names
This makes them match the names we receive in the json arguments from
clients (aside from `data`).

(Also includes a minor comment typo fix)
2021-04-21 19:37:16 -03:00
Jason Rhinelander 39c489e6dc Remove debugging 2021-04-21 18:34:05 -03:00
Jason Rhinelander 97c8bb12ef Add xchacha20 encrypt/decrypt implementatation 2021-04-21 18:23:59 -03:00
Jason Rhinelander 10b9d5accb New internal SS-to-SS onion req endpoint
Replaces the sn.onion_req_v2 OMQ endpoint with a new sn.onion_request
that takes an extendable bencoded dict (the same as used extensively in
oxen-core and lokinet), thus allowing us to pass fields such as hop
number and encryption type in the request, remaining compact (binary
data has no overhead), and allows for future additions without requiring
a new endpoint.

The new endpoint activates for SN-to-SN onion data at HF18; before then
the sn.onion_req_v2 is still used and remains backwards compatible (but
cannot be extended with encryption type or hop info).

Currently on the wire we have four fields:

    p - end encrypted payload (required)
    ek - the ephemeral key (required)
    et - the encryption type (optional, aes-gcm if not provided)
    nh - the hop number, which get incremented on each hop

Max path length is limited to 15, to allow the client to choose to
obscure it's path knowledge somewhat by using a randomized starting hop
position from `[0, 15-actual]`
2021-04-21 17:41:15 -03:00
Jason Rhinelander c0e7deef2f Convert run-time variant unpacking into a visit
This gives a compile-time failure if we don't handle a case, which is
nicer than the current run-time error log entry.

The diff looks messy but this is basically just extracting each possible
ParsedInfo option into its own method and calling it via std::visit.

(var::visit from oxenmq/variant.h *is* std::visit everywhere except
pre-10.15 macOS where std::visit doesn't work).
2021-04-21 17:36:20 -03:00
Jason Rhinelander 81f89019fe Remove v2 request parameters from code
Client requests only every call with v2=true, and the oxenmq v1 request
endpoint isn't actually used (except for the ping hack going away after
HF18), so just remove a bunch of dead code.
2021-04-21 17:36:00 -03:00
Jason Rhinelander 6e95b9c976
Merge pull request #421 from jagerman/fix-allowed-endpoints
JSON/base64 opt-out for onion requests + oxend rpc proxy unwrapping
2021-04-21 13:59:29 -03:00
Jason Rhinelander fa9c58bfd2 Make all callback invocations return
Prevents possible multiple invocation errors by make sure every place we
invoke a callback function that isn't obviously at the end of a function
explicitly returns.
2021-04-21 13:56:42 -03:00
Jason Rhinelander 2a62b4d5d3 Stop processing after invoking the callback
If one of these errors were hit processing would continue, writing
status/headers/body multiple times until we throw an exception, which
bubbles back to the exception handler which writes the body yet another
time.
2021-04-21 12:36:10 -03:00
Jason Rhinelander 670f98accd const exception lvalue refs 2021-04-21 12:30:40 -03:00
Jason Rhinelander fe102073b5 Add more output, timing info 2021-04-21 02:25:02 -03:00
Jason Rhinelander d826d2fbe4 onion-request test script: fix destination in hops 2021-04-21 02:25:02 -03:00
Jason Rhinelander d0b2323637 Update oxenmq to tagged version 2021-04-20 19:19:03 -03:00
Jason Rhinelander e7d10cb18a Onion request test program improvements
- Pass payload/control as arguments (hard-coding it and needing to
recompile was gross).

- Fix 0-hop onion requests; the last layer of data encapsulation wasn't
being applied to a 0-hop request.

- Print metadata (headers, body size, etc.) to stderr, so that stdout
can be redirected or piped to `jq` to just process the body.

- Auto-detect response encoding/encryption.  We can get back plaintext,
encrypted binary, or encrypted+base64 data, depending on the request
type and parameters; the code now probes it and attempts decryption to
figure out which one it is.
2021-04-20 18:18:41 -03:00
Jason Rhinelander 0c92ee2933 Simplifies/unwraps the oxend_request endpoint
Redoes the oxend rpc API interface to make it slightly simpler and avoid
double-encoding (or triple-encoding!) json data.

The API now looks like:

    {"method": "oxend_request", "params": {"endpoint": "get_service_nodes", "params": {"limit": 1}}}

This renames the "oxend_params" key to just "params" (because the
"oxend" bit seems redundant given the method name) and makes it optional
(because many oxend rpc endpoints, including get_service_nodes, do not
require parameters to be passed at all).

The return value is now (when also using `"json": true` in the control
parameter added in the previous commit) straight JSON:

    {"status":200,"body":{"result":{"block_hash":"699e2f20bcb...

instead of:

    {"status":200,"body":"{\"result\":\"{\\\"block_hash\\\":\\\"699e2f20bcb...

If not requesting json embedding in the control parameters (see previous
commit) then there will still be the outer later of json string encoding
for body, but the JSON is still embedded directly rather than being an
extra string layer:

    {"status":200,"body":"{\"result\":{\"block_hash\":\"699e2f20bcb...

On error of whatever reason you get back a 400 status with the error
message in "body", for example:

    {"body":"Unable to parse request: Failed to parse JSON parameters","status":400}
2021-04-20 18:03:27 -03:00
Jason Rhinelander f4b28a7e89 Allow opting out of json-nesting and base64 encoding
This adds two boolean fields to the "control" section of an onion
request (i.e.  the part where the "headers" field is passed).

`"base64": false` -- If this is specified (and false) then the onion
request response will *not* be base64 encoded after encryption (i.e.
just sent back as straight encrypted binary data).

`"json": true` -- If specified and true *and* the request returns JSON
then embed the JSON directly into the request rather than putting the
stringified JSON into the body string.  E.g. if this is specified then
you would get:

    {"status":200,"body":{"hi":"123"}}

instead of:

    {"status":200,"body":"{\"hi\":\"123\"}}

No actual parsing of the inner content is done; if the endpoint returned
invalid json then the return will contain invalid json.

The default for both fields (true and false, respectively) give back the
existing behaviour so that current onion request clients won't break.
2021-04-20 18:02:13 -03:00
Maxim Shishmarev 8b14c1fc1b
Merge pull request #420 from jagerman/fix-allowed-endpoints
Fix allowed endpoints unordered_set to be strings
2021-04-20 17:13:17 +10:00
Jason Rhinelander e8dcdb4d2b Fix allowed endpoints unordered_set to be strings 2021-04-20 03:27:46 -03:00
Jason Rhinelander 3023e10fdf
Merge pull request #419 from jagerman/ss-reach-reporting
Storage server refactor and ping reporting rewrite
2021-04-19 21:43:21 -03:00
Jason Rhinelander 41be330e00 Add ifdef'ed proxy requests code 2021-04-19 20:49:48 -03:00
Jason Rhinelander 71d96c8f7a Added onion request contrib test code 2021-04-19 20:35:17 -03:00
Jason Rhinelander e6b8d8efcf Debug message improvements 2021-04-19 19:51:52 -03:00
Jason Rhinelander 8ae2ab867c Fix empty onion request response 2021-04-19 19:50:22 -03:00
Jason Rhinelander ba2ddd4ddd Don't throw and return "std::exception" as an error string 2021-04-19 17:24:57 -03:00
Jason Rhinelander 81ad901115 Optimize get_swarm_by_pk to return a SwarmInfo reference instead of id
The id is available in `.swarm_id`, but more importantly this avoids
needing to go do linear scans when we actually need the swarm.
2021-04-19 16:22:30 -03:00
Jason Rhinelander 2361b293c9 Serialization: replace ghetto string_view with actual std::string_view
The ghetto version was not even remotely similar to a string view, but
was actually a string iterator pair container with no ability to
actually "view" anything.
2021-04-19 16:20:12 -03:00
Jason Rhinelander 60017e7e4d user pubkey tighter restrictions
- Enforce hex rather than accepting any random 66- or 64-character
  string as a pubkey
- Clean up pubkey -> integer code
- The cleanup fixes a bug where pubkey -> integer conversion was
  skipping the first two bytes on testnet (and ended up in UB by reading
  the null + one byte beyond the end of the string for testnet
  addresses).  THIS WILL BREAK EXISTING TESTNET PUBKEY->SWARM VALUES!
  (but it's only testnet, so that's okay).
2021-04-19 16:14:55 -03:00
Jason Rhinelander 2cd3998144 Avoid unnecessary json->string conversion 2021-04-19 14:07:20 -03:00
Jason Rhinelander ad10713c3a Remove gone reqidx param 2021-04-18 21:34:36 -03:00
Jason Rhinelander ffefbc3acd Remove redundant HTTP status
http::status::bad_request is already set at the beginning of this chunk
of code, and having these makes the cases that *don't* have it look
wrong.
2021-04-18 21:10:52 -03:00
Jason Rhinelander 5b57fcc7fa Add FIXME about silent failures
The protocol is currently underdesigned with no failure mechanism at
all, so there's nothing we *can* fix here.  We should fix the protocol,
of course, but that's outside the scope of this PR.
2021-04-18 20:54:29 -03:00
Jason Rhinelander 05bb4cf7ea Avoid potentially confusing bool addition 2021-04-18 20:44:58 -03:00
Jason Rhinelander ba7be1d0f5 Undo converting ReachType to a bool
The enum is more descriptive.
2021-04-18 20:41:01 -03:00
Jason Rhinelander 401afe3942 Switch derived values to std::arrays
These are 32-byte fixed size values, no need to allocate for them.
2021-04-18 20:33:29 -03:00
Jason Rhinelander 2c6b4b9fb8 Add comment about probability value 2021-04-18 20:23:55 -03:00
Jason Rhinelander 60cd3d3059 Add tester/testee sorting hack for pre-HF18 compatibility
SS's current testee/tester sorting is based on (nasty) sorting of a
lower-case hex string representation of the pubkey.

This adds a hack for compatibility up to HF18, then at HF18 switches to
sorting by direct binary pubkey values.
2021-04-18 16:51:33 -03:00
Jason Rhinelander 874e93f89d Replace asio timers with omq repeated timers
omq ones are much simpler and don't require continuous re-establishing,
saving a bunch of code.
2021-04-18 16:48:51 -03:00
Jason Rhinelander 7d9f6d1a8d Skip inactive nodes before warning about missing keys
If we're skipping it we don't care about it being missing.

Without this we get a bunch of warnings whenever an unfilled awaiting
contributions node has not yet submitted proofs or is abandoned (which
is usually the case on testnet, and sometimes on mainnet).
2021-04-18 15:26:57 -03:00
Jason Rhinelander f3a4db9a79 Add proper encrypt/decrypt unit tests 2021-04-18 14:50:40 -03:00
Jason Rhinelander 98f6140c0f Sort unit test source files 2021-04-18 14:50:40 -03:00
Jason Rhinelander 786042ecbb Replace onion_req ping hack with sn.ping endpoint
Sending a bogus sn.onion_req with a "ping" argument was a gross hack
that was needed for a backwards mid-hf update a long time ago; this
finally replaces it to a proper endpoint (starting at HF18).
2021-04-18 14:50:40 -03:00
Jason Rhinelander 31d35ce869 Remove unused variables/capture 2021-04-18 14:50:40 -03:00
Jason Rhinelander de7bf79854 Optimize/cleanup onion request parsing
- Do the json parsing as part of the payload parsing rather than
allocating a string and then making the caller do it (there's no case
where the caller *doesn't* want to do it).

- Modernize code to use structured bindings, allowing both cleaner code
and reduction in the number of moves/copies.
2021-04-18 14:50:40 -03:00
Jason Rhinelander 88de161365 Abstract encryption type API 2021-04-18 14:50:40 -03:00
Jason Rhinelander 16ec9ac0f2 Misc cleanups and optimizations 2021-04-18 14:50:40 -03:00
Jason Rhinelander afac0e7488 Don't squelch exception if x25519 extraction fails 2021-04-18 14:50:40 -03:00
Jason Rhinelander b5e8f07894 Remove static req index counter
Static local vars incur overhead due to needing thread-safe
initialization, and this one in particular is only used in a single
debug message.
2021-04-18 14:50:40 -03:00