Commit Graph

3819 Commits

Author SHA1 Message Date
Nick Mathewson 9c4bdb8d8d tor-proto: Make send_control_message wait for the reactor.
This way we don't need to worry about race conditions that happen if
the caller thinks that the handler is installed before it really is.
2023-03-08 14:21:33 -05:00
Nick Mathewson 7da5d7a8d7 Serval rustdoc link fixes. 2023-03-08 14:21:33 -05:00
Nick Mathewson fe6e7e52e3 Fix an unrelated missing cfg_attr. 2023-03-08 14:21:33 -05:00
Nick Mathewson fc31bf4e25 tor-proto: Have send_control_message install a handler, not return a stream 2023-03-08 14:21:33 -05:00
Nick Mathewson bc83d1e1de tor-proto: Implement functionality to send a message and accept replies
This new function combines "sending a message" and "accepting
replies in a stream" into a single call, so that there is no gap
between when the message is sent and the replies are available.

There are a number of compromises here, in order to avoid API
proliferation. I've tried to contain them as best I can.

See comments for additional design discussion.
2023-03-08 14:21:33 -05:00
Nick Mathewson 094fdc0d8d tor-proto: Change semantics of MetaCellHandler
Now, the MetaCellHandler is responsible for consuming the messages
it gets, and reporting status to whatever task is waiting for a
status message.

Additionally, the MetaCellHandler can decide to remain installed or
shut down the circuit after a successful message.  (Previously, it
could only uninstall itself on success and kill the circuit on
failure.)

These changes will enable MetaCellHandlers to be used as the basis
for handling more kinds of message.

(There is some moved and reformatted code here; you may want to
review it with `git {diff or show} --color-moved -b`.)
2023-03-08 14:21:33 -05:00
Nick Mathewson 7108f923e0 tor-proto: Give Path a method to access final hop num. 2023-03-08 14:21:33 -05:00
Nick Mathewson 5586a29f62 tor-proto: Give circ Reactor a constructor, and make its fields private. 2023-03-08 14:21:33 -05:00
Nick Mathewson 0df1a4a704 Merge branch 'introduce2_encrypted_portion' into 'main'
tor-cell: Add code for the payload of an hs-ntor handshake.

See merge request tpo/core/arti!1052
2023-03-08 19:20:38 +00:00
Ian Jackson 198a95c74c Merge branch 'host2' into 'main'
arti-client: Do not send resolve requests for IP addrs to exits

See merge request tpo/core/arti!1057
2023-03-08 19:10:23 +00:00
Ian Jackson f15498bc3f arti-client: Host: Be more explicit about what is allowed in Hostname 2023-03-08 18:48:28 +00:00
Ian Jackson c1ae509ce6 Introduce and use ends_with_ignore_ascii_case
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1056#note_2884428
2023-03-08 18:27:42 +00:00
Ian Jackson 939027492e Rustfmt 2023-03-08 18:15:32 +00:00
Ian Jackson 257b761042 Abolish Host::into_string_and_port
When I was trying to add HS support to these layers, I found I could
add a new variant to the `Host` enum but everything would still
compile even though I hadn't written the necessary implementation!

This method is a liability: when using it, one inevitably writes such
latent bugs.
2023-03-08 18:15:32 +00:00
Ian Jackson 5df19bc888 arti-client: Do not send resolve requests for IP addrs to exits
Doing so doesn't seem like a good idea.  It might even be some kind of
leak?

Found because I added a variant to `address::Host` for hidden
services, and noticed that the resolve code still compiled.
2023-03-08 18:15:32 +00:00
Ian Jackson fd42ada54c arti-client addr handling: Introduce StreamInstructions 2023-03-08 18:09:57 +00:00
Nick Mathewson 2b9506ae67 intro_payload: various doc fixes and TODOs from review. 2023-03-08 12:27:05 -05:00
Ian Jackson 6540f260b5 arti-client: Reject .onion, when we should, without allocating
Use new strip_suffix_ignore_ascii_case
2023-03-08 17:26:47 +00:00
Ian Jackson 8d031a7147 Use strip_suffix_ignore_ascii_case to quickly reject non-.onion HsId (fmt) 2023-03-08 17:26:47 +00:00
Ian Jackson 80b69b9900 Use strip_suffix_ignore_ascii_case to quickly reject non-.onion HsId 2023-03-08 17:26:47 +00:00
Ian Jackson 440a0eb74f tor-basic-utils: Provide str.strip_suffix_ignore_ascii_case
We're going to want this for cheaply stripping ".onion" from things.
2023-03-08 17:26:47 +00:00
Nick Mathewson 5d5e8d8337 tor-cell: Be a little more pedantic about INTRODUCE cell types. 2023-03-08 09:50:11 -05:00
Nick Mathewson 028bf6d2bc tor-cell: Better describe the parts of intro payload. 2023-03-08 09:41:22 -05:00
Ian Jackson 13b1adb55e Merge branch 'bug779' into 'main'
tor-dirmgr: Don't try to mark consensus usable in a read-only store.

Closes #779

See merge request tpo/core/arti!1055
2023-03-08 14:31:37 +00:00
Ian Jackson edc9ace4c1 Merge branch 'fuzzing_tor_bytes' into 'main'
tor-bytes: defend against misuse of extract_n().

See merge request tpo/core/arti!1053
2023-03-08 14:27:53 +00:00
Nick Mathewson ac5469d0b6 tor-dirmgr: Don't try to mark consensus usable in a read-only store.
Doing this means that any attempt to use a read-only store would
crash as soon as it found that the consensus was usable.

It seems that this bug was introduced at some point doing all the
dirmgr refactors we did over the past year.  Perhaps there should be
a test for running with a read-only store.

Fixes #779
2023-03-08 07:08:17 -05:00
Ian Jackson 034d1dfe81 Merge branch 'hsonion' into 'main'
Impl FromStr and Display for HsId, etc.

See merge request tpo/core/arti!1054
2023-03-07 19:27:34 +00:00
Ian Jackson 7081b73c92 Impl Redactable for HsId 2023-03-07 19:03:28 +00:00
Ian Jackson ab8350b712 Debug HsId as the .onion; retain the hex printing as {:x} 2023-03-07 16:33:10 +00:00
Ian Jackson 641e99af98 impl Display for HsId 2023-03-07 16:32:27 +00:00
Nick Mathewson 9cc09f97a9 tor-bytes: Add take_rest and read_nested_* to fuzzer. 2023-03-06 12:39:57 -05:00
Nick Mathewson dab21bc624 tor-bytes: defend against misuse of extract_n().
Previously, if somebody wrote this code, an attacker could easily
use it to cause an OOM panic:

```
let n = r.take_u64();
let items: Vec<Foo> = r.extract_n(n as usize)?;
```

The first line of defense here is not to write protocols like that:
we don't actually _have_ any 32-bit counters in our protocol
AFAICT.

The second line of defense is to pre-check `n` for reasonableness
before calling `extract_n`.

Here we add a third line of defense: whereas previously we would do
`Vec::with_capacity(n)` in `extract_n`, we now allocate an initial
capacity of `min(n, r.remaining())`.  This ensures that the size of
the allocation can't exceed the remaining length of the message,
which (for our cell types at least) should prevent it from
overflowing or running OOM.
2023-03-06 12:33:10 -05:00
Nick Mathewson 1254a8b86e tor-cell: Add code for the payload of an hs-ntor handshake.
(This is the encrypted information inside the INTRODUCE2 cell; it's
used by the client to tell the service where to find its rendezvous
point.)
2023-03-06 08:46:40 -05:00
Nick Mathewson 7129807843 tor-linkspec: Add a constructor for UnparsedLinkSpec 2023-03-06 08:45:05 -05:00
Dimitris Apostolou dedae15446
Fix typos 2023-03-03 13:00:33 +02:00
Ian Jackson e60ab8087d Merge branch 'hs_cert_inner_validation' into 'main'
tor-netdoc: Validate inner certs in HsDesc

Closes #744

See merge request tpo/core/arti!1044
2023-03-02 16:45:19 +00:00
Ian Jackson fd0d50a330 hsclient: Discuss HsClientConnector multiplicity/reuse
And delete the associated TODO.
2023-03-01 18:12:29 +00:00
Ian Jackson 1fc93b4215 hsclient: Remove TODOs about circular references
These Arcs are all "downward", referencing items from layers lower in
the stack.  So they don't cause cycles.

There was going to be a cycle involving the `OnionConnector` upcall
trait, but we have just abolished that.
2023-03-01 18:12:29 +00:00
Ian Jackson bf2c0d6ff8 hsclient: Abolish knowledge of HS circuits in circmgr
Abolish CircMgr::get_or_launch_onion_client and everything to support
it.  We have decided that `.onion` diversion ccan't/shouldn't occur in
tor-circmgr.  Probably, it should occur much higher up - arti-client
maybe - since it will sometimes need ambient authority (KS_hsc_*).

Now all knowledge of HS connections is in tor-hsclient.  This
gets rid of a layering inversion and the trait needed for tor-circmgr
to do the upcall to tor-hsclient.
2023-03-01 18:12:29 +00:00
Nick Mathewson ee666fb0b7 Merge branch 'rename_rend_message' into 'main'
tor-cell: Rename Rendezvous*::message to handshake_info.

See merge request tpo/core/arti!1045
2023-03-01 18:04:00 +00:00
Nick Mathewson 07b1c3a505 tor-cell: Rename Rendezvous*::message to handshake_info.
Follow-up from !1038
2023-03-01 12:38:27 -05:00
Ian Jackson c23c3faecb Merge branch 'hsconn' into 'main'
Implement HS state management

See merge request tpo/core/arti!1034
2023-03-01 17:23:55 +00:00
Nick Mathewson 992078ee43 Merge branch 'establish_intro_yet_once_more' into 'main'
Revise EstablishIntro messages so that they can generate and check their MAC and signature.

See merge request tpo/core/arti!1043
2023-03-01 17:10:49 +00:00
Ian Jackson 7230f89b32 hsclient isol_map: Use 1:1 notation in diagram to show correspondence 2023-03-01 16:39:03 +00:00
Ian Jackson fea656d7ee hsclient isol_map: Document invariant, fix comment, terminology
Use the occupied/vacant terminology that the slotmap docs use.
2023-03-01 16:39:03 +00:00
Ian Jackson d4d02fa4e9 hsclient state: Rename rechecks (from attempts) and add clarifying docs
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2882079
2023-03-01 16:39:03 +00:00
Ian Jackson 649d0e0d25 hsclient keys: Be more explicit about HsClientSecretKeys nullable
It can contain no keys; state this more prominently, and explain what
it represents.  Also fix a few typos etc.
2023-03-01 16:39:03 +00:00
Ian Jackson b2139731ac hsclient state: Implement and test MultikeyIsolatedMap::retain 2023-03-01 16:39:03 +00:00
Ian Jackson b6fc44aa71 hsclient state: Split off MultikeyIsolatedMap 2023-03-01 16:39:03 +00:00
Ian Jackson 90a7e82fcd hsclient state: Move all the data fields into the table
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2881576

This is a singificant simplification, in fact.
2023-03-01 16:39:03 +00:00
Ian Jackson 76a2e82205 tor-llcrypto: Add a TODO re impl Redactable for HsId 2023-03-01 16:39:03 +00:00
Ian Jackson 08ede75905 hsclient: Clarify period task handle TODO 2023-03-01 16:39:03 +00:00
Ian Jackson e6aa199da6 hsclient: Document sharing rules
Text largely from
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2881638
2023-03-01 16:39:03 +00:00
Ian Jackson cfa33e53d5 hsclient state: rustfmt
Autogenerated with rustfmt; no code changes.

This tidies up the bizarre formatting.
2023-03-01 16:39:03 +00:00
Ian Jackson 597601e4a3 hsclient state: Lots more doc comments about barriers, structure, etc. 2023-03-01 16:39:03 +00:00
Ian Jackson 0b39a180b0 hsclient state: Break `obtain` out into a fn
This is getting rather confusing; simply reformtting it won't do, I
think.  Also there would be much rightward drift.

So move the meat out into the new function.
(And introduce a convenience alias for its captures.)

Docs and reformatting will follow in a moment.
2023-03-01 16:39:03 +00:00
Ian Jackson a93a7b4bab hsclient state: Demonstrate that our future is now Send 2023-03-01 16:39:03 +00:00
Ian Jackson 1f03e118ef hsclient state: Restructure using a scope to drop the mutex guard
Explicit drops don't work.  Instead, introduce a scope.

We need two scopes, actually: one where we do the initial table
wrangling, and one for the retries after relock.

So we must put the meat in a closure so we can reuse it.
And we must return the flow control as an enum.  Bah, etc.

Avoid reformatting this for the moment.  This makes the delta legible...
2023-03-01 16:39:03 +00:00
Nick Mathewson 93a0b72105 tor-cell: Use a match when checking auth_key_type 2023-03-01 11:34:49 -05:00
Nick Mathewson dbecdb53aa tor_cell: Use nested readers and writers for EstablishIntro 2023-03-01 11:32:56 -05:00
Nick Mathewson c8cc4a80c3 tor-cell: tweak comments on EstablishIntro members. 2023-03-01 11:27:45 -05:00
Ian Jackson d1863c3178 hsclient state: Break out ServiceState::blank
We're going to have another function which will want this.
Leave a convenience closure to capture the runtime.
2023-03-01 16:27:19 +00:00
Ian Jackson 4f5f378516 hsclient state: Move error inspection before guard re-lock.
This is still correct from a lock hierarchy pov.  It moves the guard
relock to the end, which is going to be necessary since it is going to
have to move right outside the loop.
2023-03-01 16:27:19 +00:00
Ian Jackson 1e905763e3 hsclient keys: Add a todo to remove spurious Option 2023-03-01 16:27:19 +00:00
Ian Jackson 7134ddd454 hsclient keys: Compare all empty sets of keys as equal
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1034#note_2881575
2023-03-01 16:27:19 +00:00
Ian Jackson 5da60ff72d hsclient keys: Fix non-equal keys test to provide a (dummy) key (fmt) 2023-03-01 16:27:19 +00:00
Ian Jackson ff55d7b133 hsclient keys: Fix non-equal keys test to provide a (dummy) key
We're about to fix the comparison to treat all empty key sets as
equal.
2023-03-01 16:27:19 +00:00
Ian Jackson e3e66793c4 hsclient keys: Provide :none() and Default and .is_empty() 2023-03-01 16:27:19 +00:00
Ian Jackson 896ea10b7f hsclient keys: Fix a missing full stop 2023-03-01 16:27:19 +00:00
Ian Jackson ab163cf81a hsclient state: Test most important code paths 2023-03-01 16:27:19 +00:00
Ian Jackson 8e088d72d5 hsclient: Provide some missing debug impls and trace messages 2023-03-01 16:27:19 +00:00
Ian Jackson 83b8eb7349 tor-hscrypto: Provide manual Debug impl for HsId
This is still not great, but it at least makes the output plausible to
read by eye.
2023-03-01 16:27:19 +00:00
Ian Jackson 288b7b6ad1 Apply rustfmt 2023-03-01 16:27:19 +00:00
Ian Jackson d384c3b475 hsclient state: Provide one test 2023-03-01 16:27:17 +00:00
Nick Mathewson 5131703c22 Introduce a constant for the length of the output of hs_mac() 2023-03-01 11:26:35 -05:00
Nick Mathewson b36082255b tor-bytes: Clarify that Cursor is not a good thing, and could be neater. 2023-03-01 11:21:52 -05:00
Ian Jackson d7602c5be4 hsclient: Use a generic to provide a mock for connect()
This will allow us to test state.rs.
2023-03-01 16:20:16 +00:00
Ian Jackson feab6faa9e tor-circmgr: Provide testing feature and TestConfig
Like the similar thing in tor-guardmgr.
2023-03-01 16:20:16 +00:00
Ian Jackson 9ebe22756e hsclient: Apply standard lint block 2023-03-01 16:20:16 +00:00
Ian Jackson ff1be04012 hsclient: Move dead code allows to specific locations 2023-03-01 16:20:16 +00:00
Ian Jackson b430c65ddb hsclient: Add vacuous comments as demanded by clippy 2023-03-01 16:20:16 +00:00
Ian Jackson bac3c4a9a4 hsclient state: Bind a variable to stop rustfmt doing a terrible thing 2023-03-01 16:20:16 +00:00
Ian Jackson 76a160d5a7 hsclient: Provide a constructor for HsClientConnector 2023-03-01 16:20:16 +00:00
Ian Jackson e8b5195281 hsclient: Implement connection attempt tracking state machine
This compiles, but it cannot work yet.  Nor can it conveniently be tested.
2023-03-01 16:20:16 +00:00
Ian Jackson 4ec9ec92bc HS secret keys: Move aggregate/config to tor-hsclient
Provide a more cookied "secret keys for use to connecting to a
particular HS" type, with a builder.

This wants to use config stuff, so oughtn't to be in tor-*crypto.
The individual types remain there.
2023-03-01 16:19:31 +00:00
Nick Mathewson 03df452f7b tor-cell: Rename EstablishIntro{Body => Details} 2023-03-01 11:18:50 -05:00
Ian Jackson 891782122d hsclient API: Remove notion of ambient keys fromk this layer 2023-03-01 16:18:09 +00:00
Ian Jackson a45acb3905 HS API: Remove HS client keys from circmgr API
*If* we're going to retain any HS knowledge in circmgr, it definitely
doesn't need to know about per-operation client secrets.

(Maybe there might be ambient secrets, used for .onion diversion, but
they don't need to be in this API.)
2023-03-01 16:18:09 +00:00
Ian Jackson feeb38c750 HS planning: Discuss whether to remove all HS code from circmgr 2023-03-01 16:18:09 +00:00
Ian Jackson 06e6e11886 HS planning: Intend for HS connector to do all lifecycle mgmt
Otherwise there has to be a state entry in the circmgr *and* a state
entry in the hs connector, for every HS.  This division of
responsibilit will be confusing.

The HS code will then be more completely just a layer on top of circmgr.
2023-03-01 16:17:47 +00:00
Ian Jackson bab32c6038 clarify results of misusing cursors 2023-03-01 15:57:14 +00:00
Nick Mathewson 1251796039 Merge branch 'more_hs_msgs' into 'main'
Implement most remaining HS cell types

See merge request tpo/core/arti!1038
2023-03-01 14:50:35 +00: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 53e44b58f5 tor-cell: Fix compilation for fuzzers
(I also ran them a couple billion iterations, and didn't hit
any bugs.)
2023-03-01 07:39:17 -05:00
Nick Mathewson 8c9a1a6fad tor-cell: Make EstablishIntro do signatures
The old code parsed and encoded a signature and a mac... but there
was no way to actually set them properly.  Now EstablishIntro is
built around an EstablishIntroBody, and has the ability to check
signatures and macs.

Because there is no way to handle one of these messages if we can't
check the signature, we no longer accept unrecognized `auth_key` types
in this message.

I've added a test to make sure that we can validate a message from the
C tor implementation, and a test to make sure we can validate our
own cells.  I also had to modify the previous tests so that their
keys were well-formed.
2023-03-01 07:38:56 -05:00
Ian Jackson 22bb5bacc0 Merge branch 'main' into 'main'
Use humantime in tor-checkable and tor-guardmgr

Closes #663

See merge request tpo/core/arti!1037
2023-02-28 19:22:53 +00:00
Nick Mathewson 0f88c5131f tor-bytes: impl Readable and Writeable for CtByteArray. 2023-02-28 11:23:44 -05:00
Nick Mathewson d658fcfc52 Expose a little new functionality from tor-llcrypto.
Expose ED25519 signature length; make ValidatableEd25519Signature
implement Debug and Clone.
2023-02-28 11:23:44 -05:00
Nick Mathewson 0bf1ae70ba tor-bytes: Add cursor functionality to Reader
We'll use this to implement signature and MAC checking for
EstablishIntro cells.
2023-02-28 11:23:44 -05:00
Nick Mathewson 09d601d050 Change several cfgs to refer to new feature names. 2023-02-28 11:15:39 -05:00
Nick Mathewson 0c000a1713 Mark new tests as onion-service-only 2023-02-28 11:15:39 -05:00
Nick Mathewson ca055d4cb5 tor-cell: Support extensions in INTRODUCE{1,2} 2023-02-28 11:15:39 -05:00
Nick Mathewson 7af2efdb82 tor-cell: Implement IntroduceAck and IntroEstablished
These are fairly simple, since the bulk of them is just an extension
list with no supported extensions.
2023-02-28 11:15:39 -05:00
Nick Mathewson c302246e57 tor-cell: Implement rendezvous1 and rendezvous2. 2023-02-28 11:15:39 -05:00
Nick Mathewson 841905948f caret: work correctly when there are no defined variants. 2023-02-28 11:08:34 -05:00
Nick Mathewson d69ed3bc62 hscrypto: Make several types Readable+Writeable
Specifically, RendCookie, Subcredential, HsId, and HsBlindId.
2023-02-28 11:08:31 -05:00
Saksham Mittal e2c870ca1c
Remove unnecessary warning from arti-hyper/README
https://gitlab.torproject.org/tpo/core/arti/-/issues/715
has been fixed, so there is no need to display such a warning
2023-02-28 21:23:24 +05:30
Nick Mathewson 886faa96b3 Remove semver.md files now that 1.1.2 is out. 2023-02-28 10:06:41 -05:00
Nick Mathewson 2c9f8e3547 Follow-on patchlevel bumps for crates with changed dependencies
These crates didn't have any changes until now, when I bumped
the versions of some other crates they depend on:

tor-consdiff
arti-hyper
arti-bench
arti-testing
2023-02-28 07:18:37 -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
Nick Mathewson 3e257a7cb5 Bump minor versions for significant breaking changes.
This includes tor-cell, tor-proto, and tor-netdir.
2023-02-28 07:05:15 -05:00
Ian Jackson ddd323c6ff tor-hsservice: Fix an erroneous reference to an hs-client feature 2023-02-28 11:10:17 +00: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 fcbeceeb61 Merge branch 'cmd_checker' into 'main'
tor-proto: Introduce CmdChecker, and use it to enforce correctness for our streams.

Closes #774 and #769

See merge request tpo/core/arti!1026
2023-02-27 16:43:34 +00:00
Saksham Mittal dfb94f510d
Use humantime in tor-guardmgr 2023-02-27 21:24:29 +05:30
Saksham Mittal f5f526d1fc
Use humantime in tor-checkable
The four values of times taken in a particular test were changed to both
be human readable and have comments explaining their significance (they
are all important moments after the Unix Epoch for freedom)
2023-02-27 21:18:49 +05:30
Nick Mathewson 07473ed1fc proto: Tweak documentation and names around CmdChecker. 2023-02-27 08:14:15 -05:00
Nick Mathewson d09273a6e3 Apply a missing cfg_attr(docsrs...) in netdoc 2023-02-21 15:18:46 +00:00
Nick Mathewson c1fbcb34f6 Rearrange cfg_attr in relaycell::msg
docsrs wants to find its `cfg_attr(docsrs...)` line after the
`cfg()` line.
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
Ian Jackson 67234568bc Merge branch 'hsdir_remove_comment' into 'main'
netdoc: Remove a TODO hs comment.

See merge request tpo/core/arti!1028
2023-02-21 15:15:10 +00:00
Nick Mathewson 3233c25943 tor-netdoc: Use UnparsedLinkSpec in IntroPointDesc. 2023-02-17 15:29:37 -05:00
Nick Mathewson bc68974212 tor-linkspec: New UnparsedLinkspec type.
Unlike linkspec, this doesn't validate the actual contents of the
specifiers. We'll use this so we can handle the linkspec list for an
introduction point in an HsDesc, and just pass it on when
constructing our circuits.

I haven't added any accessor or constructor functions, because I
don't expect to need them.
2023-02-17 15:26:23 -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 2b515c8d25 tor-dirmgr: Work around an apparent regression in `time`.
Some code in our tests that worked fine with time 0.3.17 no
longer works with 0.3.19, despite the semver.

See https://github.com/time-rs/time/issues/552 for the upstream bug.
2023-02-17 14:36:19 -05:00
Nick Mathewson 814563dfd6 tor-proto: Rename end_received.
It can now indicate _any_ cell that means we can forget about a stream.
2023-02-17 11:56:53 -05:00
Nick Mathewson d81a9c9aad Use CmdChecker in our stream handling code.
This change makes sure that open streams and half-closed streams
have the same stream-type-dependent state machines with respect to
which cells are acceptable.

Fixes #774.

Fixes #769.
2023-02-17 11:52:09 -05:00
Nick Mathewson c5be3c089e tor-proto: Introduce CmdChecker, and define it for our streams.
The role of CmdChecker is to verify that messages are arriving at
the appropriate sequence on a stream, with respect to the other
messages that have been received.  Once the stream becomes
half-closed, the CmdChecker is also in charge of consuming incoming
messages on the stream and making sure that they are well-formed.
2023-02-17 11:50:27 -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
Nick Mathewson 878531af90 Merge branch 'hs-cells-1' into 'main'
Start refactoring hs cell implementations

See merge request tpo/core/arti!1020
2023-02-16 15:36:31 +00:00
Nick Mathewson c4b451ffa6 Mark a quoted block as text, so doctest ignores it. 2023-02-16 09:00:07 -05:00
Nick Mathewson 14417dc098 Add a TODO about combining several macros and patterns 2023-02-16 08:25:12 -05:00
Ian Jackson b4e48b0695 Make a comment more accurate 2023-02-16 13:19:04 +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 0f2218f4d3 Merge branch 'ticket_525_part3_take2' into 'main'
Finish #525 for relay messages: Only parse messages at the last instant.

Closes #773 and #525

See merge request tpo/core/arti!1017
2023-02-15 16:35:27 +00:00
Nick Mathewson 19c0dd153a tor-proto: Add a TODO about simplifying a common pattern. 2023-02-15 10:51:03 -05:00
Nick Mathewson 21db73f182 tor-cell: add a TODO comment about simplifying Body away. 2023-02-15 10:48:19 -05:00
Nick Mathewson fce1c83f2e tor-cell: Add another debug_assert to relay cell encoding 2023-02-15 10:48:19 -05:00
Nick Mathewson 5d28e9e7d0 slicewriter: rename a local variable. 2023-02-15 10:48:19 -05:00
Nick Mathewson 19c9593acf Move slicewriter to tor-cell and make it private.
Also, add some comments about how it is likely to change.
2023-02-15 10:48:19 -05:00
Nick Mathewson 1ee6bfa59c tor-proto: note implications for future HS work 2023-02-15 10:48:19 -05:00
Nick Mathewson 41b50b6c56 tor-proto: Push stream message parsing into the stream objects.
This closes #525, and ensures, at last, that we don't parse any
message that we wouldn't accept.
2023-02-15 10:48:19 -05:00
Nick Mathewson 58c3b8276c tor-proto: Defer parsing of messages send to half-closed streams
This includes a partial solution for #769, but also turned up
another bug (#774) while I was working on it.  I'll close them both
once I have a real solution.
2023-02-15 10:48:19 -05:00
Nick Mathewson bd0f6f5adf tor-proto: stop reactor (and kill circuit) if meta handler fails
If the meta handler reports an error, then the circuit has violated
its protocol, and needs to be shut down.

Fixes #773.
2023-02-15 10:48:19 -05:00
Nick Mathewson 2e483124cb tor-proto: defer meta-cell parsing to the last moment. 2023-02-15 10:48:19 -05:00
Nick Mathewson 0765243f5e tor-proto: Use UnparsedRelayCell to start deferring cell processing.
In general, we want to avoid parsing these cells until we are
fairly sure that they are something we would accept.
2023-02-15 10:48:19 -05:00
Nick Mathewson e4bc7ef57b tor-cell: Add RelayCell::into_msg. 2023-02-15 10:48:19 -05:00
Nick Mathewson 3f1457ea04 tor-cell: Implement {Relay,Chan}Msg for every body type
This will make it ergonomic to decode a single body type without
having to declare a variant that accepts only a single message.
2023-02-15 10:48:19 -05:00
Nick Mathewson 65cc7d0974 tor-cell: Note an opportunity for future optimization 2023-02-15 10:48:19 -05:00
Nick Mathewson a809a809ba tor-cell: Add a new UnparsedRelayCell
We'll use this to router relay messages on a circuit to the
appropriate stream, and hand them to that stream, without parsing
the message until the stream has been determined.
2023-02-15 10:48:19 -05:00
Nick Mathewson ca3b33a1af tor-cell: Refactor relay cells to copy much less
We now manipulate raw relay cell bodies as (an alias for)
`Box<[u8;509]>` rather than as (an alias for) `[u8;509]`.  This
enables us to do much less copying.  It will become more important
soon, as we defer parsing relay cell bodies even longer.

Related to #7.

We also use SliceWriter to avoid allocating a Vec<> for every relay
message we want to encode, and instead encode directly into the
cell.
2023-02-15 10:48:19 -05:00
Nick Mathewson 9e2b6f3aed tor-bytes: Add a new writer implementation for fixed-size objects
Because the API assumes that many writes are infallible, this writer
takes ownership of the backing object, and will only return it to
you if you didn't run over the end.

I'm going to use this to save some allocations in relay cell bodies
2023-02-15 10:48:19 -05:00
Nick Mathewson 5521df0909 tor-cell: Use a more generic mechanism for managing extensions
Several HS message types have an extension list type.  They all use
the same framing for extensions, but each of them has separate
extension types and separate extension namespaces.

This commit simplifies establish_intro a little, and adds support
for maintaining unrecognized extension types--at the expense of some
new internal code.
2023-02-15 08:44:43 -05:00
Ian Jackson dccb641354 Merge branch 'fuzz-hsdesc' into 'main'
Fuzzing for hsdesc parsers

See merge request tpo/core/arti!1018
2023-02-15 12:47:38 +00:00
Nick Mathewson 37fcb0ca7c tor-cell: Extract establish-intro into its own module.
Some of the HS message types have a lot of dependent types, like
extensions and options for those extensions, and so on.  Except when
those extensions are portable across cell types, it makes sense
to put them in their own modules.
2023-02-15 07:46:36 -05:00
Nick Mathewson 5c85397bb7 tor-cell: rename onion_service module to hs 2023-02-15 07:38:19 -05:00
Nick Mathewson f1ec64bfe5 Upgrade to latest toml crate.
(None of the breaking changes affect us this time.)
2023-02-14 11:06:00 -05: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
Ian Jackson 72b1cb797d batching_split_before: Rename "start" to "batch-starting"
Roughly as per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1016#note_2877822
2023-02-13 16:52:07 +00:00
Ian Jackson 09060b4748 batching_split_before: Remove false assertions about batch contents 2023-02-13 16:44:47 +00:00
Ian Jackson 4333a1ef1c batching_split_before: Clarify heading of BatchesWithPrefix 2023-02-13 16:37:13 +00:00
Nick Mathewson 5c1cbd5486 batching_split_before: docs improvements. 2023-02-13 16:12:26 +00:00
Nick Mathewson 7363bee6a4 netdoc: give hsdesc test info in its original form. 2023-02-13 10:30:27 -05:00
Ian Jackson 8703a969f4 tor-netdoc: Use batching iterator in authcert.rs
This gets rid of a lot of manual boolean state variable iterator
stuff.
2023-02-10 19:48:26 +00:00
Ian Jackson d35f7990e8 tor-netdoc: Use batching_split_before in HsDescInner 2023-02-10 19:47:45 +00:00
Ian Jackson fd35f05b26 tor-netdoc: Provide new batching_split_before
There will be two call sites to demonstrate it.

Eventually maybe this will want to be in tor-basic-utils, since it
doesn't depend on any of the tor-netdoc types.  But it would be
sensible to wait until the situation with PeekableIterator and
Itertools is improved.

For now we make this #[doc(hidden)] to avoid it becoming part of our
stable API.
2023-02-10 19:47:45 +00:00
Ian Jackson 1b5a5eb57a tor-netdoc: Provide NetDocReader::into_iter
This will avoids some hairy borrowck disasters when we try to use
iterator adapters.
2023-02-10 19:47:45 +00:00
Ian Jackson 5f0ff78c2d tor-netdoc: util: use super::* in tests
Not xure how my MR to try to do this everyone missed this one.
2023-02-10 19:47:45 +00:00
Ian Jackson a5be14ed5e tor-netdoc: util: Add standard lint block to tests
Not xure how my MR to try to do this everyone missed this one.
2023-02-10 12:47:02 +00:00
Nick Mathewson 3f5502c5bc netdoc: Add a test for HSDesc decryption. 2023-02-10 07:36:40 -05:00
Nick Mathewson ced33029f6 Add another test hsdesc to parse.
This one was generated (by dgoulet) using `ClientDescEncKey`
encryption.  Its information is:

```
Address: paozpdhgz2okvc6kgbxvh2bnfsmt4xergrtcl4obkhopyvwxkpjzvoad.onion

Time period: 19397

Client:

  paozpdhgz2okvc6kgbxvh2bnfsmt4xergrtcl4obkhopyvwxkpjzvoad:descriptor:x25519:SDZNMD4RP4SCH4EYTTUZPFRZINNFWAOPPKZ6BINZAC7LREV24RBQ

Service:

  descriptor:x25519:SACGOAEODFGCYY22NYZV45ZESFPFLDGLMBWFACKEO34XGHASSAMQ
```
2023-02-10 07:26:31 -05:00
Nick Mathewson b4cca45410 hscrypto: Use minutes, not seconds, in blinding parameter.
Fixes an instance of #768.

The problem with the test vectors is that I used a random time
period number (1234) and the default-in-tor period length (1440)
without checking whether 1440 _meant_ minutes or seconds.  I'll add
another test to Tor to make sure that the time period matches now.

With this change, I can test Tor-generated hsdescs with encryption,
so I'm fairly confident that the new behavior is correct.
2023-02-10 06:54:19 -05:00
Nick Mathewson 696b9bd2d5 Merge branch 'ticket_525_part2' into 'main'
Apply restricted_msg to ChanMsg parts of tor-proto

See merge request tpo/core/arti!1013
2023-02-09 18:06:39 +00:00