Commit Graph

5319 Commits

Author SHA1 Message Date
Ian Jackson 360c90a9d8 tor-hsservice errors: Distinguish operational errors by context
At the very least, I need FatalError to be distinct:
IptEstablisher::new ought not to fail unless everything is terrible.

Add a the Spawn variant to FatalError (that we'll need soon) and the
Bug variant (which it seems likely we might need).

This also gets rid of the crate-level Result alias.
2023-08-17 13:28:44 +01:00
Ian Jackson e1405cdb11 tor-hsservice errors: Return ReconfigureError from reconfigure
This is what we do elsewhere.
2023-08-17 13:28:44 +01:00
Ian Jackson 5e047da9cc tor-hsservice errors: Use Bug for methods that oughtn't to fail
If the service encouters operational errors, surfacing them here is
not helpful.  So these methods ought to work, if they weren't called
erroneously.
2023-08-17 13:19:21 +01:00
Nick Mathewson 2d2bf1c945 hsservice: new rend_handshake module
This code has most of what we need to go from an INTRODUCE2 message
we've just received to the point where we've connected to the
rendezvous point and we're waiting for a stream of BEGIN messages.
Unfinished pieces are marked with TODO HSS.

Most of #980.
2023-08-17 08:18:21 -04:00
gabi-250 7d3741e8dd Merge branch 'always_bug-from' into 'main'
tor-bytes: deprecate always_bug with From trait

See merge request tpo/core/arti!1500
2023-08-17 12:17:32 +00:00
Ian Jackson e3b9371ddf tor-hsservice errors: Make stop() infallible
The semantics of an Err return from this are unclear.  Was it stopped?
And what kind of error might we even return?
2023-08-17 13:16:50 +01:00
Ian Jackson c391ac2a90 tor-hsservice errors: Use `crate::Result` rather than imports
We want to change the error return types of many methods, so we need a
way to name `std::result::Result`.

We could use `StdResult`, but, actually, properly distinguishing the
kinds of errors that can occur in various contexts means we don't
actually want a single Error type for the whole crate, so
`crate::Result` is going to go away.
2023-08-17 13:12:23 +01:00
Emil Engler 73059827f0
tor-bytes: deprecate always_bug with From trait
This commit deprecates the `EncodeError::always_bug` function with a
`From<EncodeError> for Bug` trait, which is a more semantically correct
way to perform this action.
2023-08-17 13:52:29 +02:00
gabi-250 4c2f8d5a9e Merge branch 'handshake-tests' into 'main'
test: add a test for missing NETINFO cells

See merge request tpo/core/arti!1501
2023-08-17 10:17:01 +00:00
Nick Mathewson c8b721aa5d Merge branch 'all_crates_warnings' into 'main'
Resolve all warnings that appear from `maint/every-crate`

See merge request tpo/core/arti!1507
2023-08-16 18:20:21 +00:00
gabi-250 fdb411f287 Merge branch 'netdir-todo' into 'main'
tor-netdir: Only select nodes that haven't been used for lower-numbered replicas.

See merge request tpo/core/arti!1494
2023-08-16 17:52:07 +00:00
Nick Mathewson b0a30da76c arti-client: fix conditional unused_import and dead_code warnings 2023-08-16 13:44:18 -04:00
Nick Mathewson 9217278ac1 guardmgr: Fix a dead-code warning when built without bridge support. 2023-08-16 13:41:40 -04:00
Nick Mathewson e67152abb9 tor-proto: Fix dead_code when building without experimental-api 2023-08-16 13:41:40 -04:00
Nick Mathewson 6227539446 cell: Add accessors to IntroduceHandshakePayload 2023-08-16 13:23:46 -04:00
Ian Jackson 8e58ab54ba tor-hsservice: Have IptEstablisher::new() return the status watch (fmt) 2023-08-16 18:12:04 +01:00
Ian Jackson c161f41b57 tor-hsservice: Have IptEstablisher::new() return the status watch
The IPT manager is going to want to separate the IptEstablisher
struct (which contains the Drop signal) from the watch receiver.

We could add an accessor to clone the watch, but the copy in the
IptEstablisher would be redundant.

This makes new()'s signature a bit funky but it's an internal method
so I think that's fine.
2023-08-16 18:12:04 +01:00
Ian Jackson 62c50bfe75 Apply some churn from rustfmt (beta) 2023-08-16 18:11:22 +01:00
Gabriela Moldovan 7a030f8661
tor-netdir: Replace somewhat niche scan() usage with flat_map(). 2023-08-16 17:57:33 +01:00
Gabriela Moldovan d395fe356e
tor-netdir: Rework the logic for checking if a node has already been selected.
This just simplifies the expression a little bit. It still has the same
behaviour.
2023-08-16 17:57:29 +01:00
Gabriela Moldovan af99a4a7b9
tor-netdir: Store the hsdir indices in a HashSet instead of a BTreeSet. 2023-08-16 17:57:21 +01:00
Gabriela Moldovan 80f059a171
tor-netdir: Derive Hash for HsDirIndex.
This will become useful later when we build a `HashSet` of `HsDirIndex`.
2023-08-16 17:57:08 +01:00
Gabriela Moldovan b26ecd6553
tor-netdir: Explain what the ring_items_at filter is for. 2023-08-16 17:57:02 +01:00
Gabriela Moldovan ecb3783f5e
tor-netdir: Only select nodes that haven't been used for lower-numbered replicas.
This implements the part of the spec that says a node that has already
been selected for a lowered-numbered replica, shouldn't be considered
when choosing `spread` nodes for any other higher-numbered replicas.

Note: previously, the test added in this commit wouldn't have passed
(because `NetDir::hs_dirs` used to return duplicate relays under some
circumstances).

Part of #960
2023-08-16 17:56:55 +01:00
Gabriela Moldovan 315684af84
tor-netdir: Make ring_items_at() filter the items before returning.
This makes `ring_items_at()` take an extra parameter which specifies
whether an item is acceptable or not. The newly added filtering
capabilities will be used to implement the part of the spec that says
that if a node was selected for a replica, then it shouldn't be
considered when choosing `spread` nodes for any other higher-numbered
replicas.
2023-08-16 17:56:52 +01:00
Gabriela Moldovan 5d30d34b13
tor-netdir: Update ring_items_at() docs.
This updates the docs to reference the `spread` parameter (rather than
`spread_fetch`).
2023-08-16 17:56:49 +01:00
Gabriela Moldovan 619718956d
tor-netdir: Remove extraneous whitespace. 2023-08-16 17:56:45 +01:00
Gabriela Moldovan e6635b139d
tor-netdir: Use hsdir_spread_store if we're uploading.
The spread should be either `hsdir_spread_store` or
`hsdir_spread_fetch`, depending on whether we're uploading or
downloading descriptors.
2023-08-16 17:56:42 +01:00
Gabriela Moldovan 310b4bf35e
tor-dirclient: Fix clippy lints. 2023-08-16 16:14:13 +01:00
Gabriela Moldovan c3ea366539
tor-dirclient: Remove unused `StringBody` trait. 2023-08-16 16:14:09 +01:00
Gabriela Moldovan cd6c4674dc
tor-dirclient: Make Requestable return requests with String bodies.
It's simpler to always use a `String` to represent directory request bodies.
We no longer need the `StringBody` trait.
2023-08-16 16:14:06 +01:00
Gabriela Moldovan 2a7ba4ceb0
tor-dirclient: Rename StringBody::str() to StringBody::as_str(). 2023-08-16 16:14:02 +01:00
Gabriela Moldovan aa3e60b994
tor-dirclient: Deprecate download() instead of removing it. 2023-08-16 16:13:58 +01:00
Gabriela Moldovan 6625b2c55f
tor-dirclient: Extend format test to check the body is formatted too (fmt) 2023-08-16 16:13:50 +01:00
Gabriela Moldovan 966150f9b2
tor-dirclient: Extend format test to check the body is formatted too. 2023-08-16 16:13:46 +01:00
Gabriela Moldovan e71703ad90
tor-dirclient: Move request building to a test helper function. 2023-08-16 16:13:42 +01:00
Gabriela Moldovan 636a18bd7d
tor-dirclient: Add `HsDescUploadRequest`.
The hsdir publisher will send the `HsDescUploadRequest`s to the
appropriate directory using `send_request()`.
2023-08-16 16:13:34 +01:00
Gabriela Moldovan 8ce948bef9
tor-dirclient: Make the body type of a `Requestable` type configurable.
Previously, the `Requestable` trait assumed the body of the request
would always be empty (`http::Request<()>`). This change replaces the
hardcoded `()` body type with the `Requestable::Body` associated type
(which will allow implementors to create requests with non-empty
bodies). This will enable us to reuse the `Requestable` trait for
building `POST` requests for uploading descriptors.
2023-08-16 16:13:30 +01:00
Gabriela Moldovan 0fde1d09f5
tor-dirclient: Rename download() to send_request() (fmt). 2023-08-16 16:13:27 +01:00
Gabriela Moldovan 9a08f04a76
tor-dirclient: Rename download() to send_request().
`download()` is actually a general-purpose function for sending HTTP
requests on a stream. We will soon repurpose it for `POST`-ing
descriptors, so let's rename it to `send_request`.
2023-08-16 16:13:20 +01:00
Ian Jackson b2c37b0570 Merge branch 'remove-unused-import' into 'main'
tor-proto: remove unused import

See merge request tpo/core/arti!1493
2023-08-16 15:12:12 +00:00
Nick Mathewson 4a5f94daa0 cell: Add accessors to Introduce2. 2023-08-16 10:24:50 -04:00
Ian Jackson 8c73223626 Merge branch 'keystore-dir' into 'main'
arti-client: Make from_directories() derive the keystore_dir from state_dir.

Closes #988

See merge request tpo/core/arti!1498
2023-08-16 14:11:01 +00:00
Nick Mathewson 2a3fe5bf20 Merge branch 'more_introducing' into 'main'
Write more of IptEstablisher.

See merge request tpo/core/arti!1510
2023-08-16 13:02:29 +00:00
Nick Mathewson 0ee63cb04b Wire up more of IptEstablisher.
It now supports running in a loop, trying to establish an
introduction point, and reporting status.
2023-08-16 08:22:53 -04:00
Ian Jackson 2b85def3a6 Merge branch 'fix-weird-comment' into 'main'
doc: fix malformatted comment in SliceWriterError

See merge request tpo/core/arti!1503
2023-08-16 12:07:44 +00:00
Ian Jackson 3d65ab839c Merge branch 'dangerously_assume_timely' into 'main'
tor-cert: actually use dangerously_assume_timely

See merge request tpo/core/arti!1497
2023-08-16 12:07:15 +00:00
Ian Jackson 0cb789e93b Merge branch 'test-expired-certs' into 'main'
test: provide a test for expired certificates

See merge request tpo/core/arti!1496
2023-08-16 11:55:12 +00:00
Ian Jackson a2177e8d13 Merge branch 'coverage-encode' into 'main'
test: encode unrecognized `tor_cert::CertExt`

See merge request tpo/core/arti!1495
2023-08-16 10:52:10 +00:00
Gabriela Moldovan 1e002b14c9
keymgr: Write a registry sketch.
This comment will form the basis for the protocol name registry.
2023-08-16 10:45:55 +01:00
Gabriela Moldovan 4b72da73b3
tor-keymgr: Add sec1 0.7.3 dependency. 2023-08-16 10:45:47 +01:00
Gabriela Moldovan c8999f230b
tor-keymgr: Re-export ssh-key.
The `KeypairData` type from [ssh-key] at some point leaked into the
keymgr API (via the `EncodableKey` trait). Instead of re-exporting just
`KeypairData`, let's re-export the entire `ssh_key` crate
(`EncodableKey` implementors would need additional types from `ssh_key`
to construct a `KeypairData` object anyway).

[ssh-key]: https://crates.io/crates/ssh-key
2023-08-16 10:44:14 +01:00
Gabriela Moldovan f07651807b
keymgr: Implement as_ssh_keypair_data for curve25519 keys. 2023-08-16 10:44:11 +01:00
Gabriela Moldovan abf83ecfa6
keymgr: Import internal! (fmt). 2023-08-16 10:44:06 +01:00
Gabriela Moldovan 0b109f3ee8
keymgr: Import internal!. 2023-08-16 10:43:51 +01:00
Gabriela Moldovan 9d8c28c639
keymgr: Remove unused helper.
This helper is no longer needed (the logic from
`parse_ssh_format_erased` changed).
2023-08-16 10:43:35 +01:00
Gabriela Moldovan fade75ae16
tor-keymgr: Test x25519 key parsing. 2023-08-16 10:43:32 +01:00
Gabriela Moldovan 17d965e894
keymgr: Do not expect x25519 keys to be stored as ed25519 ssh keys.
Previously, the Arti key store would store x25519 secret keys as ed25519
OpenSSH keys, which it would convert to x25519 upon loading (using the
conversion function added in !1297 (merged)). This approach isn't good
enough though: most people will probably want to bring their existing
x25519 keys, and in order to store those in OpenSSH format, we'd need
convert them to ed25519, which is impossible (because the secret part of
an x25519 key contains a SHA512'd secret, whereas the corresponding,
"un-expanded", ed25519 secret key contains the secret itself rather than
the SHA).

Now that `ssh-key` has support for ssh keys with [custom algorithm
names], we can store x25519 in OpenSSH format directly. This commit
changes the storage format used by the keymgr for x25519 client auth
keys (from ed25519-ssh to our own custom key type with an algorithm name
of `"x25519@torproject.org"`).

Closes #936

[custom algorithm names]: https://github.com/RustCrypto/SSH/pull/136
2023-08-16 10:43:28 +01:00
Gabriela Moldovan b2bcbaa708
keymgr: Bump ssh-key to 0.6.0.
This brings in the changes from #936.
2023-08-16 10:43:21 +01:00
Nick Mathewson ff2d0cffab reformat establish_intro_once 2023-08-15 18:44:11 -04:00
Nick Mathewson 806b08fdbe Make establish_intro_once a method on a new IptEstablisherReactor.
This will help with making a keep_established method.
2023-08-15 18:42:31 -04:00
Nick Mathewson e2fca464c2 hsservice: Actually return from establish_intro_once. 2023-08-15 18:32:13 -04:00
Nick Mathewson 6292f3544a hsservice: migrate IptStatus design to assume a postage::watch 2023-08-15 14:10:06 -04:00
Nick Mathewson 99be70afd4 hsservice: Reject extensions in IntroEstablished cells
Intro points must not send these extensions except in response to a
request that prompts them.
2023-08-15 13:09:14 -04:00
Nick Mathewson bac156bcf5 cell: Add code to iterate over IntroEstablished extensions 2023-08-15 13:05:53 -04:00
Nick Mathewson 09d99f1053 cell, docs: Clarify what we mean by "Unrecognized". 2023-08-15 12:14:02 -04:00
Nick Mathewson a6f8b3299f hsservice: Send extensions in establish_intro msgs.
I had planned to make this code accept extensions of unknown type,
but for now I'm backing out of that plan: the set of extensions we
send influences the set that we're willing to receive.
2023-08-15 12:10:39 -04:00
Gabriela Moldovan 31645f4f37
tor-error, arti: Bump backtrace to 0.3.68.
Previously we were using backtrace 0.3.39, which has a [bug] that causes
it to segault in some circumstances. I experienced this bug while trying
to fix the minimal-versions build in !1508.

[bug]: https://github.com/rust-lang/backtrace-rs/issues/267
2023-08-15 16:34:31 +01:00
Nick Mathewson 603175b977 Start working on the backend for an IptEstablisher.
This should be enough now to establish real introduction points,
though there is still a lot of work to do.  Part of #976.

This has been rebased and edited to incorporate discussions from
!1465.
2023-08-14 13:57:49 -04:00
Nick Mathewson d46e638ff0 proto: Fix a type-complexity warning. 2023-08-14 13:15:40 -04:00
Nick Mathewson 65a0ac5512 proto: API to expose the `CircuitBinding` type.
Closes #993
2023-08-14 13:15:29 -04:00
Nick Mathewson 61513de6d0 proto: Take CircuitBinding one step forward into Reactor::add_hop. 2023-08-14 13:15:29 -04:00
Nick Mathewson 0ffa6eddf5 proto: Add (not-yet-exposed) code to remember and use KH values
These values are computed as part of the circuit extension
handshake, and are used as MAC keys to bind `ESTABLISH_INTRO`
messages to a particular circuit so that they can't be replayed.

Part of #993.
2023-08-14 13:15:29 -04:00
Nick Mathewson 926cc65a9e cell: make establish_intro accept impl<Into<HsMacKey>>
This allows us to allow passing in opaque HsMacKey objects,
rather than untyped byte slices.

Additionally, we now check both MAC and signature unconditionally,
to avoid the large timing side-channel.  The small timing
side-channel of combining booleans with `&` is considered safe.

Part of #993.
2023-08-14 13:15:00 -04:00
Nick Mathewson 0759fdf681 hscrypto: Expose hs_mac as a SimpleMac. 2023-08-14 13:15:00 -04:00
Nick Mathewson e7f803529f llcrypto: New SimpleMac trait
This will be useful in preference to the regular Mac trait for the
places where we need to pass a Mac key around, but we don't need to
support incremental operation.

Part of arti#993, where we want to expose a MAC object without
exposing sensitive data.
2023-08-14 13:15:00 -04:00
Nick Mathewson 4047236bd9 Wrap a long line in hscrypto/Cargo.toml. 2023-08-14 13:15:00 -04:00
Gabriela Moldovan 5c5a7bfb14
arti-client: Use Path::join instead of format!. 2023-08-14 16:21:55 +01:00
Emil Engler 28f0120886
doc: fix malformatted comment in SliceWriterError 2023-08-14 10:59:45 +02:00
Emil Engler 60ad15b4ff
test: add a test for missing NETINFO cells
This commit adds a unit test to the `tor_proto::handshake` module,
which tests the behavior when no NETINFO cell is present within a
channel.
2023-08-12 19:09:48 +02:00
Gabriela Moldovan d9a04ff9ad
arti-client: Make from_directories() derive the keystore_dir from state_dir.
Closes #988
2023-08-11 12:09:52 +01:00
Emil Engler 2fd4d7d3a4
tor-cert: actually use dangerously_assume_timely
This commit makes a trait function use another currently unused trait
function, thereby increasing the test coverage, as well as being
potentially more correct from a semantic point of view.
2023-08-10 16:32:52 +02:00
Emil Engler 2f90119622
test: provide a test for expired certificates
This commit implements a test for an expired Ed25519 certificate within
the `tor_cert` crate.
2023-08-10 16:27:50 +02:00
Emil Engler 3336f1c5a2
doc: note unreachable code 2023-08-10 15:32:28 +02:00
Emil Engler 2ff06b8114
test: encode unrecognized `tor_cert::CertExt`
This commit introduces a test for unrecognized `tor_cert::CertExt`
fields.
2023-08-10 15:32:26 +02:00
Emil Engler 81eb87ef3e
tor-proto: remove unused import
This commit removes an unused import within the test module of the
`tor_proto::circuit` module.
2023-08-10 13:36:27 +02:00
Ian Jackson bde9a25f06 Merge branch 'tor-proto-incoming-discard' into 'main'
tor-proto: Implement IncomingStream::discard()

See merge request tpo/core/arti!1484
2023-08-09 12:58:41 +00:00
Gabriela Moldovan 6073a4f767
tor-proto: Make update_state() and discard() return Result<(), Bug>.
These functions only ever return `Bug` errors.
2023-08-09 13:07:35 +01:00
Ian Jackson 8838c6bfd2 Merge branch 'remove-keystore-fs-perm-variant' into 'main'
tor-error: Remove KeystoreFsPermissions variant.

See merge request tpo/core/arti!1487
2023-08-09 10:57:39 +00:00
Ian Jackson 4b64f988aa bridge config: Fix an error message slightly 2023-08-08 18:01:31 +01:00
Ian Jackson 635edd4129 arti-client config test: partially un-degrade formatting 2023-08-08 18:01:31 +01:00
Ian Jackson 2fc249ce66 arti-client config test: degrade formatting
As demanded by rustfmt
2023-08-08 18:01:31 +01:00
Ian Jackson e142f9a560 arti-client config: Add an extra test case for bridges
This complements the new `check_bridge_pt` test.
2023-08-08 18:01:31 +01:00
Ian Jackson 9ba4b496fd bridge config: reject bridges=true when there are no bridges
This is a bugfix.  Perhaps it is a security fix?
2023-08-08 18:01:31 +01:00
Gabriela Moldovan 5d0fb5177f
tor-error: Remove KeystoreFsPermissions variant.
According to the `ErrorKind` lumping guidelines, `KeystoreFsPermissions`
should be lumped with `FsPermissions`: they represent the same type
of error, and their "location" is the same ("Host").

Prompted by https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1315#note_2916455
2023-08-08 16:46:20 +01:00
Gabriela Moldovan a0daa9adb6
tor-proto: Implement IncomingStream::discard(). 2023-08-08 15:25:45 +01:00
Gabriela Moldovan 4507c33479
tor-proto: Replace boolean flags with an IncomingStreamState enum.
This commit introduces an `IncomingStreamState` enum, which indicates
whether the stream was accepted, discarded, or rejected, or if it is
still pending. The `is_rejected`/`is_accepted` boolean flags are no
longer needed.

Without this change, we'd need to introduce yet another boolean flag
when we implement `discard()` (for the "discarded" state).
2023-08-08 15:25:42 +01:00
gabi-250 fa595875ec Merge branch 'tor-proto-incoming-todo' into 'main'
tor-proto: Replace IncomingStreamMsg with IncomingStreamRequest.

See merge request tpo/core/arti!1477
2023-08-08 13:13:31 +00:00
Ian Jackson bff3475cc1 Merge branch 'tor-proto-incoming-drop' into 'main'
tor-proto: Implement `Drop` for `IncomingStream`.

See merge request tpo/core/arti!1476
2023-08-08 13:08:37 +00:00
Gabriela Moldovan 7446ed08b6
tor-proto: Fix broken docs. 2023-08-08 13:14:39 +01:00