Commit Graph

5373 Commits

Author SHA1 Message Date
Ian Jackson 61f58daadd tor-hsservice: Change IptEstablisher::new to take RelayIds
The IptEstablisher needs to continuously maintain the IPT even as the
netdir is updated.  Whereas, the IPT manager just wants to select the
relay from the netdir once and then only think about the relay
identity.

So it makes sense for the establisher to do necessary lookups of the
relay's ids in the netdir.
2023-08-17 15:54:54 +01:00
Ian Jackson 64c8b38c25 tor-hsservice: Define drop behaviour of IPT establisher status 2023-08-17 14:42:26 +01:00
Ian Jackson f4dfc14694 tor-async-utils: Deprecate DropNotifyEofSignallable::is_eof
This was introduced in c82cda85d6
  tor-basic-utils: DropNotifyWatchSender: use DropNotifyEofSignallable

and already, then, the is_eof() method is redundant.
2023-08-17 14:41:56 +01:00
Nick Mathewson f63852f449 Merge branch 'rendezvous_handshake' into 'main'
hsservice: new rend_handshake module

See merge request tpo/core/arti!1512
2023-08-17 13:29:18 +00:00
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
Gabriela Moldovan a74e4cf661
tor-proto: Make it obvious that we're discarding a Result. 2023-08-08 13:07:45 +01:00
Gabriela Moldovan 4fb5121a77
tor-proto: Make StreamTarget::close return the oneshot::Receiver instead of blocking.
Instead of having 2 version of `StreamTarget::close` (a blocking one and
a nonblocking one), we can just return the `oneshot::Receiver` for
receiving the reactor's response and let the caller of
`StreamTarget::close` decide whether to block.

This allows us to reduce some code duplication in the `IncomingStream`
implementation.
2023-08-08 13:04:01 +01:00
Gabriela Moldovan 2b2f0f6065
tor-proto: Make take_inner() use mut_inner() to check the inner value. 2023-08-08 12:47:13 +01:00
Ian Jackson 849c83052e tor-config: Expand NoProjectDirs error message 2023-08-08 11:12:16 +01:00
Ian Jackson 00152515eb arti: Use ConfigurationSources::try_from_cmdline
This will allow us to proceed if

 * the default config file locations can't be established
   (eg due to failure of the `directories` crate), but

 * configuration files are explicitly specified,
   so the defaults wouldn't be used
2023-08-07 18:03:03 +01:00
Ian Jackson 6af1485a90 tor-config: Add ConfigurationSources::try_from_cmdline
We'll use this in crates/arti in a moment.
2023-08-07 18:03:03 +01:00
Ian Jackson 3d1c6cb395 arti: Add context to default config files error message
Improves the error mesage in #989 somewhat.

Before:

  target/debug/arti: error: Can't construct project directories to resolve a path element

After:

  target/debug/arti: error: identify default config file locations: Can't construct project directories to resolve a path element
2023-08-07 17:11:22 +01:00
Gabriela Moldovan 41fab65de1
tor-proto: Replace IncomingStreamMsg with IncomingStreamRequest.
The two enums essentially serve the same purpose, so we don't
need both of them.

This also addresses the TODO that says we should return an error if
`accept_data` is called for a RESOLVE stream.
2023-08-07 16:45:49 +01:00
Gabriela Moldovan ffb1360908
tor-proto: Implement `Drop` for `IncomingStream`. 2023-08-07 15:57:53 +01:00
Gabriela Moldovan df8a5b017e
tor-proto: Keep track of whether the `IncomingStream` was accepted.
The behaviour of `IncomingStream::drop` is going to depend on whether
the stream was accepted or not.
2023-08-07 15:57:50 +01:00
Gabriela Moldovan d856afe449
tor-proto: Add a function for closing a stream without waiting for the reactor to respond.
This will be used for implementing `Drop` for `IncomingStream` (it
needs to "reject" the stream on drop).
2023-08-07 15:57:36 +01:00
Gabriela Moldovan e61f1e8fbe
tor-proto: Rename misleading field in `DataCmdChecker`.
This is a follow-up from !1451.

This commit solves a `TODO HSS` introduced when `DataCmdChecker` got an
additional constructor (`new_connected`) for creating "pre-connected"
streams. See f6745d31 for more details.
2023-08-07 12:38:55 +01:00
gabi-250 9171080819 Merge branch 'proto-flaky-test' into 'main'
tor-proto: allow_stream_requests now waits until the control message is received.

Closes #994

See merge request tpo/core/arti!1474
2023-08-04 20:10:46 +00:00
Gabriela Moldovan 1a7c104d2e
tor-proto: Shut down the reactor if an error occurs in incoming stream init/close.
Propagating the error means will cause the reactor to shut down (there's
not much the control message sender can do about it, so there's no point
in sending it the error).
2023-08-04 20:46:05 +01:00
Gabriela Moldovan 2eaa0fa52b
tor-proto: reject() now waits until the control message is received.
As a result, by the time the `reject` future resolves, the stream has
been removed from the reactor's stream map and the corresponding END
cell has been sent.

Fixes #998.
2023-08-04 19:57:46 +01:00
Gabriela Moldovan f689e94f0f
tor-proto: allow_stream_requests now waits until the control message is received.
`ClientCirc::allow_stream_requests` is now `async` and waits until the
`AwaitIncomingStream` control message is processed by the reactor.

This guarantees that by the time the `allow_stream_requests` future
resolves, the reactor is ready to process BEGIN/BEGIN_DIR/RESOLVE cells.

Previously, the client tasks from allow_stream_requests tests had to
sleep before sending the BEGIN cell to give the reactor time to process
the `AwaitIncomingStream` control message (which tells the reactor to
expect incoming BEGIN/BEGIN_DIR/RESOLVE cells on the circuit).

Fixes #994
2023-08-04 19:22:45 +01:00
Nick Mathewson 64fca7e45f proto: methods to wait until a channel/circuit is shut down.
The implementation here is perhaps excessively simple: we put
a `oneshot::Sender` in the `Reactor` object, and a
`Shared<oneshot::Receiver>` in the circuit or channel.  When
the reactor is dropped, any copy of the `Shared<Receiver>` will
yield `Err(Cancelled)`.

I'm marking these methods as experimental because I'm not sure I've
thought of all the implications here, and we might want to change
things around.

Down the road, these methods might want to yield a `Result<>`
indicating why the reactor was shut down.

This feature was inspired by a request from Saksham Mittal, and a
felt need while working on !1472.
2023-08-04 13:37:28 -04:00
gabi-250 36056906ad Merge branch 'future_proof_lints' into 'main'
add_warning: Change missing_docs,unreachable_pub to warn

Closes #951

See merge request tpo/core/arti!1470
2023-08-04 14:20:54 +00:00
Gabriela Moldovan ed5a051ebe
tor-proto: Add ClientCirc::start_conversation().
This will enable hidden services to send `RENDEZVOUS1` messages to the
`N`th hop of the circuit rather than the `N + 1`th virtual one (which
can only used after the client and service have completed the
introduction handshake).

This also deprecates `start_conversation_last_hop`.

Closes #959
2023-08-04 13:08:31 +01:00
Gabriela Moldovan c23e85270e
tor-proto: Add method for getting the HopNum of the last hop. 2023-08-04 13:07:52 +01:00
Nick Mathewson cec6d0ce33 Run add_warnings on all files. 2023-08-04 07:45:04 -04:00
Gabriela Moldovan eee3bb8822
tor-proto: Make HopNum public.
`HopNum` will be used in `ClientCirc`'s public API when we refactor
`ClientCirc::start_conversation_last_hop` to use the provided hop rather
than always using the last one.
2023-08-04 10:51:05 +01:00
gabi-250 ef5fdd0647 Merge branch 'proto-incoming-stream' into 'main'
tor-proto: Let onion services accept incoming BEGIN cells and make streams

Closes #864

See merge request tpo/core/arti!1451
2023-08-03 18:15:50 +00:00
Gabriela Moldovan 71d99ce709
tor-proto: Bump test sleep to 200ms for now.
This `sleep` is to give the reactor task a chance to process the
`AwaitIncomingStream` message. With an 100ms, this test sometimes fails
because for some reason the reactor doesn't get a chance to process the
`AwaitIncomingStream` control command before the BEGIN cell from the
client task is received. This bumps the sleep time to 200ms for now
(TODO: follow-up with an MR with a less flaky approach).

While trying to repro the issue, I found another corner case for which
I've added a TODO HSS.
2023-08-03 18:50:34 +01:00
Gabriela Moldovan 0ec1303b9a
tor-proto: Handle new BEGIN cells for rejected stream.
This updates the reactor to call the incoming stream handler even for
streams for which we have a stream map entry of `EndSent`. If we've
sent an END message for a stream but have not yet received an END
message back from the other party, but we later receive a BEGIN from
them, it is safe to assume we cam remove the stream from the stream map
and handle the new incoming stream request.
2023-08-03 16:46:28 +01:00
Gabriela Moldovan 296abfddcc
tor-proto: Clarify what we mean by "stream" in allow_stream_requests. 2023-08-03 16:44:45 +01:00
Gabriela Moldovan 23f1f2ce47
tor-proto: Add note about making hop_num optional. 2023-08-03 16:43:26 +01:00
Gabriela Moldovan 2f21dc5a87
tor-proto: Add a TODO about checking if a hop is allowed to create streams. 2023-08-03 16:42:12 +01:00
Gabriela Moldovan ffe4771a83
tor-proto: Remove unnecessary else-branch.
We return early if `message_closes_stream == true`, so we can get rid of
the `else` to remove one level of indentation.
2023-08-03 16:40:57 +01:00
Gabriela Moldovan 4edff7e670
tor-proto: Update the stream map if we get an END message.
This handles the previously not handled `message_closes_stream == true`
case.
2023-08-03 16:39:42 +01:00
Gabriela Moldovan 907d8cf255
tor-proto: Add TODO regarding allow_stream_requests corner case. 2023-08-03 16:38:19 +01:00
Gabriela Moldovan f30c5897cc
tor-proto: Remove outdated comments. 2023-08-03 16:36:58 +01:00
Gabriela Moldovan 0f9bed5160
tor-proto: Add a test for allow_stream_requests. 2023-08-03 16:35:43 +01:00
Gabriela Moldovan 37154dca95
tor-proto: Implement allow_stream_requests. 2023-08-03 16:34:09 +01:00
Gabriela Moldovan ffa8056437
tor-proto: Handle RELAY_BEGIN cells if we have an incoming req handler. 2023-08-03 16:33:58 +01:00
Gabriela Moldovan f06e0e2df0
tor-proto: Implement IncomingStream::{accept_data, request, reject}. 2023-08-03 16:32:29 +01:00
Gabriela Moldovan 445c052420
tor-proto: Add StreamTarget function for sending CtrlMsg::CloseStream .
This will be used by `IncomingStream` to implement `reject()`.
2023-08-03 16:31:05 +01:00
Gabriela Moldovan b9daaa245c
tor-proto: Add reactor control commands for accepting/closing incoming streams.
This adds a new `AwaitIncomingStream` control message for registering an
interest in an incoming stream.

This also adds a `ClosePendingStream` control message for explicitly
closing a stream with a given END message (needed for implementing
`IncomingStream::reject`).
2023-08-03 16:29:26 +01:00
Gabriela Moldovan 950d0da0b5
tor-proto: Add types for sharing stream request info with the reactor. 2023-08-03 16:27:48 +01:00
Gabriela Moldovan 18b01f94cc
tor-proto: Add a helper for adding a stream entry with a specific stream ID.
This adds a new `add_ent_with_id` function for adding a new entry to the
`StreamMap`. The existing `add_ent` function auto-generates a new stream
ID, which is not good if we're a hidden service, as stream IDs are
supposed to be chosen by the OP (client). When accepting a new stream,
services, exit relays, and dir auths need to use the stream ID received
in the BEGIN cell (instead of generating a new stream ID).
2023-08-03 16:25:46 +01:00
Gabriela Moldovan 4abfe30f41
tor-proto: Remove extraneous space. 2023-08-03 16:24:30 +01:00
Gabriela Moldovan f6745d31a9
tor-proto: Add constructors for pre-connected DataStreams.
When accepting a new stream, hidden services, exit relays and dirauths
don't wait for a `CONNECTED` cell from the initiator.

This commit adds constructors for building `DataStream`s and
`DataCmdChecker`s that can immediately receive data cells (and don't
expect to receive `CONNECTED` cells at all).
2023-08-03 16:23:11 +01:00
Gabriela Moldovan 4133a9464e
tor-proto: Add a constructor for IncomingStream. 2023-08-03 16:21:55 +01:00
Gabriela Moldovan dc0b904492
tor-proto: Add imports for commonly used types. 2023-08-03 16:20:45 +01:00
Gabriela Moldovan 3d5c712c55
tor-proto: Add IncomingCmdChecker for IncomingStream. 2023-08-03 16:18:35 +01:00
Nick Mathewson 5a84da3e1b Fix and expand the description of OnionAddressDisabled
Previously there was a missing "not", and it didn't say what to do
about the error.
2023-08-03 09:43:03 -04:00