The code flow in theory can end up with a layer_hint to be NULL but in
practice it should never happen because with an origin circuit, we must have
the layer_hint.
Just in case, BUG() on it if we ever end up in this situation and recover by
closing the circuit.
Fixes #30467.
Signed-off-by: David Goulet <dgoulet@torproject.org>
David Goulet [Fri, 3 May 2019 17:24:06 +0000 (13:24 -0400)]
sendme: Add FlowCtrl protover value
See proposal 289 section 4.3 for more details.
It describes the flow control protocol at the circuit and stream level. If
there is no FlowCtrl protocol version, tor supports the unauthenticated flow
control features from its supported Relay protocols.
At this commit, relay will start advertising FlowCtrl=1 meaning they support
authenticated SENDMEs v1.
Closes #30363
Signed-off-by: David Goulet <dgoulet@torproject.org>
Hiding crypt_path_t: Ensure that ->private is initialized.
Now that we are using a constructor we should be more careful that we are
always using the constructor to initialize crypt_path_t, so make sure that
->private is initialized.
Nick Mathewson [Tue, 30 Apr 2019 16:42:33 +0000 (12:42 -0400)]
Move voteflags.[ch] to become dirauth only.
For various reasons, this was a nontrivial movement. There are
several places in the code where we do something like "update the
flags on this routerstatus or node if we're an authority", and at
least one where we pretended to be an authority when we weren't.
Nick Mathewson [Tue, 30 Apr 2019 18:45:58 +0000 (14:45 -0400)]
Use safe_mem_is_zero in a few more places.
I don't believe any of these represent a real timing vulnerability
(remote timing against memcmp() on a modern CPU is not easy), but
these are the ones where I believe we should be more careful.
Nick Mathewson [Tue, 30 Apr 2019 18:43:35 +0000 (14:43 -0400)]
Rename tor_mem_is_zero to fast_mem_is_zero()
For memeq and friends, "tor_" indicates constant-time and "fast_"
indicates optimized. I'm fine with leaving the constant-time
"safe_mem_is_zero" with its current name, but the "tor_" prefix on
the current optimized version is misleading.
Also, make the tor_digest*_is_zero() uniformly constant-time, and
add a fast_digest*_is_zero() version to use as needed.
A later commit in this branch will fix all the users of
tor_mem_is_zero().
Taylor Yu [Wed, 10 Apr 2019 20:11:36 +0000 (15:11 -0500)]
Manually fix some control replies
Manually fix up some reply-generating code that the Coccinelle scripts
won't match. Some more complicated ones remain -- these are mostly
ones that accumulate data to send, and then call connection_buf_add()
or connection_write_str_to_buf() directly.
Taylor Yu [Tue, 9 Apr 2019 17:22:31 +0000 (12:22 -0500)]
Factor out control reply output
Create a set of abstractions for controller commands and events to
output replies to the control channel. The control protocol has a
relatively consistent SMTP-like structure, so it's helpful when code
that implements control commands and events doesn't explicitly format
everything on its own.
Taylor Yu [Mon, 8 Apr 2019 16:34:12 +0000 (11:34 -0500)]
Split reply formatting out of control_fmt.c
Split the core reply formatting code out of control_fmt.c into
control_proto.c. The remaining code in control_format.c deals with
specific subsystems and will eventually move to join those subsystems.
Nick Mathewson [Fri, 26 Apr 2019 17:17:35 +0000 (13:17 -0400)]
Rename and clarify some functions for periodic events
When we tell the periodic event manager about an event, we are
"registering" that event. The event sits around without being
usable, however, until we "connect" the event to libevent. In the
end, we "disconnect" the event and remove its libevent parts.
Previously, we called these operations "add", "setup", and
"destroy", which led to confusion.
Nick Mathewson [Thu, 25 Apr 2019 18:20:41 +0000 (14:20 -0400)]
Turn 'mainloop' into a subsystem.
We need a little refactoring for this to work, since the
initialization code for the periodic events assumes that libevent is
already initialized, which it can't be until it's configured.
This change, combined with the previous ones, lets other subsystems
declare their own periodic events, without mainloop.c having to know
about them. Implements ticket 30293.