Commit Graph

5199 Commits

Author SHA1 Message Date
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