Commit Graph

2345 Commits

Author SHA1 Message Date
Ian Jackson 4111c63bd4 channel reactor: Add some commented-out debug for padding 2022-08-17 10:54:41 +01:00
Ian Jackson 46885ac14b channel padding: Correctly always send the timer parameters
Fixes "chanmgr configuration: Avoid sending needless initial update(s)"
2022-08-17 10:54:41 +01:00
Ian Jackson 496563e7cf channel padding: Abolish ARTI_EXPERIMENTAL_CHANNEL_PADDING env var
This was for testing and is no longer needed.
2022-08-17 10:54:41 +01:00
Ian Jackson 299f302f35 channel engage_padding_activities: swap docs to tor0proto
This allow us to make a working cross-reference.
2022-08-17 10:54:41 +01:00
Ian Jackson 88dc816770 channel fake_channel_details: Use precise cfg
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826169
2022-08-17 10:54:41 +01:00
Ian Jackson 97363ba250 tor-netdir: testnet: construct_custom_netdir_with_params: Fix doc
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826168
2022-08-17 10:54:41 +01:00
Ian Jackson 52848a41c6 ChannelPaddingInstructions: Update and expand docs 2022-08-17 10:54:41 +01:00
Ian Jackson 2a4fd97229 ChannelPaddingInstructions: Rename `params` field to `insns` 2022-08-17 10:54:41 +01:00
Ian Jackson 949e5395e0 Rename ChannelsParams types to ChannelPaddingInstructions (fmt)
Run rustfmt; no other changes.
2022-08-17 10:54:41 +01:00
Ian Jackson 94dd3361e2 Rename ChannelsParams types to ChannelPaddingInstructions
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826167

This makes some lines too long; I will run rustfmt in a separate
commit for clarity.
2022-08-17 10:54:41 +01:00
Ian Jackson d1a709f46d chanmgr: Fix typo
Reported here
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826166
2022-08-17 10:54:41 +01:00
Ian Jackson 590e174d3a chanmgr parameterize: Correct doc comment
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826164
2022-08-17 10:54:41 +01:00
Ian Jackson 2404357282 Rename PaddingParameters::all_zeroes constructor to disabled 2022-08-17 10:54:41 +01:00
Ian Jackson bb2ae00217 chamgr NetParamsExtract: Replace direct nf_ito access
It turns out that the TryFrom was infallible, which wasn't obvious
with the previous code structure.
2022-08-17 10:54:41 +01:00
Ian Jackson 03d8a09c0e Channel: Make mutable() and engage_padding_activities infallible
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826151

This gets rid of quite some Bug error paths.
2022-08-17 10:54:41 +01:00
Ian Jackson 5db974ef72 Move ChannelUsage from tor_proto to tor_chanmgr
Replace Channel::note_usage with Channel::engage_padding_activities,
which unconditionally causes the channel to (start to) do netflow
padding things.

The condition now lives in chanmgr.

Addresses
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826094
2022-08-17 10:54:41 +01:00
Ian Jackson 49dad4bd13 tor-chanmgr: Expand docs for map::Inner dormancy field
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826093
2022-08-17 10:54:41 +01:00
Ian Jackson 4cf418f421 tor-cell: PaddingNegotiate::default_reduced
Get rid of unneeded constructor.

We never need to use hardcoded reduced padding parameters during
negotiation cell construction.  If we are using reduced padding
parameters, the layers which decide this have netparams to use.

Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826092
2022-08-17 10:54:41 +01:00
Ian Jackson 14c6e17797 tor-cell: PaddingNegotiate::start: take IntegerMilliseconds 2022-08-17 10:54:41 +01:00
Ian Jackson 18827b7fd0 chanmgr padding_parameters: Use Option
The network consensus parameters use (0,0) to mean "no padding"
(which is not the same as (0,0) means in a PADDING_NEGOTIATE cell).

Representing "no padding" this way is actually quite convoluted and
un-Rustic.  Ensure that we convert (0,0) to None, and do the primary
logic in Option.
2022-08-17 10:54:41 +01:00
Ian Jackson bdaee82187 tor-cell: PaddingNegotiate: give better spec xrefs 2022-08-17 10:54:41 +01:00
Ian Jackson 6fdaca8eb9 channel: Clarify (and in some places replace) "frontend" terminology 2022-08-17 10:54:41 +01:00
Ian Jackson 481bf0bbe9 tor-proto channel padding: Document PADDING_NEGOTIATE overwriting
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2825979
2022-08-17 10:54:41 +01:00
Ian Jackson 1104235ee5 chanmgr: padding: Split IEFI into named function
Roughly as suggested in
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826160

IMO this is less clear, because of the way it splits the logic up.
2022-08-17 10:54:41 +01:00
Ian Jackson 58fb118480 chanmgr: NetParamsExtract: extend docs for nf_ito 2022-08-17 10:54:41 +01:00
Ian Jackson 84d8c32543 chanmgr: Get rid of final Result relating to netdir/netparams
No functional change.  (The error tyep was Void.)
2022-08-17 10:54:41 +01:00
Ian Jackson 48fc5d3c39 chanmgr: Use NetDirProvider::params and Arc<dyn..Netparameters>
This gets rid of many Result().  Many parameters are renamed.
Test cases of the now-impossible branch are removed.

Deleting the match from padding_parameters will come in a moment.
I've split off that commit since it has much whitespace noise.
for now, change the error type to Void.
2022-08-17 10:54:41 +01:00
Ian Jackson 3497d8723b chanmgr: Add a TODO for renaming NetDirExtract 2022-08-17 10:54:41 +01:00
Ian Jackson 36e3529e34 chanmgr ChannelUsage: Fix and clarify docs 2022-08-17 10:54:41 +01:00
Ian Jackson e4cd01732f chanmgr set_dormancy: Remove obsolete comment 2022-08-17 10:54:41 +01:00
Ian Jackson b5176a700b chanmgr: Extend doc comments for Dormancy
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2825962
2022-08-17 10:54:41 +01:00
eta e5396a35c8 Fix typos in comments. 2022-08-17 10:54:41 +01:00
Ian Jackson 7ed983800d channel padding: Rename low_ms and high_ms
These have the unit in the type.  Putting that in the field name too
is otiose.
2022-08-17 10:54:41 +01:00
Ian Jackson 18a6234101 channel padding: Test through most of the layers 2022-08-17 10:54:41 +01:00
Nick Mathewson bd4204a42e Merge branch 'transient_circmgr_errors' into 'main'
Mark some circuit-building errors as "transient".

Closes #517

See merge request tpo/core/arti!676
2022-08-16 18:33:17 +00:00
Nick Mathewson 8862eb1e34 Additionally, mark the LostUsablityRace error as a "reset". 2022-08-16 14:03:43 -04:00
Nick Mathewson 4c9bf4803c Mark some circuit-building errors as "transient".
A "transient" error is one that does not indicate a true failure,
but rather an _expected_ need to retry.  When we hit one of these,
we do not count it against the total number of permitted failures.

(We do impose a higher limit on "real failures plus transient
failures", though, to prevent infinite loops in the event of a
programming error.

Closes #517.
2022-08-16 14:03:43 -04:00
Ian Jackson e4e06f66ec chanmgr testing: FakeChannel: retain the ChannelsParamsUpdates 2022-08-16 18:43:23 +01:00
Ian Jackson 7ae60c229b tor-proto, testing: Provide accessors for ChannelsParamsUpdates 2022-08-16 18:43:23 +01:00
Ian Jackson 9310ee2930 tor-proto, testing: Provide new_fake_channel
To test the padding control we will want this.
2022-08-16 18:43:23 +01:00
Ian Jackson 182b9775bb tor-proto, testing: Make fake_channel_details available
Now it's not just cfg(test), but feature testing.
2022-08-16 18:43:23 +01:00
Ian Jackson db3fafb0d4 tor-proto: Make "testing" feature that exports some things
We are going to want this for through-the-layers padding control
testing.
2022-08-16 18:43:23 +01:00
Ian Jackson 76403563e5 tor-cell, testing: Provide PaddingNegotiate::from_raw
This allows test cases to describe precisely the contents of the
negotiation cell ought to be generated.
2022-08-16 18:43:23 +01:00
Ian Jackson 2385d43279 tor-netdir, testnet: Provide construct_custom_netdir_with_params
We're going to want this for testing netdirs with padding parameters
that diff ere from the spec's default.
2022-08-16 18:43:23 +01:00
Ian Jackson cd8d41fd2e tor-netdoc: NetParams: impl FromIterator
Otherwise a caller who has a set of parameters must open-code the
loop.
2022-08-16 18:43:23 +01:00
Ian Jackson 50ca64218e channel padding: Send negotiation cells 2022-08-16 18:43:23 +01:00
Ian Jackson 0a1bffb047 tor-proto channel: Make arrangements to send PADDING_NEGOTIATE
This is actually a general facility for inserting locally-generated
cells into the outgoing stream.

It doesn't seem to be possible to do this without adding an additional
condition check to the reactor, since we need to insert it into the
right place in the stream, giving it priority over data, and only
using it up if there was room in the output.

We don't engage this machinery yet, because nothing sets
special_outgoing.
2022-08-16 18:43:23 +01:00
Ian Jackson 67072de75c channel padding: Send padding iff required
Now all the information is plumbed to the right place, and we can
actually decide if we're sending padding.

Additionally, we conditionalise sending timing parameters on whether
padding is actually enabled, so in dormant mode we do not generate
updates (broadcast to all channels) just to reconfigure unused timing
parameters.
2022-08-16 18:43:23 +01:00
Ian Jackson d8972e2cde chanmgr configuration: Avoid sending needless initial update(s)
Change ChannelsParams::initial_update to compare fields with their
default values, and, if they're the same as the default, not to
include them in the returned update.

And if that update is then empty, return None.

The overall effect is to avoid the call to chan.reparameterize if
we're using the builtin default parameters, which is usual.
2022-08-16 18:43:23 +01:00
Ian Jackson ede2510695 chanmgr configuration: Initialise correctly
This arranges that the ChannelsParams we have retain, and which we
send to every newly created channel, actually has the right
parameters, even if they're not the default.
2022-08-16 18:43:23 +01:00
Ian Jackson 76314b41f6 chanmgr configuration: Break out parameterize
We're going to want to call this at startup as well as during
reconfigurations.

Code motion.
2022-08-16 18:43:23 +01:00
Ian Jackson 1694296327 chanmgr configuration: Hadle lack of a NetDir
Now that the code that actually handles the netdir information can
cope with its lack, we can change the types of the various netdir
parameters and get rid of the foolish Bugs.
2022-08-16 18:43:23 +01:00
Ian Jackson fbcc609c17 chanmgr padding: Support reduced and disabled padding (prep)
Now we actually honour the configuration variable.

However, when it is set to None, we lack proper handling.  This will
be done bh turning None into 0,0 and then treating that as disabled.
There is a TODO for that.

Note that we *still* don't actually do or negotiate padding.
2022-08-16 18:43:23 +01:00
Ian Jackson 1688b5ef2a chanmgr padding: Fix low vs high comparison
Whoops.  This bug was completely masked by the fact that we don't
actually enable padding yet.
2022-08-16 18:43:23 +01:00
Ian Jackson 0b140effc6 chanmgr: Break out padding_parameters fn
Move some logic out of reconfigure_general into what was
update_padding_parameters_from_netdir, and rename that function.

We're going to want to call this twice, shortly...

* Move out the PaddingParametersBuilder
* Have it handle missing netdir, though we currently always pass Ok
* Have it handle the error cases

It still ignores the config for now.

No overall functional change.

"git show -b" may be a useful way to review the changes in what
becomes "padding_parameters".
2022-08-16 18:43:23 +01:00
Ian Jackson 156d42ab80 chanmgr: Postpone padding parameters computation
Now that we make an extract from the incoming NetDir, we can move the
padding parameters computation to after we take the lock.

This will be necessary for it to be able to depend on the config and
dormancy, records of which are protected by the chanmgr lock.
2022-08-16 18:43:23 +01:00
Ian Jackson eb9b164fd8 chanmgr: Introduce NetDirExtract
This will allow the padding parameter computation to have access to
the config, which is within the inner lock.
2022-08-16 18:43:23 +01:00
Ian Jackson 5e307a0989 chanmgr, testing: Provide config accessor for testing
The top-level global config is going to want to see whether its
machinations have the right effect.
2022-08-16 18:39:57 +01:00
Ian Jackson 582430d1ac channel: Use channel usage to control channel padding
We introduce the per-channel state that is used to keep track of
channel usage, and defer padding setup until it's wanted.
2022-08-16 18:39:57 +01:00
Ian Jackson 498d39626f channel: Introduce padding config
Nothing actually reads this yet, and we also want a client-global
default for padding.
2022-08-16 18:39:57 +01:00
Ian Jackson 76a1c45202 Introduce ChannelConfig
This commit is just the necessary plumbing.  The config is currently
empty.  We'll add something to it, for padding control, later.
2022-08-16 18:39:57 +01:00
Ian Jackson 2fbc196f8e tor-config: Introduce PaddingLevel
This will be used for controlling channel padding, for now.
2022-08-16 18:38:53 +01:00
Ian Jackson fbe80fd417 tor-config: Introduce ReconfigureError::Bug
Reconfigurations might fail due to internal errors.
2022-08-16 18:37:06 +01:00
Ian Jackson d407ef93ee channel: Provide somewhere for the frontend's mutable state
Right now this is just furniture.  We're going to put channel padding
control state here.
2022-08-16 18:37:06 +01:00
Ian Jackson 8d44ef05dc Provide ChannelUsage and plumb it all the way down
Channel padding depends on what the channel is being used for.  We
therefore need to let the channel code know this information.

The implementation of the per-channel padding control logic will be in
the new note_usage function, which for now is simply a stub.

A future commit will introduce a `PaddingControlState` which lives in
the channel frontend; consult the doc comment for that type to see why
the plumbing through the channel manager terminates in the channel
frontend.
2022-08-16 18:37:06 +01:00
Ian Jackson 3c23c2333a chanmgr: Introduce get_or_launch_internal
This is going to be useful in a moment.
2022-08-16 18:37:06 +01:00
Ian Jackson 61ab684f74 channel reparameterize: Change error type
This is going to be able to fail in other ways too, sadly.
2022-08-16 18:37:06 +01:00
Ian Jackson 4f44ef755a dormancy: Plumb through to chanmgr reconfigure_general
The chanmgr remembers the last dormancy state it was told.

We invent a chanmgr-specific Dormancy which the arti-client code knows
how to convert from the richer top-level dormant status.  This avoids
having to have everyone know all the variants of the top-level state.

To call reconfigure_general, we must also obtain and plumb through a
netdir.  Right now we must return an internal error if there is in
fact no netdir, because reconfigure_general does not yet cope with a
missing netdir.

Nothing actually *uses* the dormancy yet.
2022-08-16 18:37:06 +01:00
Ian Jackson 7387474be2 dormancy: tor-client: Break initial dormancy out into a variable
We're going to need to reuse this, so we can plumb the dormancy to
more places.  Breaking it out avoids having repeat the initial
dormancy value in two places.
2022-08-16 18:37:06 +01:00
Ian Jackson 968e6eab34 chanmgr: reconfigure_general: Rename fn and change types
This function is going to become the code for controlling channels, in
general.  (Including padding control.)  Right now it doesn't do most
of the things.

In this commit:

 * Change the prototype and the name now.
 * Pass `()` for the dormancy and config, adding TODOs.
 * Provide update_netdir method on AbstractChanMgr, and call that,
   rather than having the ChanMgr go directly into the channel.
   (That will enable us to test that `update_netdir` method
   with test cases that don't have a complete ChanMgr.)
2022-08-16 18:37:06 +01:00
Ian Jackson 6d16e3f947 channel params: ChannelsParamssUpdates: provide combine()
We're going to need this because the frontend is going to need to
defer some channel padding parameters updates.
2022-08-16 18:37:06 +01:00
Ian Jackson d1b7c06e0a channel params: Add a missing comma.
Unfortunately, because we don't have derive-adhoc here yet, rustfmt
didn't get to notice that this comma was needed.

We are going to add field(s), so add the comma now.
2022-08-16 18:37:06 +01:00
Ian Jackson cc731cef49 channel params: Rename initial_update (from total_update)
The semantics of this are going to become a bit more subtle.
2022-08-16 18:37:06 +01:00
Ian Jackson 35c8c3cd1b tor-proto: padding::Parameters: Provide all_zeroes
This exists so that we handle this case specially, as we will need to,
and so that we can represent disablement in a Parameters.
2022-08-16 18:37:06 +01:00
Ian Jackson e8a6cb62c4 tor-proto: padding::Parameters::padding_negotiate_cell
The channel manager is going to use this as part of constructing the
right cell for padding neogotiattion.
2022-08-16 18:37:06 +01:00
Ian Jackson 7843a09c90 tor-proto: padding::Parameters: Provide default_reduced constructor
We're going to want this so that we can do reduced padding.
2022-08-16 18:37:06 +01:00
Ian Jackson 38b76578be chancell: PaddingNegotiate: Provide start_default and a Default impl
As proposed in
  https://gitlab.torproject.org/tpo/core/torspec/-/merge_requests/77
2022-08-16 18:37:06 +01:00
Ian Jackson a26f341bd7 chancell: Introduce PaddingNegotiateCmd
This gets rid of some random hardcoded literals.  We're going to want
to reuse this, too.
2022-08-16 18:37:06 +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
Ian Jackson ecd6f16b6e chancell: PaddingNegotiate: Make Eq
This will be convenient for managing when to send these negotiation
messages.

While we're here, edit the comment to explain how this is (going to
be) used.
2022-08-16 18:37:06 +01:00
Ian Jackson b417075f11 channel padding: Add doc commentary with the channel padding plan
Much of this does not exist yet.  It will do by the end of this
branch.

Expand a doc note for ChannelsParamsUpdates too.
2022-08-16 18:37:06 +01:00
Ian Jackson b4cc8de67c chanmgr: tests: Introduce new_test_channel_map
This is going to change.  Centralise it first.
2022-08-16 18:37:06 +01:00
Ian Jackson 2be3ebb2ce chanmgr: tests: Introsuce new_test_abstract_chanmgr
This is going to change.  Centralise it first.
2022-08-16 18:37:06 +01:00
Ian Jackson b2df8755a4 channel: Centralise Channel::send_control
Replaces 4 open-coded call sites.

I am going to add one more.
2022-08-16 18:37:06 +01:00
Ian Jackson 806828c01c tor-proto: padding::Parameters: use impl_standard_builder
This is more standard.  It also provides the ::build() method.

This isn't a config type, and build failures ought not to happen,
so we use Bug for the error.
2022-08-16 18:37:06 +01:00
Ian Jackson 69629e0ab0 arti-client: TorClient constructor: add a blank line
The rustfmt-mandated different formatting of these two very similar
blocks is bad enough, without them being smooshed together.
2022-08-16 18:37:06 +01:00
Emptycup 668d8d4858 Clarify `REASON_DONE` 2022-08-16 13:28:43 +00:00
Nick Mathewson 3b2d187315 Merge branch 'hardening' into 'main'
arti: Add support for process hardening

Closes #364

See merge request tpo/core/arti!672
2022-08-15 17:19:53 +00:00
Nick Mathewson 3c1bfb4916 arti: Add support for process hardening
This is a compile-time feature with an associated configuration
flag, both enabled by default.

When it's turned on, hardening prevents the arti process from
dumping core or being attached to by low-privileged processes.
(This is a defense-in-depth measure, not an absolute way to prevent
attacks.  For more information, see
[`secmem_proc`](https://docs.rs/secmem-proc/0.1.1/secmem_proc/).)

Closes #364.
2022-08-15 12:59:56 -04:00
eta d183ba0d75 Merge branch 'nightly_fix_rtt' into 'main'
Fix nightly CI: allow print_stderr in rtt tests.

See merge request tpo/core/arti!673
2022-08-15 15:56:58 +00:00
Nick Mathewson fb5695570e Add a semver note for TcpStream send conversion. 2022-08-15 09:48:54 -04:00
Ian Jackson 740f306cb0 tor-rtcompat: Require that TcpStream be Send
The lack of this seems to have been an oversight.
2022-08-15 09:47:40 -04:00
Nick Mathewson 027633b68a Fix nightly CI: allow print_stderr in rtt tests. 2022-08-11 17:20:49 -04:00
Nick Mathewson e74612456f Merge branch 'less_arti_surface' into 'main'
Reduce the arti crate's API surface; improve semver documentation.

Closes #522, #530, and #532

See merge request tpo/core/arti!664
2022-08-11 20:09:53 +00:00
Nick Mathewson 7d7cdcd749 Add a few dire warnings about main; make main_main experimental. 2022-08-11 15:35:32 -04:00
Nick Mathewson 32a78651d2 Document more explicitly what "voiding a semver warranty" entails
Closes #522.
2022-08-11 15:35:32 -04:00
Nick Mathewson 3287c30f1c arti: `main_main` takes command-line arguments does not call exit() 2022-08-11 15:35:32 -04:00
Nick Mathewson f548a6ac55 arti: Move most public APIs behind `experimental-api`.
The remaining unconditionally public APIs are those related to our
configuration objects, and the main_main() API.

The rationale for making main_main() public is to have an actual
entry point.

The rationale for making the config APIs public is:

  1. We really do intend for others to be able to read our
     configuration files using this API.
  2. The structure of our configuration files is already part of our
     interface.

Closes #530.
2022-08-11 15:35:32 -04:00
Nick Mathewson 79c609e4f1 arti: Add a feature flag for dns-proxy.
It remains on-by-default, so users shouldn't notice a difference,
but it may help when we want to save a few bytes of binary size.

Closes #532
2022-08-11 15:35:32 -04:00
eta 0775b6d42d tor-congestion: implement the RTT estimation algorithm from prop#324
This commit implements the round-trip-time estimation algorithm from Tor
proposal 324, validating the implementation against the test vectors
found in C tor. (Note that at the time of writing, the new test vectors
may not be committed to C tor yet, but they will be soon.)

This also adds the necessary consensus parameters to `NetParameters`.
Some of them have been renamed in order to (hopefully) make them more
understandable.
2022-08-11 15:33:50 +01:00
Nick Mathewson 192a48c496 tor-proto: Add a comment about the tor-proto layer.
We want to clarify that the tor-proto crate should only know _how_
its objects behave, not _why they behave that way_.  (In other
words, we can have a "padding strategy" setting on a channel, but
not a "general usage" setting.)

Closes #531.
2022-08-10 12:13:01 -04:00
Nick Mathewson 71242f1500 Clarify that tor-proto _does_ create timers. 2022-08-10 12:02:46 -04:00
Nick Mathewson 36a28a8587 Merge branch 'main' into 'linkspec_refactor_v3'
# Conflicts:
#   crates/tor-netdir/semver.md
2022-08-10 14:48:57 +00:00
Nick Mathewson 19079c5a7d tor-proto: Unify the check_match code in channel and handshake
This had to become a new internal function, since at the point that
the handshake needs this code, it does not yet have a Channel to use.

This change made the error messages in the handshake code more
informative: and now they require a regex to check.  Later, we might
want to defer formatting these strings, but I don't think we need
to do it now.
2022-08-10 10:39:47 -04:00
Nick Mathewson 9b91edcb19 tor-netdir: Add a static assertion about RelayIdType::COUNT
Doing this will make sure that we fix a correctness issue in netdir that
will be caused if we add more IDs.

(Also add RelayIdType::COUNT in tor-linkspec.)
2022-08-10 10:39:47 -04:00
Nick Mathewson 2f4d58762c Implement `Into<RelayIdRef>` for `&RelayId`.
This will let us use `&RelayId` in all the places that take
`Into<RelayIdRef>`.
2022-08-10 10:39:47 -04:00
Nick Mathewson 6dc8b1af20 Make sure all HasRelayIds constaints allow ?Sized. 2022-08-10 10:39:47 -04:00
Nick Mathewson d1b2dd6fcb netdir: remove long-unused missing_descriptor_for code 2022-08-10 10:39:47 -04:00
Nick Mathewson 8067c3f960 tor-netdir: Remove or hide some no-longer-used accessors.
The hidden ones are only used to implement higher-level accessors;
the others are not used at all.
2022-08-10 10:39:47 -04:00
Nick Mathewson 37b3daa11d tor-netdir: Collapse by_id and by_relay_id into a single fn.
There are some downstream changes required for this to work, but
they are all just unit tests that could no longer infer the type of
an Ed25519 key.
2022-08-10 10:39:46 -04:00
Nick Mathewson 2d4507ff35 Final (?) API revisions for tor-linkspec
With this change, each individual identity type becomes optional.
The functions that expose them unconditionally are now in a "legacy"
trait that only some downstream types are expected to implement.

There are new convenience APIs in HasRelayIds:
  * to return Option<&keytype>,
  * to see if one identity-set contains another.

This commit will break several downstream crates!  For the
reviewer's convenience, I will put the fixes for those crates into a
series of squash! commits on this one.

tor-netdir
----------

Revise tor-netdir to accept optional identities.  This required some
caveats and workarounds about the cases where we have to deal with a
key type that the tor-netdir code does not currently recognize at
all.  If we start to add more identity types in the future, we may
well want more internal indices in this code.

tor-proto
---------

In order to make tor-proto support optional identities, there were
fewer changes than I thought.  Some "check" functions needed to start
looking at "all the ids we want" rather than at "the two known IDs";
they also needed to accommodate that case where we don't have an ID
that we demand.

This change will also help with bridges, since we want to be able to
connect to a bridge without knowing all of its IDs up front.

The protocol currently _requires_ the two current ID types in some
places. To deal with that, I added a new `MissingId` error.

I also removed a couple of unconditional identity accessors for
chanmgr; code should use `target().identity(...)` instead.

tor-chanmgr
-----------

This is an incomplete conversion: it does not at all handle channel
targets without Ed25519 identities yet.  It still uses those
identities to index its internal map from identity to channel; but
it gives a new `MissingId` error type if it's given a channel target
that doesn't have one.

We'll want to revise the map type again down the road when we
implement bridges, but I'd rather not step on the channel-padding
work in progress right now.

tor-guardmgr
------------

This change is mostly a matter of constructing owned identity types
more sensibly, rather than unwrapping them directly.

There are some places marked with TODOs where we still depend on
particular identity types, because of how the directory protocol
works.  This will need revisiting when we add bridge support here.

tor-circmgr
-----------

These changes are just relatively simple API changes in the tests.
2022-08-10 10:39:37 -04:00
Nick Mathewson 2c2224d6db linkspec: Add more accessors (some internal) for ids.
These will all be used shortly.
2022-08-10 10:39:37 -04:00
Nick Mathewson 0d74085269 Remove get_ed_identity_key as unused. 2022-08-10 10:39:36 -04:00
Nick Mathewson b56e1bf119 Introduce a RelayIdSet and use it in place of HashSet<RelayId>.
This makes lookups a little more efficient.  I do with that HashSet
just supported this use-case, but for now this seems our best option.
2022-08-10 10:39:36 -04:00
Nick Mathewson deaf8b657d Teach guard restrictions about RelayId.
This implementation is (sadly) too copy-heavy or now, because
HashSet<RelayId> can't be indexed with RelayIdRef.
2022-08-10 10:39:36 -04:00
Nick Mathewson d60d875749 Parsing, encoding, and serde for RelayId.
The formats used here are backward-compatible with those used by C
tor and those used elsewhere in our code.  We need a way to encode
_both_ current kinds of identities as a string that tells you what
kind of ID they are.  Traditionally we have used hexadecimal,
sometimes with a $, for RSA ids, and we have used base64 for Ed25519
IDs.

We also introduce a new forward-compatible format for new identity
keys in the future.  (The new format is the key identity type, a
colon, and the id encoded as base64.)  We will use this new format
_only_ when we need to encode identities in a way where it would be
otherwise unclear what kind of key we are dealing with.
2022-08-10 10:39:36 -04:00
Nick Mathewson 8af41bd65f Use accessors in two places where tests look at specific keys.
(It's safe to require these specific keys, since we constructed the
objects for testing, and we know for certain that they contain given
keys.)
2022-08-10 10:39:36 -04:00
Nick Mathewson 9d4729a072 Add a set of Identity-related types and accessors.
I wonder if these types are correct.  I think it makes sense to have
a Ref type like this, rather than just using `&RelayId`, but it
doesn't seems that I can make `RelayId` and `RelayIdRef` implement
Borrow and ToOwned for one another, so maybe I've messed up.
2022-08-10 10:39:36 -04:00
Nick Mathewson 62850a24c9 Define a constant for ED25519 identity length. 2022-08-10 10:39:36 -04:00
Nick Mathewson 8a2a0ec1a0 Decrease the lifetimes for storing descriptors.
These values were chosen experimentally, based on those from Tor, to
save disk space without wasting much bandwidth.

Closes #527.
2022-08-09 09:30:22 -04:00
Nick Mathewson 9e1e56daf3 Merge branch 'fix-nightly-ci' into 'main'
fix nighly ci

See merge request tpo/core/arti!668
2022-08-09 12:18:50 +00:00
eta bb51292fa2 Merge branch 'fix-android-runtime' into 'main'
fix fs-misstrust on android

See merge request tpo/core/arti!667
2022-08-09 11:17:06 +00:00
trinity-1686a 07e35a816d fix nighly ci 2022-08-08 23:02:57 +02:00
trinity-1686a 3cb5d27fb7 fix fs-misstrust on android
it would fail to link at runtime due to missing getgrnam_r in bionic

and then it would fail again because some directory is group writeable
2022-08-08 22:32:07 +02:00
Ian Jackson 33e0d67018 Update shellexpand, and switch to non-fork
Now we have bus>1 ownership of the crate name `shellexpand`.  I have
made a release, and retired `shellexpand-fork`.

The new shellexpand release switches to a (quite similarly) unforked
version of `dirs`.
2022-08-05 15:36:47 +01:00
Yuan Lyu 25bb25ddcb
Implement establish rendezvous cell 2022-08-05 00:04:42 -04:00
Nick Mathewson e3cc533853 Merge branch 'zeroize' into 'main'
Revise our handling of the zeroize trait

Closes #254

See merge request tpo/core/arti!655
2022-08-04 14:54:21 +00:00
Nick Mathewson 39cd6a2dc3 Merge branch 'provide_params_too' into 'main'
Add params() method to NetDirProvider

Closes #528

See merge request tpo/core/arti!658
2022-08-04 14:17:18 +00:00
Nick Mathewson 6ee9535126 guardmgr: Avoid a case of using HasRelayIds key methods. 2022-08-02 14:33:32 -04:00
Nick Mathewson 0bfc92ce8e netdir: Add and use a new ids_listed() function. 2022-08-02 14:32:57 -04:00
Nick Mathewson c291d86311 Avoid a simple usage of ed_identity() in circmgr tests 2022-08-02 14:27:47 -04:00
Nick Mathewson fdfc5f29e3 Introduce HasRelayIds::same_relay_ids.
This method tells if two HasRelayIds contain exactly the same set of
Relay identities, and is generally useful for debugging.
2022-08-02 14:19:00 -04:00
Ian Jackson d523ad495a Merge branch 'inc-rename' into 'main'
Rename `.inc` and other included files to end in `.rs`

Closes #381

See merge request tpo/core/arti!645
2022-08-02 16:48:49 +00:00
Ian Jackson c40130d047 Merge branch 's-micros-millis' into 'main'
tor-rtcompat: s/micros/millis inside a flaky test

Closes #515

See merge request tpo/core/arti!644
2022-08-02 16:47:39 +00:00
Nick Mathewson 0e41913a4c guardmgr: Change APIs that used to take IDs.
These are the other inspiration for #428.
2022-08-02 12:40:57 -04:00
Nick Mathewson 2d32a4602b guardmgr: Replace IdPair with RelayIds
I believe that this was the original motivation behind #428.
2022-08-02 12:40:57 -04:00
Nick Mathewson be7cf7a24b Implement serde traits on RelayIds.
This will allow RelayIds to replace IdPair in tor-guardmgr.  (The
fields are named accordingly with `serde(rename)`.)
2022-08-02 12:40:55 -04:00
Nick Mathewson 9763d8227b netdir: add an accessor that takes a HasRelayIds. 2022-08-02 12:40:25 -04:00
Nick Mathewson b68a3ed5e5 tor-linkspec: Refactor out traits to represent a relay's ID set.
We want the set of identities supported by a relay to be extensible
in the future with minimal fuss; we'd also like to make working
with these ID sets more convenient.  To handle that, this commit
adds a new trait for "Something that has the same IDs as a relay"
and a new object for "an owned representation of a relay's IDs."

This commit introduces a similar trait for "Something with a list of
SocketAddr, like a relay has."  There's no owned equivelent for
that, since Vec<SocketAddr> is already a thing.

Closes #428.
2022-08-02 12:40:23 -04:00
Nick Mathewson 1eb8b02f47 Remove some testing-only reimplementations of OwnedChanTarget.
These predate OwnedChanTarget, and are no longer needed.
2022-08-02 12:39:30 -04:00
Nick Mathewson 760e2f7e95 Finish implementation of params() for DirMgr.
Now it maintains an up-to-date set of default parameters to be
handed out if there is no directory.

Closes #528.
2022-08-02 10:20:13 -04:00
Nick Mathewson 9d2fb92c37 Add params() method to NetDirProvider, and partial implementation
This method will let users get the latest `NetParameters`, with
user-configured overrides, even if there is no current directory at
all.

Part of #528
2022-08-02 09:50:39 -04:00
Dimitris Apostolou 5eb45de6f8
Fix typos 2022-08-01 23:55:33 +03:00
Nick Mathewson 37e6c95fdc tor-proto: Use correct SecretBuf in handshakes.
Everything that is a secret encryption key, or an input that is used
to produce a secret encryption key, has to get zeroized.  And that's
all!

Closes #254.
2022-08-01 15:41:22 -04:00
Nick Mathewson eedd63d5e9 tor-proto: Replace SecretBytes with SecretBuf.
This does not yet make sure that `SecretBuf` is used where it
_should_ be, but at least it ensures that most uses of `SecretBytes`
will indeed act as intended, and make sure that whatever they
contain is zeroized.

It requires some corresponding changes to method calls for
correctness and type conformance.
2022-08-01 15:41:22 -04:00
Nick Mathewson f1c6447403 New SecretBuf type in tor-bytes
This Writer is a simple wrapper around `Vec<u8>` that makes sure
that its contents are cleared whenever they are dropped _or
reallocated_.

The reallocation is the important part here: without that, we risk
not zeroizing the first allocation of the buffer.
2022-08-01 15:41:22 -04:00
Nick Mathewson 50b42b50df Add TODO comments about unwanted copies. 2022-08-01 12:40:13 -04:00
Nick Mathewson cba0f40aa4 tor-llcrypto: make AES key objects ZeroizeOnDrop when using openssl
Part of #254.
2022-08-01 12:38:34 -04:00
Nick Mathewson dd0a83925c Stop deriving Zeroize for RsaIdentity.
These are not secret.
2022-08-01 12:27:53 -04:00
Nick Mathewson 514c3a8e62 Use the `zeroize` feature in several crates
Using `zeroize` here tells these crates that they should make
various structures zeroize-on-drop.

(This is not yet implemented in `aes` 0.8.1, but support has been
merged in the repository for `aes`, so it should go out in the next
release.)

No corresponding feature flag is needed to enable zeroize-on-drop
for `rsa` and `*25519-dalek` private keys.
2022-08-01 12:13:05 -04:00