Commit Graph

351 Commits

Author SHA1 Message Date
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
Gabriela Moldovan c166c878fe Create a new `IntroPointDesc` type.
Unlike `hsdesc::IntroPointDesc`, `hsdesc::build::IntroPointDesc`
represents link specifiers as `LinkSpec`s rather than
`UnparsedLinkSpec`s.

Since this is a general-purpose representation of an introduction point
and not merely an intermediate representation for decoding/encoding, it
will probably need to be factored out of `tor-netdoc` at some point.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:58:33 +00:00
Gabriela Moldovan 1e3214a8bd Use the less ambiguous inner/middle/outer terminology. 2023-03-24 18:57:53 +00:00
Gabi Moldovan a1074c0027 Add builder for encoding hidden service descriptors.
This introduces the `NetdocBuilder` trait described in
`netdoc-builder.md` and a new `tor-netdoc::doc::hsdesc::build` module,
which exports the `HsDescBuilder`. Hidden services will use
`HsDescBuilder` to build and encode hidden service descriptors.

There are several TODOs in the code that I'm planning to address
separately.

Partially addresses #745.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:57:49 +00:00
Gabriela Moldovan 89ca965d2a Define constants for `AuthClient` field lengths.
These are used in multiple places (and will also be used by the HS
descriptor encoder later on), so let's make them named constants.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:54:35 +00:00
Gabriela Moldovan 1394a81142 Implement `ItemArgument` for `String`.
This makes some code a bit more concise, as it allows us to make
`Strings` into `ItemArgument`s without calling `.as_str()`.

Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
2023-03-24 18:54:35 +00:00
Ian Jackson 70b099fd0f Turn two blocking TODOs in hsdesc into "TODO HS"
TODO HS is blocking for HS release, but not for CI.
2023-03-21 13:08:14 +00:00
Nick Mathewson d6bb8fee0b Upgrade to bitflags 2.0
This version of bitflags now requires us to explicitly list the
traits that we want to derive for our bit-flags structs.
2023-03-13 08:47:14 -04:00
Dimitris Apostolou dedae15446
Fix typos 2023-03-03 13:00:33 +02:00
Nick Mathewson 87d9dd6423 tor-netdoc: Clarify that we must indeed check cert expiration. 2023-03-01 09:49:17 -05:00
Nick Mathewson a4a305c1cf tor-netdoc: Validate inner certs in HsDesc
This makes our implementation behave the same as the C tor
implementation, by validating all of the expiration and signatures
on the certificates in the inner document.

(It is still not semantically necessary to check these certs: the
document in which they appear is already signed by the key with
which they are allegedly signed.)

Closes #744
2023-03-01 09:48:51 -05:00
Nick Mathewson f41449d0bd Patchlevel bumps for remaining changed crates.
These crates have had small code changes, but no API additions:

tor-config
tor-socksproto
tor-cert
tor-chanmgr
tor-ptmgr
tor-guardmgr
tor-circmgr
tor-dirclient
tor-dirmgr
arti
tor-hsservice
tor-congestion

These crates have had API extensions:

fs-mistrust
tor-llcrypto
tor-bytes
tor-checkable
tor-linkspec
tor-netdoc
tor-persist
arti-client
2023-02-28 07:13:27 -05:00
Nick Mathewson 3e1ae65212 Bump tor-units version for breaking change.
(The breaking change was removing `as_days()` from IntegerMinutes.)

We are _not_ calling this a downstream-api breaking change, per
discussion at
https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1012?commit_id=bb2ab7c2a3e0994bb438188511688b5b039cae29#note_2876819
2023-02-28 07:10:00 -05:00
Nick Mathewson 4479d52a88 Bump patch-versions for breaking changes in tor-hs{crypto,client}
These are API breaks, but the crates themselves are currently
100% experimental, so there's no need to bump the minor versions
according to our semver rules.
2023-02-28 07:06:15 -05:00
Ian Jackson f63c7c48af Rename onion-* cargo features to hs-* in tor-* crates
Fixes #756
2023-02-28 11:10:17 +00:00
Nick Mathewson d09273a6e3 Apply a missing cfg_attr(docsrs...) in netdoc 2023-02-21 15:18:46 +00:00
Ian Jackson 750c512264 Merge branch 'unparsed_linkspec' into 'main'
HsDesc: Use a new UnparsedLinkSpecifier to avoid leaking which linkspec types we know

See merge request tpo/core/arti!1029
2023-02-21 15:16:45 +00:00
Nick Mathewson 3233c25943 tor-netdoc: Use UnparsedLinkSpec in IntroPointDesc. 2023-02-17 15:29:37 -05:00
Nick Mathewson 757c6d333f netdoc: Remove a TODO hs comment.
It said to check whether C enforces an absence of extraneous bytes
at the end of the link specifiers.  It does, in
`hs_desc.c:decode_link_specifiers()`, where it says:

```
  if (link_specifier_list_parse(&specs, decoded,
                                (size_t) decoded_len) < decoded_len) {
    goto err;
  }
```

The comparison with "decoded_len" checks whether all the bytes were
decoded.
2023-02-17 15:06:09 -05:00
Nick Mathewson 1297dfb5e3 Merge branch 'doc-iter' into 'main'
tor-netdoc: Abolish PauseAt in favour of using itertools

Closes #760

See merge request tpo/core/arti!1021
2023-02-17 12:34:32 +00:00
Ian Jackson 66beab6c9e tor-netdoc: Fix doc comment following removal of PauseAt 2023-02-16 11:53:32 +00:00
Ian Jackson ca127b013f Expire routerdescs as soon as any of their expiries expire
Fixes #772
2023-02-15 17:41:28 +00:00
Ian Jackson 676241c349 tor-netdoc: Run rustfmt (separately from the refactoring) 2023-02-15 17:17:01 +00:00
Ian Jackson 1993165f22 tor-netdoc: Abolish NetDocReader::iter and into_iter
Nothing uses these now; the NetDocReader is simply an iterator, itself.
2023-02-15 17:17:01 +00:00
Ian Jackson 4a91c732fe tor-netdoc: Remove many needless calls to .iter() and .into_iter() 2023-02-15 17:17:01 +00:00
Ian Jackson fa2e164939 tor-netdoc: Use impl Iterator for NetdocReader in .pause_at
This simplifies the return type!
2023-02-15 17:17:01 +00:00
Ian Jackson db79e3f369 tor-netdoc: impl Iterator etc. for NetdocReader
This will simplify things at many call sites.
2023-02-15 17:17:01 +00:00
Ian Jackson b58977b428 tor-netdoc: move PeekableIterator to util.rs
We're going to want this a bit more widely.
2023-02-15 17:17:01 +00:00
Ian Jackson 11660f84b0 tor-netdoc: Delete now-unused PauseAt type 2023-02-15 17:17:01 +00:00
Ian Jackson 15d93bd642 tor-netdoc: Use itertools to implement NetDocReader::pause_at
This is the last use of PauseAt.
2023-02-15 17:17:01 +00:00
Ian Jackson 089ebb7d11 tor-netdoc: Replace use of PauseAt::new_pred()
We can just make a new PauseAt, since it can take the inner peekable
iterator by mutable reference.

This seems to tidy the code up a bit too.
2023-02-15 17:16:57 +00:00
Ian Jackson 7491424ee9 tor-netdoc: Have sectionrules.parse take I, not &mut I
There's a blanket impl of Itertor for &mut impl Iterator, so this
isn't necessary, and it prevents us passing iterators by value
producing syntactic vinegar.
2023-02-15 17:16:57 +00:00
Ian Jackson 80d8d94c96 tor-netdoc: Import Peekable rather than referring to it by path
This makes things easier to read.  We're about to add another
site (albeit, temporarily).
2023-02-15 17:16:57 +00:00
Nick Mathewson e00dfcf41e netdoc: Add a basic fuzzer for the hsdesc layers.
I've been running this for 5 minutes and haven't found any
crashes. I'll run it for an hour or two, then add the results to the
corpus repository.
2023-02-14 07:49:34 -05:00
Nick Mathewson 79dd2ef995 netdoc: Add a feature to expose hsdesc inner doc parsers
We want to fuzz these parsers, but there's no currently way to get
at the parsers for inner documents without going through a lot of
encryption.  (Coverage-guided fuzzers are powerful, but they
can't find SHA3 preimages.)
2023-02-14 07:44:18 -05:00
Nick Mathewson 74ef8de86f Merge branch 'doc-iter' into 'main'
Introduce new batching iterator and use it in two places

See merge request tpo/core/arti!1016
2023-02-13 18:59:42 +00:00
Ian Jackson 297019bb23 batching_split_before: Whitespace error fix 2023-02-13 17:34:04 +00:00
Ian Jackson b4d0b585c2 batching_split_before: Better xref for doc hidden
And another UNSTABLE warning.
2023-02-13 17:32:54 +00:00
Ian Jackson 1232bb6661 batching_split_before: Clarify API sequential restriction 2023-02-13 17:29:17 +00:00
Ian Jackson 5be6db006c batching_split_before: Fix and clarify Batches/LendingIterator doc 2023-02-13 17:28:39 +00:00
Ian Jackson 15f33ce13c batching_split_before: Introduce unit token types
And explain why we're not using booleans.
2023-02-13 17:19:13 +00:00
Ian Jackson 73a20cdc36 batching_split_before: Expand on the remaining use of "meta-iterator" 2023-02-13 17:13:55 +00:00
Ian Jackson 04e3a22b82 batching_split_before: Fix link to BatchesWithHeader::subsequent 2023-02-13 17:12:17 +00:00
Ian Jackson 53ef0d65ea batching_split_before: Provide description for BatchesWithHeader 2023-02-13 17:09:08 +00:00
Ian Jackson 6799fb6e3e batching_split_before: Document generics on our non-private types 2023-02-13 17:04:29 +00:00
Ian Jackson e44be77f52 batching_split_before: Rename "prefix" to "header"
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1016#note_2877759

"_prefixed" becomes "_with_header".  That mirrors the returned struct
which is nice.
2023-02-13 16:55:36 +00:00