Commit Graph

5319 Commits

Author SHA1 Message Date
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
Micah Elizabeth Scott 943960e4d3 equix/bench: Update Cargo.lock
New dependency from 82eb88bd74
2023-08-02 19:29:23 -07:00
Nick Mathewson 5c607e8cf6 Merge branch 'ticket889_fuzz' into 'main'
Fuzzers for Equi-X and HashX

See merge request tpo/core/arti!1459
2023-08-02 22:12:20 +00:00
Micah Elizabeth Scott 21dfc6d58c equix/fuzz: CI and doc fixes
The build found a stale private doc comment as well as an exception
that needed to be made in check_doc_features.

The check_doc_features change solidifies a decision that things marked
with cfg(fuzzing) aren't part of the documented API.
2023-08-02 14:46:46 -07:00
Nick Mathewson c7feae494e Merge branch 'ticket991_mr' into 'main'
Reduce runtime of hspow_vectors and split it up

See merge request tpo/core/arti!1462
2023-08-02 15:49:03 +00:00
Ian Jackson 3ca2870123 Merge branch 'encodable-key-rename' into 'main'
keymgr: Replace EncodableKey::to_bytes() with SSH-specific function.

Closes #965

See merge request tpo/core/arti!1464
2023-08-02 14:59:42 +00:00
Gabriela Moldovan b57a60d7b6
keymgr: Add TODO regarding SshEncodableKey impl for x25519. 2023-08-02 14:21:41 +01:00
Gabriela Moldovan 682d20110e
keymgr: Implement SshEncodableKey for ed25519::Keypair. 2023-08-02 14:21:06 +01:00
Gabriela Moldovan e89e76f974
keymgr: Remove KeyType::to_ssh_format.
This function isn't actually needed (it's not the responsibility of
`KeyType` to encode keys).

This commit also rewrites `ArtiNativeKeystore::insert` to use the new
`as_ssh_keypair_data` function instead of `to_ssh_format`.
2023-08-02 14:21:02 +01:00
Gabriela Moldovan e70be1353c
keymgr: Replace EncodableKey::to_bytes() with SSH-specific function.
The `EncodableKey::to_bytes` function didn't make much sense, because
not all keys have a canonical byte representation.

This commit replaces `EncodableKey::to_bytes` with
`EncodableKey::as_ssh_keypair_data`. In the future, `EncodableKey` will
grow functions for encoding keys in other storage formats too.

Closes #965
2023-08-02 14:13:18 +01:00
Micah Elizabeth Scott bf0119fbfe hashx/fuzz, equix/fuzz: use arti-corpora
Remove corpus from .gitignore and add a symlink to the corpora
submodule.
2023-08-01 19:34:04 -07:00
Micah Elizabeth Scott d7c2e7996e hashx/fuzz: update tor-c-equix dependency
my cargo_hashx_rng branch was just merged into main (thanks dgoulet!)
2023-08-01 19:34:04 -07:00
Micah Elizabeth Scott 0ffb2849e1 equix/fuzz: rustfmt 2023-08-01 19:34:04 -07:00
Micah Elizabeth Scott 82eb88bd74 equix/fuzz: Fixes to get nick's prototype running
There are some places we might improve this, maybe testing more data
types and shapes. This patch just makes the minimal changes necessary
to get it working: adds allocation logic to the fuzzer itself,
and adds visibility for the bucket_array::mem interface.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:34:04 -07:00
Micah Elizabeth Scott 810adcc50d hashx/fuzz: Comments, explain our 'seed' input
In response to review feedback, explain that 'seed' here is more
for compatibility and convenience and not central to our goal of
fuzzing the program generator.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:34:04 -07:00
Micah Elizabeth Scott 5a85749e48 hashx/fuzz: Simplify, remove rayon dependency
Review feedback is that we don't want parallelism here.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:34:03 -07:00
Micah Elizabeth Scott ea2716595e hashx/fuzz: Start a cross-implementation fuzzer for HashX
Fuzz testing for HashX. Uses a hook into the pseudorandom number
stream to test the program generator deeply on input that can
be mutated by the fuzzer. Confirms program generation by running
a small number of arbitrary test hashes, so we don't need to
understand the implementation-specific program format to test the
program generator.

We test four implementations in parallel this way, the compiled and
interpreted implementations included in both this crate and c-tor.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:34:03 -07:00
Nick Mathewson 89fb338fd5 WIP: Fuzzer for BucketArray. 2023-08-01 19:34:03 -07:00
Micah Elizabeth Scott f40255cb95 tor-hspow: Shorten the solve_effort1k_aa_41_01 test
The solve tests are all tunable so that we can balance execution time
with test coverage. A longer solve will test more random programs and it
will test more of the nonce increment function, minor benefits at the
cost of much more CPU.

The starting nonce in solve_effort1k_aa_41_01 was set so that we would
exercise a rollover in bit 7 of the nonce increment before the full
width rollover, but this wasn't a particularly helpful place to test
and certainly not worth the 13+ seconds it takes on my machine.

This patch bumps the starting nonce to a value much closer to the
target, and still including the full-width rollover.

Brings solve_effort1k_aa_41_01 down from 13.2 seconds to 0.5 sec for me.

For ticket #991

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:31:23 -07:00
Micah Elizabeth Scott f84af7c360 tor-hspow: Split up hspow_vectors tests
This test had one large function for all the verifies and one for all
the solves. The solve test was slow enough to be a bottleneck,
documented in ticket #991.

This patch splits the existing tests up in to one labeled function per
solve or verify configuration.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:31:23 -07:00
Micah Elizabeth Scott 550d89fb57 hashx/bench: Shared generate wrapper for u64-hash and full-hash
Code cleanup from review feedback

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:28:46 -07:00
Micah Elizabeth Scott 315122f159 hashx/bench, equix/bench: Enable debug symbols
Propagates this setting from the outer Cargo.toml to the new
benchmark crates, since they no longer get the setting by
being included in the main workspace.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:28:46 -07:00
Micah Elizabeth Scott 256e5de9e5 hashx/bench, equix/bench: check in matching Cargo.lock files
It might be useful to keep these locked down for benchmark
reproducibility. Currently the hashx and equix crates are
fully separate.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:28:46 -07:00
Micah Elizabeth Scott ae58ea0697 equix, hashx: Benchmark against C implementation
This is a small batch of improvements for the equix and hashx
benchmarks. The headline feature is that we are now including
the C implementations (slightly modified from tevador's, hosted
as part of c-tor) and using them in apples-to-apples comparisons.

Minor features:
- Benchmarks moved to new nested crates, preventing their
  dependencies from spilling into the main workspace build.
- Tests are now grouped
- We also test the performance of memory reuse where possible
- Code cleanup for per-runtime options

These benchmark builds will now automatically pull in the c-tor
git repo and build portions of it with a Rust wrapper. This uses
the 'cc' and 'bindgen' crates, so it requires a C compiler and
libclang on the host system.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-08-01 19:28:43 -07:00
Nick Mathewson 1dc47a65cf Upgrade to sanitize-filename 0.5.0 2023-08-01 19:47:39 -04:00
Nick Mathewson f7c0350e7f hsservice: Upgrade tor-keymgr dep
This breakage was caused by increasing the version of tor-keymgr
and independently merging !1452, which added a dependency on the
old version.
2023-08-01 18:51:55 -04:00
Ian Jackson f365b41c13 Merge branch 'remove_semver' into 'main'
Remove semver.md files now that 1.1.7 is out.

See merge request tpo/core/arti!1460
2023-08-01 17:42:58 +00:00
Nick Mathewson dee95436f5 Merge branch 'hss_apis' into 'main'
hsservice: Initial data structures and APIs

Closes #972, #971, and #970

See merge request tpo/core/arti!1452
2023-08-01 17:06:10 +00:00
Nick Mathewson 1e96d1b95a Remove semver.md files now that 1.1.7 is out. 2023-08-01 12:55:52 -04:00
Saksham Mittal 752f748910 Add error if [[bridges.transports]] isn't written in config file 2023-08-01 16:43:46 +00:00
Nick Mathewson 3422169ff4 Merge branch 'bump_versions_117' into 'main'
Vesion bumps for 1.1.7.

See merge request tpo/core/arti!1458
2023-08-01 15:40:26 +00:00
Nick Mathewson 5cc3fe1629 Bump patchlevel versions of crates with trivial changes
These crates have had trivial changes only: typically,
changes to documentation or to clippy warnings.  There's no
good reason to update which version of them other crates depend on,
so we only bump _their_ patchlevels.

```
tor-async-utils
caret
safelog
tor-events
tor-units
tor-rtcompat
tor-rpcbase
tor-llcrypto
tor-protover
tor-bytes
tor-hscrypto
tor-socksproto
tor-cert
tor-cell
tor-consdiff
tor-congestion
arti-rpcserver
arti-testing
arti-bench
arti-config
arti-hyper
```
2023-08-01 11:03:56 -04:00
Nick Mathewson 3acdf102c7 Increment patchlevel versions of crates with minor changes
These crates are at version 0.x.y, so we don't need to distinguish
new-feature changes from other changes:

```
tor-basic-utils
fs-mistrust
tor-error
tor-geoip
tor-checkable
tor-linkspec
tor-netdoc
tor-netdir
tor-persist
tor-ptmgr
tor-hsservice
```

This crate has a breaking change, but only when the semver-breaking
feature `experimental-api` is enabled:

```
tor-config
```

This crate is at version 1.x.y, but has no new public APIs, and
therefore does not need a minor version bump:

```
arti
```
2023-08-01 10:57:55 -04:00
Nick Mathewson 6f2ae59603 Update minor versions on crates that have had breaking changes
These crates had first-order breaking changes:

```
retry-error
tor-keymgr
tor-proto
tor-hsclient
tor-rtmock
```

Additionally, these broke because they re-exposed RetryError:

```
tor-circmgr
```

Additionally, these broke because they may re-expose something from
tor-proto:

```
    arti-client
    tor-chanmgr
    tor-dirclient
    tor-dirmgr
    tor-guardmgr
```

Additionally, these broke for other fiddly reasons:

`tor-ptmgr` implements traits from tor-chanmgr, which has a breaking
change above.

`arti-hyper` exposes types from arti-client in its API.
2023-08-01 10:51:25 -04:00
Nick Mathewson 9ce6f0a0eb Run "fixup features" in preparation for a release. 2023-08-01 08:32:20 -04:00
Nick Mathewson 7dc24f38e0 hsservice: Add a sketched API for HsDir publishers.
As with the other APIs here, I'd expect that the implementors will
need to refactor this a lot.

Closes #972.
2023-07-31 13:47:44 -04:00
Nick Mathewson 16fef0057b A couple of notes on intropoint establisher API. 2023-07-31 13:47:44 -04:00
Nick Mathewson 982bfcba06 hsservice: Add a draft API for intropoint establisher.
Taken from @diziet's !1439 and lightly cleaned up so that it
compiles.

Closes #971.
2023-07-31 13:47:44 -04:00
Nick Mathewson 20afc76c0a hsservice: Adapt API sketches from onion-service-notes.md 2023-07-31 13:47:44 -04:00
Nick Mathewson 20b3679dbb hsservice: Adapt data structures from onion-service-notes.md
Also, removed some older structures that don't make sense in the
current design.

Closes #970
2023-07-31 13:47:44 -04:00
Micah Elizabeth Scott 9257949b80 equix, hashx: Additional comment tweaks
More review feedback. Thanks nickm!

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 13:17:23 -07:00
Micah Elizabeth Scott fdba82100f equix, hashx: Prepare for an initial LGPL release
This replaces the 'TODO' marker from earlier commits, using tevador's
copyright and license (LGPL 3.0 only) for the hashx and equix crates.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 4affddaa08 tor-hspow, equix, hashx: Comment tweaks
Making a few comment tweaks suggested in review feedback.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott bd48c23a40 tor-hspow: Simplify and optimize Challenge::new
Challenges are now built using try_extend_from_slice instead of
iterators. There's no CPU benchmark in this crate yet, but I can confirm
that the resulting code is shorter. With this patch, the entirety of
Challenge:new() is automatically inlined at call sites.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 7579febb46 hashx: Simplify RegisterWriterMap
I originally wrote this in an overcomplicated way, to avoid
frequent initialization of a RegisterWriter array. It turns out
that RegisterWriter can be fairly compact, so this extra level of
indirection isn't necessary or measurably helpful.

This still manages to avoid declaring RegisterWriter as Copy, by
using Default to initialize the array instead of an array constructor.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott f4939a5fd8 tor-hspow, equix, hashx: Make all error types Clone
This uses an Arc to hold std::io::Error for low-level HashX runtime
errors.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 10b7352c98 hashx: Simplify hash_to_bytes, only support fixed output width
In response to review feedback. The byte output is only needed
for unit tests right now, since Equi-X uses u64 output exclusively.

The optimization for shorter output widths can shave tiny amounts of
time off hash benchmarks, but in this case it's more helpful to avoid
introducing APIs that offer parameters with incomplete compile-time
range checking.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott d17c12b152 hashx: use RngCore for HashX's internal PRNG
This refactors the random number generator used within HashX's program
generator so that it uses the rand::RngCore trait. The basic SipHash
powered u64 generator now implements RngCore, while a buffer layer
wraps this and provides u8 and u32 values as needed by the generator.

Some of this new RngCore layer is now exposed to the hashx crate's
public API. The intent is to allow external code to test, benchmark, or
fuzz the program generator by supplying its own random number stream.

Benchmarks show a small but confusing performance improvement
associated with this patch. About a 2% improvement in generation.
This could be due to the Rng changes. No change in compiled hash
execution performance. Even though this patch only touches program
generation, benchmarks show a 4% speedup in interpreted execution.
This seems most likely explained by instruction cache effects,
but I'm not sure.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 2c20b46921 hashx: Implement Default for RuntimeOption 2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott c5976c6675 equix: Refactoring for bucket_array
This splits up bucket_array into two smaller modules, one for the hash
table behavior and one for the MaybeUninit memory management.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 8a79021f38 Update equix, hashx, tor-hspow for new clippy defaults
Just running maint/add_warning after the rebase
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott fdfe3ce55f hashx: register set optimizations, 20% faster generator
I was hoping most of the program generator would get inlined, so we can
resolve a lot of the edge cases at compile-time. This patch gets us
close to that, adding many inline attrs and rewriting RegisterSet with
explicit unrolling and storage types that are easier for the optimizer
to reason about.

From the disassembly of the program generator, it's now mostly one big
function with a jump table. From callgrind instruction profiles, there
are no longer obvious hotspots in register set scanning loops. It also
looks like we're often keeping per-register schedule information all
loaded into machine registers now.

Keeping the Rng entry points non-inlined for now seems to be slightly
better, by a percent or two.

There's some work left to do in compiled programs, and maybe room for
improvement in the Program representation too. That will be in a future
patch.

Benchmark shows about 20% improvement on my machine,

generate-interp         time:   [75.440 µs 75.551 µs 75.684 µs]
                        change: [-24.083% -23.775% -23.483%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  5 (5.00%) high mild
  6 (6.00%) high severe

generate-x86_64         time:   [96.068 µs 96.273 µs 96.540 µs]
                        change: [-18.699% -18.381% -18.013%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  4 (4.00%) high mild
  6 (6.00%) high severe

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott e7aa1d6b62 Start implementing Proposal 327
This adds a new tor-hspow crate with the first layers of support in
place for onion service client puzzles as described in Proposal 327.

The API here is experimental, and it's currently only implementing
the self-contained parts of the client puzzle. So, it can verify and
solve puzzles, but it has no event loop integration or nonce replay
tracking or prioritization code yet. These things seem like they would
eventually live in the same crate.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 16c9bdf178 Reimplement Equi-X in Rust
This is a new pure Rust implementation of the Equi-X algorithm
designed by tevador for Tor's onion service proof of work puzzle v1.

Equi-X is an asymmetric puzzle algorithm based on Equihash, with
N=60, K=3, the XOR replaced with modular addition, a 16-bit index
space, and HashX as the inner hash function.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott a8756f2bce Reimplement HashX in Rust
This is a new pure Rust implementation of the HashX algorithm
designed by tevador for Tor's onion service proof of work puzzle v1.

HashX is a lightweight family of randomly generated hash functions.
A seed, via blake2 and siphash, drives a program generation model
which randomly selects opcodes and registers while following some
constraints that avoid timing stalls or insufficient hash mixing.

The execution of these hash funcions can be done using a pure Rust
interpreter, or about 20x faster using a very simple just in time
compiler based on the dynasm assembler crate. This has been
implemented for x86_64 and aarch64.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:06 -07:00
Nick Mathewson 3b9cc6b4e7 Merge branch 'circuit-reactor-first-hop' into 'main'
tor-proto: Extract Create message handling from Reactor::run_once()

See merge request tpo/core/arti!1441
2023-07-27 11:56:14 +00:00
gabi-250 d4fff19ec9 Merge branch 'keymgr-api-updates-gen-key' into 'main'
keymgr: Add KeyMgr::generate() for generating new keys.

See merge request tpo/core/arti!1433
2023-07-27 11:12:12 +00:00
Gabriela Moldovan 0fbd96df82
keymgr: Add TODO regarding generate() being racy. 2023-07-27 11:46:38 +01:00
Gabriela Moldovan 74a2a7937b
keymgr: Document the TOCTOU issue with generate(). 2023-07-27 11:45:05 +01:00
Gabriela Moldovan 249149d4ce
keymgr: Make the return value of generate() indicate if a new key was created. 2023-07-27 11:13:24 +01:00
Gabriela Moldovan 44f6d1c827
keymgr: Make Keystore::generate() return a Result. 2023-07-27 11:03:06 +01:00
Gabriela Moldovan ecfec3b827
tor-proto: Rename create_firsthop() to wait_for_create(). 2023-07-27 10:56:18 +01:00
Gabriela Moldovan 6f22c16ecc
tor-proto: Update handle_control docs. 2023-07-26 19:36:54 +01:00
Gabriela Moldovan 331ec1033a
tor-proto: Add functions for handling Shutdown and AddFakeHop messages.
This helps reduce code duplication, as `CtrlMsg::Shutdown` and
`CtrlMsg::AddFakeHop` are now handled in multiple places.
2023-07-26 19:36:50 +01:00
Gabriela Moldovan fee4baa17f
tor-proto: Extract first-hop creation to a separate function.
I think it's safe to handle `ChanMsg::Create` separately, because
there's nothing for the reactor to do until the first hop of the circuit
is created (so blocking on this _should_ be alright).
2023-07-26 19:36:47 +01:00
Gabriela Moldovan 98b9be0f2d
tor-proto: Create a function for handling the initial CREATE cell.
This logic from `create_firsthop()` was extracted (copied) from
`Reactor::run_once()`. A future commit will update `Reactor::run_once()`
to use `create_firsthop()`.
2023-07-26 19:35:04 +01:00
Ian Jackson 86e76c1100 Merge branch 'sw1tch/fix_reconfigure_deadlock' into 'main'
fixes deadlock in TorClient::reconfigure

See merge request tpo/core/arti!1432
2023-07-26 10:20:49 +00:00
sw1tch b6873a9b84 pass reconfigure_lock guard into TorClient::reconfigure_inner 2023-07-25 19:31:36 +02:00
sw1tch 7347d45acc cargo fmt 2023-07-24 14:48:19 +02:00
Ian Jackson 3e2a909707 Run cargo +nightly fmt to format many let ... else ...
rustfmt has grown opinions about how let ... else ... ought to be
formatted.  They don't always agree with our previous manual
decisions.

I think our policy is to always insist on rustfmt.  When that version
of rustfmt hits stable, our CI will start to fail for everyone.
(Right now this discrepancy just causes trouble for contributors who
are using nightly by default.)
2023-07-24 13:46:05 +01:00
Gabriela Moldovan 89dc3a162a
keymgr: Move duplicated match block to KeyMgr::select_keystore(). 2023-07-24 13:17:35 +01:00
Gabriela Moldovan f96298a791
keymgr: Add KeyMgr::generate() for generating new keys. 2023-07-24 13:17:31 +01:00
Gabriela Moldovan 9c326ced81
keymgr: Add function for generating EncodableKeys. 2023-07-24 13:17:23 +01:00
Gabriela Moldovan f5f133c04c
keymgr: Test whether insert() creates the missing directories. 2023-07-24 13:17:16 +01:00
Gabriela Moldovan b9f3ba5885
keymgr: Return an unimplemented error instead of panicking.
This will enable us to test the parts of `ArtiNativeKeystore::insert`
that _are_ implemented (such as the part where it creates the missing
directories).
2023-07-24 13:17:12 +01:00
Gabriela Moldovan cfe90f1478
keymgr: Create the parent directories as needed 2023-07-24 13:17:08 +01:00
Gabriela Moldovan e36e7db6e7
keymgr: Add a Keystore::contains accessor. 2023-07-24 13:17:05 +01:00
sw1tch 3eee408985 fixes deadlock in TorClient::reconfigure 2023-07-24 13:39:49 +02:00
Dimitris Apostolou 947ddfff0c
Fix typos 2023-07-22 10:10:34 +03:00
gabi-250 15407a1a7e Merge branch 'keymgr-api-updates' into 'main'
keymgr: API updates and other improvements

Closes #903

See merge request tpo/core/arti!1421
2023-07-21 16:22:56 +00:00
gabi-250 3ceff307bf Merge branch 'keymgr-api-updates-minor-fixes' into 'keymgr-api-updates'
Keymgr api updates minor fixes

See merge request gabi-250/arti!1
2023-07-21 15:54:52 +00:00
Ian Jackson 611576c515 Merge branch 'access' into 'main'
Add getters to a couple of config builders

See merge request tpo/core/arti!1425
2023-07-21 15:10:31 +00:00
Ian Jackson f00ac8e747 tor-geoip: Fix a doc warning
cargo doc --locked --document-private-items --workspace --all-features

warning: unclosed HTML tag `CountryCode`
  --> crates/tor-geoip/src/lib.rs:90:54
   |
90 |     /// We store these as NonZeroU8 so that an Option<CountryCode> only has to
   |                                                      ^^^^^^^^^^^^^
   |
   = note: `#[warn(rustdoc::invalid_html_tags)]` on by default
2023-07-21 14:44:14 +01:00
Gabriela Moldovan 96e59cb97f
keymgr: Use KeystoreId instead of a static string. 2023-07-21 12:36:29 +01:00
Gabriela Moldovan 32083cbd51
keymgr: Add a newtype for keystore identifiers. 2023-07-21 12:36:22 +01:00
Gabriela Moldovan ec82795614
keymgr, tor-error: Remove unused error type and HasKind. 2023-07-21 12:36:19 +01:00
Gabriela Moldovan c7d29dfc3d
keymgr: Use BadApiUsage instead of KeystoreMisuse.
Trying to use a keystore that doesn't exist is `bad_api_usage!`.
2023-07-21 12:36:16 +01:00
Gabriela Moldovan d48cc2ca6b
keymgr: Remove unused KeystoreSelector::All variant.
This also removes the corresponding
`KeyMgrError::UnsupportedKeystoreSelector` error, because it's not
needed anymore.
2023-07-21 12:36:13 +01:00
Gabriela Moldovan a4c5edd165
Revert "keymgr: Require callers to be explicit about which keystore to get keys from." (fmt) 2023-07-21 12:21:39 +01:00
Gabriela Moldovan 98337afec9
Revert "keymgr: Require callers to be explicit about which keystore to get keys from."
This reverts commit 38a6c74c78.

This also updates some tests to make them compile with the reverted
version of the code.
2023-07-21 12:21:36 +01:00
Ian Jackson 562c1a00be Merge branch 'access2' into 'main'
tor-linkspec: impl AsRef<str> for PtTransportName

See merge request tpo/core/arti!1426
2023-07-21 09:48:52 +00:00
Ian Jackson cfbff212d4 tor-guardmgr: bridges: fix typo in getter doc 2023-07-21 10:48:16 +01:00
Nick Mathewson c8e1dad298 Merge branch 'pwd-grp' into 'main'
Update pwd-grp to 0.1.1 to fix MacOS build etc.

See merge request tpo/core/arti!1427
2023-07-20 21:48:33 +00:00
Gabriela Moldovan 3cc2da91f2
keymgr: Remove unnecessary dependency. 2023-07-20 19:37:04 +01:00
gabi-250 56a4d7317c Merge branch 'rlimit_up' into 'main'
Bump requirement to rlimit 0.10.1

See merge request tpo/core/arti!1423
2023-07-20 18:36:32 +00:00
Gabriela Moldovan 3dbc49f3d0
keymgr: Use std::cfg instead of if_cfg. 2023-07-20 19:35:54 +01:00
Gabriela Moldovan 9d818f164b
keymgr: Require callers to be explicit about where to remove keys from.
As with `KeyMgr::insert`, only `KeystoreSelector::Id` and
`KeystoreSelector::Default` are supported.
2023-07-20 19:25:12 +01:00
Gabriela Moldovan 9ece85e572
keymgr: Add tests for KeyMgr. 2023-07-20 19:25:08 +01:00
Gabriela Moldovan 79c382ff50
keymgr: Add EncodableKey::to_bytes for encoding keys.
We'll need this to implement `Keystore::insert`.
2023-07-20 19:25:04 +01:00
Gabriela Moldovan 483bb6712d
keymgr: Add some extra derives to ArtiPath and KeyType. 2023-07-20 19:25:01 +01:00
Gabriela Moldovan 38a6c74c78
keymgr: Require callers to be explicit about which keystore to get keys from. 2023-07-20 19:24:57 +01:00
Gabriela Moldovan 85be9c0d30
keymgr: Move KeyMgr::get impl to Keymgr::get_from_store.
This refactoring will make more sense later, when we give
`KeyMgr::get` an extra parameter that specifies which keystore to
retrieve the key from.
2023-07-20 19:24:53 +01:00
Gabriela Moldovan 8b0b8785f4
keymgr: Remove unimplemented/unnecessary has_key_bundle function.
The concept of a "key bundle" would introduce a lot of complexity while
providing little to no gain.

Some context:
```
Originally, "key bundles" were meant to be the answer to the question
"which keystore should insert place keys in?":
36606a66dd/crates/tor-keymgr/src/mgr.rs (L60-69)
However, I'm not so sure anymore that "key bundles" are the answer. I
don't think there is any way we can "guess" where a key should go. When
inserting/generating a new key, we should either:

always write to the same, primary key store, OR require the user to be
explicit about which key store the new key should go in (by assigning an
ID to each key store and expecting the user to provide it when
inserting/generating new keys)

I prefer the latter option, because it provides more flexibility, which
we're going to need when implementing the key management CLI (which I
think should allow users to generate keys anywhere they want, e.g. arti
keymgr generate <key type> --keystore hsm ...)
```

For more details, see the discussion on #903.

Closes #903
2023-07-20 19:24:44 +01:00
Gabriela Moldovan 0b20806213
keymgr: Require callers to specify which keystore to insert keys in.
The caller uses `KeystoreSelector` to specify which keystore to insert
the new key into (only `KeystoreSelector::Id` and
`KeystoreSelector::Default` are supported for `insert`).

The ability to insert keys in a particular keystore will come in handy
when we implement the key management CLI (the CLI will have an option
for specifying the keystore to access/modify).
2023-07-20 19:24:29 +01:00
Gabriela Moldovan 6ec1b55938
keymgr: Add a convenience function for boxing keystore errors. 2023-07-20 19:24:19 +01:00
Gabriela Moldovan a794d78894
keymgr: Add an error type for misuse errors.
This error will be returned by `KeyMgr` if the caller tries to access a
keystore that does not exist, or if the requested `KeystoreSelector`
cannot be applied.
2023-07-20 19:24:16 +01:00
Gabriela Moldovan cf038fb772
keymgr: Add type for specifying which keystore to access. 2023-07-20 19:24:12 +01:00
Gabriela Moldovan d6d67769c9
keymgr: Add a function for looking keystores up by ID.
This will be used by `KeyMgr::insert` after we add an additional
argument to `insert` for specifying the keystore it should be using.
2023-07-20 19:24:08 +01:00
Gabriela Moldovan 04379dcae6
keymgr: Add an `id` function to `Keystore`.
This will enable the `KeyMgr` to look up `Keystore`s by ID (which is
a requirement for disambiguating the semantics of `insert`, which
currently tries to "guess" which keystore it should be using).
2023-07-20 19:24:05 +01:00
Gabriela Moldovan 2f05920c4d
keymgr: Iterate over all the stores, not just the secondary ones. 2023-07-20 19:24:01 +01:00
Gabriela Moldovan 9f5974fb7f
keymgr: Explicitly specify the default keystore for `KeyMgr`. 2023-07-20 19:23:58 +01:00
Gabriela Moldovan 8e49d1dd11
keymgr: Add a type alias for `Box<dyn Keystore>`.
This makes the code slightly less verbose.
2023-07-20 19:23:51 +01:00
Gabriela Moldovan ac93b1aef6
keymgr-config: Make fields private, add function for checking if keystore is enabled.
Hiding the underlying value of `enabled` enables us to give it a
different `auto` value depending on whether the `keymgr` feature is
enabled or not (it defaults to `true` if `keymgr` is enabled, and
`false` otherwise).
2023-07-20 19:23:48 +01:00
Gabriela Moldovan f18e773332
arti-client: Use a default keystore config if `experimental-api` is disabled.
The `experimental-api` was only meant to apply to the use of the
unstable `ArtiNativeKeystoreConfig` in the Arti config.
`experimental-api` was _not_ supposed to be used for enabling/disabling
the keystore (that's what the `enabled` flag is for).
2023-07-20 19:23:45 +01:00
Gabriela Moldovan b4bf421c11
arti-client: Move variable closer to where it's used (fmt). 2023-07-20 19:23:41 +01:00
Gabriela Moldovan ea02824547
arti-client: Move variable closer to where it's used. 2023-07-20 19:23:33 +01:00
Gabriela Moldovan d7c1b2cf03
arti-client: Make the `KeyMgr` optional.
If the Arti keystore is disabled, we have nothing to initialize the
`KeyMgr` with, so we might as well make it optional.
2023-07-20 19:23:30 +01:00
Ian Jackson 1f7911f0d9 Update pwd-grp to 0.1.1 to fix MacOS build etc.
This also gets rid of a duplicate copy of derive-adhoc.
2023-07-20 18:58:02 +01:00
Ian Jackson e3d5f25750 tor-linkspec: impl AsRef<str> for PtTransportName 2023-07-20 18:49:28 +01:00
Ian Jackson b5e6af9f5c tor-guardmgr: bridges: getter for ManagedTransportConfigBuilder.protocols
It's a bit of a wart that tor-ptmgr calls these "protocols" and
tor-guardmgr calls these "transport names".
2023-07-20 16:42:03 +01:00
Ian Jackson 3343e70c68 tor-guardmgr: bridges: getter for BridgeConfigBuilder.transport
BridgeConfigBuilder is Serialize so this isn't making any new API
promises.  Ideally we'd have getters like this everywhere.
2023-07-20 16:42:03 +01:00
Nick Mathewson c498cc2512 Merge branch 'cc_niche' into 'main'
geoip: Enable the niche optimization for CountryCode.

See merge request tpo/core/arti!1384
2023-07-20 12:18:58 +00:00
Nick Mathewson 3b7400621c Bump requirement to rlimit 0.10.1
There was a bug in 0.10.0 that broke MacOS.

Part of #963.
2023-07-20 08:15:38 -04:00
Nick Mathewson 027b3472a8 Fix a pair of rustdoc links in chanmgr. 2023-07-19 11:57:55 -04:00
Nick Mathewson 43481d1797 Merge branch 'issue961_01' into 'main'
geoip: Allow ASNs as zeros when creating NetDefn

Closes #961

See merge request tpo/core/arti!1417
2023-07-19 15:55:27 +00:00
Ian Jackson ad48335b91 tor-hsclient: Document API break.
This would be a break in higher-layer crates which incorproate this
error but:

 1. That's just arti-client which hides it behind the detailed errors
    cargo feature
 2. I'm hoping cargo-semver-checks would spot it, anyway.
2023-07-19 14:16:13 +01:00
Ian Jackson 36b9d11ecb retry-error: Attempts must be AsRef<dyn Error>; print their sources
The effect is that everywhere a RetryError is used, the error sources
for the contained errors will be Display'd.

In tor-hsclient we no longer need to explicitly wrap things up in
tor_error::Report.
2023-07-19 14:16:13 +01:00
Ian Jackson ed29dbcbd4 retry-error: Introduce a Wrapper type in a test
We're going to require that a RetryError contains things that are
AsRef<dyn Error> and ParseIntError isn't so we need a newtype.
2023-07-19 14:16:13 +01:00
Ian Jackson 882ce8c8ce retry-error: Provide fmt_error_with_sources in retry-error
This code came from tor-error.  So now tor-error depends on
retry-error.
2023-07-19 14:16:13 +01:00
juga 92baa823b9 geoip: Add derive macros to GeoipDb
to be able to debug it, for instance.
2023-07-18 14:39:52 +00:00
juga c42f84bd1e geoip: Allow ASNs as zeros when creating NetDefn
so that GeoipDb can be created from files including ASNs generated with
tor/scripts/maint/geoip/geoip-db-tool.

Closes #961
2023-07-18 14:39:52 +00:00
Ian Jackson dd5ceed791 tor-circmgr: impl AsRef<dyn std::error::Error> for some error types
We're about to want this.
2023-07-18 13:10:03 +01:00
Alexander Færøy bd21ea34c2 Merge branch 'upgrades_20230717' into 'main'
Mid-month dependency upgrades

See merge request tpo/core/arti!1412
2023-07-17 20:19:59 +00:00
Nick Mathewson a783a4f932 Upgrade to latest derive-adhoc. 2023-07-17 10:24:38 -04:00
gabi-250 89436bbfec Merge branch 'pwd-grp' into 'main'
Replace use of unmaintained users crate with homegrown pwd-grp

Closes #877

See merge request tpo/core/arti!1410
2023-07-17 14:18:02 +00:00
Nick Mathewson 1b3206ca0b Upgrade to latest rlimit. 2023-07-17 10:12:08 -04:00
Nick Mathewson 119bb68cbc keymgr: Upgrade to latest itertools.
(Everything else is already on 0.11.0.)
2023-07-17 10:08:38 -04:00
gabi-250 4338080799 Merge branch 'keymgr-config-tweaks' into 'main'
tor-keymgr config updates

Closes #939

See merge request tpo/core/arti!1404
2023-07-17 10:38:58 +00:00
Gabriela Moldovan caf2ce3f6b
arti-client: Add TODO about expanding the keystore_dir in build(). 2023-07-17 11:12:37 +01:00
Ian Jackson 967a36ee42 fs-mistrust: Run rustfmt to apply deferred formatting churn 2023-07-14 16:02:45 +01:00
Ian Jackson f137cbbe7c fs-mistrust: In a test, simplify env var handling 2023-07-14 16:02:45 +01:00
Ian Jackson 792371a688 fs-mistrust: users: Use OsStr and OsString a lot less
We don't use OsString now except where it appears in our public API,
or where we get it from std::env.

Moving the `use` statements into the use sites enabled me to see
that I had found all the places I wanted to change.
2023-07-14 16:02:45 +01:00
Ian Jackson 5f3571fdf3 fs-mistrust: Remove a now-unneeded suppression
This function is actually (properly) fallible now.
2023-07-14 16:02:45 +01:00
Ian Jackson 41543b06d6 fs-mistrust: forbid unsafe code 2023-07-14 16:02:45 +01:00
Ian Jackson c943f734d6 fs-mistrust: Replace a direct libc call in a test 2023-07-14 16:02:45 +01:00
Ian Jackson e4bb7c388a fs-mistruct: Abolish some now-unneeded muts
MockPwdGrpProvider has internal mutability and is Sync, so its add
functions take &self.
2023-07-14 16:02:45 +01:00
Ian Jackson fe79f423f7 fs-mistrust: Use pwd-grp's getgroups function
This gets rid of some unsafe code here, with doubtful error handling,
in favour of the unit-tested version in pwd-grp.
2023-07-14 16:02:45 +01:00
Ian Jackson 5f46bacbb2 fs-mistruct: switch from users to pwd-grp
users is unmaintained.  pwd-grp is the crate I have just written to
replace it. In this commit:

Change the cargo dependency and imports.

Replace the cacheing arrangements.  users has a built-in cache;
pwd-grp doesn't.  Now, instead of cashing individual lookups, we cache
the trusted user and trusted gid calculation results.
This saves on some syscalls, and is also more convenient to write.
(Mocking is still done via the dependency.)

Many systematic consequential changes of details:

 * The entrypoint names to the library are different:
   pwd-grp uses the names of the corresponding Unix functions.

 * pwd-grp's returned structs are transparent, so we don't
   call accessors for .uid(), .name(), etc.

 * pwd-grp's methods are much more often fallible
   (returning io::Result<Option<...>)

 * We're using the non-UTF-8 pwd-grp API, which means we must
   use turbofish syntax in some places.

 * The mocking API is a bit different.
2023-07-14 16:02:45 +01:00
Ian Jackson bf65b7763e fs-mistrust: Introduce tempoary PwdGrpProvider alias
This allows us to change a number of trait bounds in advance, reducing
noise in the next commit.
2023-07-14 16:02:45 +01:00
Ian Jackson a6108bb9b3 fs-mistrust: impl Hash for TrustedUser and TrustedGroup (config) 2023-07-14 16:02:45 +01:00
Ian Jackson a45eefec1a fs-mistrust: users: tests: Introduce mock_users etc.
Add some wrapper functions for convenience.

The pwd-grp crate has a richer and more faithful, but not so
convenient, way of creating dummy user/group entries.  Also the type
names are all going to change.

Doing this now reduces churn.
2023-07-14 16:02:45 +01:00
Ian Jackson cdafa2ce01 fs-mistrust: users: Make several functions fallible
The actual underlying operations here *are* fallible.
The `users` crate hides those errors in several cases.

(Failures are very rare (at least unless NIS is involved), so this is
not of much practical import, but it's going to be necessary when we
use the more careful pwd-grp crate.
2023-07-14 16:02:45 +01:00
Alexander Færøy ce64ade742 Merge branch 'unused_import' into 'main'
Move an import to resolve a warning.

See merge request tpo/core/arti!1407
2023-07-14 13:35:27 +00:00
Alexander Færøy 63a3bbc33c Merge branch 'bug638' into 'main'
Stop unconditionally marking bridges as having dir info.

Closes #638

See merge request tpo/core/arti!1408
2023-07-14 13:35:04 +00:00
Nick Mathewson b8334292fb Bridges: deduplicate addresses.
Currently we list an address for a bridge twice if it is listed both
in the bridge line and the bridge descriptor. That can't be right.
2023-07-13 16:58:12 -04:00