Commit Graph

333 Commits

Author SHA1 Message Date
Nick Mathewson 39f5f90f3f netdoc: Fix most "TODO HS rename" comments 2023-02-08 13:23:21 -05:00
Nick Mathewson 8c3bd3626b netdoc::hsdesc: Distinguish layer from document. 2023-02-08 13:16:44 -05:00
Nick Mathewson 966ddeb092 netdoc::hsdesc: Rename "layer" modules. 2023-02-08 13:08:57 -05:00
Nick Mathewson 964ca511c4 netdoc::hsdesc: Excise reference to "password" authentication
As far as we can tell, this never existed.
2023-02-08 12:57:52 -05:00
Nick Mathewson cce56c793b hscrypto,netdoc: Add and use a type for KP_hss_desc_enc. 2023-02-08 12:50:34 -05:00
Nick Mathewson 99ec1c9818 tor-hscrypto: Rename key types to correspond to new spec names. 2023-02-08 12:27:36 -05:00
Nick Mathewson d1ee5807ed Rename DescriptorCookie to DescEncNonce
(I think it's okay to omit the Hs here, since this type is not
visible outside the hsdesc parsing code. I'll rename if others
disagree.)
2023-02-08 12:10:24 -05:00
Nick Mathewson 39e1116ece Renaming cleanup for and around now-renamed "KP_hs_desc_ephem". 2023-02-08 12:06:42 -05:00
Nick Mathewson 18e8ac7cb6 Rename key identifiers that have changed in the spec
Generated with perl:

s/K([PS])_hs_intro_tid/K$1_hs_ipt_sid/g;
s/K([PS])_onion_ntor/K$1_ntor/g;
s/K([PS])_hs_intro_ntor/K$1_hss_ntor/g;
s/K([PS])_hs_desc_ephem/K$1_hss_desc_enc/g;
2023-02-08 11:57:51 -05:00
Dimitris Apostolou d1eeffbf42
Fix typo 2023-02-08 00:04:25 +02:00
Nick Mathewson f537a7ad48 Update hsdesc parser code to new sectionrules::builder code. 2023-02-07 15:28:10 -05:00
eta c7c4fff66e Merge branch 'authcert_bug' into 'main'
Fix AuthCert behavior on unrecognized tokens, and prevent bug from recurring elsewhere.

Closes #752

See merge request tpo/core/arti!1006
2023-02-07 16:06:20 +00:00
Nick Mathewson a1c36b2087 netdoc: Add a comment about renaming layer to document. 2023-02-07 09:02:15 -05:00
Nick Mathewson 257aaf9e5b netdoc::hsdesc: rename Passwd to Password. 2023-02-07 09:02:15 -05:00
Nick Mathewson 2ba28aa289 netdoc: Rename/comment objects from hsdesc. 2023-02-07 09:02:15 -05:00
Nick Mathewson d10ccf0dc5 netdoc: Rename/comment objects from inner_layer. 2023-02-07 09:02:15 -05:00
Nick Mathewson 1cdd36f511 netdoc: Rename/comment objects from middle_layer. 2023-02-07 09:02:15 -05:00
Nick Mathewson 1a59005ae0 netdoc: Rename/comment objects from desc_enc 2023-02-07 09:02:15 -05:00
Nick Mathewson 7701e02aad netdoc: Renaming and comments in outer_layer. 2023-02-07 09:02:15 -05:00
Nick Mathewson 68d2ccf5fe netdoc: Use Itertools::exactly_once in hsdesc parsing 2023-02-07 09:02:15 -05:00
Nick Mathewson 3d53a30c94 netdoc: Remove useless should_be_exhausted calls. 2023-02-07 09:02:15 -05:00
Nick Mathewson cff2326f6f Remove a needless line. 2023-02-07 09:02:15 -05:00
Nick Mathewson fbffd3168c Even more clarifying comments. 2023-02-07 09:02:15 -05:00
Nick Mathewson 328535855a netdoc: Try to add a bunch of clarifying documentation.
In the process I found a couple of keys without identifiers in the
spec.
2023-02-07 09:02:15 -05:00
Nick Mathewson 6954c6b488 netdoc: Use Signature::from to construct ed25519 sigs. 2023-02-07 09:02:15 -05:00
Nick Mathewson 4c24f8e8a2 netdoc: Clear up a few typos in hsdesc comments and strings. 2023-02-07 09:02:15 -05:00
Nick Mathewson d699742400 netdoc: Implement onion service descriptor parsers. 2023-02-07 09:02:15 -05:00
Nick Mathewson 23757d90c1 netdoc: Parse the inner layer of an onion service descriptor.
There are some places where I note certificates which are not
currently validated, because there is no cryptographic point in
doing so.  We should either document that this is okay, or validate
the certificates anyway.

This code might benefit from refactoring to make it prettier.
2023-02-07 09:02:15 -05:00
Nick Mathewson 6817f61641 netdoc: Add a workaround for C Tor's lack of mid-layer NL
It turns out that C Tor doesn't add a newline at the end of the
middle layer of an onion service descriptor.  I've made a spec MR
(torspec!109) to document this: here, it's time to work around the
issue.
2023-02-07 09:02:15 -05:00
Nick Mathewson 4be4d178fa netdoc: Parse the middle layer of a hsdesc, and decrypt it. 2023-02-07 09:02:15 -05:00
Nick Mathewson 321c8582ce netdoc: Use correct size for descriptor encryption cookie 2023-02-07 09:02:15 -05:00
Nick Mathewson d8849f583e netdoc: move test descriptor to a higher level test module
We're going to make use of it in all of our tests, so we may as well
expose it to them from hsdesc::test.
2023-02-07 09:02:15 -05:00
Nick Mathewson 02fa682bc0 netdoc: implement onion service descryptor encryption
This is tested via a round-trip check, and via a successful
decryption of our example descriptor's outer layer.
2023-02-07 09:02:13 -05:00
Nick Mathewson 6c4e9c8f1d netdoc: Parser for outer layer of onion service descriptors. 2023-02-07 09:00:19 -05:00
Nick Mathewson d35e8a751d netdoc: Add an example onion service descriptor to test our parsing.
I generated this using C tor (latest main) and a Chutney network
about a week ago.

The subcredential is:
   78210A0D2C72BB7A0CAF606BCD938B9A3696894FDDDBC3B87D424753A7E3DF37
The HS_blind_id is:
   43CC0D62FC6252F578705CA645A46109E265290343B1137E90189744B20B3F2D
2023-02-07 09:00:19 -05:00
Nick Mathewson 0f1cfc308a netdoc: Derive Debug and Clone on HsDesc and its kin. 2023-02-07 09:00:19 -05:00
Nick Mathewson 73199ebf68 netdoc: Require that unrecognized tokens be handled explicitly.
Now we require that, for all `SectionRules`, either the caller say
how to handle unrecognized tokens (using `.add(UNRECOGNIZED...)`),
or that they explicitly reject unrecognized tokens (using
`reject_unrecognized`()`.)

This solution uses an assert!() rather than an Error to indicate
failure.  I say that's fine, since
  1. This is a crate-internal API.
  2. We never dynamically construct SectionRules according to
     different behavior: they are always prefabricated in a fixed
     code block.  Thus, if we test a parser at all, we will make
     sure that its SectionRules are well-formed.

I considered and explicitly rejected a solution where the builder
had to be finalized with separate methods `build_strict()` or
`build_tolerant()`: It's too easy IMO for the caller to forget what
these call means.

Prevents further recurrences of #752.

Closes #752.
2023-02-03 11:33:30 -05:00
Nick Mathewson 13d5452e2e netdoc: Switch SectionRules building to use a Buidler pattern.
No new behavior yet.
2023-02-03 11:14:00 -05:00
Nick Mathewson 266c61f721 Add a rule to handle UNRECOGNIZED in AuthCert.
This fixes an instance of bug#752.  Previously, we would reject any
AuthCert that contained an unexpected keyword.  (Fortunately, this
data format does not change very often.)
2023-02-03 10:53:23 -05:00
Ian Jackson 5bca38acc5 tor-netdoc: Suppress a cfg-dependent dead code warning
This is dead code when
  cargo +stable clippy -p tor-netdir --all-features --all-targets
2023-02-01 18:46:54 +00:00
Nick Mathewson 7c1b6a5a81 Bump the patch version of every crate that had API additions
These crates had API or behavior changes that may affect downstream
crates. Fortunately, they're all version 0.x, and don't need minor
bumps for this.
2023-02-01 10:36:29 -05:00
Nick Mathewson 66f594a4b6 Bump the patch-level version of crates with _minor_ changes.
These changes influence behavior, but not effect compatibility.
(If I messed up, and any crate except for `arti` has non-breaking
API changes, that's still fine, since they are all version
0.x.)
2023-02-01 10:23:58 -05:00
Nick Mathewson 2490b3cdc6 Use derive_more on SharedRandVal
This may be temporary if we wind up converting to CtByteArray,
but for now it's good to be terse.
2023-01-28 12:43:08 -05:00
Ian Jackson a51c76178e Several suggestions on gitlab. 2023-01-28 12:43:08 -05:00
Nick Mathewson 9f3e6783ca netdoc: Add Eq and a note to SharedRandVal. 2023-01-28 12:12:17 -05:00
Nick Mathewson 790b38eec8 netdoc: Add SRV accessors.
These are deliberately unsophisticated accessors, in that they return Option<>
rather than filling in missing values with the documented
fallbacks. It seems better to leave a way to distinguish the absent
case in the API.
2023-01-28 12:12:17 -05:00
Nick Mathewson c1ced84239 netdoc: Add a timestamp to SRVs per prop#342.
This breaks some experimental APIs, but since they are experimental
no semver note is needed.
2023-01-28 12:12:17 -05:00
Nick Mathewson 8ce447b7e2 netdoc: Add Iso8601 time _with_ a "T" as an argument type. 2023-01-28 12:12:17 -05:00
Dimitris Apostolou 3da36c5c8b
Fix typos 2023-01-28 01:31:10 +02:00
Nick Mathewson a6dd92843e Allow clippy::unchecked_duration_subtraction in tests
This panics on error, and we're fine with a panic on misbehavior in
tests.
2023-01-27 08:28:02 -05:00
Nick Mathewson ed74c62931 Elide a bunch of lifetimes.
Clippy now warns about these; I'm not sure how these warnings snuck
up on us.
2023-01-27 08:28:02 -05:00
Nick Mathewson bf04641c68 Disable clippy::unlinlined-format-args
This warning kind of snuck up on us! (See #748)  For now, let's
disable it.  (I've cleaned it up in a couple of examples, since
those are meant to be more idiomatic and user-facing.)

Closes #748.
2023-01-27 08:27:47 -05:00
Ian Jackson 92ba020534 Add missing docsrs attribute 2023-01-24 16:19:05 +00:00
Ian Jackson 15a543d738 netdoc builder: Add two TODOs, prompted by testing experience 2023-01-24 16:15:17 +00:00
Ian Jackson be1cd7789d netdoc builder test: Make a bigger dummy document and test reparsing 2023-01-24 16:15:17 +00:00
Ian Jackson eb3b261595 netdoc builder: Implement object() and add one test case 2023-01-24 16:15:17 +00:00
Ian Jackson 4f0d17d96d netdoc-builder: Initial test case (no object yet) 2023-01-24 16:15:17 +00:00
Ian Jackson 066eb12f50 netdoc-builder: Provide new() method 2023-01-24 16:15:17 +00:00
Ian Jackson e989871a7b netdoc-builder: Implement ItemArgument for more needed types 2023-01-24 16:15:17 +00:00
Ian Jackson 94fec1e12c netdoc-builder: Remove some obsolete comments 2023-01-24 16:15:17 +00:00
Ian Jackson 16c4fee4b8 netdoc-builder: Move example into implementation doc comment
Not actually tested yet
2023-01-24 16:15:17 +00:00
Ian Jackson 8f725a19f8 netdoc-builder: Implement most of the internal general doc builder 2023-01-24 16:15:17 +00:00
Ian Jackson 22cf060426 netdoc-builder api: Clarify docs for object() 2023-01-24 16:15:17 +00:00
Ian Jackson c7e816d263 netdoc-builder api: Introduce ItemArgument trait 2023-01-24 16:15:17 +00:00
Ian Jackson eac7befc87 netdoc-builder api: Have .item() return ItemBuilder
This was a slip in the design doc.
2023-01-24 16:15:17 +00:00
Ian Jackson 8c8ff4948f netdoc-builder api: Abolish `K` generic on ItemEncoder
We're going to eagerly encode the keyword, so this will be easy.
Removing the generic simplifies the API.
2023-01-24 16:15:17 +00:00
Ian Jackson 669a399c46 netdoc-builder api: Don't promise to check args_raw_string value 2023-01-24 16:15:17 +00:00
Ian Jackson 2bc7a371b4 netdoc-builder api: Make ItemEncoder methods consume and return self
This will actually make the pattern in the example work.

The mentioned `ItemArgument` trait will arrive soon.
2023-01-24 16:15:17 +00:00
Ian Jackson 5fccbce160 netdoc-builder api: Move internal API into actual code file (fmt) 2023-01-24 16:15:17 +00:00
Ian Jackson e971d1ad59 netdoc-builder api: Move internal API into actual code file
Motion, plus the bare minimum needed to make it compile.
2023-01-24 16:15:17 +00:00
Ian Jackson f735a128bb tor-netdoc: tokenize: Provide BASE64_PEM_MAX_LINE
We'll use this in the netdoc builder, but it naturally lives here.
2023-01-24 16:15:17 +00:00
Ian Jackson c8ac951cf5 tor-netdoc: tokenize: Rename to tag_keywords_ok, document, expose
Rename from _keyword_, since this actually checks the *multiple*
keywords that can appear in an object's BEGIN line.

Make this clear in the doc comment.

Expose it for use by the netdoc builder.
2023-01-24 16:15:17 +00:00
Ian Jackson a8ab0a5f46 tor-netdoc: tokenize: crate-Expose object::BEGIN_STR etc.
The document builder wants these too.
2023-01-24 16:15:17 +00:00
Ian Jackson 5bd54f3701 tor-netdoc: Make AuthCertKwd pub(crate)
For now, this will be useful in a test.
2023-01-24 16:15:17 +00:00
Ian Jackson 4e6f5b7ff3 Do not .gitignore crates/*/fuzz/corpus
These are symlinks which are actually checked in.  They should not be
ignored.  (This caused trouble for some of my privsep tooling...)
2023-01-20 17:29:00 +00:00
Nick Mathewson 2c41321710 Netdoc: Refactor SharedRandVal.
SharedRandVal now holds only the 32-byte random value itself; the
"number of commits" field is in SharedRandStatus.

This commit also makes the SharedRandVal be exactly 32 bytes, since
we've set it to that value in the spec.
2023-01-11 09:04:12 -05:00
Nick Mathewson eba937e54c netdoc: Outline some basic types for encoding HsDescs. 2023-01-06 13:03:50 -05:00
Nick Mathewson e650e07cd4 netdoc: note some changes we will have to make to srv 2023-01-06 13:03:50 -05:00
eta 118050e54c Merge branch 'test-lints' into 'main'
Add test lint blocks to all "mod test"

See merge request tpo/core/arti!937
2023-01-06 17:16:09 +00:00
Neel Chauhan a180f911bd Use parse_rfc3339() in the tor-netdoc crate 2022-12-16 12:56:00 -08:00
Ian Jackson 125a455bdc test lint blocks: Add many many automatically
This is precisely the result of running the rune in
maint/adhoc-add-lint-blocks.
2022-12-12 18:00:30 +00:00
Ian Jackson baf78361e8 test lint blocks: Do some semi-manually
This is the hunks from running the rune in maint/adhoc-add-lint-blocks
but which require some subsequent manual fixup: usually, deleting
now-superfluous outer allows, but in some cases manually putting back
lints that the adhoc script deleted.
2022-12-12 18:00:29 +00:00
coral 25f113b8b3 Tackling issue #663 (Use humantime in tests) 2022-12-12 17:41:22 +00:00
Nick Mathewson e0aeda3071 Remove semver.md files now that 1.1.0 is released. 2022-11-30 17:10:29 -05:00
Nick Mathewson 38bef96b99 Bump the minor version of every crate.
We made this job easy this time around: by incrementing our MSRV, we
have forced ourselves to do at least a minor bump everywhere.
2022-11-30 15:10:16 -05:00
Ian Jackson d78295929b Merge branch 'more_netdoc_tests' into 'main'
tor-netdoc: More tests for routerdesc accessors and parsing.

See merge request tpo/core/arti!870
2022-11-29 11:11:47 +00:00
Nick Mathewson 829cb708e2 Fix a couple of rustdoc issues.
These slipped in while nightly was broken.
2022-11-18 10:19:54 -05:00
Nick Mathewson d51162e55b Fix a bunch of "needless borrow" warnings on nightly
It looks like, despite a few false starts, they've got this warning
right; there weren't any false positives.
2022-11-18 10:12:05 -05:00
Nick Mathewson cb3a790084 netdoc: Add a test for routerdesc family parsing. 2022-11-17 14:40:15 -05:00
Nick Mathewson 5655b95b54 netdoc: Correct and test some tricky routerdesc errors
These required hex-editing identity certificates :P
2022-11-17 14:35:40 -05:00
Nick Mathewson c0bc7bb11e netdoc: Add tests for routerdesc accessors. 2022-11-17 13:43:32 -05:00
Nick Mathewson 9f53a79ddf Netdoc: use a different desc in tests.
This is from Akka, which ahf runs.
2022-11-17 13:25:05 -05:00
Ian Jackson b46d1600e7 Merge branch 'real_netdoc_pos' into 'main'
Replace `Option<Pos>` with `Pos` in `ParseError`.

Closes #640

See merge request tpo/core/arti!859
2022-11-16 11:50:20 +00:00
Nick Mathewson 7a42cb0e45 Remove a `TODO pt-client` in netdoc.
This issue is now torspec!94.
2022-11-15 17:19:26 -05:00
Nick Mathewson 39615516fd Replace `Option<Pos>` with `Pos` in `ParseError`.
We already have `Pos::Unknown` for an error at an unknown
location and `Pos::None` for an error where no location is
sensible. There's no reason to have an additional `Option` here.

Additionally, the use of `Option` gave us a bug where our old
`ParseError::at_pos()` method didn't actually set the position
unless the position was already set.  That's not what we want!

Fixes #640.

Finally, we have to fix a test that was a bit broken because it was
working around #640.
2022-11-15 16:58:23 -05:00
Nick Mathewson 2bd422663e Resolve a dead-code warning. 2022-11-15 13:53:14 -05:00
Nick Mathewson 89be046466 netdoc: Allow empty lines at the end of a router descriptor. 2022-11-15 11:27:43 -05:00
Nick Mathewson bc7780bffd tor-netdoc: Add a new ErrorKind for EmptyLine.
Empty lines were previously reported as BadKeyword, which is
confusing.
2022-11-15 11:27:43 -05:00
Nick Mathewson 9c9f9bbd25 Merge branch 'guardmgr-todo-misc' into 'main'
Resolve most "TODO pt-client" comments in GuardMgr

See merge request tpo/core/arti!840
2022-11-10 17:50:34 +00:00
Nick Mathewson dcfb4d0956 RouterDesc: Add an or_ports method. 2022-11-10 12:11:28 -05:00