Commit Graph

396 Commits

Author SHA1 Message Date
Nick Mathewson 82801d9963 netdoc, hsclient: Update remaining ed25519::SecretKey users
Fortunately, these are all in experimental code.

Closes #798
2023-05-18 14:18:53 -04:00
Nick Mathewson b84f122aab Merge branch 'ticket_759' into 'main'
tor-cert: Replace the KeyUnknownCert::check_key API

Closes #759

See merge request tpo/core/arti!1184
2023-05-16 22:23:17 +00:00
Nick Mathewson 56c6e4345b Replace usage of KeyUnknownCert::check_key. 2023-05-16 17:53:15 -04:00
Nick Mathewson 6fa821238d Revise all XXXXs from fixup-features 2023-05-15 11:00:28 -04:00
Nick Mathewson 4b08ef76a0 Run fixup-features _with_ annotations.
This litters our Cargo.toml files with "XXX" entries that we should
fix.
2023-05-15 10:41:32 -04:00
Nick Mathewson e2e125fef7 Reformat Cargo.toml files. 2023-05-15 09:09:43 -04:00
Nick Mathewson 7a5373c110 Run fixup-features --no-annotate for initial Cargo.toml fixes.
This does the following:
  - Gives every crate a `full`.
  - Cause every `full` to depend on `full` from the lower-level
    crates.
  - Makes every feature listed _directly_ in `experimental` depend
    on `__is_experimental`.
2023-05-15 09:07:21 -04:00
Nick Mathewson bfda3082d4 Use non-deprecated *Secret::random_from_rng.
The `new` function is deprecated in x25519-dalek 2.0.0-rc.2
2023-05-13 16:52:23 -04:00
Gabriela Moldovan f9c6cc11bb
netdoc: Use the RangeBoundsExt impl of TimerangeBound.
We can now get rid of the standalone `intersect_bounds` function.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-13 12:48:52 +01:00
Gabriela Moldovan 9dbf162c90
netdoc: Do not consume EncryptedHsDesc when decrypting.
`parse_decrypt_validate` will need to "peek" inside an encrypted
descriptor (before validating it) to extract the `TimerangeBound` of the
inner layer. This is needed to compute the intersection of the
`TimerangeBound`s of both layers.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-13 12:48:23 +01:00
Gabriela Moldovan 92e0b6a029
hsclient: Compute HsDesc validity time from the TimerangeBounds of its layers.
This makes `descriptor_ensure` refetch the descriptor if either of its
layers (inner or outer) expires.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-13 12:48:20 +01:00
Gabriela Moldovan 88ea5032f4
hsclient: Build cached descriptor TimerangeBounds from descriptor lifetime.
This makes `descriptor_ensure` refetch the descriptor if it has been
cached for longer than `descriptor-lifetime` minutes.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-13 12:48:13 +01:00
Gabriela Moldovan 0422893373
netdoc: Rename parse_error_kind() to netdoc_error_kind().
`ParseErrorKind` was renamed to `NetdocErrorKind`, so we need to
rename this acccessor too.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-11 18:39:40 +01:00
Nick Mathewson ca96b77b15 Merge branch 'hs-linkspec-work-v2' into 'main'
Second take on linkspec manipulation code needed by onion services

Closes #794

See merge request tpo/core/arti!1177
2023-05-11 13:16:13 +00:00
Nick Mathewson 02785ca650 Rename UnparsedLinkSpec => EncodedLinkSpec 2023-05-10 11:23:39 -04:00
Gabriela Moldovan 410ca23d2d
netdoc: Remove experimental-api gate from parse_decrypt_validate.
`parse_decrypt_validate` was marked as experimental because it was
unclear if the newly added `BadTimeBound` error kind belongs in
`ParseErrorKind`. However, we have since renamed `ParseErrorKind` to
`NetdocErrorKind` and decided to keep the new variant, so this API
doesn't need to be experimental anymore.

Closes arti #852

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-10 15:53:54 +01:00
Gabriela Moldovan 099b2315b0
netdoc: Rename `ParseError{Kind, Source}` to `NetdocError{Kind, Source}`.
`ParseErrorSource` was originally meant to represent a parsing error,
this enum has since gained some variants that aren't really parsing
related (`Signature`, `CertSignature`, `UntimelyDescriptor`).

Since this error type is now used for general-purpose netdoc errors,
let's rename `ParseError{Kind, Source}` to `NetdocError{Kind, Source}`.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-10 15:52:28 +01:00
gabi-250 2c2d9e9425 Merge branch 'hsdesc-parse-decrypt-validate' into 'main'
netdoc: Add a convenience method for HS descriptor parsing.

Closes #809

See merge request tpo/core/arti!1152
2023-05-03 14:34:42 +00:00
Nick Mathewson 1904cfc8b9 Increment crate versions.
Because of the errorkind bumps, we're calling this a breaking change
in everything lower-level than `arti`.

Generated with:
```
cargo set-version -p tor-basic-utils --bump minor
cargo set-version -p tor-async-utils --bump minor
cargo set-version -p caret --bump minor
cargo set-version -p fs-mistrust --bump minor
cargo set-version -p safelog --bump minor
cargo set-version -p retry-error --bump minor
cargo set-version -p tor-error --bump minor
cargo set-version -p tor-config --bump minor
cargo set-version -p tor-events --bump minor
cargo set-version -p tor-units --bump minor
cargo set-version -p tor-rtcompat --bump minor
cargo set-version -p tor-rtmock --bump minor
cargo set-version -p tor-rpcbase --bump minor
cargo set-version -p tor-llcrypto --bump minor
cargo set-version -p tor-protover --bump minor
cargo set-version -p tor-bytes --bump minor
cargo set-version -p tor-hscrypto --bump minor
cargo set-version -p tor-socksproto --bump minor
cargo set-version -p tor-checkable --bump minor
cargo set-version -p tor-cert --bump minor
cargo set-version -p tor-linkspec --bump minor
cargo set-version -p tor-cell --bump minor
cargo set-version -p tor-proto --bump minor
cargo set-version -p tor-netdoc --bump minor
cargo set-version -p tor-consdiff --bump minor
cargo set-version -p tor-netdir --bump minor
cargo set-version -p tor-congestion --bump minor
cargo set-version -p tor-persist --bump minor
cargo set-version -p tor-chanmgr --bump minor
cargo set-version -p tor-ptmgr --bump minor
cargo set-version -p tor-guardmgr --bump minor
cargo set-version -p tor-circmgr --bump minor
cargo set-version -p tor-dirclient --bump minor
cargo set-version -p tor-dirmgr --bump minor
cargo set-version -p tor-hsclient --bump minor
cargo set-version -p tor-hsservice --bump minor
cargo set-version -p arti-client --bump minor
cargo set-version -p arti-rpcserver --bump minor
cargo set-version -p arti-config --bump minor
cargo set-version -p arti-hyper --bump minor

cargo set-version -p arti --bump patch
cargo set-version -p arti-bench --bump patch
cargo set-version -p arti-testing --bump patch
```
2023-05-03 08:31:11 -04:00
Gabriela Moldovan dfc22beddf
netdoc: Mark parse_decrypt_validate as experimental.
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-05-02 17:18:53 +01:00
Gabriela Moldovan b967749325
netdoc: Document how to extract an `HsDesc` out of an `UncheckedEncryptedHsDesc`.
This adds an example to the `HsDesc::parse` docs. The constants from the
example are lifted from the `parse_desc_good` test.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-04-25 18:15:56 +01:00
Gabriela Moldovan 8f4e876924
netdoc: Add a convenience method for HS descriptor parsing.
This adds the `HsDesc::parse_decrypt_validate` method, which parses,
decrypts, and validates HS descriptors.

Closes #809

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-04-25 18:15:53 +01:00
Nick Mathewson 543e089b82 netdoc: Document that particular bit values for flags are not part of our API. 2023-04-17 17:09:58 -04:00
Nick Mathewson 11945e8b4e netstatus: re-number routerstatus flags to go in order.
Otherwise there is too much risk of accidentally adding in another
1<<12 when we meant to add a 1<<13.

(It would be neat to have an alternative to bitflags here that would
auto-number our bitflags for us.)
2023-04-17 16:50:08 -04:00
Nick Mathewson 3985700216 netdir: more documentation on MIDDLE_ONLY flag.
Clarify that it isn't anything that most users will need to check.
2023-04-17 16:48:15 -04:00
juga eee1dbee7a netdoc: Add MiddleOnly flag to RelayFlags
Closes #833
2023-04-17 09:53:04 +00:00
Nick Mathewson 4efb423947 Upgrade our hex-literal dependency 2023-04-13 07:51:26 -04:00
Ian Jackson 835480e98f Merge branch 'remove-hsdesc-todo' into 'main'
Remove misleading TODO.

See merge request tpo/core/arti!1130
2023-04-12 16:52:59 +00:00
Nick Mathewson 104d64589d Increment MSRV to 1.65 in every crate. 2023-04-11 15:31:12 -04:00
Gabriela Moldovan 631a1e1a86
Remove misleading TODO.
The `superencrypted` blob is, in fact, followed by a newline.

See [core/torspec!122].

[core/torspec!122]: https://gitlab.torproject.org/tpo/core/torspec/-/merge_requests/122

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-04-11 19:44:50 +01:00
Ian Jackson 24efbf4df7 tor-netdoc: Tidy up and fix some broken intra-doc links
1. Abbreviate the link text, and don't have it contain `crate`
   which is not really great in docs.

2. Use `super::` for the link target, to find the right thing.
   (`crate` doesn't seem to work in rustdoc, perhaps deliberately,
   although the error messages are ridiculous and claim the
   nonexistence of intermediate modules.)

3. Wrap the lines a bit more.
2023-04-11 19:31:10 +01:00
Ian Jackson 38805f53b2 tor-netdoc: Expose test data under new "testing" feature flag 2023-04-05 11:02:36 +01:00
Ian Jackson 646e291f96 tor-netdoc: Fix feature builds
Fixes
  cargo +stable test --locked --offline F -p tor-netdoc
  cargo +stable clippy -p tor-netdoc F --all-targets
for values of F including
  --all-features
  --features=hs-client
  --features=hs-common
  --features=hs-service
  (nothing)
2023-04-05 11:02:33 +01:00
Gabriela Moldovan 3d0bf0d6ab
Generate a new KP_hss_desc_enc keypair for each new descriptor.
Previously, to build descriptors for hidden services with client auth
enabled, in addition to the list of authorized clients, users of
`HsDescBuilder` were required to also provide a descriptor encryption
keypair and a descriptor cookie. This was potentially dangerous and/or
error-prone, because the ephemeral encryption key and the descriptor
cookie are expected to be randomly generated and unique for each
descriptor.

This change makes `ClientAuth` private to the `hsdesc::build` module and
updates `HsDescBuilder` to build `ClientAuth`s internally. Users now
only need to provide the list of authorized client public keys.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-31 15:04:30 +01:00
Gabriela Moldovan 94a4d2ea43
Remove unnecessary test constant.
It's not really needed, it can just be generated at (test) runtime.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-31 15:04:26 +01:00
Gabriela Moldovan cd66781577
Add an encode-decode test for descriptors with client auth.
This adds a test for an `encode -> decode -> encode` flow for a hidden
service descriptor with client authorization enabled.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-31 15:04:23 +01:00
Gabriela Moldovan 8aa930a645
Use constants instead of magic numbers.
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-31 15:04:19 +01:00
Gabriela Moldovan 2d9d16aabc
Stop requiring the caller to supply `AuthClient`s.
`AuthClient`s were originally meant to represent parsed `auth-client`
lines. In !1070, this struct was repurposed for representing individual
authorized clients in the HS descriptor encoder. However, hidden
services will likely use a list of public keys to represent the
authorized clients rather than a list of `AuthClient`s, as the
information from an `AuthClient` (`client_id`, `iv`, `encrypted_cookie`)
likely won't be immediately available to the hidden service.

This change updates the HS descriptor encoder to represent authorized
clients as a list of `curve25519::PublicKey`s. As such, it is now the
responsibility of the encoder to create the `client_id`, `iv`, and
`encrypted_cookie` using the available keys, the unencrypted descriptor
cookie, and HS subcredential.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-31 15:04:15 +01:00
Nick Mathewson 9ef115a7fb Patchlevel bumps for crates whose dependencies just changed.
These crates had no changes until just a moment ago. But since
we updated the versions on some of their dependents, they have now
changed themselves.  Thus they get patchlevel bumps.

```
tor-rtmock
tor-protover
tor-socksproto
tor-consdiff
tor-chanmgr
tor-dirclient
tor-hsservice
```
2023-03-31 08:30:14 -04:00
Nick Mathewson e208fb15ad Bump crate versions that have breaking changes
These crates have had breaking changes.  They are pre-1.0, so they get
a minor bump.

```
tor-basic-utils
tor-config
```
2023-03-31 08:28:06 -04:00
Nick Mathewson a81ab391ae Bump patchlevel on crates with non-breaking changes
For these crates, the changes are nontrivial, so we
_do_ bump the versions on which their dependent crates depend.

Fortunately, since they are all pre-1.0, we don't need to
distinguish semver-additions from other changes.  (Except for arti,
which _is_ post-1.0, but gets a patchlevel bump anyway.)

These are unstable crates with breaking changes:

```
tor-hscrypto
tor-hsclient
```

These have new or extended APIs:

```
safelog
tor-bytes
tor-cell
tor-linkspec
tor-llcrypto
tor-proto
tor-cert
arti-client
```

These have new unstable APIs or features:
```
tor-netdoc
tor-circmgr (also broke some unstable APIs)
arti (is post-1.0)
```

These have bugfixes only:
```
caret
tor-dirmgr
```
2023-03-31 08:24:39 -04:00
Nick Mathewson 626f47a5cc Merge branch 'fix-broken-doc-links' into 'main'
Fix broken doc link.

See merge request tpo/core/arti!1082
2023-03-30 19:12:01 +00:00
Gabriela Moldovan ef72e927ac
Remove hard-coded test certs.
We can use a deterministic rng to generate predictable keypairs instead.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 19:44:49 +01:00
Gabriela Moldovan 70d247e59c
Make the HS encoder randomness source injectable.
This makes it possible to plug in a deterministic randomness source for
testing.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 19:07:41 +01:00
Gabriela Moldovan a14d95a8a0
Fix broken doc link.
This fixes a broken doc link I introduced in !1070:

```
error: unresolved link to `crate::doc::hsdesc::build::inner::HsDescInnerBuilder`
  --> crates/tor-netdoc/src/doc/hsdesc/build/middle.rs:34:11
   |
34 |     /// [`crate::doc::hsdesc::build::inner::HsDescInnerBuilder`] as described in sections
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `HsDescInnerBuilder` in module `inner`
   |
   = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`

error: could not document `tor-netdoc`
```

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 13:29:24 +01:00
Gabriela Moldovan 1d4069cc7f
Use the type system to enforce use of blinded keys.
Hidden services use blinded singing keys derived from the identity key
to sign descriptor signing keys.

Before this patch, the hidden descriptor builder represented its blinded
signing keys (`blinded_id`) as plain `ed25519::Keypair`s. This was not
ideal, as there was nothing preventing the caller from accidentally
initializing `blinded_id` with an unblinded keypair.

This introduces a new `HsBlindKeypair` type to represent blinded
keypairs.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-27 11:45:51 +01:00
Gabriela Moldovan 71686a9c49 Use transparent structs instead of builders.
The consensus seems to be the builders don't add much value, see [this comment].

[this comment]: https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1070#note_2889488

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan 6da39c0093 Refactor the inner doc tests to be more DRY.
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan 2fda37f5ea Remove `NetdocText` and replace its uses with `String`.
`NetdocText` is a wrapper around a `String` and a type marker. The type
annotation proved of limited use, and made the netdoc builder API
somewhat awkward to use.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00
Gabriela Moldovan 8d0d52f193 Remove some unnecessary visibility restrictions.
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:34 +00:00