Commit Graph

342 Commits

Author SHA1 Message Date
Nick Mathewson a94dc1c7f1 LogId test: tolerate concurrent tests. 2020-10-21 14:09:20 -04:00
Nick Mathewson b528c914ff Start on some tests for pieces of tor-proto::channel 2020-10-21 12:45:36 -04:00
Nick Mathewson 3f3e98d190 Follow API convention about mutable getters.
They're supposed to be called field_mut().
2020-10-21 08:12:46 -04:00
Nick Mathewson 743c3167e8 Rename as_message to into_message.
According to the API guidelines, "as_" is only for
borrowed->borrowed conversions.
2020-10-21 08:05:33 -04:00
Nick Mathewson 486693115a Add a close() method for streams 2020-10-20 14:46:59 -04:00
Nick Mathewson 425ee8376b Add new `terminate()` method to circuits and channels.
These aren't called "close" because they're more destructive than
that: they can be called even if other parties are using the circuit
or channel.

This is for arti#21.
2020-10-20 14:28:44 -04:00
Nick Mathewson c554db9881 Missing file and docs 2020-10-20 13:46:43 -04:00
Nick Mathewson 6e5d248418 Add a TODO for register_meta_handler API 2020-10-20 13:41:34 -04:00
Nick Mathewson 4f567e4a94 Work on closing flooding-based side-channels
We need to make sure that we're dropping cells that we don't
recognize or want, so that we can't be flooded with bogus junk.
2020-10-20 13:22:16 -04:00
Nick Mathewson b0cdd025a1 Add some helpful logs in circuit code. 2020-10-20 12:40:08 -04:00
Nick Mathewson 7ce158ed1e Add reasonable logging (I hope!) to channel 2020-10-20 11:45:53 -04:00
Nick Mathewson 1dc3fc214a Implement From, not Into.
These traits are inverses of one another, but implementing From is
always preferred since rust 1.41 relaxed the "orphan rules".
2020-10-19 17:40:43 -04:00
Nick Mathewson c7a2efe72b Add and use remaining CertType values in tor-cert 2020-10-19 14:17:25 -04:00
Nick Mathewson 378aa6d639 Add an enumeration for destroy reasons. 2020-10-19 13:13:55 -04:00
Nick Mathewson 295a791a82 Improvements to Relay type in tor-netdir.
Now, a Relay is always valid.  This required some changes to the
API: all_relays() has to return a new UncheckedRelay type that might
or might not be valid, and the functions on Relay and ChanTarget
that return ed25519 identities need to return an Ed25519Identity,
not an ed25519::PublicKey.

This change required some new encoding/decoding/conversion functions
on Ed25519Identity.
2020-10-19 09:22:49 -04:00
Nick Mathewson 5523134607 Mark must-resolve XXXX issues with "XXXXM3".
"M3" is for "milestone 3" -- my target to fix the technical debt
that I think will be bad if we ship even a pre-alpha with it.

These aren't necessarily _all_ must-resolve, but they're all
must-look-at.

Closes #15
2020-10-18 17:38:59 -04:00
Nick Mathewson 5173ee960f tor-proto: Add a ClientCircChanMsg type.
This wraps exactly the ChanMsg values that are valid on open client
circuits, so that we can be sure that only those cells are sent to a
ClientCirc's reactor.
2020-10-15 14:23:12 -04:00
Nick Mathewson 34962c3c9f tor-proto: Add a "CreateResponse" type.
CreateResponse includes exactly those cells that are a correct
response to a CREATE2/CREATE_FAST, so we can be sure that only those
cells are actually passed to a PendingClientCirc.
2020-10-15 14:09:19 -04:00
Nick Mathewson 3408c9ad26 Run "cargo upgrade". 2020-10-15 13:32:02 -04:00
Nick Mathewson ae19caed7d Fix a couple of clippy warnings 2020-10-15 08:36:04 -04:00
Nick Mathewson 22f260872b Turn the channel's ref to its circmap into a Weak reference
This way, when the channel reactor is dropped, the circuit map
can get dropped too, which will cause reading circuits to notice.
2020-10-15 08:30:46 -04:00
Nick Mathewson 5c70790701 Mark channels as unusable if reactor gets an error.
Similarly as with circuits, we want this code to set a "closed" flag
so that attempts to write on the channel will fail.
2020-10-15 07:38:03 -04:00
Nick Mathewson 691eab53d6 Use weak references from circuit reactor to circimpl.
This prevents the reactor from keeping the circuit alive forever.
2020-10-14 14:30:48 -04:00
Nick Mathewson 4646a4546e Use a weak reference from channel reactor to channel. 2020-10-14 14:21:02 -04:00
Nick Mathewson ffe605aa52 Send DESTROY cells when a circuit is dropped.
This reuses a lot of mechanism from the circuit code that sends END
cells when streams are dropped.

There is a problem here: Circuits and channels won't actually get
dropped, because we should be using a weak reference from the
reactor.
2020-10-14 14:17:08 -04:00
Nick Mathewson 1085ca86dc Revise DropMark defense to use a better type and match Tor's behavior. 2020-10-13 11:52:05 -04:00
Nick Mathewson 3d597a10bc Document all private members in tor-proto 2020-10-13 10:55:07 -04:00
Nick Mathewson b2007b7082 Make sure that protocol errors terminate the circuit responsible. 2020-10-13 10:14:01 -04:00
Nick Mathewson 6b0e3efbd0 Improve handling of circuit closure or failure on reactor shutdown.
We already handled the case okay when we were reading on streams,
since the reactor's going away would drop the sender side of their
mpsc channels.  But if the reactor went away, nothing would tell
_writing_ streams that they needed to close.

Now we handle that case, as well as anybody who is waiting on
a meta-cell to get back to them.
2020-10-13 09:26:23 -04:00
Nick Mathewson 119ff0abba Another tweak to handling closing streams
When a stream is closed and we haven't adjusted its state in the
stream map yet, remember how many cells we've dropped so we can
decrement them from the window later on.
2020-10-13 08:52:01 -04:00
Nick Mathewson c12aed3d0d Try giving distinct handling to streams where END has been sent
This is the first step along the line to handling Tor issue
tor#27557.  We want to remember streams that we've ended and treat
them as distinct from streams that have never existed
2020-10-12 11:36:17 -04:00
Nick Mathewson 74624e6250 Tweak terminate hand handle_close() functions.
These need to become functions about terminating and noticing a
termination request.
2020-10-11 15:25:06 -04:00
Nick Mathewson 1a406b8fe9 Rename StreamMap::Closing to EndReceived
This is in preparation for adding a different EndSent stream state.
2020-10-11 14:49:50 -04:00
Nick Mathewson 40eb26e1a7 Fix a pair of bugs in SENDME handling.
The problem is that we would count begin and end cells towards
towards window totals when we are only supposed to count DATA
cells, *and* that we would we send our sendmes one cell too early
(or maybe late?).

Closes #1.
2020-10-09 15:23:26 -04:00
Nick Mathewson b3a809b1e3 Move counts_towards_windows() code into circuit module 2020-10-09 15:07:12 -04:00
Nick Mathewson 569eff88c4 Split information about circuit hops into inbound and outbound.
Previously the circuit object owned not only the outbound crypto,
but also the inbound crypto and the stream maps.  That's not so
great, since the reactor needs to use the inbound crypto and the
stream maps all the time, whereas the circuit doesn't need them much
(or at all).

Moving these objects to the reactor-owned structure should let us
fix the deadlock case in stream sendme handling, since the circuit
reactor no longer needs to lock the circuit in order to do crypto
and demultiplexing.  It should also speed up the code a bit, since
it doesn't need to grab the circuit lock nearly so often as before.

This change forced me to add a couple of new reactor CtrlMsg values,
since the circuit can no longer add streams and layers directly.  I
think it will still be a performance win, though.
2020-10-09 11:28:09 -04:00
Nick Mathewson 5a8300f0f4 Split client relay crypto into separate directions
I think we should have the reactor task own the reverse crypto and
the circuit own the forward crypto.
2020-10-09 11:28:09 -04:00
Nick Mathewson e0941523eb Use batch verification in client<->relay handshake. 2020-10-02 12:01:46 -04:00
Nick Mathewson 610739c139 Enable batch ed25519 verification. 2020-10-02 11:53:50 -04:00
Nick Mathewson beee7a7f2a cargo upgrade 2020-09-29 16:43:16 -04:00
Nick Mathewson b0a53d4d40 Move RelayCell into a more reasonable place. 2020-09-29 08:43:13 -04:00
Nick Mathewson 5844037f89 Remove idmap as needlessly complex. 2020-09-29 08:24:51 -04:00
Nick Mathewson 5bb01ba305 make it work on rust 1.45 2020-09-28 21:57:29 -04:00
Nick Mathewson 8d5957ca4b test vectors for cell crypto. 2020-09-28 21:36:10 -04:00
Nick Mathewson f43db0d048 Mark most of the cell crypto code as crate-local. 2020-09-28 18:20:16 -04:00
Nick Mathewson 56101a0673 Add a round-trip test for cell encryption. 2020-09-28 18:16:30 -04:00
Nick Mathewson 98ab84e774 Rename remaining get_ accessors 2020-09-28 16:13:14 -04:00
Nick Mathewson 9b276e6a5a tor_cert: rename accessors 2020-09-28 16:01:33 -04:00
Nick Mathewson 05da5a7f73 Rename some identifiers in tor-linkspec.
By convention, rust accessor functions don't start with 'get'.
2020-09-28 15:29:39 -04:00
Nick Mathewson 3b3a6736f6 Rename ExtendTarget to CircTarget. 2020-09-28 15:22:24 -04:00
Nick Mathewson 397d753e4e Fix a few clippy issues 2020-09-27 03:30:09 -04:00
Nick Mathewson ad36e3acec Fix some comments that reflected a misunderstanding in SENDMEs
I had thought that the sendme authentication things used for
onion services were 32-byte; they're still only 20.
2020-09-26 19:25:51 -04:00
Nick Mathewson b710e5c770 Split the cell-handling parts of tor-proto into a new crate. 2020-09-26 12:49:03 -04:00
Nick Mathewson 653de035bc Make sendme authentication optional.
This code deviates from current tor in that it allows missing
sendme authentications only when we know we're talking to an old
relay, or when we don't know the version of the relay we're talking
to.
2020-09-25 19:20:32 -04:00
Nick Mathewson adf5ef3f5c Lower our "#[allow(dead_code)]" decl in tor_proto." 2020-09-25 18:57:21 -04:00
Nick Mathewson 343af46715 Improve documentation and lightly refactor SENDME code 2020-09-25 18:49:23 -04:00
Nick Mathewson ba1600371b Implement authenticated sendme output for circuit-level sendmes.
This patch has a XXXXX kludge note in it.
2020-09-25 18:49:23 -04:00
Nick Mathewson c0ee910413 Add a bad workaround for a deadlock: we should look for a better one. 2020-09-25 17:06:33 -04:00
Nick Mathewson 6071b0e903 Fix encoding/decoding of authenticated sendme. 2020-09-25 17:06:33 -04:00
Nick Mathewson 08cfb40350 Try to get sendme crypto working
There's a problem, though: this code assumes that tags are 20 bytes
long whereas actually the tag type is part of the crypto layer info.

So maybe in the long term we need to move the queue of tags from the
send window into being part of the crypto layers.
2020-09-25 17:06:33 -04:00
Nick Mathewson bc4c05d6a7 Incomplete implementation of circuit SENDME handling.
This is incomplete because the cell crypto code doesn't actually
expose tags yet, and because it demands tags unconditionally,
without caring about the linkspec protocol version.
2020-09-25 17:06:33 -04:00
Nick Mathewson 06ede86f7f Attempted implementation of stream sendme cells 2020-09-25 17:06:33 -04:00
Nick Mathewson 92463dc03e Initial work on a sendme backend.
Parameterized for authenticated/unauthenticated operation, and
operation on circuits and streams.
2020-09-25 09:47:55 -04:00
Nick Mathewson 60ff67113f Initial error cleanup on streams/circuits 2020-09-25 08:35:48 -04:00
Nick Mathewson 18b13e8cae Migrate ClientMain to byte-oriented API. 2020-09-24 18:56:54 -04:00
Nick Mathewson 50848b8fa0 Try to make a send/receive style API for streams. 2020-09-24 18:03:03 -04:00
Nick Mathewson da3a8fdd50 Add support for RELAY_END cells.
This was a hard one.  I need to make sure that we send an END cell
when the stream is dropped.  But we can't call an .await from inside
the drop() function, since drop() isn't async, and we don't have an
executor.

Fortunately, you can call send() on a oneshot::Sender without having
to await on it, so that's the obvious thing to put in drop().  But
we need some way to make sure that the oneshot::Receiver is given to
the reactor, and is .awaited.  For that, we needed a control
channel.  And the reactor needs to treat the control channel and the
close messages as equally important.

So that's how I wound up with a
  Fuse<Select<mpsc::Receiver<Result<Foo>>,
              SelectAll<Once<oneshot::Receiver<Foo>>>>>.

I doubt that this is actually the best way to handle any of this!
2020-09-24 15:33:54 -04:00
Nick Mathewson 9e8350aea0 as Tor does, skip to random initial stream member. 2020-09-23 19:50:15 -04:00
Nick Mathewson c35477bb3d Fuse input streams on creation. 2020-09-23 19:21:49 -04:00
Nick Mathewson 6492334aff Turn IdMap into an extension trait.
Also, use the "right" (cyclic, potentially expensive) algorithm for
stream IDs.
2020-09-23 17:53:58 -04:00
Nick Mathewson 0c131dc080 Run cargo upgrade 2020-09-21 13:45:36 -04:00
Nick Mathewson 3eb087bf16 turn hopnum into a first-class type 2020-09-21 12:56:30 -04:00
Nick Mathewson c276cfcb73 Add is_zero for ID types. 2020-09-21 12:27:45 -04:00
Nick Mathewson fb7703f7e9 Fix some errors; document some places where error handling is bogus 2020-09-21 12:22:35 -04:00
Nick Mathewson 68fc1b0f4d More documentation for channel, circuit, stream. 2020-09-21 12:10:51 -04:00
Nick Mathewson bc00417f01 Start implementing streams and circuit-level reactors.
Also, revise nearly all of the circuit/channel interaction to
actually send relay cells to the right place and do sensible things
with them.
2020-09-21 10:42:36 -04:00
Nick Mathewson 296bfbe57b Add RelayCmd::accepts_streamid_val 2020-09-20 14:09:10 -04:00
Nick Mathewson 9567689a30 Refactor accetps_circid_val to be less wonky. 2020-09-20 14:09:10 -04:00
Nick Mathewson a3384bc126 Move is_recognized function into caret. 2020-09-20 14:09:10 -04:00
Nick Mathewson a547cda19f Rename StreamCmd to RelayCmd 2020-09-20 14:09:10 -04:00
Nick Mathewson c6d403472f Improve shutdown support for channel. No idea if it works. 2020-09-20 14:09:10 -04:00
Nick Mathewson 9c4685968c rename a field in RelayCell 2020-09-20 14:09:10 -04:00
Nick Mathewson 988556dbef Create a StreamID->Stream map type.
Also extract the shared part of CircMap and StreamMap into a new
IdMap type.
2020-09-20 14:09:10 -04:00
Nick Mathewson 0075b784a1 De-parameterize channel and circuit
By putting the cell-sink in a box, we can get rid of the need for
having everything that uses a channel or a circuit know what kind
of underlying TLS implementation it has.
2020-09-19 22:29:18 -04:00
Nick Mathewson 56d8bc1756 Add tests for CREATE_FAST handshake 2020-09-19 13:06:40 -04:00
Nick Mathewson 80d1d27810 Add tests for failing ntor handshakes. 2020-09-19 12:37:17 -04:00
Nick Mathewson 389fc03e1e ntor: test the ClientHandshake/ServerHandshake impl 2020-09-18 21:20:22 -04:00
Nick Mathewson 3907e4a0c9 tests for kdf functions in tor_proto 2020-09-18 20:57:56 -04:00
Nick Mathewson 69e1c91ba1 Add tests for tor_proto::util::ct 2020-09-18 20:00:06 -04:00
Nick Mathewson 5f54be2234 Give up on suppressing that nightly-only clippy warning 2020-09-18 19:28:55 -04:00
Nick Mathewson 6a2c803f98 Resolve some nightly-only clippy warnings 2020-09-17 19:13:56 -04:00
Nick Mathewson 91db8ab6fb Add fuzzers for certs, netdoc, and proto.
This was remarkably simple.
2020-09-17 19:06:56 -04:00
Nick Mathewson f256847f82 Sort linkspecs in the same order as tor does 2020-09-17 15:33:18 -04:00
Nick Mathewson ee9b871bc5 Make client-demo launch a request to www.torproject.org:80 2020-09-12 21:32:00 -04:00
Nick Mathewson 02fc8b2528 Implement extend2/extended2 handshake.
This is not a production-ready implementation: it will break if a
circuit is used for anything while an extend is pending.

Client-demo can now build 3-hop circuits.
2020-09-12 20:48:07 -04:00
Nick Mathewson df0ebf857f Make more types implement Debug. 2020-09-12 20:45:59 -04:00
Nick Mathewson a9181131d2 Fix a bug in encoding extend2 cells. 2020-09-12 20:44:25 -04:00
Nick Mathewson dc287d4457 WIP: extend. 2020-09-12 17:01:15 -04:00
Nick Mathewson d1039dda9b Simple functions to send and receive relay cells. 2020-09-12 16:25:10 -04:00
Nick Mathewson 3e342a69ae Add a function to pad relay cells. 2020-09-12 15:55:04 -04:00
Nick Mathewson 2fb71d2b13 Refactoring around our 509-byte array type. 2020-09-12 15:47:12 -04:00
Nick Mathewson 74798337dd Ntor handshake (first hop) is go. 2020-09-11 20:00:26 -04:00
Nick Mathewson e10fc436a9 Wrap ntor handshake in appropriate trait. 2020-09-11 19:45:15 -04:00
Nick Mathewson b2c2fb66c9 Parameterize the circuit create code. 2020-09-11 19:35:38 -04:00
Nick Mathewson b29f9f0772 Make create_fast implementation a little more generic. 2020-09-11 19:15:27 -04:00
Nick Mathewson a4697e4528 For circuits: Implement first hop create via create_fast. 2020-09-11 19:00:55 -04:00
Nick Mathewson a62717690b proto: add minimal (raw) circuit support.
This is about enough to make a circuit, send a create_fast cell, and
get a created_fast cell back.
2020-09-11 15:10:34 -04:00
Nick Mathewson f20eb2f43f proto::channel: add piping to move cells around.
There's a "reactor" task to move cells to the appropriate circuit,
and a "send_cell" to send a cell directly.

This is client-only for now.
2020-09-11 13:58:05 -04:00
Nick Mathewson 49bbb4baa6 Turn channel into a handle-to-inner type.
I think I'll likely be refactoring this a _bunch_ before I actually
get to use this.
2020-09-10 13:19:39 -04:00
Nick Mathewson 812056d663 Move channel handshake into its own module. 2020-09-10 12:43:55 -04:00
Nick Mathewson ee71abe560 Pare down and sort dependencies 2020-09-09 19:17:49 -04:00
Nick Mathewson 9f30b47cb7 Run cargo upgrade, except for stream-cipher. 2020-09-09 19:06:00 -04:00
Nick Mathewson e95dec2437 cargo fix --edition-idioms 2020-09-09 18:59:04 -04:00
Nick Mathewson 34843f1fde Add some missing documentation 2020-09-09 18:58:33 -04:00
Nick Mathewson e02255ec00 Also RSA identities on channel handshakes
This took a good bit of hacking, including a kludge to extract an
RSA subject key from an x509 cert, since we didn't have a good way
to do that.
2020-09-09 18:08:33 -04:00
Nick Mathewson 8d01a0a808 Implement most of client-side channel cert validation. 2020-09-09 16:19:42 -04:00
Nick Mathewson e395ad5801 Declare Into<ChanCell> for channel messages without circids 2020-09-09 14:38:16 -04:00
Nick Mathewson e45e6f5954 Work on client channel handshake: mostly done, except for verification 2020-09-09 14:32:41 -04:00
Nick Mathewson 875e932898 New "linkspec" module to encapsulate info needed to connect/extend. 2020-09-08 20:43:15 -04:00
Nick Mathewson 541b6fa55f relaycell: slight error cleanup 2020-09-07 12:25:41 -04:00
Nick Mathewson 6456653941 relaycell: move cmd into Unrecognized. 2020-09-07 12:19:19 -04:00
Nick Mathewson 010d93f453 proto::relaycell: documentation and light refactoring 2020-09-07 12:14:23 -04:00
Nick Mathewson b91f6b2cbd rename relaycell stuff to its own module; rename a bit 2020-09-06 22:01:15 -04:00
Nick Mathewson 4266aa7d12 proto: Finish documenting chancell 2020-09-06 21:49:30 -04:00
Nick Mathewson 7095192063 proto: small err cleanups 2020-09-06 17:50:06 -04:00
Nick Mathewson b54a960f3d proto: make write_body_onto destructive. That might help down the road 2020-09-06 17:20:02 -04:00
Nick Mathewson ae1c813a70 Reinstate ChanCell as a meaningful type. 2020-09-06 17:15:07 -04:00
Nick Mathewson e749e2bc27 proto: major refactor to channel cells
The protocol is now based around a message-oriented scheme intended
to use futures_codec, which in turn uses BytesMut.  The transition
to BytesMut is incomplete, and we're not nearly so zero-copy as
intended.  We should think about that.
2020-09-06 16:00:14 -04:00
Nick Mathewson 4b75c51882 Run cargo-upgrade. 2020-08-28 18:14:17 -04:00
Nick Mathewson 173bec26a5 Update to latest packages; ed25519 now needs signature crate traits. 2020-07-20 20:55:03 -04:00
Nick Mathewson 7bd7e7ec7d Run cargo fix --edition-idioms 2020-06-26 13:17:14 -04:00
Nick Mathewson c602883881 Use "cargo upgrade" from cargo-edit to list current versions 2020-06-12 21:06:07 -04:00
Nick Mathewson 6264041b77 update to use latest rust-crypto traits and modules 2020-06-10 14:16:07 -04:00
Nick Mathewson 86894926aa tor-proto: use caret_int!() for cell and relay commands. 2020-05-15 16:27:03 -04:00
Nick Mathewson 9c62d15846 tor-proto: Simplify ct::lookup API. 2020-05-10 12:10:16 -04:00
Nick Mathewson 240badb20b Document most of tor-proto
(except for the worst parts that need refactoring the most)
2020-05-09 16:25:17 -04:00
Nick Mathewson 11abdcbf3e tor-proto: Fix a logic error in KDF-TOR implementation. 2020-05-09 14:01:48 -04:00
Nick Mathewson 641576aa44 Use links for traits in llcrypto docs 2020-05-08 22:32:17 -04:00
Nick Mathewson f24ddf0682 Upgrade to a modern version of "sha-1".
Apparently the "sha1" crate doesn't implement the RustCrypto
API, but the "sha-1" crate does.
2020-05-08 22:32:17 -04:00
Nick Mathewson 75a1269429 make id field in RSAIdentity private 2020-05-08 22:32:17 -04:00
Nick Mathewson 3c7f75302b Stop re-exporting traits from tor-llcrypto. It does not help. 2020-05-08 22:32:17 -04:00
Nick Mathewson bbcbf47902 Fresh git repository for work on "arti"
Arti is a rust tor implementation.  It's project I've been working
on for a few months now, in weekends and in spare time.  It doesn't
speak the tor protocol yet, and it doesn't connect to the network at
all.

It needs much more documentation and testing, but I'm just about
ready to show it to others.  See the README.md for a description of
what is there and what isn't.
2020-05-07 19:58:14 -04:00