Commit Graph

2203 Commits

Author SHA1 Message Date
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