Commit Graph

19142 Commits

Author SHA1 Message Date
Nick Mathewson
10b2428224 Merge branch 'bug23291_028' into maint-0.3.1 2017-08-21 15:06:39 -04:00
Ties Stuij
7ba873ca2d 22839: fix check_heap_buffer buffer size in test-memwipe 2017-08-21 15:03:54 -04:00
Nick Mathewson
6f3208670a Merge branch 'maint-0.3.1' 2017-08-21 14:20:38 -04:00
Nick Mathewson
6be0e28670 whitespace fixes 2017-08-21 14:18:41 -04:00
George Kadianakis
1491c0d024 Fix triggerable BUG() when decoding hsv3 descriptors.
Also improve the unittest to make sure it catches the right error.
2017-08-21 19:16:45 +03:00
George Kadianakis
45732a1a13 Add unittest for #23233.
This will fail currently since the bug is not fixed yet.
2017-08-21 19:16:30 +03:00
George Kadianakis
5d89ea1e6c prop224: Decouple the HS part of connection_ap_handshake_rewrite_and_attach().
We will need to edit this function, and it's already pretty huge. Let's make
it a bit smaller.

This commit moves code, fixes a 80 char line and add two lines at the start to
make it compile. Trivial change.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-19 16:42:26 +03:00
George Kadianakis
bce18a7642 prop224: Refactor parse_extended_hostname() to parse v3 addrs.
We need this func so that we recognize SOCKS conns to v3 addresses.

- Also rename rend_valid_service_id() to rend_valid_v2_service_id()

- Also move parse_extended_hostname() tests to their own unittest, and
  add a v3 address to the test as well.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-19 16:42:26 +03:00
George Kadianakis
3e593f09ad prop224: Recompute all HSDir indices when we enter overlap mode.
When we enter overlap mode we start using the next hsdir index of
relays. However, we only compute the next hsdir index of relays when we
receive a consensus or their descriptor. This means that there is a
window of time between entering the overlap period and fetching the
consensus where relays have their next hsdir index uninitialized. This
patch fixes this by recomputing all hsdir indices when we first enter
the overlap period.
2017-08-19 16:29:23 +03:00
George Kadianakis
7823c98a38 prop224: Improve descriptor reupload logic.
We want to reupload our descriptor if its set of responsible HSDirs
changed to minimize reachability issues.

This patch adds a callback everytime we get new dirinfo which checks if
the hash ring changed and reuploads descriptor if needed.
2017-08-19 16:28:48 +03:00
George Kadianakis
26c85fcc86 test: Improve get_responsible_hsdirs test. 2017-08-19 16:28:48 +03:00
George Kadianakis
1f7b8012ae prop224: Only upload descriptor if we have good hash ring and SRV.
Make sure we have a live consensus (for SRV) and enough descriptors (for
hash ring).

Also fix unittests that broke.
2017-08-19 16:28:47 +03:00
George Kadianakis
43343ec019 prop224: Improve our checks for unset HSDir index.
We used to not check next hsdir index.
2017-08-19 16:28:43 +03:00
David Goulet
5750f18bc7 sr: Log voting schedule at debug level
Because the HS subsystem calls it every second, change the log level to debug
so it doesn't spam the info log.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-19 16:20:07 +03:00
Suphanat Chunhapanya
97347b1109 Fuzz outer layer of hsv3 descriptor
The code in fuzz_hsdescv3.c fuzzes the unencrypted layer of the hsv3
descriptor. We need to fuzz the encrypted layer later.
2017-08-13 17:50:51 +07:00
Suphanat Chunhapanya
c860282fc0 Mock rsa_ed25519_crosscert_check
This commit just mocks the rsa_ed25519_crosscert_check to be used later
in the fuzzer.
2017-08-13 16:15:40 +07:00
David Goulet
257f50b22f Make Windows happy for time_t printf format
Our Windows compiler treats "time_t" as long long int but Linux likes it
long int so cast those to make Windows happy.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-11 15:08:45 -04:00
David Goulet
598bf986b6 test: Fix typing issues found by clang
Partially fix #23224.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-11 14:59:28 -04:00
David Goulet
9df4261407 test: Fix memory leak in test_hs_common.c
Partially fixes #23223

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-11 14:46:27 -04:00
David Goulet
60c7da71ab test: Fix hs common test for Windows
Use the PATH_SEPARATOR for a path comparaison so it works with Windows as
well.

Partially fix #23223

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-11 14:42:20 -04:00
Nick Mathewson
efbd4a33f4 Raise MIN_DL_PER_REQUEST to 32
This change should improve overhead for downloading small numbers of
descriptors and microdescriptors by improving compression
performance and lowering directory request overhead.

Closes ticket 23220.
2017-08-11 13:54:01 -04:00
Nick Mathewson
a368cadf95 Merge branch 'bug18982' 2017-08-11 12:11:42 -04:00
Nick Mathewson
c3a0cdeaab Add # to "hop N" messages to disambiguate from old messages. 2017-08-11 12:11:27 -04:00
Nick Mathewson
6247f5a5ba Merge branch 'maint-0.3.1' 2017-08-11 11:51:06 -04:00
Nick Mathewson
133e1e870b Merge remote-tracking branch 'dgoulet/bug23091_032_01' 2017-08-11 09:39:57 -04:00
Nick Mathewson
b4963da987 Treat a bad tor_spawn_background() as a BUG().
The contract is that, if may_spawn_background_process() is 0, you're
not even allowed to try to spawn a process.
2017-08-09 10:58:07 -04:00
Nick Mathewson
5fa8d05bfa Block managed proxies at a higher point 2017-08-09 10:58:07 -04:00
Nick Mathewson
801aa5d03b Block the port-forwarding helper at a higher point 2017-08-09 10:58:07 -04:00
Nick Mathewson
eb43401bfb Add a 'NoExec' option that causes tor_spawn_background() to fail
Core of an implementation for 22976.
2017-08-09 10:45:48 -04:00
Nick Mathewson
94352368db Remove the #if 0ed code that was supposed to let the sandbox allow exec 2017-08-09 10:36:45 -04:00
Nick Mathewson
418f3d6298 Make sure we always wind up checking i2d_*'s output.
The biggest offender here was sometimes not checking the output of
crypto_pk_get_digest.

Fixes bug 19418.  Reported by Guido Vranken.
2017-08-09 09:24:16 -04:00
Nick Mathewson
6f7d548bc4 Make write_escaped_data more robust to large inputs.
The old implementation would fail with super-long inputs. We never
gave it any, but still, it's nicer to dtrt here.

Reported by Guido Vranken. Fixes bug 19281.
2017-08-09 09:02:12 -04:00
Nick Mathewson
d2713b4ddc fix another 32-bit warning 2017-08-09 08:32:39 -04:00
Nick Mathewson
a3685ba0c5 Fix a warning on 32-bit clang 2017-08-09 08:31:44 -04:00
George Kadianakis
21e5146529 prop224: Fix coverity warnings from #20657 merge.
- Fix various ssize_t/size_t confusions in the tests.

- Fix a weird memset argument:
  "bad_memset: Argument -16 in memset loses precision in
  memset(&desc_two->blinded_kp.pubkey.pubkey, -16, 32UL)."

- Fix check_after_deref instance in check_state_line_for_service_rev_counter():
  "check_after_deref: Null-checking items suggests that it may be null,
  but it has already been dereferenced on all paths leading to the
  check."
2017-08-09 13:49:12 +03:00
Nick Mathewson
8e84968ffb Re-run trunnel. 2017-08-08 20:34:39 -04:00
Nick Mathewson
34e4122025 Merge branch 'ticket20657_nickm_bugfixes_squashed' 2017-08-08 20:31:57 -04:00
Nick Mathewson
2f17743d6f Put comment in the trunnel file, so it wont go away. 2017-08-08 20:31:47 -04:00
George Kadianakis
686891d67e prop224: Add XXX about opaqueness of link_specifier_t. 2017-08-08 20:29:35 -04:00
George Kadianakis
5c4f4acedb prop224: Function to inc/decrement num rendezvous stream
Add a common function for both legacy and prop224 hidden service to increment
and decrement the rendezvous stream counter on an origin circuit.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:35 -04:00
David Goulet
400ba2f636 prop224: Always note down the use of internal circuit
Also, this removes all the callsite of this rephist in the hs subsystem

Fixes #23097

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:35 -04:00
George Kadianakis
0a0bbfe96f Add note about handling INTRODUCE2 cells.
Also fix a check-spaces instance.
2017-08-08 20:29:35 -04:00
George Kadianakis
ff249ee4a6 Start caching disaster SRV values.
Also add some unittests.
2017-08-08 20:29:35 -04:00
George Kadianakis
101ce6da01 Fix the build_hs_index() function.
Also add a unittest for hs_get_responsible_hsdirs() which was used to
find and fix the bug.
2017-08-08 20:29:35 -04:00
George Kadianakis
8bac50d755 prop224: Improve comments and tests for ed25519 keys in IPs/RPs.
Also make sure we are not gonna advertise the ed25519 key of an intro
point that doesn't support it.
2017-08-08 20:29:35 -04:00
George Kadianakis
273638288d Improve docs on rendezvous circ relaunch. 2017-08-08 20:29:35 -04:00
George Kadianakis
827bd0e882 Increase HS desc cert lifetime.
We used to have a small HS desc cert lifetime but those certs can stick
around for 36 hours if they get initialized in the beginning of overlap
period.

[warn] Bug: Non-fatal assertion !(hs_desc_encode_descriptor(desc->desc, &desc->signing_kp, &encoded_desc) < 0) failed in
upload_descriptor_to_hsdir at src/or/hs_service.c:1886. Stack trace: (on Tor 0.3.2.0-alpha-dev b4a14555597fb9b3)
2017-08-08 20:29:35 -04:00
George Kadianakis
bd3213b17e prop224 tests: Better HS time period tests. 2017-08-08 20:29:35 -04:00
George Kadianakis
e70341deb7 prop224 tests: Better HS address tests. 2017-08-08 20:29:35 -04:00
George Kadianakis
4a1b57e9b0 prop224 tests: Improve SRV protocol tests. 2017-08-08 20:29:35 -04:00
George Kadianakis
0bf8587858 Do more type checking when setting HS idents.
I repurposed the old directory_request_set_hs_ident() into a new
directory_request_upload_set_hs_ident() which is only used for the
upload purpose and so it can assert on the dir_purpose.

When coding the client-side we can make a second function for fetch.
2017-08-08 20:29:35 -04:00
George Kadianakis
fe0c40c9b3 Fix broken intro point unittest.
The structure was not zeroed out, and left some boolean fields
uninitialized.
2017-08-08 20:29:35 -04:00
George Kadianakis
471489ca03 Extract intro point onion key even with multiple types. 2017-08-08 20:29:34 -04:00
George Kadianakis
a464d49aeb prop224 tests: test_gen_establish_intro_cell() check cell contents. 2017-08-08 20:29:34 -04:00
George Kadianakis
c62da5cf95 Improve code based on Nick review:
- Fix some more crazy ternary ops.
- Fix the order of disaster SRV computation.
- Whitespace fixes.
- Remove a redundant warn.
- Better docs.
2017-08-08 20:29:34 -04:00
George Kadianakis
4ad4467fa1 Don't double hash the ed25519 blind key parameter.
We used to do:
   h = H(BLIND_STRING | H(A | s | B | N )
when we should be doing:
   h = H(BLIND_STRING | A | s | B | N)

Change the logic so that hs_common.c does the hashing, and our ed25519
libraries just receive the hashed parameter ready-made. That's easier
than doing the hashing on the ed25519 libraries, since that means we
would have to pass them a variable-length param (depending on whether
's' is set or not).

Also fix the ed25519 test vectors since they were also double hashing.
2017-08-08 20:29:34 -04:00
George Kadianakis
b89d2fa1db Don't set HSDir index if we don't have a live consensus.
We also had to alter the SRV functions to take a consensus as optional
input, since we might be setting our HSDir index using a consensus that
is currently being processed and won't be returned by the
networkstatus_get_live_consensus() function.

This change has two results:

a) It makes sure we are using a fresh consensus with the right SRV value
   when we are calculating the HSDir hash ring.

b) It ensures that we will not use the sr_get_current/previous()
   functions when we don't have a consensus which would have falsely
   triggered the disaster SRV logic.
2017-08-08 20:29:34 -04:00
George Kadianakis
440eaa9b22 Correctly assign HSDir flags based on protocol list
In Nick's words:

"We want to always return false if the platform is a Tor version, and it
is not as new as 0.3.0.8 -- but if the platform is not a Tor version, or
if the version is as new as 0.3.0.8, then we want to obey the protocol
list.

That way, other implementations of our protocol won't have to claim any
particular Tor version, and future versions of Tor will have the freedom
to drop this protocol in the distant future."
2017-08-08 20:29:34 -04:00
George Kadianakis
a561a10da7 Fix small easy bugs all around
- Fix log message format string.
- Do extra circuit purpose check.
- wipe memory in a clear function
- Make sure we don't double add intro points in our list
- Make sure we don't double close intro circuits.
- s/tt_u64_op/tt_i64_op/
2017-08-08 20:29:34 -04:00
George Kadianakis
2c6f2e9be9 Constify functions that can be constified. 2017-08-08 20:29:34 -04:00
George Kadianakis
5ca9b830ea Improve documentation all around the codebase. 2017-08-08 20:29:34 -04:00
George Kadianakis
f106af3c41 Make ed25519 id keys optional for IPs and RPs. 2017-08-08 20:29:34 -04:00
George Kadianakis
d88984a137 Improve setting hsdir index procedure.
- Fix memleak.
2017-08-08 20:29:34 -04:00
George Kadianakis
706392e6b5 Make HidServRevCounter be a LINELIST as it should. 2017-08-08 20:29:34 -04:00
George Kadianakis
3ce69a58ce Rename some free() functions that are actually clear(). 2017-08-08 20:29:34 -04:00
George Kadianakis
3bc52dae89 Validate intro point limits to avoid asserts. 2017-08-08 20:29:34 -04:00
George Kadianakis
7c507a1f7f Relax assertions: turn them to BUGs and non-fatal asserts. 2017-08-08 20:29:34 -04:00
George Kadianakis
e42c55626a prop224: Don't use nodes as HSDirs if they don't have an HSDir index. 2017-08-08 20:29:34 -04:00
George Kadianakis
74981d1f13 memwipe interesting unused memory 2017-08-08 20:29:34 -04:00
George Kadianakis
29b3dd1c05 Fix 32-bit bug when writing address to descriptor.
We used to sizeof() a pointer. Let's just use asprintf to avoid having
to be smart.
2017-08-08 20:29:34 -04:00
George Kadianakis
434112df4b Fix ternary operator abuse. 2017-08-08 20:29:34 -04:00
George Kadianakis
1397ac11d6 Use htonll() when INT_8 is used.
Also prepend period_length to any period_num, as specified by the spec.
2017-08-08 20:29:34 -04:00
David Goulet
708789025d prop224: Remove INTRODUCE2 legacy handling
Turns out that introduction points don't care about the INTRODUCE2 cell
format as long as the top field is LEGACY_KEY_ID as expected. So let's
use a single INTRODUCE format regardless of the introduction point being
legacy or not.

This also removes the polymorphic void* situation.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
George Kadianakis
ec0da9a6f1 test: Unbreak test_upload_descriptors()
To upload the descriptor we needed a state file to write the rev counters in,
but that test did not have a state file initialized.

Also fix the typo in its func name.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
George Kadianakis
b47139d758 test: Unit tests for the revision counter state file codethe
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
George Kadianakis
6f046b2191 prop224: Use state file to save/load revision counters
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
George Kadianakis
2e5a2d64bd prop224: Refactor the overlap function to not use absolute time.
We consider to be in overlap mode when we are in the period of time between a
fresh SRV and the beginning of the new time period (in the normal network this
is between 00:00 and 12:00 UTC). This commit edits that function to use the
above semantic logic instead of absolute times.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
George Kadianakis
6c00bd1f10 prop224: Make prop224 time periods smaller in testnets.
It used to be that time periods were 24 hours long even on chutney,
which made testing harder. With this commit, time periods have the same
length as a full SRV protocol run, which means that they will change
every 4 minutes in a 10-second voting interval chutney network!
2017-08-08 20:29:34 -04:00
George Kadianakis
cf58451a8b prop224: Refactor hs_get_time_period_num() to not use absolute time.
Instead use the SRV protocol duration to calculate the rotation offset
that was previously hardcoded to 12 hours.
2017-08-08 20:29:34 -04:00
George Kadianakis
2cd5f9a2fc prop224: Compute start time of next time period. 2017-08-08 20:29:34 -04:00
George Kadianakis
0b22b7fce3 SR: Calculate current SRV phase/run duration.
This is also needed to make the HS desc overlap mode function
independent of absolute hours.
2017-08-08 20:29:34 -04:00
George Kadianakis
2af254096f SR: Compute the start time of the current protocol run.
This function will be used to make the HS desc overlap function be
independent of absolute times.
2017-08-08 20:29:34 -04:00
David Goulet
85c80adf4a prop224: HSDir v3 support is >= 0.3.0.8
Because of bug #22447, we have to select nodes that are at least this version.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
2cae4f4100 prop224: Move get_intro_circuit() to hs_circuit.c
Make this function public so we can use it both in hs_circuit.c and
hs_service.c to avoid code duplication.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
6c3d525c36 prop224: Make circuit prediction aware of v3 services
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
713eb08bc9 prop224: Add service rendezvous circuit relaunch
This introduces a callback to relaunch a service rendezvous circuit when a
previous one failed to build or expired.

It unifies the legacy function rend_service_relaunch_rendezvous() with one for
specific to prop224. There is now only one entry point for that which is
hs_circ_retry_service_rendezvous_point() supporting both legacy and prop224
circuits.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
1b403a8382 prop224: Different intro point timings with TestingNetwork
Change the timing for intro point's lifetime and maximum amount of circuit we
are allowed to launch in a TestingNetwork. This is particurlarly useful for
chutney testing to test intro point rotation.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
15864a1b70 prop224: Add a circuit has closed callback
When the circuit is about to be freed which has been marked close before, for
introduction circuit we now call this has_closed() callback so we can cleanup
any introduction point that have retried to many times or at least flag them
that their circuit is not established anymore.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
4a8cf17897 hs: Rename num_rend_services()
Renamed to rend_num_services() so it is consistent with the legacy naming.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
George Kadianakis
a6b6227b21 test: Fix prop224 HS descriptor to use subcredential
We used to use NULL subcredential which is a terrible terrible idea.  Refactor
HS unittests to use subcredentials.

Also add some non-fatal asserts to make sure that we always use subcredentials
when decoding/encoding descs.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
b547c54239 test: Add unit test coverage of hs_service.c
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
559ffd7179 test: Refactor HS tests to use the new ESTABLISH_INTRO cell code
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
8ffb49422b test: Add test_hs_common unit tests
Move tests from test_hs_service.c to this file.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
6061f5e2bd test: Add test_hs_ntor unit tests
Move the ntor test from test_hs_service.c to this file.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:34 -04:00
David Goulet
472835d6e9 test: Add test_hs_cell unit tests
Move ESTABLISH_INTRO tests from test_hs_service.c to this new file.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
30b5c6a95e prop224: Link rendezvous circuit to edge connection
This commit refactors the handle_hs_exit_conn() function introduced at a prior
commit that connects the rendezvous circuit to the edge connection used to
connect to the service virtual port requested in a BEGIN cell.

The refactor adds the support for prop224 adding the
hs_service_set_conn_addr_port() function that has the same purpose has
rend_service_set_connection_addr_port() from the legacy code.

The rend_service_set_connection_addr_port() has also been a bit refactored so
the common code can be shared between the two HS subsystems (legacy and
prop224).

In terms of functionallity, nothing has changed, we still close the circuits
in case of failure for the same reasons as the legacy system currently does.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
7163ce7f62 hs: Refactor the service exit connection code
This commit simply moves the code from the if condition of a rendezvous
circuit to a function to handle such a connection. No code was modified
_except_ the use or rh.stream_id changed to n_stream->stream_id so we don't
have to pass the cell header to the function.

This is groundwork for prop224 support which will break down the
handle_hs_exit_conn() depending on the version of hidden service the circuit
and edge connection is for.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
5d2506d70c prop224: Sandbox support for service
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
848e701f55 prop224: Make the number of extra intro point a consensus param
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
f0e02e3a14 prop224: Make intro point min/max lifetime a consensus param
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
670cecaf66 prop224: Make INTRODUCE2 min/max a consensus param
Introduction point are rotated either if we get X amounts of INTRODUCE2 cells
on it or a time based expiration. This commit adds two consensus parameters
which are the min and max value bounding the random value X.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
feed375f19 prop224: Implement a service intro point failure cache
Imagine a Tor network where you have only 8 nodes available due to some
reasons. And your hidden service wants 8 introduction points. Everything is
fine but then a node goes down bringing the network to 7. The service will
retry 3 times that node and then give up but keep it in a failure cache for 5
minutes (INTRO_CIRC_RETRY_PERIOD) so it doesn't retry it non stop and exhaust
the maximum number of circuit retry.

In the real public network today, this is unlikely to happen unless the
ExcludeNodes list is extremely restrictive.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
ac848777f9 prop224: Upload service descriptors
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
bce0c6caad prop224: Directory function to upload descriptor
This commit adds a directory command function to make an upload directory
request for a service descriptor.

It is not used yet, just the groundwork.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
0bcc9ad58d prop224: Add a responsible HSDir function
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
06909cafef prop224: Add hsdir consensus parameters
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
267bc7bc3b prop224: Build hsdir index for node_t
This hsdir index value is used to give an index value to all node_t (relays)
that supports HSDir v3. An index value is then computed using the blinded key
to know where to fetch/upload the service descriptor from/to.

To avoid computing that index value everytime the client/service needs it, we
do that everytime we get a new consensus which then doesn't change until the
next one. The downside is that we need to sort them once we need to compute
the set of responsible HSDir.

Finally, the "hs_index" function is also added but not used. It will be used
in later commits to compute which node_t is a responsible HSDir for the
service we want to fetch/upload the descriptor.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
77b279c35c prop224: Add service replay cache
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
27dd1a716c prop224: Support INTRODUCE2 cell replay cache
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
100386e659 prop224: Support legacy INTRODUCE2 cell
Also rename some function to follow a bit more the naming convention in that
file.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
dfa6301aed prop224: Handle service RENDEZVOUS1 cell
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
acc7c4ee95 prop224: Establish rendezvous circuit for service
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
5e710368b3 prop224: Handle service INTRODUCE2 cell
At this commit, launching rendezvous circuit is not implemented, only a
placeholder.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
faadbafba3 prop224: Add helper function to lookup HS objects
Add this helper function that can lookup and return all the needed object from
a circuit identifier. It is a pattern we do often so make it nicer and avoid
duplicating it everywhere.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
79e8d113d5 prop224: Handle service INTRO_ESTABLISHED cell
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
d765cf30b5 prop224: Circuit has opened and ESTABLISH_INTRO cell
Add the entry point from the circuit subsystem of "circuit has opened" which
is for all type of hidden service circuits. For the introduction point, this
commit actually adds the support for handling those circuits when opened and
sending ESTABLISH_INTRO on a circuit.

Rendevzou point circuit aren't supported yet at this commit.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
6a21ac7f98 prop224: Introduction circuit creation
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
00a02a3a59 prop224: Service v3 descriptor creation and logic
This commit adds the functionality for a service to build its descriptor.
Also, a global call to build all descriptors for all services is added to the
service scheduled events.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
c4ba4d4cc8 prop224: Implement subcredential creation
Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
George Kadianakis
f53b72baf7 prop224: Add descriptor overlap mode function
The function has been added but not used except for the unit tests.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
0f104ddce5 prop224: Scheduled events for service
Add the main loop entry point to the HS service subsystem. It is run every
second and make sure that all services are in their quiescent state after that
which means valid descriptors, all needed circuits opened and latest
descriptors have been uploaded.

For now, only v2 is supported and placeholders for v3 actions for that main
loop callback.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
9052530bdd prop224: API for the creation of blinded keys
Add a function for both the client and service side that is building a blinded
key from a keypair (service) and from a public key (client). Those two
functions uses the current time period information to build the key.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
David Goulet
44e3255c4d hs: Implement constructor for hs_desc_intro_point_t
Add a new and free function for hs_desc_intro_point_t so the service can use
them to setup those objects properly.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-08 20:29:33 -04:00
Nick Mathewson
72832086e2 Use a single free-and-exit strategy in config_process_include.
This avoids a double-free when a pointer already freed with
tor_free(config_line) is freed again in the cleanup-and-exit code.

Fixes bug 23155.
2017-08-08 20:08:43 -04:00
Nick Mathewson
649104fdb9 Remove a needless memwipe.
The interior of ctx here is already wiped by
crypto_digest_free(). This memwipe call only wiped the pointer
itself, which isn't sensitive.
2017-08-08 19:58:19 -04:00
Nick Mathewson
b08a2dc954 Merge branch 'maint-0.3.1' 2017-08-08 19:29:10 -04:00
Nick Mathewson
a47b8fcf92 Merge branch 'bug23139' into maint-0.3.1 2017-08-08 19:29:05 -04:00
Nick Mathewson
48a57f9815 Merge branch 'maint-0.3.1' 2017-08-08 10:10:52 -04:00
Nick Mathewson
7465ea4ad9 Remove some LCOV_EXCL stuff that I think may be testable after all.
This is partial revert on 22286.

Also, tweak some log messages to be distinct.
2017-08-08 10:08:06 -04:00
Nick Mathewson
6121ca16bc Merge remote-tracking branch 'ahf/bugs/22286' into maint-0.3.1 2017-08-08 10:03:08 -04:00
Nick Mathewson
3af4aafbcb Fix a memory leak in consdiffmgr.c
Fixes bug 23139; bugfix on 0.3.1.1-alpha.
2017-08-08 09:13:45 -04:00
Roger Dingledine
2032b9b1b1 fix typo in comment 2017-08-07 00:22:27 -04:00
Nick Mathewson
ce07b4dd91 Fix memory leak of "torrcd" in test_config_include_folder_order()
Bugfix on 0265ced02b7a652c5941cb2c14ee1e0de0b1d90e; bug not in any
released Tor.
2017-08-04 13:50:27 -04:00
Nick Mathewson
89407bedf8 Tweak usage of get_current_working_dir() for tor_malloc() paranoia.
We assume that tor_free() is not required to be compatible with
the platform malloc(), so we need to use a strdup here.
2017-08-04 12:26:35 -04:00
cypherpunks
bfe740f065 Refactor retrieving the current working directory
The GNU C Library (glibc) offers an function which allocates the
necessary memory automatically [0]. When it is available, we use that.

Otherwise we depend upon the `getcwd` function which requires a
preallocated buffer (and its size). This function was used incorrectly
by depending on the initial buffer size being big enough and otherwise
failing to return the current working directory. The proper way of
getting the current working directory requires a loop which doubles the
buffer size if `getcwd` requires it. This code was copied from [1] with
modifications to fit the context.

[0] https://www.gnu.org/software/hurd/hurd/porting/guidelines.html
[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html
2017-08-04 12:22:53 -04:00
cypherpunks
0265ced02b Remove usage of the PATH_MAX variable
GNU Hurd does not define the PATH_MAX variable. Using the variable on
this platform results in compilation errors.

Closes #23098.
2017-08-04 12:22:53 -04:00
Nick Mathewson
3b646bf887 Fix ntohs() that should have been htons()
Fixes bug 23106; bugfix on 0.2.4.8-alpha.

Fortunately, we only support big-endian and little-endian platforms,
and on both of those, hton*() and ntoh*() behave the same.  And if
we did start to support middle endian systems (haha, no), most of
_those_ have hton*(x) == ntoh*(x) too.
2017-08-04 12:17:53 -04:00
Nick Mathewson
32b4fd5be9 Handle CMD_KEY_EXPIRATION in ntmain.c switch statement
This fixes a compilation warning on windows.

Bug not in any released Tor.
2017-08-04 12:00:51 -04:00
Isis Lovecruft
b2a7e8df90
routerkeys: Add cmdline option for learning signing key expiration.
* CLOSES #17639.
 * ADDS new --key-expiration commandline option which prints when the
   signing key expires.
2017-08-03 22:20:02 +00:00
Nick Mathewson
96cf608b2e Merge branch 'bug22885_squashed' 2017-08-03 09:33:40 -04:00
Nick Mathewson
7f32920648 Don't send missing X-Desc-Gen-Reason on startup
Since we start with desc_clean_since = 0, we should have been
starting with non-null desc_dirty_reason.

Fixes bug 22884; bugfix on 0.2.3.4-alpha when X-Desc-Gen-Reason was
added.
2017-08-03 09:33:33 -04:00
Nick Mathewson
1168e21b45 Merge branch 'maint-0.3.0' into maint-0.3.1 2017-08-03 09:14:12 -04:00
Nick Mathewson
40c7871f46 Merge branch 'maint-0.3.1' 2017-08-03 09:14:12 -04:00
Nick Mathewson
b548371f76 Merge remote-tracking branch 'dgoulet/bug23078_030_01' into maint-0.3.0 2017-08-03 09:12:23 -04:00
Nick Mathewson
17073d7234 Merge branch 'maint-0.3.1' 2017-08-03 09:11:03 -04:00
Nick Mathewson
b13bf65062 Merge branch 'bug23081_025' into maint-0.3.1 2017-08-03 09:10:58 -04:00
Nick Mathewson
3e68db02c4 In ntmain, call set_main_thread() before running the loop.
Patch from Vort; fixes bug 23081; bugfix on fd992deeea in
0.2.1.16-rc when set_main_thread() was introduced.

See the changes file for a list of all the symptoms this bug has
been causing when running Tor as a Windows Service.
2017-08-03 09:09:08 -04:00
Neel Chauhan
5ee6ca8da2 Switch to offsetof() 2017-08-03 08:56:35 -04:00
Nick Mathewson
02fcb29d11 Merge branch 'maint-0.3.1' 2017-08-03 08:44:32 -04:00
Nick Mathewson
93b28972c1 Merge branch 'maint-0.2.5' into maint-0.2.8 2017-08-03 08:44:31 -04:00
Nick Mathewson
9696021593 Merge branch 'maint-0.2.8' into maint-0.2.9 2017-08-03 08:44:31 -04:00
Nick Mathewson
f33c96610f Merge branch 'maint-0.2.9' into maint-0.3.0 2017-08-03 08:44:31 -04:00
Nick Mathewson
e220e6e437 Merge branch 'maint-0.3.0' into maint-0.3.1 2017-08-03 08:44:31 -04:00
Karsten Loesing
1280de42a4 Update geoip and geoip6 to the August 3 2017 database. 2017-08-03 10:00:54 +02:00
David Goulet
5b03c7ba6d Fix check_expired_networkstatus_callback() if condition
The condition was always true meaning that we would reconsider updating our
directory information every 2 minutes.

If valid_until is 6am today, then now - 24h == 1pm yesterday which means that
"valid_until < (now - 24h)" is false. But at 6:01am tomorrow, "valid_until <
(now - 24h)" becomes true which is that point that we shouldn't trust the
consensus anymore.

Fixes #23091

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-02 13:28:45 -04:00
Nick Mathewson
c4c5077af2 Merge branch 'maint-0.3.1' 2017-08-02 12:51:46 -04:00
Nick Mathewson
a9a8d53dec Merge branch 'bug23071_031' into maint-0.3.1 2017-08-02 12:51:42 -04:00
Nick Mathewson
ee849ee8b6 Make the hs_ntor_ref logic more correct when there is no sha3 module 2017-08-02 12:44:46 -04:00
Nick Mathewson
8925e84beb version bump to 0.3.0.10-dev 2017-08-02 12:28:34 -04:00
Nick Mathewson
4f7955d5de Bump to 0.3.0.10 2017-08-01 14:38:49 -04:00
David Goulet
ff9c529667 hs: Cleanup logging statement in hs_intropoint.c
One log statement was a warning and has been forgotten. It is triggered for a
successful attempt at introducting from a client.

It has been reported here:
https://lists.torproject.org/pipermail/tor-relays/2017-August/012689.html

Three other log_warn() statement changed to protocol warning because they are
errors that basically can come from the network and thus triggered by anyone.

Fixes #23078.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2017-08-01 14:15:47 -04:00
Nick Mathewson
9c294d29ea bump to 0.3.1.5-alpha-dev 2017-08-01 12:08:30 -04:00
Nick Mathewson
58e1c6dd86 Merge remote-tracking branch 'public/bug19769_19025_029' into maint-0.2.9 2017-08-01 11:30:29 -04:00
Nick Mathewson
8500f0e4e1 Merge remote-tracking branch 'public/bug20059_024_v2' into maint-0.2.9 2017-08-01 11:28:36 -04:00
Nick Mathewson
84c4a2bc3f Merge remote-tracking branch 'public/bug20270_029' into maint-0.3.0 2017-08-01 11:24:02 -04:00
Nick Mathewson
7c68b2f1a5 Merge branch 'maint-0.2.9' into maint-0.3.0 2017-08-01 11:23:00 -04:00
Nick Mathewson
2b94b0ea72 Merge remote-tracking branch 'public/bug22245_024' into maint-0.2.9 2017-08-01 11:22:42 -04:00
Nick Mathewson
1d48712c28 Merge branch 'maint-0.2.9' into maint-0.3.0 2017-08-01 11:21:19 -04:00
Nick Mathewson
f6ecda8400 Merge remote-tracking branch 'public/bug18100_029' into maint-0.2.9 2017-08-01 11:21:14 -04:00
Nick Mathewson
4a19498edc Merge branch 'maint-0.3.0' into maint-0.3.1 2017-08-01 11:19:30 -04:00
Nick Mathewson
64e5600103 Merge branch 'maint-0.3.1' 2017-08-01 11:19:30 -04:00
Nick Mathewson
9d24a352c0 Merge branch 'maint-0.2.9' into maint-0.3.0 2017-08-01 11:19:30 -04:00
Nick Mathewson
0e7558ab64 Merge branch 'maint-0.2.7-redux' into maint-0.2.8 2017-08-01 11:19:29 -04:00
Nick Mathewson
925ef048a9 Merge branch 'maint-0.2.8' into maint-0.2.9 2017-08-01 11:19:29 -04:00
Nick Mathewson
a48ae2aa67 Merge branch 'maint-0.2.6' into maint-0.2.7-redux 2017-08-01 11:19:29 -04:00
Nick Mathewson
6862eada65 Merge branch 'maint-0.2.5' into maint-0.2.6 2017-08-01 11:19:29 -04:00
Nick Mathewson
0bfd1c318c Merge branch 'maint-0.2.4' into maint-0.2.5 2017-08-01 11:19:28 -04:00
Nick Mathewson
ec99f038fa Improve the keypin failure message
Closes the human-factors part of ticket 22348.
2017-07-31 20:40:23 -04:00
Nick Mathewson
df3bdc6bde Clean up choose_good_entry_server() doc; add assertion
We used to allow state==NULL here, but we no longer do.

Fixes bug 22779.
2017-07-31 20:35:58 -04:00
Nick Mathewson
8b5b7d470f Fix the hs_ntor integration tests to work with the pysha3 module
The sha3 module should still work.  Fixes bug 23071; bugfix on
0.3.1.1-alpha.
2017-07-31 20:28:42 -04:00
Nick Mathewson
572f23a96e Now that "base -1" is a bug, tell our unit tests to expect bug warnings
Bugfix on accb734c5fc45481231b837; bug not in any released Tor.
2017-07-31 14:30:04 -04:00
Nick Mathewson
2cb8c8d99f Bump to 0.3.1.5-alpha 2017-07-31 14:29:33 -04:00
Nick Mathewson
769a94d9ce Bug 23055: cast, then multiply when doing u32*u32->u64.
No backport, since this bug won't trigger until people make
certificates expiring after the Y2106 deadline.

CID 1415728
2017-07-28 10:33:51 -04:00
Nick Mathewson
accb734c5f Turn base < 0 into a BUG() in our long-parse functions. 2017-07-28 10:26:06 -04:00
Nick Mathewson
decb927685 Add an assertion to try to please coverity.
Coverity, for some reason, thought that weight_scale might be 0,
leading to a divide-by-zero error.
2017-07-28 10:17:57 -04:00
Nick Mathewson
602c52cad4 Coverity deadcode shenanigans on BUG() macro.
We don't actually want Coverity to complain when a BUG() check can
never fail, since such checks can prevent us from introducing bugs
later on.

Closes ticket 23054. Closes CID 1415720, 1415724.
2017-07-28 10:02:38 -04:00
Nick Mathewson
5f0fa480dd Merge branch 'maint-0.3.1' 2017-07-28 09:54:39 -04:00
Nick Mathewson
eb677c5870 Fix an unreachable memory leak in the unit tests
This is CID 1415726.
2017-07-28 09:52:34 -04:00
Nick Mathewson
6252e04a37 Merge branch 'maint-0.3.1' 2017-07-28 09:50:26 -04:00
Nick Mathewson
911e2dc530 Merge branch 'bug23053_029' into maint-0.3.1 2017-07-28 09:50:16 -04:00
Nick Mathewson
9a0f38a349 Fix a small memory leak when parsing unix: ports twice
Fixes bug 23053; CID 1415725.
2017-07-28 09:49:42 -04:00
Nick Mathewson
baf53300d7 Merge branch 'maint-0.3.1' 2017-07-27 20:33:01 -04:00
Nick Mathewson
af3079a492 Try to work around a compile warning in workqueue.c 2017-07-27 20:32:59 -04:00
Nick Mathewson
15ed1c0c83 Merge branch 'maint-0.3.1' 2017-07-27 16:30:52 -04:00
Nick Mathewson
ba334c00da Merge branch 'multi-priority_squashed' into maint-0.3.1 2017-07-27 16:29:34 -04:00
Nick Mathewson
fdd8156ea3 Fix the cpuworker.c documentation to mention all the kinds of work 2017-07-27 16:28:59 -04:00
Nick Mathewson
f5a852de91 Note that threadpool_queue_work...() can't actually return NULL 2017-07-27 16:28:59 -04:00
Nick Mathewson
250c88014d Always start with one additional worker thread
Now that half the threads are permissive and half are strict, we
need to make sure we have at least two threads, so that we'll
have at least one of each kind.
2017-07-27 16:28:59 -04:00
Nick Mathewson
0ae0b5aa41 Queue consensus diffs at LOW priority.
Fixes bug 22883.
2017-07-27 16:28:59 -04:00
Nick Mathewson
bddea78ded Fix a pair of stale comments in workqueue.c
These comments said that each thread had a separate queue, but we
haven't been using that design for some while.
2017-07-27 16:28:59 -04:00