Commit Graph

5366 Commits

Author SHA1 Message Date
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
Nick Mathewson 3f2d4f8cec Better report for any recurrence of bug #638. 2023-07-13 15:43:57 -04:00
Nick Mathewson 7a915f5454 Stop unconditionally marking bridges as having dir info.
When we implemented bridges, we added code in 08473872ab to
conditionally mark their directory info as present or not present.
But the we didn't remove the old code to mark them present
unconditionally!

Fixes #638.
2023-07-13 15:43:42 -04:00
eta 41bb03c6cc Add country codes to relays inside a NetDir
- When the `geoip` feature flag of `tor-netdir` is enabled, perform
  GeoIP lookups for all relays added to the directory and add the
  resulting country code to the `Relay` struct.
  - The GeoIP database is provided in a new
    `PartialNetDir::new_with_geoip` constructor.
- A new trait was also added to `tor-linkspec`, `HasCountryCode`, to
  enable getting this data out from other crates.

Part of onionmasq#47.
2023-07-13 17:47:00 +01:00
Nick Mathewson ce8848f348 Move an import to resolve a warning. 2023-07-13 12:33:01 -04:00
gabi-250 b53d42f23e geoip: Use from_raw_parts instead of transmute. 2023-07-13 11:53:41 -04:00
Nick Mathewson 157d134a65 Explain better why you would use build_unmanaged_channel 2023-07-13 11:51:12 -04:00
gabi-250 56d96e4253 Resolve numerous typos in `ChanMgr::build_unmanaged_channel` code 2023-07-13 15:47:05 +00:00
Nick Mathewson 6b61eec987 chanmgr: Remove now-unused (and never usable) builder() method. 2023-07-13 09:33:06 -04:00
Nick Mathewson ed455023c2 chanmgr: Document makeup and timeout behavior of our factories
Basically, it's all ChanBuilder at some point, and ChanBuilder
has a timeout.
2023-07-13 09:33:06 -04:00
Nick Mathewson 7a38d68528 chanmgr: Add an experimental build_unmanaged_channel() method.
This method will let the user construct a channel that isn't
stored or monitored by the ChanMgr.
2023-07-13 09:31:57 -04:00
Gabriela Moldovan 99b73cb22a
arti-client: Log whether a keystore is in use. 2023-07-13 12:30:10 +01:00
Gabriela Moldovan 5b97b0b2ce
tor-config: Remove unused ItemOrBool helper.
`ItemOrBool` is currently not used anywhere (it was previously used by
the keymgr config).
2023-07-13 12:30:07 +01:00
Gabriela Moldovan d5339772f1
arti cfg tests: Add keystore to example config.
Closes #939
2023-07-13 12:30:04 +01:00
Gabriela Moldovan f609ae2661
arti config: Remove extraneous whitespace. 2023-07-13 12:30:01 +01:00
Gabriela Moldovan 0260405603
arti-client: Use the config struct from tor-keymgr. 2023-07-13 12:29:57 +01:00
Gabriela Moldovan d8299e8d2f
tor-keymgr: Add ArtiNativeKeystoreConfig.
Previously, the keystore config consisted of a single field in
`StorageConfig`, which encoded 2 bits of information: whether the
keystore is enabled, and its root directory:
```
[storage]
# use this path, fail if compiled out
# keystore = "/path/to/arti/keystore"
#
# use default path, fail if compiled out
# keystore = true
#
# disable
# keystore = false
```

This commit adds `ArtiNativeKeystoreConfig`, which will replace the
multi-purpose `keystore` field. The new config will look like this:
```
#[storage.keystore]
# Whether the keystore is enabled.
#
# If the `keymgr` feature is enabled and this option is:
#     * set to false, we will ignore the configured keystore path.
#     * set to "auto", the configured keystore, or the default keystore, if the
#     keystore path is not specified, will be used
#     * set to true, the configured keystore, or the default keystore, if the
#     keystore path is not specified, will be used
#
# If the `keymgr` feature is disabled and this option is:
#     * set to false, we will ignore the configured keystore path.
#     * set to "auto", we will ignore the configured keystore path.
#
# Setting this option to true when the `keymgr` feature is disabled is a
# configuration error.
#enabled = "auto"
# The root directory of the arti keystore
#path = "${ARTI_LOCAL_DATA}/keystore"
```

While `ArtiNativeKeystoreConfig` currently only has 2 fields, `enabled`
and `path`, future versions of the keystore might require additional
config options.
2023-07-13 12:13:59 +01:00
gabi-250 42115116e4 Merge branch 'keymgr-integration-test' into 'main'
CI: Add client auth integration test.

Closes #954

See merge request tpo/core/arti!1399
2023-07-12 16:35:43 +00:00
Alexander Færøy 89a3d43aa6 Merge branch 'feat' into 'main'
"Fix" CI complaints about "Conversation"

See merge request tpo/core/arti!1402
2023-07-12 15:34:45 +00:00
Gabriela Moldovan c942f02dea
arti-client: Log whether the client auth keys were retrieved. 2023-07-12 16:30:06 +01:00
Saksham Mittal 7933a93d3a
Gate builder() behind experimental-api feature 2023-07-12 20:14:12 +05:30
Ian Jackson f6d5cae574 tor-circmgr: Add two possibly-needed docsrs annotations
I don't know if these are needed because the rules are not documented
afaict.  But it seems like probably they ought to be there?
2023-07-12 15:32:26 +01:00
Ian Jackson 1fa692d63d tor-proto: Conversation: drop two otiose cfg(feature)
These fns are in a feature-gated impls on feature-gated structs.
2023-07-12 15:31:30 +01:00
Nick Mathewson 1737832164 Merge branch 'channelfactory' into 'main'
Expose channel builder in order to create channels more efficiently in external code

See merge request tpo/core/arti!1374
2023-07-12 13:40:54 +00:00
Gabriela Moldovan 674fc9d7dc
arti-client: Remove outdated TODO.
These errors aren't ignored anymore.
2023-07-11 16:49:44 +01:00
Nick Mathewson bcf574cef5 Merge branch 'explain_952_fix' into 'main'
Explain the code for the #952 fix.

See merge request tpo/core/arti!1391
2023-07-11 09:53:09 +00:00
Ian Jackson 3acc2af4f3 Merge branch 'clippy-allow' into 'main'
clippy: Allow some of our existing code patterns

See merge request tpo/core/arti!1396
2023-07-11 09:37:42 +00:00
Ian Jackson 24bec4552b rng docs: Fix two links 2023-07-10 16:08:03 +01:00
Ian Jackson a0a17e4074 rng ranges: Provide examples (doctests) 2023-07-10 16:08:03 +01:00
Ian Jackson d1ed505b61 rng ranges: Forbid use of panicky Rng::gen_range
Fixes #920
2023-07-10 16:08:03 +01:00
Ian Jackson b151237a7f rng ranges: Use gen_range_infallible() for Duration::ZERO..=T 2023-07-10 16:08:03 +01:00
Ian Jackson 09f0ecaa71 rng ranges: Introduce gen_range_infallible
There are a number of places where we generate random Durations
in a range which starts at zero.

These call sites currently (i) have to write out Duration::ZERO
or equivalent, and (ii) would have to use gen_range_checked and expect
the result, even though it can be statically proven to be OK.

To make this slightly smoother, provide `GenRangeInfallible` and
`gen_range_infallible`.
2023-07-10 16:07:18 +01:00
Ian Jackson 8ae759ef95 rng ranges: Use gen_range_checked().unwrap() in test case
Ideally we would be allowed to use vanilla gen_range() here, but there
doesn't seem to be a way to allow a specific clippy-forbidden method
using #[allow] and we probably don't want to make a blanket allow.
2023-07-10 16:07:18 +01:00
Ian Jackson 332285015f rng ranges: Use gen_range_checked().expect() in obvious cases (fmt) 2023-07-10 16:07:18 +01:00
Ian Jackson 5e10805ede rng ranges: Use gen_range_checked().expect() in obvious cases
In each of these, it is locally obvious that the range is nonempty.
2023-07-10 16:07:18 +01:00
Ian Jackson 36f998b690 tor-basic-utils: retry: Use and justify gen_range_checked
delay_bounds's implementation ensures the postcondition, so the
potential p[anic in next_delay_msec cannot happen.
2023-07-10 16:07:18 +01:00
Ian Jackson 58da20b708 rng ranges: Introduce RngExt and gen_range_checked
We will use this in many places instead of gen_range.
2023-07-10 16:07:18 +01:00
gabi-250 1510cf42b7 Merge branch 'keymgr-erased-key' into 'main'
keymgr: Use Box<dyn EncodableKey> instead of Box<dyn Any>.

Closes #937

See merge request tpo/core/arti!1398
2023-07-10 15:06:34 +00:00
Gabriela Moldovan bd4955f9ed keymgr: Add semver.md. 2023-07-10 15:38:58 +01:00
Gabriela Moldovan 9cde64c2c8 keymgr: Use Box<dyn EncodableKey> instead of Box<dyn Any>.
Prompted by https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1337#note_2917701

This will make it harder to accidentally return the wrong value from
`Keystore::get` (the returned value is now at least guaranteed to
implement `EncodableKey`).

Closes #937
2023-07-10 14:41:30 +01:00
Alexander Færøy 6be6352b98 Merge branch 'conversation' into 'main'
Overhaul send_control_message

See merge request tpo/core/arti!1367
2023-07-10 13:14:11 +00:00
Alexander Færøy 943c12739d Merge branch 'recurse' into 'main'
tor-hsclient: Mock traits: Work around an async boobytrap

See merge request tpo/core/arti!1365
2023-07-10 13:13:31 +00:00
Ian Jackson fd2e4979be clippy: tor-error: Use convert::identity for into_internal!
This launders the closure so that clippy's
clippy::redundant_closure_call can't see it.

We can't have a local #[allow] because it would be on an expression,
which isn't allowed on stable.

This avoids having to use more clumsy idioms at call sites.
2023-07-10 13:49:51 +01:00
Ian Jackson 1a8395cd11 tor-llcrypto: Add a missing instance of the standard lint block
This fixes a needless_vec lint on nightly.
2023-07-10 13:49:51 +01:00
Ian Jackson 473447a82e Run maint/add_warning to actually apply new lint allows 2023-07-10 13:49:51 +01:00
Nick Mathewson 9f3619d5c9 Merge branch 'clippy-vec' into 'main'
Fix new "useless_vec" warning from clippy +nightly

See merge request tpo/core/arti!1395
2023-07-10 12:07:31 +00:00
Nick Mathewson c2601ec896 Explain the code for the #952 fix.
Let's explain what Trinity did in its fix for #952, so that we know
why this code is here the next time we find it.
2023-07-10 08:00:08 -04:00
Ian Jackson 501454370f Fix new "useless_vec" warning from clippy +nightly
Explanation at
https://rust-lang.github.io/rust-clippy/master/index.html#/useless_vec

This is the non-tests subset of the same-named commmit in !1388,
(recreated by hand by me, and then checked against that commit;
I stole the commit message from Nick's.)

This should be uncontroversial I think.
2023-07-10 12:35:21 +01:00
Nick Mathewson 22f55b7cf8 Remove some needless into_iter() calls.
Clippy nightly now detects when you're calling into_iter() and
passing the result into something that accepts an
`impl IntoIterator`.
2023-07-10 12:33:21 +01:00
Nick Mathewson 0b6cc7ba5e Add exceptions for some cases of diverging_sub_expression
See here for documentation on the lint:
https://rust-lang.github.io/rust-clippy/master/index.html#/diverging_sub_expression

The issue here, from what I can tell, is that the lint triggers
whenever you use a diverging expression as a function body within an
2023-07-10 12:33:21 +01:00
Nick Mathewson 7e78224460 Add an exception for clippy::arc_with_non_send_sync.
We're doing this deliberately, I believe.
2023-07-10 12:33:21 +01:00
gabi-250 2db3e73434 Merge branch 'da-task' into 'main'
RFC: tor-rtmock: Use derive-adhoc for composite runtimes

See merge request tpo/core/arti!1381
2023-07-10 10:53:23 +00:00
Kunal Mehta 7acd7de369 Update documentation regarding the `onion-service-client` feature
It is no longer experimental, but still not rated for security-sensitive
usage per <https://blog.torproject.org/arti_116_released/>.
2023-07-07 22:01:51 -04:00
Nick Mathewson 53c599d50f Fix warn_report and error_report macros.
Originally they didn't check err.kind(), since err.kind() can never
increase their severity.  We lost that behavior with !1386, and we
became dependent on it with arti!1383.  Since they both merged at
the same time, CI broke.

This patch restores their original behavior.
2023-07-07 15:46:41 -04:00
Nick Mathewson ba3876b22a Merge branch 'feat' into 'main'
arti: Build with HS client support by default

Closes #948

See merge request tpo/core/arti!1382
2023-07-07 19:28:05 +00:00
Nick Mathewson b6b7edad59 Merge branch 'event_report_everywhere' into 'main'
Throughout: Use event_report!() macros for reporting Errors.

Closes #949

See merge request tpo/core/arti!1383
2023-07-07 19:27:20 +00:00
trinity-1686a 2d170425c0 be more lenient while parsing inner hs desc 2023-07-07 21:06:05 +02:00
Ian Jackson 778244c3af Merge branch 'report' into 'main'
tor-error: tracing module: Use macro to generate macros

See merge request tpo/core/arti!1386
2023-07-07 18:09:46 +00:00
Ian Jackson 696adc3c94 tor-error: tracing module: Use macro to generate macros
This abolishes some quintuplication.

The output is identical except that:
 * The syntax display in the rustdoc output for the resulting macros
   seems to have somewhat less whitepsace.
 * The whimsical error messages in the examples are all identical.
   Ah well.
2023-07-07 18:38:24 +01:00
Nick Mathewson 7d1c8dfde0 Merge branch 'inclusive' into 'main'
rng ranges: Use inclusive Duration ranges in several places

See merge request tpo/core/arti!1385
2023-07-07 17:07:58 +00:00
Nick Mathewson 25c6fe61e4 Throughout: Use *_report!() macros for reporting Errors.
I identified the cases to replace by searching for the string
`.report()`.  There are a few that I didn't change:

  * A couple of cases that used anyhow::Error,
  * One case that reported two Errors.
  * Two cases in `tor_hsclient::err` that just did
    `error!("Bug: {}")`.

I have also not audited the cases in `tor-hsclient` where we're using
`tor_error::Report` manually.

Nonetheless, closes #949.
2023-07-07 13:00:21 -04:00
Ian Jackson 220900a852 tor-error: tracing module: Fix link to tracing macro 2023-07-07 17:48:05 +01:00
Ian Jackson bcc3e6fef8 rng ranges: Use inclusive Duration ranges in several places
Many of these call sites would panic if, somehow, the upper bound was
zero.  In most cases it is very complicated to see if whether this
could happen.

However, there is a better answer:

Durations are (conceptually) dense, so picking the closed set (which
includes its boundary) rather than the open one (which doesn't) will
make little practical difference.

So change four call sites to use `..=` instead of just `..`.
2023-07-07 16:13:52 +01:00
Nick Mathewson 6187b6d5ca geoip: Enable the niche optimization for CountryCode.
Since we're going to be using `Option<CountryCode>` all over, let's
save the extra byte.

Sadly this required std::mem::transmute(), which is unsafe, so maybe
we should think twice.
2023-07-07 10:33:33 -04:00
Nick Mathewson 70f0fe634f Merge branch 'report-bugs-v2' into 'main'
Optional tracing support in tor-error for error reporting

See merge request tpo/core/arti!1379
2023-07-07 13:49:59 +00:00
Nick Mathewson 023d288ba2 event_report: assert correctness of format ending
(Also, document that this static assertion is the reason why you are
seeing a confusing error message.)
2023-07-07 09:00:31 -04:00
Nick Mathewson a441b4e9d3 circmgr: Use event_report!() and similar macros
This simplifies our logging a little, and implements part of
2023-07-07 09:00:31 -04:00
Nick Mathewson 7168feefdd tor-error: Add optional tracing support
The main contribution here is a set of convenience macros for
logging error `Report`s.  Notably, this macros always logs
`Internal` and `BadAspiUsage` errors at `WARN`, unless they
are already at `ERROR` or more.

This is a little tricky because `tracing::event!()` requires
its Level argument to be a constant.
2023-07-07 09:00:31 -04:00
Ian Jackson 80f397fb0b Merge branch 'allow_missing_panics' into 'main'
add_warning: Tolerate clippy::missing_panics_doc

Closes #950

See merge request tpo/core/arti!1380
2023-07-07 12:53:46 +00:00
Saksham Mittal 9de4f38b38
Make CompoundFactory private for external code 2023-07-07 18:18:44 +05:30
Nick Mathewson 2b3d4150e3 Merge branch 'clippy-nightly-20230703' into 'main'
Fix various warnings from clippy nightly

Closes #943

See merge request tpo/core/arti!1369
2023-07-07 12:26:45 +00:00
Ian Jackson 4c0935e13a arti: Build with HS client support by default
Fixes #948
2023-07-07 12:54:08 +01:00
Ian Jackson 61344f68a5 arti Cargo.tomL: wrap default features list 2023-07-07 12:52:05 +01:00
Ian Jackson 6e495d8400 tor-rtmock: Use derive-adhoc for composite runtimes 2023-07-07 10:26:44 +01:00
Nick Mathewson 4caf86349c Remove explicit allows for missing_panics_docs.
These are no longer needed.
2023-07-06 14:36:13 -04:00
Nick Mathewson 03f9f9987a Run add_warning to remove `missing_panics_doc` deny.
Closes #950.
2023-07-06 14:32:23 -04:00
Nick Mathewson 07b4b11d7a Avoid matches!(x, None), matches!(x, Ok(_))
This appeases clippy-nightly.
2023-07-06 14:26:48 -04:00
Nick Mathewson 486b6b8c82 tor-rtcompat: Simplify trivial all() expressions.
Clippy nightly doesn't like `#[cfg(all(...))]` with only a single
expression inside the `all(...)`.

This requires an adjustment in check_doc_features.
2023-07-06 14:26:43 -04:00
Ian Jackson de97288c53 tor-rtmock: statically assert that the macro makes a Runtime impl 2023-07-06 15:58:42 +01:00
Ian Jackson f0168b5220 tor-rtmock: Use the same specified field for BlockOn and Spawn
These are always the same and probably always will be.
2023-07-06 15:58:42 +01:00
Ian Jackson 1ec339daf4 Merge branch 'task4' into 'main'
Introduce a MockExecutor for fully-isolated test cases

See merge request tpo/core/arti!1375
2023-07-06 14:41:04 +00:00
Nick Mathewson 36a92e44d9 Merge branch 'log_precision' into 'main'
arti: Add a `logging.time_granularity` option with 1s default.

Closes #551

See merge request tpo/core/arti!1376
2023-07-06 14:37:49 +00:00
Saksham Mittal c238434194
Mark builder() as experimental 2023-07-06 19:49:37 +05:30
Saksham Mittal 175b2911da
Import ChannelFactory instead of CompoundFactory 2023-07-06 19:48:28 +05:30
Saksham Mittal 008a9b7bc5
Rename get_channelbuilder() to builder() 2023-07-06 19:46:39 +05:30
Saksham Mittal be6b72f946
Conditionally make CompoundFactory public 2023-07-06 19:45:34 +05:30
Ian Jackson 0b8b965cf7 tor-rtmock: Add semver.md 2023-07-06 15:14:41 +01:00
Ian Jackson 6ed8e0b669 tor-rtmock: task: Fix a typo
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1375#note_2919976
2023-07-06 15:14:41 +01:00
Ian Jackson 7e7428611e tor-rtmock: task: clarify progress_until_stalled a little 2023-07-06 15:14:41 +01:00
Ian Jackson 6aff623c08 tor-rtmock: Runtime: Expand on "allowed" documentation 2023-07-06 15:14:41 +01:00
Ian Jackson 02293bd42d tor-rtmock: task: Remove a () assignment
Discussion:
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1375#note_2919928
2023-07-06 15:14:41 +01:00
Ian Jackson 89994142d3 tor-rtmock: task: Abolish TaskFutureInfo alias (fmt) 2023-07-06 15:14:41 +01:00
Ian Jackson 78071c30ef tor-rtmock: task: Abolish TaskFutureInfo alias
Requested by:
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1375#note_2919926
2023-07-06 15:14:41 +01:00
Ian Jackson 55329fe85b tor-rtmock: Net: Make UDP sockets un-constructable
This will hopefully mean anyone trying to use this will notice that
it's not implemented.

Prompted by:
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1375#note_2919925
2023-07-06 15:14:41 +01:00
Ian Jackson 5a05960958 tor-rtmock: Add a cross-reference from MockSleepRuntime::wait_for 2023-07-06 15:14:41 +01:00
Ian Jackson 1f41281cfd tor-dirmgr: bridge descriptor tests: Add a missing #[traced_test]
This seems to have been overlooked.
2023-07-06 15:14:41 +01:00
Ian Jackson a4bb2a8b57 tor-dirmgr: bridge descriptor tests: Use MockRuntime (drop Tokio dep)
This isn't used any more.
2023-07-06 15:14:40 +01:00
Ian Jackson 25e51f212a tor-dirmgr: bridge descriptor tests: Use MockRuntime (fmt)
Run rustfmt.
2023-07-06 15:14:40 +01:00
Ian Jackson 5eb066acf9 tor-dirmgr: bridge descriptor tests: Use MockRuntime
This abolishes a bodge sleep.  It should make the tests deterministic.
2023-07-06 15:14:40 +01:00
Ian Jackson 473fd23f8b tor-dirmgr: bridge descriptor tests: Fix a v. low prob. race
Drain a number of events, not just one.  The stream might yield many
events, as explained in this new comment.

This fails every time with MockExecutor::try_test_with_various().

I think it might fail with the tokio exeuctor too, but evidently not
with high probability or we would have noticed.
2023-07-06 15:14:40 +01:00
Ian Jackson bc63fdb34c tor-hsclient: Abolish ad-hoc real-world-time sleeps
Now we can reliably wait precisely for the tasks to be all waiting.

This test case no longer involves any real executor.
2023-07-06 15:14:40 +01:00
Ian Jackson dc28b320f4 tor-rtmock: MockRuntime: provide test_with_various
In both fallible and infallible variants, for convenience.
2023-07-06 15:14:40 +01:00
Ian Jackson e23b1e00b5 tor-rtmock: MockExecutor: Configurable scheduling policy 2023-07-06 15:14:40 +01:00
Ian Jackson be632ba0f9 tor-rtmock: Provide MockRuntime 2023-07-06 15:14:40 +01:00
Ian Jackson 67941488ab tor-rtmock: Unit tests for MockExecutor 2023-07-06 15:14:40 +01:00
Ian Jackson d82ed8d793 tor-rtmock: Provide MockExecutor 2023-07-06 15:14:40 +01:00
Ian Jackson 70fdd92030 tor-rtmock: impl Default for MockNetProvider 2023-07-06 15:14:40 +01:00
Ian Jackson 24da490ef5 tor-rtmock: impl Default for MockNetProvider (prep)
We want MockNetProvider to be Default.

In this commit: impl Default for MockNetwork and use it in new().
2023-07-06 15:14:40 +01:00
Ian Jackson 29cc83b35e tor-rtmock: impl Default for MockSleepProvider
Pick an arbitrary start time roughly now.  This will do for many
tests.
2023-07-06 15:14:40 +01:00
Ian Jackson 395a616c9f tor-rtmock: net: "Provide" a UDP "implementation" which doesn't work
Nothing in our tree actually *uses* the UDP in tests.

We want a mock UDP provider that isn't part of a real runtime, so that
we can make a totally-mock runtime for properly controlled testing.

It seems best to make this part of MockNetProvider rather than a
separate type.
2023-07-06 15:14:40 +01:00
Ian Jackson 070a934451 tor-rtmock: Introduce impl_runtime_prelude (fmt) 2023-07-06 15:14:40 +01:00
Ian Jackson 492699d522 tor-rtmock: Introduce impl_runtime_prelude
This deduplicates some imports, which would otherwise be about to
become triplicated.
2023-07-06 15:14:40 +01:00
Ian Jackson 97e817b330 tor-rtmock: Introduce impl_runtime! macro
This deduplicates some trait delegation.

We want this now because we're about to introduce a third mock
runtime, so this would become triplication otherwise.
2023-07-06 15:14:40 +01:00
Nick Mathewson 5a46dfef8f arti: comments about catch_unwind 2023-07-06 09:44:51 -04:00
Nick Mathewson 6b6b3d9e53 time_granularity: Make sure formatter can't panic
I was unable to assure myself that tracing_subscriber could
withstand a panicking Timer, so instead I'm trying to make sure
our own LogTimer can't panic.
2023-07-06 09:44:50 -04:00
Nick Mathewson 512064cc19 arti: Add a `logging.time_granularity` option with 1s default.
This lets us provide less information in our logs: in particular, it
lets us avoid logging with microsecond precision.

Closes #551.
2023-07-06 09:44:09 -04:00
Nick Mathewson 5f896aa504 Merge branch 'tracing-panic' into 'main'
arti: Install a panic hook that sends messages to `tracing`

Closes #921

See merge request tpo/core/arti!1377
2023-07-06 13:09:54 +00:00
Nick Mathewson d2b6fee3f9 arti: Note possibility for future use of other tracing panic provider 2023-07-06 08:50:53 -04:00
Nick Mathewson 01f1192b20 arti: On panic, avoid allocation even more.
The original version of our panic handler would allocate a string
for the panic `Location`.  But if we're panicking we'd like to keep
allocations to a minimum: so instead format the `Location`
conditionally.

This also drops a useless `std::borrow::Cow`.  (The possibility of a
"Don't have a `Cow`" commit message was considered and rejected.)
2023-07-06 08:45:34 -04:00
Gabriela Moldovan 258dd195e0 keymgr: Explain why the TODO regarding EncodableKey can't be addressed. 2023-07-05 22:21:47 +01:00
Nick Mathewson afa51fd5ca Add TODO comments about possibly migrating away from the backtrace crate. 2023-07-05 16:39:11 -04:00
Nick Mathewson 9c4de185e9 arti: Install a panic hook that sends messages to `tracing`
(Also leaves installed the default handler that sends messages to
stderr.)

Closes #921.
2023-07-05 16:37:10 -04:00
Ian Jackson 0003a632de Merge branch 'unpublishing' into 'main'
Mark several crates with `publish=false`.

Closes #944

See merge request tpo/core/arti!1371
2023-07-05 16:49:41 +00:00
Saksham Mittal c94b1b6574
Remove now unnecessary lines for import 2023-07-05 19:03:53 +05:30
Saksham Mittal 68948e9677
Import CompoundFactory regardless of feature level 2023-07-05 18:59:54 +05:30
Saksham Mittal 58df83dcde
Create new method to expose CompoundFactory 2023-07-05 18:53:22 +05:30
Saksham Mittal 7600200f15
Expose CompoundFactory for later exposure in API 2023-07-05 18:39:44 +05:30
Nick Mathewson 517bf1cf03 Mark arti-bench with "publish = false"
This crate is only useful for development; earlier we published it,
but I believe that was in error.
2023-07-03 13:52:20 -04:00
Nick Mathewson 2c5b81e872 Mark vestigial crates as "publish=false"
These crates were started, but they aren't integrated into
Arti (yet?).  As such it doesn't make sense to keep publishing
updated versions of them every time we tweak our standard
lints.
2023-07-03 13:49:51 -04:00
Nick Mathewson 19b1d3bba5 Additional documentation around bridges/PT configuration
This tries to flesh out some of the details for users who may be new
to bridges and PTs.

Closes #706.
2023-07-03 13:00:25 -04:00
Nick Mathewson f626bcd7f1 Finish a sentence in the documentation for TorClient::netdir() 2023-07-03 12:35:31 -04:00
Nick Mathewson 1f49be1a77 tor-config: Use next_back() instead of rev().next()
This is a new warning^Wsuggestion from clippy nightly.
2023-07-03 08:34:54 -04:00
Ian Jackson 27ad9ca249 tor-proto: run rustfmt 2023-06-30 18:43:20 +01:00
Ian Jackson a97cb2af6a tor-proto conversations: semver 2023-06-30 18:43:20 +01:00
Ian Jackson 2a67468d27 tor-proto conversations: Update a TODO
The feature name is wrong now.
2023-06-30 18:43:20 +01:00
Ian Jackson 78e4f9e86b tor-proto conversations: Drop a TODO
I think this name is fine.
2023-06-30 18:43:20 +01:00
Ian Jackson 226bca984b tor-proto conversation API: Provide ConversationInHandler 2023-06-30 18:43:20 +01:00
Ian Jackson 800f390a9d tor-proto circuit: Plumb async Context through
handle_msg is going to want this in a moment.
2023-06-30 18:28:41 +01:00
Ian Jackson c599258b85 tor-proto conversation API: Soften a warning
If the circuit is just being used by us (which is likely, if we're
using this API) then the only reactor we're blocking is our own.
2023-06-30 18:28:41 +01:00
Ian Jackson 287c458731 tor-proto conversation API: Implement Conversation
Now, after you call start_conversation_last_hop, you can send more
messages if you like.
2023-06-30 18:28:41 +01:00
Ian Jackson 77903a295f tor-proto: Make the handler in SendMsgAndInstallHandler optional
We're going to want to do almost-the-same thing but without installing
a new handler.
2023-06-30 18:14:34 +01:00
Ian Jackson 20f1e065b3 tor-proto conversation API: Return a Conversation
This is just a placeholder for now, but it'll be a thing you can send
more messages with.
2023-06-30 18:03:17 +01:00
Ian Jackson 2882e3a93e tor-proto conversation API: Rename to start_conversation_last_hop
Was send_control_message.
2023-06-30 18:02:56 +01:00
Ian Jackson 3812e3ccdd tor-proto conversation API: Make starting message optional
We're going to let people start a conversation and either expect to
receive first, or send messages ad-hoc later.
2023-06-30 18:02:15 +01:00
Ian Jackson b162d005a7 tor-proto conversation API: Rename to ConversationFinished
Was UninstallHandler.  We are going to talk more about conversations
and less about handlers (although, the fact of there being a handler
will still be visible).
2023-06-30 18:02:04 +01:00
Ian Jackson 408c8f30ad tor-proto circuit: Make reactor::run_once modulae-private
Nothing else wants this and having it pub(super) is confusing.
2023-06-30 17:34:50 +01:00
Ian Jackson 21c564fa01 tor-hsclient: Mock traits: Work around an async boobytrap 2023-06-30 17:34:01 +01:00
Nick Mathewson 27bd990a79 Remove semver.md files for 1.1.6 2023-06-30 10:28:53 -04:00
Gabriela Moldovan 3afe810a3b keymgr: Fix broken doc link. 2023-06-30 14:41:33 +01:00
Nick Mathewson de13a7319b Bump patchlevel versions on crates with smaller changes
Done with the commands below.

The following crates have had various changes, and should get a
patchlevel bump. Since they are pre-1.0, we do not need to
distinguish new APIs from other changes.

```
cargo set-version --bump patch -p arti-client
cargo set-version --bump patch -p safelog
cargo set-version --bump patch -p tor-bytes
cargo set-version --bump patch -p tor-cert
cargo set-version --bump patch -p tor-circmgr
cargo set-version --bump patch -p tor-config
cargo set-version --bump patch -p tor-consdiff
cargo set-version --bump patch -p tor-dirclient
cargo set-version --bump patch -p tor-dirmgr
cargo set-version --bump patch -p tor-error
cargo set-version --bump patch -p tor-hsservice
cargo set-version --bump patch -p tor-linkspec
cargo set-version --bump patch -p tor-llcrypto
cargo set-version --bump patch -p tor-netdir
cargo set-version --bump patch -p tor-netdoc
cargo set-version --bump patch -p tor-proto
cargo set-version --bump patch -p tor-rpcbase
cargo set-version --bump patch -p tor-socksproto
```

This crate has new features, but no new non-experimental Rust APIs.
So even though it is post-1.0, it gets a patchlevel bump.

```
cargo set-version --bump patch -p arti
```
2023-06-30 08:42:21 -04:00
Nick Mathewson 65e81bf0ca Bump minor versions on crates with breaking changes
Done with:
```
cargo set-version --bump minor -p tor-hsclient
cargo set-version --bump minor -p arti-rpcserver
cargo set-version --bump minor -p tor-hscrypto
cargo set-version --bump minor -p tor-cell
```
2023-06-30 08:38:16 -04:00
Nick Mathewson 40768a9f61 Bump versions on crates with nonfunctional changes
These crates have had nonfunctional changes only, mostly due to !1271,
or ac90cb7500, or documentation changes: crates that depend on
them do not require a version bump.

```
arti-bench
arti-config
arti-hyper
arti-testing
caret
fs-mistrust
retry-error
tor-async-utils
tor-basic-utils
tor-chanmgr
tor-checkable
tor-congestion
tor-consdiff
tor-events
tor-guardmgr
tor-persist
tor-protover
tor-ptmgr
tor-rtcompat
tor-rtmock
tor-units
```
2023-06-30 08:30:55 -04:00
gabi-250 8c1e96a22c Merge branch 'arti-path-bug' into 'main'
keymgr: Allow periods in ArtiPath and ArtiPathComponent.

See merge request tpo/core/arti!1358
2023-06-30 11:30:45 +00:00
Gabriela Moldovan a61071f7b6 keystore: Change the dummy HsClientSpecifier to "default". 2023-06-30 11:49:07 +01:00