Commit Graph

3937 Commits

Author SHA1 Message Date
Alexander Færøy c8a8aeae50 Merge branch 'send' into 'main'
tor-circmgr: Make take_or_launch_stub_circuit future Send

See merge request tpo/core/arti!1096
2023-03-30 15:58:32 +00:00
gabi-250 2cd36a4c44 Merge branch 'ring' into 'main'
tor-netdir: Implement `HsDirRing::find_pos`

See merge request tpo/core/arti!1095
2023-03-30 15:37:42 +00:00
gabi-250 e7e305f9cd tor-netdir: Minor docs fixes 2023-03-30 15:37:07 +00:00
Ian Jackson 23c7bd9174 Run rustfmt
Apply this churn, which I deferred for ease of review.
2023-03-30 15:58:47 +01:00
Ian Jackson a14d18d295 arti-client: Call HsCircPool::launch_background_tasks
I found that I had the bug where I forgot to call this function, and
reached
   bad_api_usage!("The circuit launcher wasn't initialized")

The possibility of such a bug is a hazard of this API pattern.
2023-03-30 15:58:09 +01:00
Ian Jackson 577940853f tor-netdir: Implmeent HsDirRing::find_pos 2023-03-30 15:53:51 +01:00
Ian Jackson 3ed9dca842 tor-hsconn: Rename ConnError (from HsClientConnError)
The old name was unwieldy and other crates can just as well name it by
the crate scope.
2023-03-30 15:49:07 +01:00
Ian Jackson 255b9cac96 arti-client: When making hs conn, wait for bootstrap
Not doing this was a bug.  The bug was possible because of some code
duplication between the exit and hs paths.  Add a comment about that.
2023-03-30 15:49:07 +01:00
Ian Jackson 926abf3ade tor-client: Pass a netdir for each request
This will be more convenient inside tor-hsclient.  In arti-client,
this mirrors the way TorClient::get_or_launch_exit_circ works.
2023-03-30 15:49:07 +01:00
Ian Jackson 9b831933ef tor-netdir: Provide accessor for params field of HsDirParams 2023-03-30 15:47:06 +01:00
Ian Jackson 544d0e6d18 tor-netdir: Implement hs_dirs accessor 2023-03-30 15:47:06 +01:00
Ian Jackson 3c39c2f544 tor-netdir: hs_dirs accessor: change semantics, type, and name
Don't have it take the TP, so that the caller must call it multiple
times.  Instead, have it return all the relevant relays.
2023-03-30 15:47:06 +01:00
Ian Jackson e15f3c5348 tor-netdir: Provide hs_all_time_periods instead of ..._secondary_...
I don't think the server-side support will want to explicitly call
current and then secondary.  Rather, it will want to iterate over all
the relevant ones.

And fix the name, and add another comment about whether we need this.
2023-03-30 15:47:06 +01:00
Ian Jackson 4cf3cd00ef tor-netdir: Rename hs_time_period
Change its name to hs_* like we do with things at this layer.

But, it turns out, that at least for hs client connections to fetch
the descriptor, I don't seem to need to call it yet ?  Maybe it's not
needed.
2023-03-30 15:47:06 +01:00
Ian Jackson db028a6d34 tor-netdir: Sort out HsDirOp
* Change its name to Hs* like we do with things at this layer
* Make the Upload variant cfg-conditional
2023-03-30 15:47:06 +01:00
Ian Jackson 4d3d79a511 tor-netdir: Reorganise iteration over hsdir rings
Provide iter_for_op, by changing iter into iter_filter_secondary and
having a new entrypoint iter.
2023-03-30 15:47:06 +01:00
Ian Jackson 7924e995f1 tor-netdir: Provide relay_by_rs_idx 2023-03-30 15:47:06 +01:00
Ian Jackson dd493307f9 tor-circmgr: Make take_or_launch_stub_circuit future Send
thread_rng() isn't Send.  We can fix this by not holding it over an
await point.
2023-03-30 15:46:15 +01:00
Ian Jackson db968033cf tor-netdir: Make the hsdir ring be a TiVec
This eliminates an untyped `usize` index.
2023-03-30 15:43:48 +01:00
Nick Mathewson 26ee1feeb1 Upgrade dependency to latest rusqlite. 2023-03-30 08:33:44 -04:00
Nick Mathewson 289c30c5f0 Upgrade dependency to latest async-native-tls. 2023-03-30 08:32:18 -04:00
Nick Mathewson a62affd66e Move functionality from tor_basic_utils to tor_async_utils
This commit is mostly code movement; I'd recommend reviewing it
with git's `--color-moved` option.
2023-03-29 13:57:11 -04:00
Nick Mathewson 1ee4a98a27 Make a new empty tor-async-utils crate. 2023-03-29 09:02:20 -04:00
Ian Jackson 13edaf68de Merge branch 'blind' into 'main'
key blinding: Use consistent terminology

See merge request tpo/core/arti!1085
2023-03-29 09:44:50 +00:00
Ian Jackson edb3ac26f3 Merge branch 'hspre' into 'main'
Miscellanious tidying up (pursuant to HS client work)

See merge request tpo/core/arti!1086
2023-03-29 09:44:48 +00:00
eta a6fe3803a0 arti-client: add accessors for `Blockage`
Fixes #800.
2023-03-28 19:27:04 +01:00
Ian Jackson b982ee678d Tidy up an unused import warning
Now
  cargo +stable clippy --locked --offline --workspace --all-targets
is clean.
2023-03-28 15:49:45 +01:00
Ian Jackson 5ff24c9f84 Pass HS identity to hsclient connection function
Obviously it will need this!
2023-03-28 15:49:45 +01:00
Ian Jackson df8e4dd497 Pass HsCircPool to hsclient connect function, not CircMgr (fmt) 2023-03-28 15:49:45 +01:00
Ian Jackson 9b6be7eaa7 Pass HsCircPool to hsclient connect function, not CircMgr
We separated this out in the circmgr API.  This is what the HS client
needs.  It doesn't want to participate in the general circuit pool.
2023-03-28 15:49:45 +01:00
Ian Jackson 00e522a91a Add some missing imports
Now
  nailing-cargo +stable clippy -p tor-hsclient --all-features --all-targets
actually works.

squash! Add some missing imports
2023-03-28 15:49:45 +01:00
Ian Jackson 4c2a9332db tor-hscrypto: key blinding: Use consistent terminology
* Don't ever use the words "parameter" or "param".
  These doesn't appear in the spec anywhere.

* Use `h` as the variable name for the unclamped blinding factor,
  and `blinding_factor` in function names.
2023-03-28 12:47:14 +01:00
Ian Jackson def291dcb5 tor-llcrypto: key blinding: Use consistent terminology
Unhelpfully, the spec uses the variable name `h` and the phrase
"blinding factor" for both the unclamped and clamped value.  The
clamped value is internal to the algorithm.

In our code:

* Don't ever use the word "parameter" or variable name `param`.
  This doesn't appear in the spec anywhere.

* Use `h` for the unclamped blinding factor, and `blinding_factor` for the
  clamped blinding factor.

* Rename `blinding_factor` function to `clamp_blinding_factor`, since
  in the spec's terminology it takes an (unclamped) "blinding factor"
  and returns a (clamped) "blinding factor".

* State explicitly what thing in the spec the `h` parameters are.
2023-03-28 12:47:12 +01:00
Gabriela Moldovan ef72e927ac
Remove hard-coded test certs.
We can use a deterministic rng to generate predictable keypairs instead.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 19:44:49 +01:00
Gabriela Moldovan 70d247e59c
Make the HS encoder randomness source injectable.
This makes it possible to plug in a deterministic randomness source for
testing.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 19:07:41 +01:00
Ian Jackson 9940bd1eb4 tor-netdir: Use `pos` not `idx` in test network constructors
There are too many things called "index" here.  `idx` could be read to
mean the table index `RouterStatusIdx`, the hsdir hash `HsDirIndex`,
or an entry in some other one of these tables.

Here's, it's just the sequence number of the index in the test netdir.
Use `pos` for that.  (`seq` would have been another possibility.)
2023-03-27 17:32:16 +01:00
Ian Jackson 4da12a26a9 tor-netdir: Use `hsdir_index` for hidden service directory hashval (fmt) 2023-03-27 17:32:16 +01:00
Ian Jackson 325526a903 tor-netdir: Use `hsdir_index` for hidden service directory hashval
The hidden services directory hashring is a ring of hsdir relays,
sorted by a hash that the spec calls the "index".  That's `HsDirIndex`.

This was a bad idea because the word "index" is seriously overused,
but in Arti we must use the same terminology.

At least, qualify it everywhere.  Now one of these hsdir sort position
hashes is always, in our code, an `hsdir_index`.

I think this is necessary even inside modules called `hsdir_*`,
because those can deal with other kind of "index" too.
2023-03-27 17:31:23 +01:00
Ian Jackson a746e17c8e tor-netdir: eliminate ref to abolished MdEntry
This was removed in c3e74973b4
  netdir: Use an even smaller rep for list of microdescs
2023-03-27 17:26:51 +01:00
Ian Jackson 99ffb89b48 tor-netdir: Use `rsidx` consistent for `RouterStatusIdx`
This is an `IndexVec` key type.  Some places used `idx`, some `rsi`,
some `rs_idx`.

Use `rsidx` for it everywhere, including in locals, function names,
and fields.  `rsidx` is a compromise.  `rsi` might be a bit opaque,
but we want a one-"word" name since it appears inside other names.
2023-03-27 17:25:52 +01:00
Gabriela Moldovan a14d95a8a0
Fix broken doc link.
This fixes a broken doc link I introduced in !1070:

```
error: unresolved link to `crate::doc::hsdesc::build::inner::HsDescInnerBuilder`
  --> crates/tor-netdoc/src/doc/hsdesc/build/middle.rs:34:11
   |
34 |     /// [`crate::doc::hsdesc::build::inner::HsDescInnerBuilder`] as described in sections
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `HsDescInnerBuilder` in module `inner`
   |
   = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`

error: could not document `tor-netdoc`
```

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 13:29:24 +01:00
Gabriela Moldovan 1d4069cc7f
Use the type system to enforce use of blinded keys.
Hidden services use blinded singing keys derived from the identity key
to sign descriptor signing keys.

Before this patch, the hidden descriptor builder represented its blinded
signing keys (`blinded_id`) as plain `ed25519::Keypair`s. This was not
ideal, as there was nothing preventing the caller from accidentally
initializing `blinded_id` with an unblinded keypair.

This introduces a new `HsBlindKeypair` type to represent blinded
keypairs.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 11:45:51 +01:00
Nick Mathewson 4af2c2ec33 tor_client: Add some example code for BridgeConfig.
Closes #791
2023-03-24 16:25:10 -04:00
Nick Mathewson 455a7a7109 arti-client: Make TransportConfigListBuilder public.
Without this there's no convenient way to add a transport without
messing with serde/toml.

Found while working on #791
2023-03-24 16:25:10 -04:00
Gabriela Moldovan 71686a9c49 Use transparent structs instead of builders.
The consensus seems to be the builders don't add much value, see [this comment].

[this comment]: https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1070#note_2889488

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan 6da39c0093 Refactor the inner doc tests to be more DRY.
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan 2fda37f5ea Remove `NetdocText` and replace its uses with `String`.
`NetdocText` is a wrapper around a `String` and a type marker. The type
annotation proved of limited use, and made the netdoc builder API
somewhat awkward to use.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan 8d0d52f193 Remove some unnecessary visibility restrictions.
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan c166c878fe Create a new `IntroPointDesc` type.
Unlike `hsdesc::IntroPointDesc`, `hsdesc::build::IntroPointDesc`
represents link specifiers as `LinkSpec`s rather than
`UnparsedLinkSpec`s.

Since this is a general-purpose representation of an introduction point
and not merely an intermediate representation for decoding/encoding, it
will probably need to be factored out of `tor-netdoc` at some point.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:33 +00:00
Gabriela Moldovan 1e3214a8bd Use the less ambiguous inner/middle/outer terminology. 2023-03-24 18:57:53 +00:00
Gabi Moldovan a1074c0027 Add builder for encoding hidden service descriptors.
This introduces the `NetdocBuilder` trait described in
`netdoc-builder.md` and a new `tor-netdoc::doc::hsdesc::build` module,
which exports the `HsDescBuilder`. Hidden services will use
`HsDescBuilder` to build and encode hidden service descriptors.

There are several TODOs in the code that I'm planning to address
separately.

Partially addresses #745.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:57:49 +00:00
Gabriela Moldovan 89ca965d2a Define constants for `AuthClient` field lengths.
These are used in multiple places (and will also be used by the HS
descriptor encoder later on), so let's make them named constants.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:54:35 +00:00
Gabriela Moldovan 1394a81142 Implement `ItemArgument` for `String`.
This makes some code a bit more concise, as it allows us to make
`Strings` into `ItemArgument`s without calling `.as_str()`.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:54:35 +00:00
Ian Jackson ba88761520 Merge branch 'openssl_update' into 'main'
Update required openssl version

See merge request tpo/core/arti!1077
2023-03-24 12:32:00 +00:00
Nick Mathewson 3459d39906 Update required openssl version
cargo-audit is complaining about 0.10.45.
2023-03-24 08:02:59 -04:00
Dimitris Apostolou 629fa80674
Fix typos 2023-03-24 09:56:08 +02:00
Alexander Færøy f923e403f0 Merge branch 'paths' into 'main'
Do minimal $ and ~ handling even without expand-paths and fix build

Closes #790

See merge request tpo/core/arti!1069
2023-03-23 17:31:04 +00:00
Alexander Færøy 6fae5cc7e9 Merge branch 'upgrade_dirs' into 'main'
Bump to the lastest versions of dirs and directories.

See merge request tpo/core/arti!1072
2023-03-23 16:00:50 +00:00
Nick Mathewson a7b238483e Add an experimental circuit accessor to DataStream.
Closes #784.
2023-03-23 09:18:42 -04:00
Ian Jackson b6f5c066b4 Apply deferred rustfmt churn 2023-03-23 11:50:18 +00:00
Ian Jackson 9d7983a6ea arti-client: Include redacted HsId in ObtainHsCircuit error
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1071/diffs?commit_id=580fe1118dbbbfa086d11b28e3e26d7c91afe21c#fbd7ab2d6d0a5b515697d4f9f99a42ebd508aa4b_153_165
2023-03-23 11:50:18 +00:00
Ian Jackson 1f2728caab safelog: impl From<T> for Redacted<T>
I think this is uncontroversial; we already have it for Sensitive.
2023-03-23 11:50:18 +00:00
Ian Jackson 58311571d9 arti-client: Fix wording of docs for TorClient::isolation 2023-03-23 11:50:18 +00:00
Nick Mathewson 8a11e0f6ad arti-client: Strengthen an HS todo 2023-03-23 11:50:18 +00:00
Ian Jackson b834535347 tor-proto: Feature-conditionalise some enum variants
This avoids some dead code warnings when building without send-control-msg.
2023-03-23 11:50:18 +00:00
Ian Jackson 93809cc594 tor-proto: Split off send-control-msg feature 2023-03-23 11:50:18 +00:00
Ian Jackson 14e5219f55 arti: Provide onion-service-client feature
Here I use the name I propose in !1039.
2023-03-23 11:50:18 +00:00
Ian Jackson cb93d1bee7 arti-client: Call tor-hsclient to create HS connections
Obviously this still doesn't work because the actual impl in hsclient
is just a todo!().
2023-03-23 11:50:18 +00:00
Ian Jackson 3d33ad7fdf arti-client: Create an HsClientConnector 2023-03-23 11:50:18 +00:00
Ian Jackson a2aa701eb6 arti-client: Move client stream creation out of match, in connect
We want this part for HS too.
2023-03-23 11:50:14 +00:00
Ian Jackson ca73dcfb31 arti-client: Break out TorClient::isolation(prefs)
We're going to want to reuse this.

Also: rename StreamPrefs::isolation and update the docs, to better
reflect its rather limited functionality.  The new
TorClient::isolation is the only call site.
2023-03-23 11:50:14 +00:00
Ian Jackson c36177733d tor-hsclient: Have the public API take StreamIsolation 2023-03-23 11:50:14 +00:00
Ian Jackson adc180294a tor-hsclient: impl HasKind for errors 2023-03-23 11:50:14 +00:00
Ian Jackson 2edd71a4f0 tor-hsclient: Swap errors so Bug comes last
This seems more consistent with the way it's done elsewhere.
2023-03-23 11:50:14 +00:00
Ian Jackson a2f4260666 tor-hsclient: Document clone-nature of HsClientConnector 2023-03-23 11:50:14 +00:00
Nick Mathewson 19cdb239bf Bump to the lastest versions of dirs and directories. 2023-03-22 15:15:42 -04:00
Nick Mathewson dffaf60e4a hspool: simplify loop and add a maximum 2023-03-22 12:35:41 -04:00
Nick Mathewson bd80125d73 hspool: Clarify/document more TODO HS items. 2023-03-22 12:35:41 -04:00
Nick Mathewson 19a229155c circmgr: Make a separate SupportedCircUsage for HS stuff
This uncovered a bug: NoUsage wasn't correct for Hs circuits because
of its behavior with channel_usage().
2023-03-22 12:35:41 -04:00
Nick Mathewson 0521aa855e tor-proto: document deep-copy in ClientCirc::path() 2023-03-22 12:35:41 -04:00
Nick Mathewson 35967ca38d circmgr: Declare builder() unconditionally.
(Still, only expose it when experimental-api is enabled.)
2023-03-22 12:35:41 -04:00
Nick Mathewson 5b3c6b6bb3 hspool: Tweak comments and add more TODOs. 2023-03-22 12:35:41 -04:00
Nick Mathewson fcb4df8b5b circmgr: hspool now launches circuits in the background.
The prediction and scheduling logic here is quite primitive;
we should probably refactor it considerably.  This should be good
enough for now, though.
2023-03-22 12:35:41 -04:00
Nick Mathewson a14214fae6 circmgr: Add an actual pool to HsCircPool.
We now have support for a pool of pre-build circuits that we can use
for HS-related purposes, and we take circuits from this pool as
needed.

Nothing populates or cleans the circuit pool yet.
2023-03-22 12:35:41 -04:00
Nick Mathewson adafae8b3f circmgr: Begin an HS circuit pool structure
This is now enough to launch circuits on demand.  It still needs to
pre-build the first three hops, and to retry on failure.
2023-03-22 11:52:17 -04:00
Nick Mathewson bb47d42315 proto: Stabilize ClientCirc::n_hops. 2023-03-22 11:52:17 -04:00
Nick Mathewson dce4da55ae circmgr: Add a usage for building the beginning of an hs circ
This only builds the first 3 hops. It can be extended to a fourth
hop later -- or not, depending on the circuit kind.
2023-03-22 11:52:17 -04:00
Nick Mathewson ec8c7eec4e circmgr: Functions to launch an unmanaged circuit.
We'll use this to implement the circuits used by onion circuits.
2023-03-22 11:52:11 -04:00
Ian Jackson cc399c3a29 tor-config: Apply deferred rustfmt churn 2023-03-21 16:37:50 +00:00
Ian Jackson c18f5c35dc tor-config: Do minimal $ and ~ handling even without expand-paths
Fixes #790
2023-03-21 16:37:50 +00:00
Ian Jackson 92bc9ef790 tor-config: Make CfgPathError PartialEq but only when testing
So, this is not a semver addition.
2023-03-21 16:33:24 +00:00
Ian Jackson a0b78837ad tor-config: Fix build when expand-paths is disabled 2023-03-21 16:33:12 +00:00
Ian Jackson 42ad8d99aa tor-config: paths, unexpanded: use infallible conversion
str can always be made into a PathBuf.
2023-03-21 16:08:47 +00:00
Ian Jackson 70b099fd0f Turn two blocking TODOs in hsdesc into "TODO HS"
TODO HS is blocking for HS release, but not for CI.
2023-03-21 13:08:14 +00:00
Ian Jackson d24a47c1d9 Sort out some TODOs in bdtest.rs 2023-03-21 13:08:14 +00:00
Ian Jackson 52470e4ffe Convert blockers in arti-testing to TODOs
I don't think these are that bad in testing code.
2023-03-21 13:08:14 +00:00
trinity-1686a a2f2b31751 remove unused type parameter 2023-03-18 20:43:17 +01:00
Alexander Færøy d8f77018f7 Merge branch 'fix-ptmgr-fuzz' into 'main'
tor-ptmgr: Fix fuzzer compilation.

See merge request tpo/core/arti!1063
2023-03-13 19:28:29 +00:00
Nick Mathewson d6bb8fee0b Upgrade to bitflags 2.0
This version of bitflags now requires us to explicitly list the
traits that we want to derive for our bit-flags structs.
2023-03-13 08:47:14 -04:00
Nick Mathewson 2ddaaafafb tor-ptmgr: Fix fuzzer compilation.
Since we made the internals of the ptmgr protocol parser
conditionally private, we need to tell Cargo to build the fuzzer
with the `experimental-api` feature so that it can access them.
2023-03-13 07:28:55 -04:00
Alexander Færøy c3347d9821 Merge branch 'warnings_168' into 'main'
Resolve a couple of new lints with Rust 1.68

See merge request tpo/core/arti!1062
2023-03-10 12:40:59 +00:00
Nick Mathewson 552acbf07f Fix a bunch of needless-conversion warnings.
Apparently 1.68 now warns when you call into_iter() on something
that's already an iterator.  Fair enough.  Let's stop doing that.
2023-03-10 07:09:50 -05:00
Nick Mathewson bd0f595b83 Suppress a renamed-lint lint.
The derive_hash_xor_eq lint was renamed in 1.68, but we can't use
it under its new name, since we still need to support back to 1.60.

Instead, we suppress the warning about the lint being renamed.
2023-03-10 07:09:50 -05:00
Ian Jackson 8c7224ef36 Discuss in comment why we're not using a newtype for the Strings in Host 2023-03-09 18:09:11 +00:00
Ian Jackson 04d843d846 Classify OnionAddressResolveRequest as NotImplemented
We have a theory about how this ought to work, so it's noit an API
usage error - it's an unimplemented feature.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1060#note_2884757
2023-03-09 18:09:08 +00:00
Ian Jackson 5000d11ac3 Reject invalid hostnames
Reject them both for .onion and for "exit" hostnames

This prevents a `Host` from having an invalid hostname in it.
2023-03-09 18:09:08 +00:00
Ian Jackson 8f8df071bc Fix reference to no-longer-contemplated Host variant
Reported in
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1060#note_2884755
2023-03-09 18:09:08 +00:00
Ian Jackson 8ead708512 Dummy HsId::from_str on .onion: Return Bug, rather than panicking
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1060#note_2884754
2023-03-09 18:09:08 +00:00
Ian Jackson 654f6689cf Improve error from HsId parse of "www.B32.onion"
And add some clarity and todos about address errors.
2023-03-09 18:09:08 +00:00
Ian Jackson 0a618cbe84 Avoid arti_client::ErrorDetail::Address for TorAddrError::InvalidHostname
Provide an explicit From impl isntead.
2023-03-09 18:09:06 +00:00
Ian Jackson 2957719c86 Test HsId parse of subdomain
This error is not great.
2023-03-09 13:41:12 +00:00
Ian Jackson c198a26bf7 arti-client: Parse .onion addresses and dispatch to client.rs
Now, a Host has a separate variant for `.onion` which is always used,
even when HS is disabled.

Currently it ends in a todo!.
2023-03-09 13:41:12 +00:00
Ian Jackson 4502528d0e arti-client: DoThingInstructions: Make error returns consistent
This is more comprehensible, and will be more convenient.
2023-03-09 13:41:12 +00:00
Ian Jackson c31bc1dafe arti-client: Host: Use Display::fmt rather than write!
write! is less good because the `{}` overwrites stuff like "did the
caller ask for padding".
2023-03-09 13:41:12 +00:00
Nick Mathewson 2bf71de199 Merge branch 'tor-proto-extensions' into 'main'
tor-proto: send an outbound meta/control-message and expect similar messages in return.

See merge request tpo/core/arti!1051
2023-03-08 20:09:20 +00:00
Nick Mathewson e08c229412 Merge branch 'suffix' into 'main'
Introduce and use ends_with_ignore_ascii_case

See merge request tpo/core/arti!1058
2023-03-08 19:36:28 +00:00
Nick Mathewson f3b8f4f73f tor-proto: Document limitation on send_control_message 2023-03-08 14:21:33 -05:00
Nick Mathewson c1b45e1be4 tor-proto: Say "control message" a little more consistently
(I found "user request" in one place, and fixed that.  I am not
currently going to try to unify "control message" and "meta message"
since both terms are misleading and we already have TODOs to try to
merge them into a third better term.)
2023-03-08 14:21:33 -05:00
Nick Mathewson 9c4bdb8d8d tor-proto: Make send_control_message wait for the reactor.
This way we don't need to worry about race conditions that happen if
the caller thinks that the handler is installed before it really is.
2023-03-08 14:21:33 -05:00
Nick Mathewson 7da5d7a8d7 Serval rustdoc link fixes. 2023-03-08 14:21:33 -05:00
Nick Mathewson fe6e7e52e3 Fix an unrelated missing cfg_attr. 2023-03-08 14:21:33 -05:00
Nick Mathewson fc31bf4e25 tor-proto: Have send_control_message install a handler, not return a stream 2023-03-08 14:21:33 -05:00
Nick Mathewson bc83d1e1de tor-proto: Implement functionality to send a message and accept replies
This new function combines "sending a message" and "accepting
replies in a stream" into a single call, so that there is no gap
between when the message is sent and the replies are available.

There are a number of compromises here, in order to avoid API
proliferation. I've tried to contain them as best I can.

See comments for additional design discussion.
2023-03-08 14:21:33 -05:00
Nick Mathewson 094fdc0d8d tor-proto: Change semantics of MetaCellHandler
Now, the MetaCellHandler is responsible for consuming the messages
it gets, and reporting status to whatever task is waiting for a
status message.

Additionally, the MetaCellHandler can decide to remain installed or
shut down the circuit after a successful message.  (Previously, it
could only uninstall itself on success and kill the circuit on
failure.)

These changes will enable MetaCellHandlers to be used as the basis
for handling more kinds of message.

(There is some moved and reformatted code here; you may want to
review it with `git {diff or show} --color-moved -b`.)
2023-03-08 14:21:33 -05:00
Nick Mathewson 7108f923e0 tor-proto: Give Path a method to access final hop num. 2023-03-08 14:21:33 -05:00
Nick Mathewson 5586a29f62 tor-proto: Give circ Reactor a constructor, and make its fields private. 2023-03-08 14:21:33 -05:00
Nick Mathewson 0df1a4a704 Merge branch 'introduce2_encrypted_portion' into 'main'
tor-cell: Add code for the payload of an hs-ntor handshake.

See merge request tpo/core/arti!1052
2023-03-08 19:20:38 +00:00
Ian Jackson 198a95c74c Merge branch 'host2' into 'main'
arti-client: Do not send resolve requests for IP addrs to exits

See merge request tpo/core/arti!1057
2023-03-08 19:10:23 +00:00
Ian Jackson f15498bc3f arti-client: Host: Be more explicit about what is allowed in Hostname 2023-03-08 18:48:28 +00:00
Ian Jackson c1ae509ce6 Introduce and use ends_with_ignore_ascii_case
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1056#note_2884428
2023-03-08 18:27:42 +00:00
Ian Jackson 939027492e Rustfmt 2023-03-08 18:15:32 +00:00
Ian Jackson 257b761042 Abolish Host::into_string_and_port
When I was trying to add HS support to these layers, I found I could
add a new variant to the `Host` enum but everything would still
compile even though I hadn't written the necessary implementation!

This method is a liability: when using it, one inevitably writes such
latent bugs.
2023-03-08 18:15:32 +00:00
Ian Jackson 5df19bc888 arti-client: Do not send resolve requests for IP addrs to exits
Doing so doesn't seem like a good idea.  It might even be some kind of
leak?

Found because I added a variant to `address::Host` for hidden
services, and noticed that the resolve code still compiled.
2023-03-08 18:15:32 +00:00
Ian Jackson fd42ada54c arti-client addr handling: Introduce StreamInstructions 2023-03-08 18:09:57 +00:00
Nick Mathewson 2b9506ae67 intro_payload: various doc fixes and TODOs from review. 2023-03-08 12:27:05 -05:00
Ian Jackson 6540f260b5 arti-client: Reject .onion, when we should, without allocating
Use new strip_suffix_ignore_ascii_case
2023-03-08 17:26:47 +00:00
Ian Jackson 8d031a7147 Use strip_suffix_ignore_ascii_case to quickly reject non-.onion HsId (fmt) 2023-03-08 17:26:47 +00:00
Ian Jackson 80b69b9900 Use strip_suffix_ignore_ascii_case to quickly reject non-.onion HsId 2023-03-08 17:26:47 +00:00
Ian Jackson 440a0eb74f tor-basic-utils: Provide str.strip_suffix_ignore_ascii_case
We're going to want this for cheaply stripping ".onion" from things.
2023-03-08 17:26:47 +00:00
Nick Mathewson 5d5e8d8337 tor-cell: Be a little more pedantic about INTRODUCE cell types. 2023-03-08 09:50:11 -05:00
Nick Mathewson 028bf6d2bc tor-cell: Better describe the parts of intro payload. 2023-03-08 09:41:22 -05:00
Ian Jackson 13b1adb55e Merge branch 'bug779' into 'main'
tor-dirmgr: Don't try to mark consensus usable in a read-only store.

Closes #779

See merge request tpo/core/arti!1055
2023-03-08 14:31:37 +00:00
Ian Jackson edc9ace4c1 Merge branch 'fuzzing_tor_bytes' into 'main'
tor-bytes: defend against misuse of extract_n().

See merge request tpo/core/arti!1053
2023-03-08 14:27:53 +00:00
Nick Mathewson ac5469d0b6 tor-dirmgr: Don't try to mark consensus usable in a read-only store.
Doing this means that any attempt to use a read-only store would
crash as soon as it found that the consensus was usable.

It seems that this bug was introduced at some point doing all the
dirmgr refactors we did over the past year.  Perhaps there should be
a test for running with a read-only store.

Fixes #779
2023-03-08 07:08:17 -05:00
Ian Jackson 034d1dfe81 Merge branch 'hsonion' into 'main'
Impl FromStr and Display for HsId, etc.

See merge request tpo/core/arti!1054
2023-03-07 19:27:34 +00:00
Ian Jackson 7081b73c92 Impl Redactable for HsId 2023-03-07 19:03:28 +00:00
Ian Jackson ab8350b712 Debug HsId as the .onion; retain the hex printing as {:x} 2023-03-07 16:33:10 +00:00
Ian Jackson 641e99af98 impl Display for HsId 2023-03-07 16:32:27 +00:00
Nick Mathewson 9cc09f97a9 tor-bytes: Add take_rest and read_nested_* to fuzzer. 2023-03-06 12:39:57 -05:00
Nick Mathewson dab21bc624 tor-bytes: defend against misuse of extract_n().
Previously, if somebody wrote this code, an attacker could easily
use it to cause an OOM panic:

```
let n = r.take_u64();
let items: Vec<Foo> = r.extract_n(n as usize)?;
```

The first line of defense here is not to write protocols like that:
we don't actually _have_ any 32-bit counters in our protocol
AFAICT.

The second line of defense is to pre-check `n` for reasonableness
before calling `extract_n`.

Here we add a third line of defense: whereas previously we would do
`Vec::with_capacity(n)` in `extract_n`, we now allocate an initial
capacity of `min(n, r.remaining())`.  This ensures that the size of
the allocation can't exceed the remaining length of the message,
which (for our cell types at least) should prevent it from
overflowing or running OOM.
2023-03-06 12:33:10 -05:00
Nick Mathewson 1254a8b86e tor-cell: Add code for the payload of an hs-ntor handshake.
(This is the encrypted information inside the INTRODUCE2 cell; it's
used by the client to tell the service where to find its rendezvous
point.)
2023-03-06 08:46:40 -05:00
Nick Mathewson 7129807843 tor-linkspec: Add a constructor for UnparsedLinkSpec 2023-03-06 08:45:05 -05:00
Dimitris Apostolou dedae15446
Fix typos 2023-03-03 13:00:33 +02:00
Ian Jackson e60ab8087d Merge branch 'hs_cert_inner_validation' into 'main'
tor-netdoc: Validate inner certs in HsDesc

Closes #744

See merge request tpo/core/arti!1044
2023-03-02 16:45:19 +00:00
Ian Jackson fd0d50a330 hsclient: Discuss HsClientConnector multiplicity/reuse
And delete the associated TODO.
2023-03-01 18:12:29 +00:00
Ian Jackson 1fc93b4215 hsclient: Remove TODOs about circular references
These Arcs are all "downward", referencing items from layers lower in
the stack.  So they don't cause cycles.

There was going to be a cycle involving the `OnionConnector` upcall
trait, but we have just abolished that.
2023-03-01 18:12:29 +00:00
Ian Jackson bf2c0d6ff8 hsclient: Abolish knowledge of HS circuits in circmgr
Abolish CircMgr::get_or_launch_onion_client and everything to support
it.  We have decided that `.onion` diversion ccan't/shouldn't occur in
tor-circmgr.  Probably, it should occur much higher up - arti-client
maybe - since it will sometimes need ambient authority (KS_hsc_*).

Now all knowledge of HS connections is in tor-hsclient.  This
gets rid of a layering inversion and the trait needed for tor-circmgr
to do the upcall to tor-hsclient.
2023-03-01 18:12:29 +00:00
Nick Mathewson ee666fb0b7 Merge branch 'rename_rend_message' into 'main'
tor-cell: Rename Rendezvous*::message to handshake_info.

See merge request tpo/core/arti!1045
2023-03-01 18:04:00 +00:00
Nick Mathewson 07b1c3a505 tor-cell: Rename Rendezvous*::message to handshake_info.
Follow-up from !1038
2023-03-01 12:38:27 -05:00
Ian Jackson c23c3faecb Merge branch 'hsconn' into 'main'
Implement HS state management

See merge request tpo/core/arti!1034
2023-03-01 17:23:55 +00:00
Nick Mathewson 992078ee43 Merge branch 'establish_intro_yet_once_more' into 'main'
Revise EstablishIntro messages so that they can generate and check their MAC and signature.

See merge request tpo/core/arti!1043
2023-03-01 17:10:49 +00:00
Ian Jackson 7230f89b32 hsclient isol_map: Use 1:1 notation in diagram to show correspondence 2023-03-01 16:39:03 +00:00
Ian Jackson fea656d7ee hsclient isol_map: Document invariant, fix comment, terminology
Use the occupied/vacant terminology that the slotmap docs use.
2023-03-01 16:39:03 +00:00
Ian Jackson d4d02fa4e9 hsclient state: Rename rechecks (from attempts) and add clarifying docs
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2882079
2023-03-01 16:39:03 +00:00
Ian Jackson 649d0e0d25 hsclient keys: Be more explicit about HsClientSecretKeys nullable
It can contain no keys; state this more prominently, and explain what
it represents.  Also fix a few typos etc.
2023-03-01 16:39:03 +00:00
Ian Jackson b2139731ac hsclient state: Implement and test MultikeyIsolatedMap::retain 2023-03-01 16:39:03 +00:00
Ian Jackson b6fc44aa71 hsclient state: Split off MultikeyIsolatedMap 2023-03-01 16:39:03 +00:00
Ian Jackson 90a7e82fcd hsclient state: Move all the data fields into the table
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2881576

This is a singificant simplification, in fact.
2023-03-01 16:39:03 +00:00
Ian Jackson 76a2e82205 tor-llcrypto: Add a TODO re impl Redactable for HsId 2023-03-01 16:39:03 +00:00
Ian Jackson 08ede75905 hsclient: Clarify period task handle TODO 2023-03-01 16:39:03 +00:00
Ian Jackson e6aa199da6 hsclient: Document sharing rules
Text largely from
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2881638
2023-03-01 16:39:03 +00:00
Ian Jackson cfa33e53d5 hsclient state: rustfmt
Autogenerated with rustfmt; no code changes.

This tidies up the bizarre formatting.
2023-03-01 16:39:03 +00:00
Ian Jackson 597601e4a3 hsclient state: Lots more doc comments about barriers, structure, etc. 2023-03-01 16:39:03 +00:00
Ian Jackson 0b39a180b0 hsclient state: Break `obtain` out into a fn
This is getting rather confusing; simply reformtting it won't do, I
think.  Also there would be much rightward drift.

So move the meat out into the new function.
(And introduce a convenience alias for its captures.)

Docs and reformatting will follow in a moment.
2023-03-01 16:39:03 +00:00
Ian Jackson a93a7b4bab hsclient state: Demonstrate that our future is now Send 2023-03-01 16:39:03 +00:00
Ian Jackson 1f03e118ef hsclient state: Restructure using a scope to drop the mutex guard
Explicit drops don't work.  Instead, introduce a scope.

We need two scopes, actually: one where we do the initial table
wrangling, and one for the retries after relock.

So we must put the meat in a closure so we can reuse it.
And we must return the flow control as an enum.  Bah, etc.

Avoid reformatting this for the moment.  This makes the delta legible...
2023-03-01 16:39:03 +00:00
Nick Mathewson 93a0b72105 tor-cell: Use a match when checking auth_key_type 2023-03-01 11:34:49 -05:00
Nick Mathewson dbecdb53aa tor_cell: Use nested readers and writers for EstablishIntro 2023-03-01 11:32:56 -05:00
Nick Mathewson c8cc4a80c3 tor-cell: tweak comments on EstablishIntro members. 2023-03-01 11:27:45 -05:00
Ian Jackson d1863c3178 hsclient state: Break out ServiceState::blank
We're going to have another function which will want this.
Leave a convenience closure to capture the runtime.
2023-03-01 16:27:19 +00:00
Ian Jackson 4f5f378516 hsclient state: Move error inspection before guard re-lock.
This is still correct from a lock hierarchy pov.  It moves the guard
relock to the end, which is going to be necessary since it is going to
have to move right outside the loop.
2023-03-01 16:27:19 +00:00
Ian Jackson 1e905763e3 hsclient keys: Add a todo to remove spurious Option 2023-03-01 16:27:19 +00:00
Ian Jackson 7134ddd454 hsclient keys: Compare all empty sets of keys as equal
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2881575
2023-03-01 16:27:19 +00:00
Ian Jackson 5da60ff72d hsclient keys: Fix non-equal keys test to provide a (dummy) key (fmt) 2023-03-01 16:27:19 +00:00
Ian Jackson ff55d7b133 hsclient keys: Fix non-equal keys test to provide a (dummy) key
We're about to fix the comparison to treat all empty key sets as
equal.
2023-03-01 16:27:19 +00:00
Ian Jackson e3e66793c4 hsclient keys: Provide :none() and Default and .is_empty() 2023-03-01 16:27:19 +00:00
Ian Jackson 896ea10b7f hsclient keys: Fix a missing full stop 2023-03-01 16:27:19 +00:00
Ian Jackson ab163cf81a hsclient state: Test most important code paths 2023-03-01 16:27:19 +00:00
Ian Jackson 8e088d72d5 hsclient: Provide some missing debug impls and trace messages 2023-03-01 16:27:19 +00:00
Ian Jackson 83b8eb7349 tor-hscrypto: Provide manual Debug impl for HsId
This is still not great, but it at least makes the output plausible to
read by eye.
2023-03-01 16:27:19 +00:00
Ian Jackson 288b7b6ad1 Apply rustfmt 2023-03-01 16:27:19 +00:00
Ian Jackson d384c3b475 hsclient state: Provide one test 2023-03-01 16:27:17 +00:00
Nick Mathewson 5131703c22 Introduce a constant for the length of the output of hs_mac() 2023-03-01 11:26:35 -05:00
Nick Mathewson b36082255b tor-bytes: Clarify that Cursor is not a good thing, and could be neater. 2023-03-01 11:21:52 -05:00
Ian Jackson d7602c5be4 hsclient: Use a generic to provide a mock for connect()
This will allow us to test state.rs.
2023-03-01 16:20:16 +00:00
Ian Jackson feab6faa9e tor-circmgr: Provide testing feature and TestConfig
Like the similar thing in tor-guardmgr.
2023-03-01 16:20:16 +00:00
Ian Jackson 9ebe22756e hsclient: Apply standard lint block 2023-03-01 16:20:16 +00:00
Ian Jackson ff1be04012 hsclient: Move dead code allows to specific locations 2023-03-01 16:20:16 +00:00
Ian Jackson b430c65ddb hsclient: Add vacuous comments as demanded by clippy 2023-03-01 16:20:16 +00:00
Ian Jackson bac3c4a9a4 hsclient state: Bind a variable to stop rustfmt doing a terrible thing 2023-03-01 16:20:16 +00:00