Commit Graph

46 Commits

Author SHA1 Message Date
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 03df452f7b tor-cell: Rename EstablishIntro{Body => Details} 2023-03-01 11:18:50 -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
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
Ian Jackson f63c7c48af Rename onion-* cargo features to hs-* in tor-* crates
Fixes #756
2023-02-28 11:10:17 +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 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 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
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 48ab7b0463 Change tor_bytes::Error::BadMessage to a Cow.
Actually, to avoid making a breaking change, I'm deprecating
BadMessage and creating a new InvalidMessage variant that takes a
Cow.  This way I don't need to track every crate that re-exposes
tor_bytes::Error and call this a breaking change in those.

Making this change will allow tor_bytes errors to be much more
helpful.
2023-02-09 10:20:31 -05:00
Nick Mathewson b6f6fa4d4b cell: Parameterize ChannelCodec::decode and encode.
This change lets us use ChannelCodec to encode and decode any
restricted channel message type we want.  (Later on, we'll turn the
related Codec class in tor-proto into a more type-restricted version
of this.)
2023-02-09 08:26:09 -05:00
Nick Mathewson d63d7926bd tor-cell: Rename RelayMsg and RelayCell-related types.
Thanks to rust-analyzer for making this simple.
2023-02-07 16:03:14 -05:00
Nick Mathewson d99c130679 tor-cell: Rename ChanMsg and ChanCell-related types. 2023-02-07 16:03:14 -05:00
Nick Mathewson c529bb9c30 tor-cell: Remove RelayMsg methods that are duplicated in RelayMsgClass. 2023-02-07 16:03:14 -05:00
Nick Mathewson 3c7aea723b tor-cell: Remove ChanMsg methods that are duplicated in ChanMsgClass. 2023-02-07 16:03:14 -05:00
Nick Mathewson 71445f7ace tor-cell: Use macro to generate ChanMsg too. 2023-02-07 16:03:14 -05:00
Nick Mathewson ffb443709b tor-cell: Change all variants of RelayMsg to have a body.
Previously, there were some unit variants, but that makes things
quite awkward for #525.
2023-02-07 16:03:14 -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
Neel Chauhan b649a1d86f msg::{CreateFast/CreatedFast}: Rename accessor to (into_)body() 2022-12-18 21:00:24 -08:00
Emil Engler e5429a2891
tor-cell: Rename for_client and for_relay
This commit renames the for_client and for_relay functions to
from_client and from_relay respectively, in order to indicate their
origin, as the term "for" is more likely to indicate a destination,
which is not true in that situation.
2022-10-21 13:21:52 +02:00
Nick Mathewson 5786637b4f Fix various typos (using typos tool and hand-inspection) 2022-10-18 15:39:33 -04:00
Yuan Lyu 6e5874d15b
Implement Introduce2 tor cell
Reuse the same Introduce inner body implementation
of Introduce1.
2022-09-21 00:34:13 -04:00
Yuan Lyu 1a3b979ecf
Implement onion service Introduce1 2022-09-08 23:48:56 -04:00
Yuan Lyu 08e55bc9b1
Clean up EstablishIntro cell 2022-08-25 16:45:40 -04:00
Ian Jackson 14c6e17797 tor-cell: PaddingNegotiate::start: take IntegerMilliseconds 2022-08-17 10:54:41 +01:00
Ian Jackson 0df72449b8 chancell: PaddingNegotiate: Provide two constructors, not one
We don't really want the caller to pass ignored timeout parameters.
And this makes more semantic sense.

The stop constructor uses zero, which is what C Tor does.  See
  https://gitlab.torproject.org/tpo/core/torspec/-/merge_requests/76
2022-08-16 18:37:06 +01:00
Yuan Lyu 25bb25ddcb
Implement establish rendezvous cell 2022-08-05 00:04:42 -04:00
Nick Mathewson a0a88643f8 tor-cell: Make encoding method signatures fallible. 2022-07-11 11:18:51 -04:00
Ian Jackson bcf3bca211 tor-cell: udp: Remove manual length calculations
This does away entirely with `wire_addr_len`, which recapitulates the
length calculation.
2022-06-09 17:08:56 +01:00
Nick Mathewson 5854e4bbd9 Merge branch 'use-testing-rng' 2022-06-07 19:02:12 -04:00
David Goulet 3da4b95434 udp: New AddressPort used in cells
Signed-off-by: David Goulet <dgoulet@torproject.org>
2022-06-07 12:29:51 -04:00
Ian Jackson a591bf353a udp: Allow empty hostname and no nul byte
After changes to the prop339, the domain name in an Address can only be
255 bytes max and can NOT contain nul byte(s).

Unit tests had to be modified to accept this change:

- Centralise msg_ip_address
- Add currently-passing tests for address length
- Test counted address length longer than type wants

Related to #463

Signed-off-by: David Goulet <dgoulet@torproject.org>
2022-06-07 12:23:27 -04:00
David Goulet 2ea709674d cell: Don't use NUL terminated string in CONNECT_UDP
Signed-off-by: David Goulet <dgoulet@torproject.org>
2022-06-07 12:22:05 -04:00
David Goulet 8fd6541985 cell: Move UDP to its own module and feature gate it
Related to #463

Signed-off-by: David Goulet <dgoulet@torproject.org>
2022-06-07 12:22:05 -04:00
David Goulet b7ae1976b5 cell: Implement CONNECTED_UDP cell from prop339
Decoding and encoding implemented according to proposal 339.

Related to #463
2022-06-07 12:22:05 -04:00
David Goulet d74482cd90 cell: Implement CONNECT_UDP cell from prop339
Decoding and encoding is implemented according to proposal 339
specifications.

Related to #463

Signed-off-by: David Goulet <dgoulet@torproject.org>
2022-06-07 12:22:05 -04:00
Nick Mathewson 967ea67b7d Use testing_rng() in tests throughout our crates.
This only affects uses of thread_rng(), and affects them all more or
less indiscriminately.  One test does not work with
ARTI_TEST_PRNG=deterministic; the next commit will fix it.
2022-06-02 14:56:42 -04:00
Ian Jackson b7fec1c8a4 Remove many needless borrows and slices
Found via clippy::needless_borrow.  In some cases I removed needless
`[..]` too.  See also:
  needless_borrow suggestion doesn't go far enough
  https://github.com/rust-lang/rust-clippy/issues/8389
2022-02-02 18:34:26 +00:00
Daniel Eades fb3b8b84b5 fix/silence clippy lints in test modules 2021-09-08 17:28:31 +02:00
Nick Mathewson 557a0ff40b Move all crates into a `crates` subdirectory.
This will cause some pain for now, but now is really the best time
to do this kind of thing.
2021-08-27 09:53:09 -04:00