Commit Graph

27178 Commits

Author SHA1 Message Date
Nick Mathewson
c4e0b28ecb Merge remote-tracking branch 'tor-gitlab/mr/214' into master 2020-11-19 10:42:04 -05:00
David Goulet
ea52705e4b config: Bridge line with a transport must have a ClientTransportPlugin
Fixes #25528

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-18 11:31:37 -05:00
George Kadianakis
34feedea60 Merge remote-tracking branch 'tor-gitlab/mr/216' 2020-11-18 12:37:02 +02:00
David Goulet
16351d655d sendme: Turn log warning into debug
When sending the stream level SENDME, it is possible the cirucit was marked
for close or any other failures that can occur. These events can occur
naturally.

Fixes #40142

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-17 13:23:34 -05:00
David Goulet
0921fdf633 Merge branch 'maint-0.4.5' into master 2020-11-17 12:25:56 -05:00
David Goulet
07006785fd Merge branch 'tor-gitlab/mr/203' into maint-0.4.5 2020-11-17 12:25:48 -05:00
Neel Chauhan
bc968097f2 Fix script failures 2020-11-17 11:23:08 -05:00
Neel Chauhan
1588767e65 Allow listing ed25519 fingerprints on the command line 2020-11-17 11:23:08 -05:00
Nick Mathewson
3900b19379 Merge branch 'maint-0.4.5' into master 2020-11-17 10:53:39 -05:00
David Goulet
7c06707750 Merge branch 'tor-gitlab/mr/182' into master 2020-11-17 10:36:05 -05:00
David Goulet
d04a27bed2 config: Really ignore non ORPorts when removing duplicates
The function in charge of removing duplicate ORPorts from our configured ports
was skipping all non ORPorts port but only for the outer loop thus resulting
in comparing an ORPort with a non-ORPort which lead to problems.

For example, tor configured with the following would fail:

  ORPort auto
  DirPort auto

Both end up being the same configuration except that one is a OR listener and
one is a Dir listener. Thus because of the missing check in the inner loop,
they looked exactly the same and thus one is removed.

Fixes #40195

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-17 09:40:16 -05:00
Nick Mathewson
6c61011781 Merge remote-tracking branch 'tor-gitlab/mr/184' into master 2020-11-17 08:22:44 -05:00
Nick Mathewson
aed2a48c66 Bump version to 0.4.6.0-alpha-dev 2020-11-17 08:01:08 -05:00
Nick Mathewson
b13f32ee97 Merge branch 'ticket40071_045_01_squashed' into master 2020-11-17 07:58:37 -05:00
David Goulet
bc5f26ff70 relay: Launch dummy circuit only when descriptor build fails
First, this commit moves the launch_dummy_circuit_as_needed() function into
relay_find_addr.c and renames it to relay_addr_learn_from_dirauth(). This is
an attempt to centralize anything relate with address discovery in the right
module.

Second, when building a descriptor and we fail to discover our address,
immediately launch a dummy circuit to an authority in an attempt to learn our
descriptor.

It is still only done every 20 minutes even though the descriptor build is
done every minute. We ought to avoid load on the authority and if we can't
learn in the first place our address from them, chances are more things are
wrong.

Related to #40071

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-17 07:58:26 -05:00
David Goulet
a5538a3603 relay: Look at our cache when looking for an IP change
Regularly, tor looks if its IP has changed. It does the entire auto discovery
process again. However, it is possible that it does not find anything.

Instead of thinking the IP changed to an unknown address, look at our cache
and see if that value has changed.

The reason for this is because if tor gets its address as a suggestion from a
directory authority, it is because the auto discovery failed and thus that
address should be consider for the IP change check.

Related to #40071

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-17 07:58:26 -05:00
David Goulet
4b98140733 relay: Use testing circuit instead of dummy descriptor fetch
Tor now can learn its address from a NETINFO cell coming from an authority.
Thus, instead from launching a dummy descriptor fetch to learn the address
from the directory response (unauthenticated), we simply now launch a one-hop
testing circuit.

Related to #40071

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-17 07:58:26 -05:00
Guinness
4382e977f7
Add the compiler name, version and libs used to compile
This changes the behaviour of `tor --version` in such a way.
```console
src/app/tor --version
Tor version 0.4.5.1-alpha-dev (git-46ccde66a97d7985).
Tor is running on Linux with Libevent 2.1.12-stable, OpenSSL 1.1.1h, Zlib 1.2.11, Liblzma 5.2.4, Libzstd 1.4.5 and Glibc 2.31 as libc.
Tor compiled with GCC version 10.2.0
```

Fixes #32102
2020-11-17 10:43:00 +01:00
Nick Mathewson
41bea71adc Merge remote-tracking branch 'tor-gitlab/mr/197' into master 2020-11-16 22:43:09 -05:00
Nick Mathewson
c79957581e Merge branch 'maint-0.4.4' into master 2020-11-16 22:42:23 -05:00
Nick Mathewson
9001732394 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-11-16 22:42:22 -05:00
Nick Mathewson
7c0778ef7e Merge branch 'maint-0.3.5' into maint-0.4.3 2020-11-16 22:42:22 -05:00
Nick Mathewson
fcae26adf7 Merge remote-tracking branch 'tor-gitlab/mr/195' into maint-0.3.5 2020-11-16 22:42:15 -05:00
Neel Chauhan
8785a75e2f Give a descriptive error message with "tor-gencert --create-identity-key" 2020-11-16 09:35:23 -08:00
Neel Chauhan
af48afe667 Unbreak build 2020-11-16 08:47:12 -08:00
Neel Chauhan
eacf528915 Add support for creating v3 onion services form the control port 2020-11-15 16:02:59 -08:00
David Goulet
d425dbf04a port: Don't ignore ports of a different family
Commit c3a0f75796 added this feature for ORPort
that we ignore any port that is not the family of our default address when
parsing the port. So if port_parse_config() was called with an IPv4 default
address, all IPv6 address would be ignored.

That makes sense for ORPort since we call twice port_parse_config() for
0.0.0.0 and [::] but for the rest of the ports, it is not good since a
perfectly valid configuration can be:

  SocksPort 9050
  SocksPort [::1]:9050

Any non-ORPort only binds by default to an IPv4 except the ORPort that binds
to both IPv4 and IPv6 by default.

The fix here is to always parse all ports within port_parse_config() and then,
specifically for ORPort, remove the duplicates or superseding ones. The
warning is only emitted when a port supersedes another.

A unit tests is added to make sure SocksPort of different family always exists
together.

Fixes #40183

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-13 08:38:22 -05:00
Daniel Pinto
877dbfc056 Use SRWLocks to implement locking on Windows #17927
Replace the Windows locking implementation which used critical
sections with the faster SRWLocks available since Vista.
2020-11-12 19:50:55 +00:00
Neel Chauhan
d1494d140c Remove orconn_ext_or_id_map and related functions 2020-11-12 11:19:21 -08:00
Neel Chauhan
46ccde66a9 Use connection_or_change_state() in v3 handshaking state change 2020-11-12 12:06:34 -05:00
Nick Mathewson
dbc8d2a4e4 When handling includes, detect missing interned strings earlier.
There were three separate places where we were hitting a sandbox Bug
warning before we actually exited.

Fixes #40094; bugfix on 0.3.1.1-alpha when %includes were introduced.
2020-11-12 11:55:55 -05:00
Samanta Navarro
4a0cd79588 Fix typos.
Typos found with codespell.

Please keep in mind that this should have impact on actual code
and must be carefully evaluated:

src/core/or/lttng_circuit.inc
-    ctf_enum_value("CONTROLER", CIRCUIT_PURPOSE_CONTROLLER)
+    ctf_enum_value("CONTROLLER", CIRCUIT_PURPOSE_CONTROLLER)
2020-11-12 11:44:09 -05:00
Nick Mathewson
ffa7b15950 Deliberately close OR connections if proxies leave extra data
We already did this, but we did it by accident, which is pretty
risky: if we hadn't, then our code would have treated extra data in
the inbuf as having been transmitted as TLS-authenticated data.

Closes ticket 40017; Found by opara.
2020-11-12 11:07:33 -05:00
Nick Mathewson
f2168d28f7 Fake the current time when we're loading TEST_DESCRIPTORS.
Fixes bug 40187; bugfix on 0.4.5.1-alpha.
2020-11-12 09:28:27 -05:00
Nick Mathewson
7d8290f0ac Merge remote-tracking branch 'tor-gitlab/mr/183' into master 2020-11-12 08:47:05 -05:00
Nick Mathewson
3f1544bbd9 Bump to 0.4.4.6-dev 2020-11-12 08:13:07 -05:00
Nick Mathewson
fd22fa183b Bump to 0.4.3.7-dev 2020-11-12 08:12:11 -05:00
Nick Mathewson
862c44e4ec Bump to 0.3.5.12-dev 2020-11-12 08:11:01 -05:00
Nick Mathewson
210a94b231 Bump to 0.4.4.6 2020-11-09 17:13:02 -05:00
Nick Mathewson
6338c35e9d Bump to 0.4.3.7 2020-11-09 17:12:41 -05:00
Nick Mathewson
665083be9f Bump to 0.3.5.12 2020-11-09 17:12:18 -05:00
Nick Mathewson
ec0f000445 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-11-09 16:17:42 -05:00
Nick Mathewson
0b2c64effd Merge branch 'maint-0.3.5' into maint-0.4.3 2020-11-09 16:13:42 -05:00
Nick Mathewson
52e439c13e Merge remote-tracking branch 'tor-gitlab/mr/189' into maint-0.3.5 2020-11-09 16:13:24 -05:00
Alexander Færøy
0702cf10db Merge remote-tracking branch 'tor-gitlab/mr/192' 2020-11-09 14:15:03 +00:00
Alexander Færøy
5e65a746aa Merge remote-tracking branch 'tor-gitlab/mr/190' 2020-11-09 14:12:45 +00:00
Nick Mathewson
b22568a545 Rename OpenSSL_version_num() as defined in Tor
This way, if we guess wrong about whether the library has it,
we don't conflict with the library's headers.

Fixes #40181; bug not in any released version.
2020-11-06 10:31:32 -05:00
Nick Mathewson
4154158d79 Make config/parse_tcp_proxy_line work in the presence of DNS hijacking
We can use our existing mocking functionality to do this: We have
been in this position before.

Fixes part of #40179; bugfix on 0.4.3.1-alpha.
2020-11-05 09:47:32 -05:00
Nick Mathewson
31a6a101a0 Handle a change in the implementation of hashlib in Python 3.9
Previously, hashlib.shake_256 was a class (if present); now it can
also be a function.  This change invalidated our old
compatibility/workaround code, and made one of our tests fail.

Fixes bug 40179; bugfix on 0.3.1.6-rc when the workaround code was
added.
2020-11-05 09:34:36 -05:00
George Kadianakis
0812ecd517 Add more docs about the HSv3 stat collection period. 2020-11-03 19:19:02 +02:00
George Kadianakis
810183aaf1 Improve string formatting in rep_hist_format_hs_stats(). 2020-11-03 19:15:01 +02:00
George Kadianakis
7ae576edaf Use CONST_TO_OR_CIRCUIT() in v2/v3 rend cell detection. 2020-11-03 19:14:57 +02:00
George Kadianakis
9a98d1da30 Switch v3_onions_seen_this_period to digest256map_t. 2020-11-03 19:14:57 +02:00
George Kadianakis
dd119b277b Merge remote-tracking branch 'tor-gitlab/mr/185' into master 2020-11-03 16:06:12 +02:00
George Kadianakis
4f5a116618 Merge remote-tracking branch 'tor-gitlab/mr/187' into master 2020-11-03 13:04:09 +02:00
George Kadianakis
a96432ab06 Abstract v2/v3 "format stats to str" logic into a single function. 2020-11-03 11:12:17 +02:00
George Kadianakis
6178a64fcf Abstract v2/v3 "write stats to file" logic into a single function. 2020-11-03 11:12:17 +02:00
George Kadianakis
131da887d7 Write unittests for v3 metrics. 2020-11-03 11:12:17 +02:00
George Kadianakis
5c00bee1b1 Introduce v3 stat formatting functions.
They will be merged with the v2 ones in later commits.
2020-11-03 11:12:17 +02:00
George Kadianakis
d0be2ae7f9 Extend get_voting_interval() so that it's callable by relays.
In the past, only authorities and clients had to use that function because of
the SRV subsystem. However, because of its use in rep_hist_hs_stats_init() it
will now also be used by relays when bootstrapping without a consensus. Make it
do something sensible.

Another approach (instead of using magic values) would be to wait
initialization of HSv3 stats until we get a consensus but that seems messy to
schedule.

Another approach would be to make dirauth_sched_get_configured_interval() also
work for relays (particularly when TestingNetwork is enabled), but that also
seems a good amount of work.
2020-11-03 11:12:17 +02:00
George Kadianakis
f2eff17126 Introduce generic HS stats methods that apply to v2 and v3. 2020-11-03 11:12:17 +02:00
George Kadianakis
3cbc513ae7 Implement support for "v3 rend traffic" stat. 2020-11-03 11:09:34 +02:00
George Kadianakis
05880d238a Implement support for "unique v3 onions" stat. 2020-11-03 11:09:34 +02:00
George Kadianakis
bd28551763 Introduce v3_stats_t structure and some of its methods. 2020-11-03 11:09:24 +02:00
George Kadianakis
5ed7fcec41 Make room for v3: Complete move from hs_stats_t to hs_v2_stats_t. 2020-11-02 21:05:50 +02:00
George Kadianakis
1de7843658 Make room for v3: s/hs_stats/hs_v2_stats/ 2020-11-02 21:05:05 +02:00
George Kadianakis
62d682e624 Make room for v3: Rename rephist objects to signify they are v2-only. 2020-11-02 21:04:43 +02:00
David Goulet
474369e3fa Merge branch 'tor-gitlab/mr/186' 2020-11-02 13:14:02 -05:00
David Goulet
8b240fbe40 Merge branch 'tor-gitlab/mr/188' 2020-11-02 13:09:15 -05:00
David Goulet
dc6438b549 or: Missing .inc file in include.am
Fixes #40173

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-11-02 08:25:48 -05:00
Nick Mathewson
7a75a1064f Fix another duplicate typedef.
Fixes #40177; bugfix on 0.4.5.1-alpha.
2020-11-02 07:15:10 -05:00
Nick Mathewson
aa85284038 Update to 0.4.5.1-alpha-dev 2020-11-01 16:41:56 -05:00
Daniel Pinto
f3b9be4422 Implement WIN32 tor_cond_wait using condition variables #30187
Fix bug where running a relay on Windows would use 100% CPU
after some time. Makes Windows >= Vista the required Windows
version to build and run tor.
2020-11-01 03:10:25 +00:00
Nick Mathewson
e01f586e05 Bump version to 0.4.5.1-alpha 2020-10-30 11:05:22 -04:00
Nick Mathewson
148b5b03a3 Merge branch 'bug40080_035' 2020-10-30 10:51:20 -04:00
George Kadianakis
54e6109499 Merge remote-tracking branch 'tor-gitlab/mr/174' into master 2020-10-30 14:14:14 +02:00
Nick Mathewson
df16376004 Fix duplicate typedef in metrics_store_entry.h
Fixes #40171. Bug not in any released Tor.
2020-10-28 16:36:14 -04:00
Nick Mathewson
f7d0bde4f0 Remove "GETINFO network-status".
It was deprecated 0.3.1.1-alpha.

According to #22473, nothing uses it.

Closes #22473.
2020-10-28 11:48:23 -04:00
Alexander Færøy
b0e6ec627c Merge branch 'maint-0.4.3' into maint-0.4.4 2020-10-28 15:39:37 +00:00
Alexander Færøy
4876409c2a Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-28 15:39:37 +00:00
Nick Mathewson
3f442987f1 Log a warning if Tor was built with any "risky" compile-time options
These options are meant for testing builds only, and are likely to
cause trouble if used in a production environment.

Closes #18888.
2020-10-28 11:34:30 -04:00
Alexander Færøy
c37d05d0c6 Merge remote-tracking branch 'tor-gitlab/mr/171' 2020-10-28 15:15:39 +00:00
Nick Mathewson
c48d25ac8d Fix a previously overstrict log message check.
OpenSSL doesn't seem to report error locations in the same way as
before, which broke one of our tests.

Fixes bug 40170; bugfix on 0.2.8.1-alpha.
2020-10-28 10:47:39 -04:00
Nick Mathewson
2b4a3d07b2 Do not define OPENSSL_VERSION in compat_openssl.h
Apparently it conflicts with definitions elsewhere in Openssl 3.0.0.
2020-10-28 10:32:06 -04:00
Nick Mathewson
d9221968ce Include a more modest openssl header in crypto_openssl_mgt.h
The "engines.h" header has lots of stuff; the "opensslv.h" header
has the version number, which is all we actually need here.

We need to do this because we're about to change this header to
conditionally define OPENSSL_SUPPRESS_DEPRECATED, and it would be
too late to do so if we'd already included "engines.h".
2020-10-28 10:11:42 -04:00
Nick Mathewson
511822529a Revise fix for bug 32178 (spaces at end of log msg).
The loop in the earlier patch would invoke undefined behavior in two
ways: First, it would check whether it was looking at a space before
it checked whether the pointer was in-range.  Second, it would let a
pointer reach a position _before_ the start of a string, which is
not allowed.

I've removed the assertion about empty messages: empty messages can
be their own warning IMO.

I've also added tests for this formatting code, to make sure it
actually works.
2020-10-28 09:41:51 -04:00
Amadeusz Pawlik
ec7a6757ec Removes trailing spaces in control event log 2020-10-28 09:08:53 -04:00
David Goulet
2edda444da test: Missing tor_free() in metrics unit tests
Found by coverity:

  *** CID 1468664:  Resource leaks  (RESOURCE_LEAK)
  /src/test/test_metrics.c: 83 in test_config()
  77       tt_int_op(ret, OP_EQ, false);
  78
  79      done:
  80       SMARTLIST_FOREACH(ports, port_cfg_t *, c, port_cfg_free(c));
  81       smartlist_free(ports);
  82       or_options_free(options);
  >>>     CID 1468664:  Resource leaks  (RESOURCE_LEAK)
  >>>     Variable "err_msg" going out of scope leaks the storage it points to.
  83     }
  84
  85     static char _c_buf[256];
  86     #define CONTAINS(conn, msg) \
  87       do { \
  88         tt_int_op(buf_datalen(conn->outbuf), OP_EQ, (strlen(msg))); \

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-28 08:52:02 -04:00
Neel Chauhan
09b3af578d Stop forcing IPv4 and IPv6 traffic on non-SOCKSPorts 2020-10-27 17:57:48 -07:00
Neel Chauhan
0c79cddc6b Avoid asserts with flag 2020-10-27 14:47:42 -07:00
David Goulet
362229f184 lib/metrics: Fix wrong macro expansion
The "METRICS_PREFIX" was not expanded but rather used as a litteral. Fix that
by just removing the define and using "tor_" directly.

Reviewed-by: Alexander Færøy <ahf@torproject.org>
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 13:00:20 -04:00
David Goulet
5de6673972 metrics: Add tor_ namespace to all metrics
Closes #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
238340ce54 test: Add test for onion service metrics module
Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
f65c0820af test: Metrics tests for lib/ and feature/
Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
4c19eed35c tests: Fix unit tests after adding new HS metrics module
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
1c06c9f1c0 doc: Initial documentation of the lib/metrics
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
97731196c4 hs: Collect introduction circuit metrics
Tracks the total number of established introduction circuit.

Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
c081bee38a hs: Collect rendezvous circuit metrics
The total number of rendezvous circuit created and the number of established
ones which is a gauge that decreases to keep an updated counter.

Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
2fe0322fe4 hs: Collect service traffic metrics
Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
695957511b hs: Always note the virtual port in the ident
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
50f44afeb4 hs: New metrics module
At this commit, a new service registers to the module and a store is created.
It also remove itself from the metrics module if it goes away.

In order to hook into the metrics subsystem, this commit attaches the HS
subsystem into the subsystem global list so its get_metrics() call can be
accessible.

HS initialization is still _not_ done through the subsys module as it is
likely require much more testing.

Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
4f5cea1f59 conn: New Metrics listener port
If MetricsPort is defined, listen on it and handle the incoming request.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
a882d1bf0a metrics: New feature module to track tor metrics
Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
ec731290a5 lib: New metrics library
Used to provide an interface to create metrics store and update the entries.

Related to #40063

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-27 10:43:42 -04:00
David Goulet
26cfac1880 Merge branch 'tor-gitlab/mr/176' into maint-0.4.4 2020-10-27 10:18:16 -04:00
David Goulet
6338fc2afa Merge branch 'tor-gitlab/mr/173' 2020-10-27 09:43:04 -04:00
David Goulet
683c794273 Merge branch 'tor-gitlab/mr/176' 2020-10-27 09:36:16 -04:00
Nick Mathewson
c90535c539 Merge branch 'maint-0.4.4' 2020-10-26 16:39:31 -04:00
George Kadianakis
07f2a06c61 Merge remote-tracking branch 'tor-gitlab/mr/169' into master 2020-10-26 17:04:58 +02:00
Nick Mathewson
f43fe890dd Merge remote-tracking branch 'tor-gitlab/mr/127' 2020-10-23 11:47:40 -04:00
Nick Mathewson
fd58e74ddc Update required/recommended protocol lists more systematically
First I began with a set of candidates:

  The client's _required_ list starts with all the protocols
  supported by every release in 0.2.9-stable through current
  master.

  The client's _required_ list starts with all the protocols
  supported by every release in 0.3.5-stable through current
  master.

  Everybody's _recommended_ list starts with all the protocols
  supported by every release in 0.3.5-stable through current master.

Then I removed the protocol versions that we do not actually want to
require or recommend:

  DirCache=1 (deprecated)
  HSDir=1, HSIntro=1-3, HSRend=1 (deprecated)
  (All HS* protocol requirements for clients)
  Link=1-3 (deprecated)
  LinkAuth=1 (obsolete)
  Relay=1 (obsolete)
2020-10-23 11:23:08 -04:00
Nick Mathewson
2908086694 Merge branch 'combined_libs' 2020-10-23 10:33:07 -04:00
Roger Dingledine
00118355f5 Turn ConsensusParams into a Linelist
Make it possible to specify multiple ConsensusParams torrc
lines.

Now directory authority operators can for example put the
main ConsensusParams config in one torrc file and then add to it
from a different torrc file.

Closes ticket 40164.
2020-10-22 03:26:03 -04:00
David Goulet
0d420918e7 main: Off by one when dumping subsystem list
Fixes #40163

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-21 13:48:37 -04:00
Daniel Pinto
bb9707420e Allow mutiple lines on configuration for ROUTERSET entries. #28361
Affected entries are: EntryNodes, ExcludeNodes, ExcludeExitNodes,
ExitNodes, MiddleNodes, HSLayer2Nodes and HSLayer3Nodes.
2020-10-21 01:53:50 +01:00
Guinness
0668437b58
Set is_padding_timer_scheduled to 0
When calling `circpad_send_padding_cell_for_callback()`, the flag
`is_padding_timer_scheduled` was not resetted to 0 which caused an issue
in the circpad simulator.
This commit fixes this problem.

Fixes #32671.
2020-10-20 21:04:33 +02:00
Nick Mathewson
579f200efc Merge branch 'mr_175_squashed' 2020-10-20 09:03:26 -04:00
Guinness
5248d08ede Consider 301 as an error like 404
Tor does not follow redirects when bootstraping so we encountered an
error.

Fixes #40053
2020-10-20 08:57:42 -04:00
George Kadianakis
19302a1dfd Merge remote-tracking branch 'tor-gitlab/mr/148' into master 2020-10-20 13:26:19 +03:00
Nick Mathewson
cb4cedae68 Explain why we use "mark_as_used_for_origin_circuit" where we do
Also, explain why it's relevant for bootstrapping.

This is a comments-only patch.
2020-10-19 11:45:24 -04:00
Nick Mathewson
f7adf3653f Simplify logic to use smartlist_add_asprintf() 2020-10-19 11:24:32 -04:00
Nick Mathewson
151d446aa1 Merge remote-tracking branch 'tor-gitlab/mr/167' 2020-10-19 11:15:20 -04:00
Nick Mathewson
d872c69255 Update required/recommended protocol versions.
Cons=1 is the old format of consensuses, without ed25519 keys. It
  is no longer required or recommended.

  Cons=2 is the new format of consensuses, with ed25519 keys. It
  is now required.

  (Similarly for Desc=1,2 and Microdesc=1,2)

No supported client or relay versions should be affected by this
change, since these versions are supported by clients and relays
running 0.2.9 and later.  It will only take effect once enough
authorities vote for it.

Closes ticket 40162.
2020-10-18 16:23:53 -04:00
Nick Mathewson
4298d87756 Split required/recommended protocol lists into multiple lines
This should make diffs easier to read.
2020-10-18 16:18:42 -04:00
Nick Mathewson
62667b49e9 Regenerate extample_extrainfo.inc and adjust tests. 2020-10-16 16:07:46 -04:00
Nick Mathewson
5032b8f178 Regenerate complete failing_routerdescs.inc and adjust tests accordingly. 2020-10-16 16:07:46 -04:00
Nick Mathewson
0031d2b0ad Update makedesc.py script so that it works with python3. 2020-10-16 16:07:46 -04:00
Nick Mathewson
98c4e218b8 Update slow_ed25519.py to work with python 3. 2020-10-16 16:07:46 -04:00
Nick Mathewson
5e2294c6fe Fix formats_rsa_ed25519 tests.
The "protos" field is mandatory, and so are Ed25519 signatures.

Also, remove formats_rsa (the version without Ed25519), since
RSA-only relays are no longer supported.
2020-10-16 16:07:46 -04:00
Nick Mathewson
84c13a35db Add pr= lines to test_dir_clip_unmeasured*. 2020-10-16 16:07:46 -04:00
Nick Mathewson
bae5ba8073 Fix a couple of routerstatus-based tests. 2020-10-16 16:07:46 -04:00
Nick Mathewson
61a5a303f9 Replace the contents of test_descriptors.inc with a new set.
Had to replace these since we're updating the list of required fields.

These are taken from a chutney instance.  Shockingly, this is enough
to make the test_dir_handle_get.c tests pass again.
2020-10-16 16:07:46 -04:00
Nick Mathewson
769882ea7c test_dir_handle_get: add ntor-onion-key to microdescriptor example
Shockingly, this test didn't break after this change!
2020-10-16 16:07:46 -04:00
Nick Mathewson
acf4225441 Fix up vote tests in test_dir_handle_get.
These tests used a hardcoded vote with a hardcoded digest.  That
vote didn't have any pr lines, and so it is now invalid. I've
adjusted the testing code so that it mocks the signature-checking,
so that we can more easily change the contents of the vote.
2020-10-16 16:07:46 -04:00
Nick Mathewson
36ea25c236 Fix the tests in test_microdesc.c
This was fairly simple: just had to replace the examples with ones
that had ntor keys.  There were a couple of example chutney
routerinfos that I had to replace too.

I also removed tests for producing microdescs via consensus methods
that we don't support any longer.
2020-10-16 16:07:46 -04:00
Nick Mathewson
bb275e3712 Fix router/dump_router_to_string_no_bridge_distribution_method
The descriptor it generated needed to include ed25519 keys; needed
to have a correct TAP crosscert.
2020-10-16 16:07:46 -04:00
Nick Mathewson
6d419a3da3 test_dir_common: make sure we include pr lines. Fixes 7 tests. 2020-10-16 07:40:54 -04:00
Nick Mathewson
e934d713b3 Mark as required fields from prop315.
This change breaks some unit tests; it's time to fix those in
subsequent commits.
2020-10-15 18:02:16 -04:00
Nick Mathewson
47d6eef190 Also, include ed25519 identities in connection_describe().
Related to #22668.
2020-10-15 10:53:45 -04:00
Nick Mathewson
5718f38c85 Add ed25519 identities to relay descriptions.
(Or at least, to all those relay descriptions that derive from
format_node_description()).

Closes #22668.
2020-10-15 10:29:01 -04:00
Nick Mathewson
93e7661fef Add a function to get an ed25519 ID from a routerinfo. 2020-10-15 10:20:42 -04:00
Nick Mathewson
33fb51a111 Protover: simplify implementation structure to use 64-bit property
Now that prop318 is in, we can simplify our representation for
protocol range sets to just be a bitmask.
2020-10-14 13:09:29 -04:00
Nick Mathewson
4a80dde43c Merge branch 'prop318_limit_protover_035' into prop318_limit_protover_045 2020-10-14 11:31:58 -04:00
Nick Mathewson
dd63b97288 Implement proposal 318: Limit protovers to 0..63
In brief: we go through a lot of gymnastics to handle huge protover
numbers, but after years of development we're not even close to 10
for any of our current versions.  We also have a convenient
workaround available in case we ever run out of protocols: if (for
example) we someday need Link=64, we can just add Link2=0 or
something.

This patch is a minimal patch to change tor's behavior; it doesn't
take advantage of the new restrictions.

Implements #40133 and proposal 318.
2020-10-14 11:28:37 -04:00
David Goulet
bb249a221f Merge branch 'tor-gitlab/mr/170' 2020-10-14 09:46:44 -04:00
Nick Mathewson
42a5e652cb Make OptimisticData always-on.
We've been using it for years, and it seems to work just fine.  This
patch removes the option and its network parameter.

Part of #40139
2020-10-13 14:38:32 -04:00
Nick Mathewson
ac311a38ec Make "usecreatefast" always-off.
Part of #40139, where I'm removing network parameters that we
shouldn't be looking at any longer.
2020-10-13 14:00:34 -04:00
Alexander Færøy
78aa037c41 Merge remote-tracking branch 'tor-gitlab/mr/161' 2020-10-13 13:50:14 +00:00
Neel Chauhan
05242f5555 Pass the SOCKS request address in relay begin cells 2020-10-12 20:46:42 -07:00
Alex Xu (Hello71)
29065db381 dirclient: print bandwidth usage on one line (#40159) 2020-10-08 09:48:38 -04:00
Nick Mathewson
c4812698c3 Remove long-obsolete members from the state file.
Tor has a feature to preserve unrecognized state file entries in
order to maintain forward compatibility.  But this feature, along
with some unused code that we never actually removed, led to us
keeping items that were of no use to the user, other than at worst
to preserve ancient information about them.

This commit adds a feature to remove obsolete entries when we load
the file.

Closes ticket 40137.
2020-10-07 20:46:37 +03:00
Nick Mathewson
2ceea13140 Merge remote-tracking branch 'tor-gitlab/mr/164' 2020-10-07 09:42:37 -04:00
Nick Mathewson
741edf1b45 Merge remote-tracking branch 'tor-github/pr/1827/head' into maint-0.3.5 2020-10-07 09:29:07 -04:00
Nick Mathewson
40f0db75bd Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:38:30 -04:00
David Goulet
b404f085ad hs-v2: Add deprecation warning for service
If at least one service is configured as a version 2, a log warning is emitted
once and only once.

Closes #40003

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-07 08:38:23 -04:00
Nick Mathewson
0e2e517019 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-10-07 08:35:18 -04:00
Neel Chauhan
884cad3edf Make HSFETCH take the decoded length into account, not the base32 one 2020-10-07 08:35:12 -04:00
Nick Mathewson
3e9fa5a029 Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:29:31 -04:00
Nick Mathewson
5f5587ee50 Merge remote-tracking branch 'tor-gitlab/mr/77' into maint-0.3.5 2020-10-07 08:29:23 -04:00
Nick Mathewson
701a1936fa Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:26:04 -04:00
Nick Mathewson
ad7ffa5240 Merge remote-tracking branch 'tor-gitlab/mr/79' into maint-0.3.5 2020-10-07 08:25:55 -04:00
Nick Mathewson
98e14720b5 Merge remote-tracking branch 'tor-github/pr/1661/head' into maint-0.3.5 2020-10-07 08:14:46 -04:00
Nick Mathewson
9587512578 Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:10:08 -04:00
Nick Mathewson
968b6c30c1 Merge remote-tracking branch 'tor-gitlab/mr/43' into maint-0.3.5 2020-10-07 08:09:59 -04:00
Nick Mathewson
8505dd5e37 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-10-07 08:08:02 -04:00
Nick Mathewson
9029444482 Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:08:01 -04:00
Nick Mathewson
e0e0ef713e Merge remote-tracking branch 'tor-gitlab/mr/137' into maint-0.3.5 2020-10-07 08:07:53 -04:00
Nick Mathewson
8a561fc5bf Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:05:40 -04:00
Nick Mathewson
84a5bd48e2 Merge remote-tracking branch 'tor-gitlab/mr/103' into maint-0.3.5 2020-10-07 08:05:31 -04:00
Nick Mathewson
b5a88e8d47 Merge branch 'maint-0.3.5' into maint-0.4.3 2020-10-07 08:01:37 -04:00
Nick Mathewson
ed6a328297 Merge branch 'mr_124_squashed' into maint-0.3.5 2020-10-07 08:00:59 -04:00
Nick Mathewson
c5ba8b6221 Parallelize src/test/test into chunks.
First, we introduce a flag to teach src/test/test to split its work
into chunks.  Then we replace our invocation of src/test/test in our
"make check" target with a set of 8 scripts that invoke the first
8th of the tests, the second 8th, and so on.

This change makes our "make -kj4 check" target in our hardened
gitlab build more than twice as fast, since src/test/test was taking
the longest to finish.

Closes 40098.
2020-10-07 08:00:49 -04:00
George Kadianakis
438aba6c0b Merge branch 'maint-0.4.4' into master 2020-10-07 13:42:57 +03:00
George Kadianakis
a914ac5d7c Merge remote-tracking branch 'tor-gitlab/mr/154' into maint-0.4.4 2020-10-07 13:32:17 +03:00
George Kadianakis
84e825598a Merge branch 'maint-0.4.4' into master 2020-10-07 13:29:16 +03:00
George Kadianakis
149b7a2418 Merge remote-tracking branch 'tor-gitlab/mr/163' into maint-0.4.4 2020-10-07 13:29:00 +03:00
Alexander Færøy
5f61e19d8a Expose TOR_PT_OUTBOUND_BIND_ADDRESS_{V4,V6} to Pluggable Transports.
This patch adds support for exposing the environment variables
`TOR_PT_OUTBOUND_BIND_ADDRESS_V4` and `TOR_PT_OUTBOUND_BIND_ADDRESS_V6` to
Pluggable Transport proccesses. These two values will contain the IPv4
and IPv6 address that the user have specified in torrc that they wish
the PT to use for all outgoing IP packets.

It is important to note here that it is up to the indvidual Pluggable
Transport if they are willing to honor these values or ignore them
completely.

One can test this feature using the following dummy PT written in POSIX
shell script:

    #!/bin/sh

    echo "LOG SEVERITY=warning MESSAGE=\"Value for IPv4: ${TOR_PT_OUTBOUND_BIND_ADDRESS_V4}\""
    echo "LOG SEVERITY=warning MESSAGE=\"Value for IPv6: ${TOR_PT_OUTBOUND_BIND_ADDRESS_V6}\""

    while true ; do
        sleep 1
    done

with the following entries in your torrc:

    OutboundBindAddressPT 203.0.113.4
    OutboundBindAddress 203.0.113.5
    OutboundBindAddressPT 2001:db8::4
    OutboundBindAddress 2001:db8::5

See: https://bugs.torproject.org/5304
2020-10-06 09:30:11 -04:00
Alexander Færøy
69c1a4ebc3 Move parse logic for outbound addresses to before we handle PT's.
This patch moves the logic for handling outbound addresses in torrc to
before we handle pluggable transports. Since we need access to the
values in OutboundBindAddress and friends for #5304 we have to parse
these values before we spawn any PT's.

This commit is code movement only.

See: https://bugs.torproject.org/5304
2020-10-06 09:30:10 -04:00
Alexander Færøy
ad08743299 Rename OUTBOUND_ADDR_EXIT_AND_OR to OUTBOUND_ADDR_ANY.
This patch renames the enumeration value in `outbound_addr_t` from
`OUTBOUND_ADDR_EXIT_AND_OR` to `OUTBOUND_ADDR_ANY` since with the
arrival of `OUTBOUND_ADDR_PT` it no longer makes sense to call the
fallback value for "Exit and OR". Instead we rename it to "any".

See: https://bugs.torproject.org/5304
2020-10-06 09:30:10 -04:00
Alexander Færøy
db0aaf428e Add OutboundBindAddressPT to torrc.
This patch adds a new option to torrc: `OutboundBindAddressPT`. This
option works in the same way as `OutboundBindAddressOR` and
`OutboundBindAddressExit` in that it allows the user to specify which
outbound IP address the user wants the PT to make its connections from.

There is one difference though in that OutboundBindAddressPT will only
be a suggestion for the PT to use since Tor cannot enforce whether or
not the PT actually uses this option for anything.

See: https://bugs.torproject.org/5304
2020-10-06 09:30:10 -04:00
Alexander Færøy
25bffccd71 Document enumeration values for outbound_addr_t.
This patch adds doxygen documentation strings for each of the values in
`outbound_addr_t`.

See: https://bugs.torproject.org/5304
2020-10-06 09:30:10 -04:00
Daniel Pinto
304ae473ca Fix %include bug with pattern with */ on glibc < 2.19 #40141
Fix bug where %including a pattern ending in */ would include
files and folders (instead of folders only) in versions of
glibc < 2.19.
2020-10-03 04:10:52 +01:00
Roger Dingledine
4f114f59e6 fix typos
no actual changes
2020-10-01 19:32:32 -04:00
Nick Mathewson
f5ddc45647 Merge branch 'bug40133_035' into bug40133_043 2020-09-28 10:37:14 -04:00
Nick Mathewson
79d7773968 Merge branch 'maint-0.3.5' into bug40133_035 2020-09-28 10:35:12 -04:00
Nick Mathewson
e68770719e Add missing documentation for get_net_param_from_list 2020-09-28 08:41:47 -04:00
Nick Mathewson
228ac47c2c Fix memory leak in vote generation 2020-09-23 15:41:27 -04:00
Nick Mathewson
2b39543dfc Move a DIGESTMAP_FOREACH_END (cosmetic) 2020-09-23 15:19:25 -04:00
Nick Mathewson
458897e3c5 Remove parseconf test with AndroidIdentityTag. 2020-09-23 14:40:38 -04:00
Nick Mathewson
5c9b4a0060 Remove support for old android "logcat" API
This is apparently obsolete; syslog is modern instead.  If users
have an android log configured, given them a syslog if we can.

Closes #32181.
2020-09-23 12:33:58 -04:00
Nick Mathewson
d07f17f676 IPv6 sybil: consider addresses in the same /64 to be equal. 2020-09-23 12:06:38 -04:00
Nick Mathewson
1be9e84b9c Refactor address comparison in get_sybil_list_by_ip_version 2020-09-23 12:04:09 -04:00
Nick Mathewson
2dba667928 get_all_possible_sybil: small indentation and comment cleanups 2020-09-23 11:53:28 -04:00
Nick Mathewson
e0f6047ea0 Remove needless sort operation. 2020-09-23 11:50:57 -04:00
Nick Mathewson
3196de33a5 Tidy up compare_routerinfo_by_ipv{4,6} to match better. 2020-09-23 11:48:20 -04:00
Nick Mathewson
81c05e1e98 Style and correctness issues in test_dirvote.
Style:
  - We end our types with _t.
  - Use 'static' to declare functions that only exist in a single
    module.

Correctness:
  - Many tt_...() macros can invoke "goto done;" -- we need to make
    sure that all the variables that could get freed are initialized
    before any "goto done" is hit, or else we might free an
    uninitialized variable.
2020-09-23 11:32:28 -04:00
Nick Mathewson
939d12be58 Fix memory leaks. 2020-09-23 11:32:22 -04:00
vnepveu
43672f9fca Implement IPv6 sybil protection.
[This is a squashed patch for ticket 7193, based on taking a "git
   diff" for the original branch, then applying it with "git apply
   -3".  I earlier attempted to squash the branch with "git rebase",
   but there were too many conflicts. --nickm]
2020-09-23 11:30:15 -04:00
David Goulet
beffad8529 Merge branch 'maint-0.3.5' into maint-0.4.3 2020-09-22 13:47:08 -04:00
David Goulet
b6429430c6 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-09-22 13:47:08 -04:00
David Goulet
3f8201f229 Merge branch 'maint-0.4.4' 2020-09-22 13:47:08 -04:00
David Goulet
4dbbc000b5 Merge branch 'tor-gitlab/mr/145' 2020-09-22 13:39:55 -04:00
David Goulet
faf89ec6c2 srv: Remove spammy debug log
Fixes #40135

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-09-22 11:06:34 -04:00
Nick Mathewson
88d99fc1bd Fix warnings when using two unusual options together.
The option `--enable-all-bugs-are-fatal` when used with
`--disable-module-relay` caused GCC to warn about functions that
it thought should be labeled noreturn.

I've tried a couple of approaches, but disabling the warning on
these functions seems to be the best approach.

Fixed #40129; bugfix on 0.4.4.1-alpha.
2020-09-22 10:07:14 -04:00
Nick Mathewson
6bf964a3e5 Renerate src/test/fuzz/include.am 2020-09-18 16:08:41 -04:00
Nick Mathewson
e9dbb5e395 Build one big .a library full of Tor's implementation.
This is experimental and probably will break some platforms
2020-09-18 16:08:24 -04:00
Alexander Færøy
485990641b Merge remote-tracking branch 'tor-gitlab/mr/137' 2020-09-18 14:51:54 +00:00
Nick Mathewson
781ab9eea4 Add flag for whether an OR conn "counts" for bootstrap tracking
We set this flag if we've launched the connection in order to
satisfy an origin circuit, or when we decide the connection _would_
satisfy an origin circuit.  These are the only or_connections we
want to consider for bootstrapping: other or_connections are opened
because of client EXTEND requests, and they may succeed or fail
because of the clients' confusion or misconfiguration.

Closes #25061.
2020-09-18 10:03:57 -04:00
David Goulet
2ddbfc64af Merge branch 'maint-0.3.5' into maint-0.4.3 2020-09-18 09:45:25 -04:00
David Goulet
2e3603d96d Merge branch 'maint-0.4.3' into maint-0.4.4 2020-09-18 09:45:25 -04:00
David Goulet
e8a4482335 Merge branch 'maint-0.4.4' 2020-09-18 09:45:25 -04:00
Nick Mathewson
7945e075a4 Fix underflow in rend_cache/free_all test.
We already fixed these in #40099 and #40125.

This patch fixes #40126.  Bugfix on 0.2.8.1-alpha.
2020-09-17 14:04:54 -04:00
Nick Mathewson
404c224c71 Merge branch 'maint-0.4.4' 2020-09-17 13:56:40 -04:00
Nick Mathewson
078194ecaf Merge branch 'maint-0.3.5' into maint-0.4.3 2020-09-17 13:56:40 -04:00
Nick Mathewson
54cd2578ef Merge branch 'maint-0.4.3' into maint-0.4.4 2020-09-17 13:56:40 -04:00
David Goulet
47f1d19f8e test: Increment rend cache allocation before freeing
The rend_cache/entry_free was missing the rend cache allocation increment
before freeing the object.

Without it, it had an underflow bug:

  Sep 17 08:40:13.845 [warn] rend_cache_decrement_allocation(): Bug: Underflow
  in rend_cache_decrement_allocation (on Tor 0.4.5.0-alpha-dev
  7eef9ced61)

Fixes #40125

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-09-17 13:00:23 -04:00
David Goulet
a47d12c64d Merge branch 'tor-gitlab/mr/129' 2020-09-17 09:17:53 -04:00
Nick Mathewson
4e8cb410a7 Resolve some coverity complaints in test_util_glob().
Coverity's first complaint was that we didn't check the return
values from chmod.  That's easily fixed.

Coverity's second complaint was that there were code paths where we pass
NULL to chmod.  For example, if this line failed, we'd "goto done",
and then pass NULL to chmod.
  tt_ptr_op(dirname, OP_NE, NULL);

Closes #40103.  Bug not in any released Tor.
2020-09-17 09:17:49 -04:00
Nick Mathewson
5d1d7afcd3 Use the correct SIGNED_KEY_TYPE value for signing->link certs
Our code was using [01] as for the key type of signed->link certs,
which was incorrect.  The value should be [03], to indicate that the
value as the SHA256 of an x.509 cert.

Fortunately, nothing cares about this value, so there shouldn't be
compatibility issues.

Fixes bug 40124; bugfix on 0.2.7.2-alpha.
2020-09-17 08:42:25 -04:00
David Goulet
7eef9ced61 Merge branch 'tor-gitlab/mr/131' 2020-09-17 08:33:10 -04:00
Nick Mathewson
22643272d2 Fix wide lines 2020-09-17 08:19:53 -04:00
Nick Mathewson
c92e19268b Rename tor_cert_create to tor_cert_create_ed25519
This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        tor_cert_create tor_cert_create_ed25519

It was generated with --no-verify, so it probably breaks some commit hooks.
The commiter should be sure to fix them up in a subsequent commit.
2020-09-17 08:17:36 -04:00
Nick Mathewson
bf5bf33661 Bump version to 0.4.4.5-dev. 2020-09-15 08:52:37 -04:00
Nick Mathewson
f6b8894726 Bump version to 0.4.4.5 2020-09-14 13:17:37 -04:00
Nick Mathewson
020e8e41c6 Resolve a compilation warning in test_connection.c
Instead of casting an enum to a void and back, use a string --
that's better C anyway.

Fixes bug 40113; bugfix on 0.2.9.3-alpha.
2020-09-14 11:50:38 -04:00
Nick Mathewson
33380f6b27 Update remaining trac.tpo wiki urls 2020-09-14 11:02:38 -04:00
Alexander Færøy
1c4b140427 Check if glob() is available at build-time.
This patch disables the glob() support in the path library if glob() is
unavailable at build-time. This currently happens with the Android NDK
used for Tor Browser.

See: https://bugs.torproject.org/tpo/core/tor/40114
2020-09-10 10:51:57 -04:00
David Goulet
12c7583126 Merge branch 'maint-0.4.4' 2020-09-08 11:14:12 -04:00
George Kadianakis
85a1e6c601 statistics: Properly count all rendezvous cells (avoid undercounting).
tl;dr We were not counting cells flying from the client to the service, but we
were counting cells flying from the service to the client.

When a rendezvous cell arrives from the client to the RP, the RP forwards it to
the service.

For this to happen, the cell first passes through command_process_relay_cell()
which normally does the statistics counting. However because the `rend_circ`
circuit was not flagged with `circuit_carries_hs_traffic_stats` in
rend_mid_rendezvous(), the cell is not counted there.

Then the cell goes to circuit_receive_relay_cell() which has a special code
block based on `rend_splice` specifically for rendezvous cells, and the cell
gets directly passed to `rend_circ` via a direct call to
circuit_receive_relay_cell(). The cell never passes through
command_process_relay_cell() ever again and hence is never counted by our
rephist module.

The fix here is to flag the `rend_circ` circuit with
`circuit_carries_hs_traffic_stats` so that the cell is counted as soon as it
hits command_process_relay_cell().

Furthermore we avoid double-counting cells since the special code block of
circuit_receive_relay_cell() makes us count rendezvous cells only as they enter
the RP and not as they exit it.

Fixes #40117.
2020-09-07 13:30:21 +03:00
George Kadianakis
248cbc2d22 statistics: Properly count all rendezvous cells (avoid undercounting).
tl;dr We were not counting cells flying from the client to the service, but we
were counting cells flying from the service to the client.

When a rendezvous cell arrives from the client to the RP, the RP forwards it to
the service.

For this to happen, the cell first passes through command_process_relay_cell()
which normally does the statistics counting. However because the `rend_circ`
circuit was not flagged with `circuit_carries_hs_traffic_stats` in
rend_mid_rendezvous(), the cell is not counted there.

Then the cell goes to circuit_receive_relay_cell() which has a special code
block based on `rend_splice` specifically for rendezvous cells, and the cell
gets directly passed to `rend_circ` via a direct call to
circuit_receive_relay_cell(). The cell never passes through
command_process_relay_cell() ever again and hence is never counted by our
rephist module.

The fix here is to flag the `rend_circ` circuit with
`circuit_carries_hs_traffic_stats` so that the cell is counted as soon as it
hits command_process_relay_cell().

Furthermore we avoid double-counting cells since the special code block of
circuit_receive_relay_cell() makes us count rendezvous cells only as they enter
the RP and not as they exit it.

Fixes #40117.
2020-09-07 13:29:44 +03:00
David Goulet
ae6430818e addr: Missing AF family to index conversion
When accessing the last_resolved_address cache we always need to convert the
AF family value to an index value else we are out of bound and thus
overflowing if we write to it.

This fix is on code that has not been released.

GeKo reported the following libasan crash using Tor Browser alpha with tor
0.4.5.0-alpha-dev (3c884bc9e0):

==4240==ERROR: AddressSanitizer: global-buffer-overflow on address
0x55888490e388 at pc 0x5588842cc216 bp 0x7ffc8c421b00 sp 0x7ffc8c421af8
READ of size 2 at 0x55888490e388 thread T0
    #0 0x5588842cc215 in tor_addr_compare_masked
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x5a6215)
    #1 0x558884203210 in is_local_to_resolve_addr
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x4dd210)
    #2 0x558883f7e252 in channel_tls_connect
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x258252)
    #3 0x558883f87ff7 in channel_connect_for_circuit
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x261ff7)
    #4 0x558883f8bc90 in circuit_handle_first_hop
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x265c90)
    #5 0x558883f8c891 in circuit_establish_circuit
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x266891)
    #6 0x558883fc3bbc in circuit_launch_by_extend_info
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x29dbbc)
    #7 0x558883fc5900
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x29f900)
    #8 0x558883fc6988 in connection_ap_handshake_attach_circuit
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x2a0988)
    #9 0x558883fd0d3f in connection_ap_attach_pending
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x2aad3f)
    #10 0x7f4d50110885  (TorBrowser/Tor/libevent-2.1.so.7+0x22885)
    #11 0x7f4d501110de in event_base_loop
(TorBrowser/Tor/libevent-2.1.so.7+0x230de)
    #12 0x558883f69b3c in do_main_loop
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x243b3c)
    #13 0x558883f3f70c in tor_run_main
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x21970c)
    #14 0x558883f3c2f7 in tor_main
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x2162f7)
    #15 0x558883f3531b in main
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x20f31b)
    #16 0x7f4d4f76acc9 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x26cc9)
    #17 0x558883f3ba00
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x215a00)

0x55888490e388 is located 24 bytes to the left of global variable
'state_mgr' defined in 'src/app/config/statefile.c:184:22'
(0x55888490e3a0) of size 8
0x55888490e388 is located 32 bytes to the right of global variable
'global_state' defined in 'src/app/config/statefile.c:204:20'
(0x55888490e360) of size 8
SUMMARY: AddressSanitizer: global-buffer-overflow
(/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x5a6215)
in tor_addr_compare_masked
Shadow bytes around the buggy address:
  0x0ab190919c20: 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
  0x0ab190919c30: 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 03 f9 f9 f9
  0x0ab190919c40: f9 f9 f9 f9 03 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0ab190919c50: 00 00 00 04 f9 f9 f9 f9 00 00 00 00 00 00 00 04
  0x0ab190919c60: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
=>0x0ab190919c70: f9[f9]f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0ab190919c80: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ab190919c90: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ab190919ca0: 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0ab190919cb0: 01 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
  0x0ab190919cc0: 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==4240==ABORTING

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-09-03 16:07:19 +00:00
David Goulet
ea339227c2 conn: Remove assert on new listener connection when retrying
Opening a new listener connection can fail in many ways like a bind()
permission denied on a low port for instance.

And thus, we should expect to handle an error when creating a new one instead
of assert() on it.

To hit the removed assert:

  ORPort 80
  KeepBindCapabilities 0

Start tor. Then edit torrc:

  ORPort <some-IP>:80

HUP tor and the assert is hit.

Fixes #40073

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-09-01 10:01:21 -04:00
Alexander Færøy
511730db2d Merge remote-tracking branch 'tor-gitlab/mr/133' 2020-08-26 21:55:39 +00:00
David Goulet
a6a97236fc Merge branch 'tor-gitlab/mr/135' 2020-08-26 11:04:53 -04:00
George Kadianakis
d4f3cfe99a Merge branch 'mr/113' 2020-08-25 20:37:04 +03:00
Neel Chauhan
90707c9264 Even argument spacing for some functions in feature/client/bridges.c 2020-08-25 09:16:58 -04:00
Nick Mathewson
75772ea096 Validate address more carefully when checking self-reachability
Previously, we would treat *any* incoming circuit on a non-local
channel as meaning that our ORPort was reachable.  With this patch,
we make sure that the address that the peer _says_ we have is the
same as the one we're trying to advertise right now.

Closes 20165. Bugfix on 4f5192b280 in 0.1.0.1-rc, when
reachability self-tests were first introduced.
2020-08-25 16:02:59 +03:00
George Kadianakis
cc4e42ee32 Merge remote-tracking branch 'tor-gitlab/mr/115' 2020-08-25 15:43:00 +03:00
David Goulet
6dc0b04319 Merge branch 'maint-0.4.4' 2020-08-25 08:23:06 -04:00
George Kadianakis
53cd1c9710 Avoid guard-related warning when upgrading from 043 to 044.
Fixes #40105.
2020-08-25 15:09:57 +03:00
George Kadianakis
4b9ed14d9b Merge remote-tracking branch 'tor-gitlab/mr/108' 2020-08-25 15:02:04 +03:00
George Kadianakis
935160ce86 Merge branch 'maint-0.4.4' 2020-08-25 14:51:23 +03:00
George Kadianakis
1397a86bbd Merge remote-tracking branch 'tor-gitlab/mr/130' into maint-0.4.4 2020-08-25 14:51:05 +03:00
Neel Chauhan
b16d82043c Include crypto_rand.h in ed25519_tor.c 2020-08-23 06:05:08 -07:00
George Kadianakis
36203e8894 Merge branch 'maint-0.4.4' 2020-08-20 14:34:56 +03:00
Neel Chauhan
6e37086f85 v3 control: Persist ONION_CLIENT_AUTH_ADD client name 2020-08-20 14:34:21 +03:00
David Goulet
83052372a0 relay: Query our cache when deciding for dummy descriptor fetch
Instead of looking at the "Address" option alone, instead check if we have an
address in our cache (that is discovered by tor). If not, then it tells us
that tor does not have an address to work with so we can then ask a directory
authority for a suggestion.

Related #2178

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-08-19 10:25:47 -04:00
David Goulet
f5c9f6d432 hs: Don't overwrite DoS parameters on circuit with consensus params
Turns out that the HS DoS defenses parameters were overwritten by the
consensus parameters everytime a new consensus would arrive.

This means that a service operator can still enable the defenses but as soon
as the intro point relay would get a new consensus, they would be overwritten.
And at this commit, the network is entirely disabling DoS defenses.

Fix this by introducing an "explicit" flag that indicate if the
ESTABLISH_INTRO cell DoS extension set those parameters or not. If set, avoid
using the consenus at once.

We are not bumping the protover HSIntro value for this because 0.4.2.x series
is EOL in 1 month and thus 0.4.3.x would be the only series with this bug. We
are confident that a backport and then upgrade path to the latest 0.4.4.x
stable coming up soon is enough to mitigate this problem in the coming months.

It avoids the upgrade path on the service side by keeping the requirement for
protover HSIntro=5.

Fixes #40109

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-08-19 09:47:34 -04:00
George Kadianakis
4e3f55fba1 Merge branch 'maint-0.4.4' 2020-08-19 13:56:34 +03:00
George Kadianakis
b1b0079675 Merge branch 'mr/124' into maint-0.4.4 2020-08-19 13:55:07 +03:00
Nick Mathewson
974abdf632 Parallelize src/test/test into chunks.
First, we introduce a flag to teach src/test/test to split its work
into chunks.  Then we replace our invocation of src/test/test in our
"make check" target with a set of 8 scripts that invoke the first
8th of the tests, the second 8th, and so on.

This change makes our "make -kj4 check" target in our hardened
gitlab build more than twice as fast, since src/test/test was taking
the longest to finish.

Closes 40098.
2020-08-19 13:46:50 +03:00
David Goulet
1089ac6f22 Merge branch 'tor-gitlab/mr/126' 2020-08-18 08:56:27 -04:00
David Goulet
80d2376f33 Merge branch 'maint-0.4.4' 2020-08-18 08:49:07 -04:00
David Goulet
deea196370 Merge branch 'tor-gitlab/mr/121' into maint-0.4.4 2020-08-18 08:49:01 -04:00
Daniel Pinto
ebaa1a1d23 Make options_init_from_torrc smaller #40102
Split implementation of several command line options from
options_init_from_torrc into smaller isolated functions.
2020-08-14 16:01:02 +01:00
Nick Mathewson
563f8610fd Revise trac.torproject.org urls to refer to gitlab replacements.
Closes #40101.
2020-08-14 09:21:28 -04:00
Nick Mathewson
7915b651d9 Merge branch 'maint-0.4.2' into maint-0.4.3 2020-08-13 14:20:39 -04:00
Nick Mathewson
ef18fb56c9 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-08-13 14:20:39 -04:00
Nick Mathewson
8669ace2fb Merge branch 'maint-0.4.4' 2020-08-13 14:20:39 -04:00
Nick Mathewson
45d9830493 Merge branch 'maint-0.3.5' into maint-0.4.2 2020-08-13 14:20:39 -04:00
Nick Mathewson
26b257757b Bump to 0.4.4.4-rc-dev 2020-08-13 09:43:54 -04:00
Nick Mathewson
7b4716a762 Make test_glob() pass even when run as root.
Previously the test relied on not being able to look inside 000
directories, which is a thing root _can_ do.

Bug not in any released Tor version.
2020-08-12 20:36:23 -04:00
Nick Mathewson
9ef991dbe3 Use correct type for gl_closedir to avoid a compiler warning 2020-08-12 14:42:30 -04:00
Nick Mathewson
e151442037 Merge remote-tracking branch 'tor-gitlab/mr/62' 2020-08-12 14:37:21 -04:00
Nick Mathewson
f9bb49d870 Fix allocation counting in clean_v2_descs_as_dir test.
Without this fix, running this test on its own would fail.

Fixes bug 40099. Bugfix on ade5005853 in 0.2.8.1-alpha.
2020-08-12 14:25:46 -04:00
Daniel Pinto
60c436d14d Attempt to fix test_include.py on TravisCI #25140 2020-08-12 14:35:51 +01:00
George Kadianakis
347f87ae9d Merge branch 'maint-0.4.4' 2020-08-12 13:47:59 +03:00
George Kadianakis
5a1918d7e7 Merge remote-tracking branch 'tor-gitlab/mr/107' into maint-0.4.4 2020-08-12 13:47:34 +03:00
George Kadianakis
c591a0d246 Merge branch 'maint-0.4.4' 2020-08-12 13:23:33 +03:00
George Kadianakis
8e9edb93be Merge remote-tracking branch 'tor-gitlab/mr/104' into maint-0.4.4 2020-08-12 13:23:08 +03:00
Nick Mathewson
4fdec27a12 Remove extraneous EVENT_CONTROLLER_WAIT
This turned into a new StreamStatus value.

Closes #40092. Bug not in any released Tor.
2020-08-11 18:41:15 -04:00
Nick Mathewson
1770d1c216 bump version to 0.4.4.4-rc 2020-08-11 17:46:44 -04:00
Nick Mathewson
a02002dc99 Lower the minimum value for MaxMemInQueues to 64 MB for relays.
For clients, there is no minimum value; in both cases, we warn if
the value seems too low.

Closes ticket 24308.
2020-08-11 17:01:49 -04:00
Daniel Pinto
0b633b1f6d Improved documentation and comments #25140 2020-08-11 18:26:41 +01:00
Nick Mathewson
431dcc42e0 Rename argument to compute_real_max_mem_in_queues() 2020-08-11 12:59:07 -04:00
Nick Mathewson
d76f8457f3 Merge remote-tracking branch 'tor-gitlab/mr/119' into maint-0.4.4 2020-08-11 12:40:02 -04:00
Nick Mathewson
11961f0bc5 Merge remote-tracking branch 'tor-gitlab/mr/119' 2020-08-11 12:39:30 -04:00
George Kadianakis
b705cfa024 Merge remote-tracking branch 'tor-gitlab/mr/111' 2020-08-11 15:12:43 +03:00
George Kadianakis
f971a8fbad Merge branch 'mr/105' 2020-08-11 15:04:15 +03:00
Nick Mathewson
7df52b71bf Only log port self-testing message when we are _starting_ to test.
(Unlike approaches in earlier versions of Tor, this one logs if and
only if we are launching a test, and we haven't said that we're
testing this port.)

Fixes bug 40068; bug not in any released version.

Closes #40068.
2020-08-11 15:02:44 +03:00
George Kadianakis
b8003fbe99 Merge branch 'maint-0.4.4' 2020-08-11 14:54:26 +03:00
George Kadianakis
ab9c35f043 Merge remote-tracking branch 'tor-gitlab/mr/102' into maint-0.4.4 2020-08-11 14:53:03 +03:00
George Kadianakis
9316ca9f06 Remove a BUG() that could normally trigger in edge-cases. 2020-08-11 14:42:18 +03:00
Nick Mathewson
069946852a Merge branch 'maint-0.4.4' 2020-08-10 19:33:07 -04:00
Nick Mathewson
7d80bf80fe Merge branch 'maint-0.4.3' into maint-0.4.4 2020-08-10 19:33:07 -04:00
Nick Mathewson
f3fcc89d05 Merge branch 'maint-0.4.2' into maint-0.4.3 2020-08-10 19:33:06 -04:00
Nick Mathewson
68f8250cbb Merge branch 'maint-0.3.5' into maint-0.4.2 2020-08-10 19:32:49 -04:00
Nick Mathewson
e873c7e893 small code tweaks to try to work around debian stable complaints 2020-08-10 19:20:05 -04:00
Nick Mathewson
3eb9331133 Merge remote-tracking branch 'tor-gitlab/mr/110' 2020-08-10 14:51:12 -04:00
Nick Mathewson
24c721de37 Log number of inbound/outbound ipv4/6 conns as part of heartbeat
Closes #29113
2020-08-07 10:45:29 -04:00
Nick Mathewson
6fde1548f2 Revise test_status to use log testing helpers.
This change lets us make these tests much shorter and easier to
maintain.
2020-08-07 10:42:12 -04:00
Nick Mathewson
afb6ff1739 Validate ed25519 keys and canonicity from circuit_n_conn_done()
Fixes bug 40080. Bugfix on 0.2.7.2-alpha.
2020-08-06 15:59:28 -04:00
Nick Mathewson
b417594dbc Replace several C identifiers for ticket 18106.
We used to have a single boolean, "FascistFirewall".  Ages ago, in
tickets #17840 and #9067, we added an improved "ReachableAddresses"
mechanism.  It's time to rename related identifiers in the code for
consistency.  This closes #18106.

This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        fascist_firewall_allows_address reachable_addr_allows \
        fascist_firewall_use_ipv6 reachable_addr_use_ipv6 \
        fascist_firewall_prefer_ipv6_impl reachable_addr_prefer_ipv6_impl \
        fascist_firewall_prefer_ipv6_orport reachable_addr_prefer_ipv6_orport \
        fascist_firewall_prefer_ipv6_dirport reachable_addr_prefer_ipv6_dirport \
        fascist_firewall_allows_address_addr reachable_addr_allows_addr \
        fascist_firewall_allows_address_ap reachable_addr_allows_ap \
        fascist_firewall_allows_base reachable_addr_allows_base \
        fascist_firewall_allows_ri_impl reachable_addr_allows_ri_impl \
        fascist_firewall_allows_rs_impl reachable_addr_allows_rs_impl \
        fascist_firewall_allows_rs reachable_addr_allows_rs \
        fascist_firewall_allows_md_impl reachable_addr_allows_md_impl \
        fascist_firewall_allows_node reachable_addr_allows_node \
        fascist_firewall_allows_dir_server reachable_addr_allows_dir_server \
        fascist_firewall_choose_address_impl reachable_addr_choose_impl \
        fascist_firewall_choose_address reachable_addr_choose \
        fascist_firewall_choose_address_base reachable_addr_choose_base \
        fascist_firewall_choose_address_rs reachable_addr_choose_from_rs \
        fascist_firewall_choose_address_ls reachable_addr_choose_from_ls \
        fascist_firewall_choose_address_node reachable_addr_choose_from_node \
        fascist_firewall_choose_address_dir_server reachable_addr_choose_from_dir_server
2020-08-05 16:34:45 -04:00
George Kadianakis
afd88ee87f Merge remote-tracking branch 'tor-gitlab/mr/88' 2020-08-05 14:57:20 +03:00
Neel Chauhan
d1413e04f8 ipv6: Specialize GETINFO address interface for v4 and v6 2020-08-04 13:59:49 -07:00
Nick Mathewson
1d0695fe7e Improve ratelimit message to list true interval.
Previous message would say "N messages in the last T seconds", but
would give an inaccurate number for N.

We now give an accurate number, rounded up to the nearest 60 seconds.

Closes #19431.
2020-08-04 13:56:28 -04:00
Nick Mathewson
04926126ee Merge remote-tracking branch 'tor-gitlab/mr/100' 2020-08-04 13:28:51 -04:00
Nick Mathewson
08de260682 Merge branch 'bug40083_035' into bug40083_042
Fixes conflicts due to code movement.
2020-08-04 13:10:16 -04:00
Nick Mathewson
62361cc698 Launch early reachability tests once a minute, not once a second.
This fixes bug 40083, which was introduced in 9f31908a in
0.2.8.1-alpha.
2020-08-04 13:05:07 -04:00
Daniel Pinto
ccdd0d801a Minor style improvements. #30045 2020-08-03 20:08:17 +01:00
Nick Mathewson
aef9c0f580 Merge branch 'ticket40081_035' into ticket40081_044
Resolves conflicts:
	src/core/or/channel.c
        src/test/test_channel.c
2020-08-03 11:49:09 -04:00
Nick Mathewson
435f31aed3 Remove channel_is_canonical_is_reliable()
This function once served to let circuits continue to be built over
version-1 link connections.  But such connections are long-obsolete,
and it's time to remove this check.

Closes #40081.
2020-08-03 11:25:37 -04:00
Nick Mathewson
ea876ab00e Wipe address strings from connections before freeing them them.
This is a defense-in-depth fix; closes 6198.
2020-08-03 10:15:08 -04:00
Nick Mathewson
5b9508c9a5 Add a tor_str_wipe_and_free() function.
Frequently we want to do

    if (s) {
      memwipe(s, 0, sizeof(s));
      tor_free(s);
    }

and it's good to have a way to do this concisely.
2020-08-03 10:11:03 -04:00
George Kadianakis
e069b0af4b Merge branch 'maint-0.4.4' 2020-08-03 16:49:05 +03:00
George Kadianakis
18d2c7c5d7 Merge remote-tracking branch 'tor-gitlab/mr/79' into maint-0.4.4 2020-08-03 16:48:52 +03:00
Nick Mathewson
ce57404a42 Fix comment on protover_list_is_invalid 2020-08-03 08:57:21 -04:00
Nick Mathewson
efc969e862 Rename protover_contains_long_protocol_names to protover_list_is_invalid
This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        protover_contains_long_protocol_names protover_list_is_invalid
2020-08-03 08:55:17 -04:00
Nick Mathewson
d1fda62d11 Merge remote-tracking branch 'tor-gitlab/mr/94' 2020-08-03 08:54:03 -04:00
Nick Mathewson
3e3b0b0443 Merge remote-tracking branch 'tor-github/pr/1986/head' 2020-08-03 08:33:22 -04:00
Nick Mathewson
efe8a98817 Fix a leak-on-failure on test_get_bandwidth_lines()
Spotted by coverity. This is CID 1465571.
2020-08-01 09:29:08 -04:00
Daniel Pinto
1474ab3395 Add --format argument to --key-expiration option. #30045 2020-08-01 01:08:37 +01:00
Neel Chauhan
837e0c4dc9 Code simplifications for AP_CONN_STATE_CONTROLLER_WAIT 2020-07-31 09:21:43 -07:00
MrSquanchee
bb585c5e37
test_stats : Removed CONFIG_PRIVATE
Signed-off-by: Suraj Upadhyay <usuraj35@gmail.com>
2020-07-31 21:12:29 +05:30
MrSquanchee
a93c3d7a8d
Added tests for bandwidth functions
Added tests for
1. commit_max
2. advance_obs
3. add_obs
4. rep_hist_fill_bandwidth_history
5. rep_hist_get_bandwidth_lines

 (Lightly edited by nickm to use new names from bwhist refactoring.)

Signed-off-by: Suraj Upadhyay <usuraj35@gmail.com>
2020-07-31 21:12:16 +05:30
MrSquanchee
708f51637f
Added tests for bandwidth functions
Added tests for
1. commit_max
2. advance_obs
3. add_obs
4. rep_hist_fill_bandwidth_history
5. rep_hist_get_bandwidth_lines

Signed-off-by: Suraj Upadhyay <usuraj35@gmail.com>
2020-07-31 21:10:54 +05:30
Nick Mathewson
b5068e4826 Extract bw_array_t and related constants into a header.
This will be used for testing.

Partially reproduces work by MrSquanchee in #33812.
2020-07-31 10:46:52 -04:00
Alexander Færøy
e78a7450a2 Merge branch 'maint-0.4.2' into maint-0.4.3 2020-07-31 02:03:34 +00:00
Alexander Færøy
4e684c8695 Merge branch 'maint-0.3.5' into maint-0.4.2 2020-07-31 02:03:34 +00:00
Nick Mathewson
4c810a6abe Merge branch 'bug40076_044' 2020-07-30 14:35:06 -04:00
Nick Mathewson
b4400e2093 Merge branch 'bug40076_043' into bug40076_044 2020-07-30 14:28:11 -04:00
Nick Mathewson
69d7752937 Merge branch 'bug40076_042' into bug40076_043 2020-07-30 14:27:29 -04:00
Nick Mathewson
c2d5ec5e43 Merge branch 'maint-0.4.2' into bug40076_042 2020-07-30 14:27:29 -04:00
Nick Mathewson
c4742b89b2 Fix a bug in buf_move_all() when the input buffer is empty.
We found this in #40076, after we started using buf_move_all() in
more places.  Fixes bug #40076; bugfix on 0.3.3.1-alpha.  As far as
I know, the crash only affects master, but I think this warrants a
backport, "just in case".
2020-07-30 14:24:25 -04:00
Nick Mathewson
0a588821cb Add unit test for buf_move_all(), including a failing case
The failing case is #if'd out for now, but will be fixed in the next
commit.

Testing for a fix for #40076.
2020-07-30 14:19:32 -04:00
George Kadianakis
155e0dee49 Merge branch 'tor-gitlab/mr/84' 2020-07-30 19:49:25 +03:00
Nick Mathewson
219edc9ab1 Handle ORPort auto when logging about removed orports.
Closes #40075
2020-07-30 19:46:44 +03:00
George Kadianakis
2bb9acca73 Write unittest for #40065.
Make the unit test pass by including an explicit IPv6 port and an
implicit IPv4 port.  See comments for more details.
2020-07-30 19:46:39 +03:00
Nick Mathewson
fc5fe094b1 Fix segfault and logic error in remove_duplicate_orports()
This function tried to modify an array in place, but did it in a
pretty confusing and complicated way.  I've revised it to follow a
much more straightforward approach.

Fixes bug #40065.
2020-07-30 19:46:02 +03:00
Nick Mathewson
fcf4954cc8 Add a unit test for write_str_to_file_if_not_equal() 2020-07-30 10:46:15 -04:00
Nick Mathewson
f3e5b283ad test_util.c: Extract utime() function.
We need this to manipulate mtimes, but only in this file.
2020-07-30 10:46:15 -04:00
Neel Chauhan
67a62ccf51 Use write_str_if_not_equal() for onion services 2020-07-30 10:46:15 -04:00
Neel Chauhan
c212578bf0 Introduce write_str_if_not_equal() 2020-07-30 10:46:15 -04:00
Nick Mathewson
9164d7c75e Merge branch 'maint-0.4.4' 2020-07-29 12:37:08 -04:00
Nick Mathewson
3b8bf743ae Merge branch 'maint-0.4.2' into maint-0.4.3 2020-07-29 12:37:07 -04:00
Nick Mathewson
cdb0e6c252 Merge branch 'maint-0.3.5' into maint-0.4.2 2020-07-29 12:37:07 -04:00
Nick Mathewson
8c92d44622 Merge remote-tracking branch 'tor-gitlab/mr/68' into maint-0.4.4 2020-07-29 12:35:57 -04:00
Nick Mathewson
75f94ea1ec Merge remote-tracking branch 'tor-github/pr/1987/head' 2020-07-29 10:58:47 -04:00
Alexander Færøy
eba2870d18 Merge branch 'maint-0.4.4' 2020-07-29 13:58:14 +00:00
Alexander Færøy
8e690ce736 Merge remote-tracking branch 'tor-gitlab/mr/85' into maint-0.4.4 2020-07-29 13:57:47 +00:00
Alexander Færøy
109063185b Merge branch 'tor-gitlab/mr/73_squashed' 2020-07-29 13:34:24 +00:00
Nick Mathewson
3cb9a9b8ce Remove the connection_t.outbuf_flushlen field
This was once used for rate-limiting, but now it's only for
accounting.  It hasn't served a useful purpose in a long time.

Closes ticket 33097.
2020-07-29 13:33:35 +00:00
Daniel Pinto
eab8e7af52 Fix startup crash with seccomp sandbox enabled #40072
Fix crash introduced in #40020. On startup, tor calls
check_private_dir on the data and key directories. This function
uses open instead of opendir on the received directory. Data and
key directoryes are only opened here, so the seccomp rule added
should be for open instead of opendir, despite the fact that they
are directories.
2020-07-29 00:34:08 +01:00
Nick Mathewson
dcc60294ad Use _lseeki64() on windows.
Fixes bug 31036; bugfix on 0.2.1.8-alpha when we moved the logging
system to use posix fds.
2020-07-28 11:30:47 -04:00
Nick Mathewson
0a38e02fb3 bump to 0.4.4.3-alpha-dev 2020-07-27 19:15:15 -04:00
Nick Mathewson
98d84587a8 Fix documentation of cache_failure_intro_lookup
Closes ticket 17793
2020-07-27 14:22:10 -04:00
Nick Mathewson
31eba7f009 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-07-27 12:56:19 -04:00
Nick Mathewson
64d7b28298 Merge branch 'maint-0.4.4' 2020-07-27 12:56:19 -04:00
Nick Mathewson
97d0cb83ed Merge branch 'maint-0.4.2' into maint-0.4.3 2020-07-27 12:56:18 -04:00
Nick Mathewson
c0bc30b6f0 Merge branch 'maint-0.3.5' into maint-0.4.2 2020-07-27 12:56:18 -04:00
Nick Mathewson
95914ceb57 Bump to 0.4.4.3-alpha 2020-07-27 08:32:56 -04:00
Nick Mathewson
010387e4bd Merge branch '40068_maybe' 2020-07-24 15:15:46 -04:00
David Goulet
564a9a54a1 fallbackdir: Remove all three Digitalcourage3 relays
They are about to be shutdown in September.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-24 14:56:07 -04:00
Nick Mathewson
2299b31f40 Don't let a bad IPv6 orport stop our IPv4 bandwidth test.
Specifically: do not close IPv4 bandwidth-testing circuits just
because our IPv6 orport is unreachable.

Attempted fix for #40068.
2020-07-24 14:50:42 -04:00
David Goulet
ad9806b539 relay: Publish IPv4 descriptor on guessed IPv6 reachability failure
On an IPv6 reachability failure test, if the address was configured, don't
publish the descriptor and log warn. If the address was auto discovered, still
publish the descriptor.

Closes #33247.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-24 12:18:07 -04:00
David Goulet
fda0fa02bf relay: Add a cache that tracks which address was configured
Related to #33247

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-24 11:32:49 -04:00
David Goulet
bf2b1e7a6f relay: Turn find address "method_used" into enum
Enum allows us to easily compare what is being returned but also better
semantic to the code.

Related #33247

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-24 11:32:49 -04:00
Nick Mathewson
9d922b8eaa Merge branch 'maint-0.4.4' 2020-07-23 10:10:32 -04:00
Nick Mathewson
6354b70e49 Merge branch 'maint-0.4.2' into maint-0.4.3 2020-07-23 10:09:14 -04:00
Nick Mathewson
3bcbd69a77 Merge branch 'maint-0.3.5' into maint-0.4.2 2020-07-23 10:09:14 -04:00
Nick Mathewson
07934664c5 Merge branch 'maint-0.4.3' into maint-0.4.4 2020-07-23 10:09:14 -04:00
David Goulet
6f19e67c98 fallbackdir: Update list for 2020
Closes #40061

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-23 10:05:11 -04:00
Nick Mathewson
b3112a6d26 Merge branch 'remove-padding-fix-7869-v2' 2020-07-23 08:26:44 -04:00
Daniel Pinto
d72618eb7f Remove padding from ntor-onion-key #7869 2020-07-23 08:25:22 -04:00
David Goulet
9cd20e8276 Merge branch 'tor-gitlab/mr/75' 2020-07-23 07:16:05 -04:00
David Goulet
884ccd6996 Merge branch 'maint-0.4.4' 2020-07-22 16:14:19 -04:00
David Goulet
1ee164afc2 Merge branch 'tor-gitlab/mr/77' into maint-0.4.4 2020-07-22 16:14:11 -04:00
David Goulet
492625badf Merge branch 'tor-gitlab/mr/74' 2020-07-22 16:09:11 -04:00
David Goulet
053e02a487 addr: Always set addr_out to UNSPEC in find_my_address
Related #40058

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-22 16:09:07 -04:00
David Goulet
65c7d33d33 relay: Support IPv6 when checking if our address changed
Now support IPv4 _and_ IPv6.

This also cleans up nicely the function that was moving IPv4 addresses from
uint32_t to tor_addr_t.

Fixes #40058

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-22 16:09:07 -04:00
Nick Mathewson
ceb6585a4b Treat all extorport connections with un-set addresses as remote
Without this fix, if an PT forgets to send a USERADDR command, that
results in a connection getting treated as local for the purposes of
rate-limiting.

If the PT _does_ use USERADDR, we still believe it.

Closes ticket 33747.
2020-07-22 15:21:56 -04:00
Nick Mathewson
faa752f3c9 Adjust the rules for warning about too many connections.
Previously we tolerated up to 1.5 connections for every relay we
were connected to, and didn't warn if we had fewer than 5
connections total.

Now we tolerate up to 1.5 connections per relay, and up to 4
connections per authority, and we don't warn at all when we have
fewer than 25 connections total.

Fixes bug 33880, which seems to have been provoked by our #17592
change in 0.3.5.
2020-07-22 14:45:03 -04:00
David Goulet
f0da04bb7b relay: Limit Directory Authority Addresses to Address and ORPort
Closes #33239

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-22 14:17:21 -04:00
David Goulet
6de860497e log: Don't use twice fmt_addr() in same logging statement
Fixes #40059

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-22 11:09:21 -04:00
David Goulet
a4c5b7d742 Rename check_server_ports to check_and_prune_server_ports
This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        check_server_ports check_and_prune_server_ports
2020-07-21 15:51:48 -04:00
David Goulet
28c1b60476 relay: Change router_can_extend_over_ipv6() to look at configured port
In routerconf_find_ipv6_or_ap(), we check if the returned ORPort is internal
but not for listening. This means that IPv6 [::] is considered internal.

Thus, we can't use it, we have to look directly at the configured address and
port and if they are valid, we do consider that we have a valid IPv6 ORPort
and that we can thus extend in IPv6.

Related #33246

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21 15:50:16 -04:00
David Goulet
803e769fb2 relay: Remove possible ORPorts duplicate from parsed list
Now that tor automatically binds to IPv4 _and_ IPv6, in order to avoid
breaking configurations, we sanitize the parsed lists for duplicate ORPorts.
It is possible to happen because we still allow this configuration;

  ORPort 9888
  ORPort [4242::1]:9888

Meaning that the first ORPort value will bind to 0.0.0.0:9888 _and_ [::]:9888
which would lead to an error when attempting to bind on [4242::1]:9888.
However, that configuration is accepted today and thus we must not break it.

To remedy, we now sanitize the parsed list and prioritize an ORPort that has
an explicit address over the global one.

A warning is emitted if such configuration pattern is found. This is only for
the ORPort.

Related to #33246

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21 15:48:05 -04:00
David Goulet
c3a0f75796 relay: Automatically Enable an IPv6 ORPort
This commit makes it that if the ORPort is set with a single port, it will
bind to both global listen IPv4 and IPv6 addresses.

To pin an "ORPort <PORT>" to be IPv4 or IPv6, the IPv4Only/IPv6Only flags are
honored thus this will _only_ bind on IPv6 for that port value:

  ORPort 9050 IPv6Only
    Results in: [::]:9050

  ORPort 9051 IPv4Only
    Results in: [0.0.0.0]:9051

Attempting to configure an explicit IPv4 address with IPv6Only flag is an
error and vice versa.

Closes #33246

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21 15:48:05 -04:00
Nick Mathewson
088100d698 Rename router_get_advertised_*() functions.
These now (or_port and dir_port) now have "find" names, since they
look at the portcfg first, then at the actual ports from the
listeners.

This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        router_get_advertised_or_port routerconf_find_or_port \
        router_get_advertised_ipv6_or_ap routerconf_find_ipv6_or_ap \
        router_has_advertised_ipv6_orport routerconf_has_ipv6_orport \
        router_get_advertised_dir_port routerconf_find_dir_port
2020-07-21 12:59:03 -04:00
Nick Mathewson
f478080bd0 Combine router_get_advertised_or_port{,by_af_}() functions 2020-07-21 12:47:33 -04:00
Nick Mathewson
39146383fc Rename get_primary_dir_port()
Also, remove get_primary_or_port() -- nothing used it.
2020-07-21 12:47:09 -04:00
Nick Mathewson
f57c31e4be Extract shared parts of portcfg_get_first_advertised_*() 2020-07-21 12:47:09 -04:00
Nick Mathewson
fda9d7f5ed Rename get_first_advertised_{addr,port}_by_type_af().
Rationale: these don't actually give the first advertised
address/port, but instead give us the first such port that we are
_configured_ to advertise.  Putting them in a portconf_ namespace
therefore makes sense.

Similarly, there are no other functions that get the first
configured advertised addr/port, so the "by_type_af()" part is needless.

This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        get_first_advertised_addr_by_type_af portconf_get_first_advertised_addr \
        get_first_advertised_port_by_type_af portconf_get_first_advertised_port
2020-07-21 12:02:01 -04:00
Nick Mathewson
e8497bfaa7 Merge remote-tracking branch 'tor-gitlab/mr/64' 2020-07-21 09:33:41 -04:00
Nick Mathewson
7d0e64016e Merge branch 'maint-0.4.4' 2020-07-21 09:29:13 -04:00
Nick Mathewson
5cd85feaa7 Merge remote-tracking branch 'tor-gitlab/mr/68' into maint-0.4.4 2020-07-21 09:29:03 -04:00
Nick Mathewson
2ee33765ae Merge branch 'maint-0.4.4' 2020-07-21 09:24:27 -04:00
Nick Mathewson
95d4bff784 Merge remote-tracking branch 'tor-gitlab/mr/67' into maint-0.4.4 2020-07-21 09:24:15 -04:00
Nick Mathewson
7a2fe93529 Merge remote-tracking branch 'tor-gitlab/mr/70' 2020-07-21 09:03:38 -04:00
David Goulet
c3d113a464 relay: Add AddressDisableIPv6 torrc option
This option controls if a tor relay will attempt address auto discovery and
thus ultimately publish an IPv6 ORPort in the descriptor.

Behavior is from proposal 312 section 3.2.6.

Closes #33245

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21 08:18:31 -04:00
David Goulet
fbee4d25cc relay: Don't publish IPv6 if found ORPort is 0
The ORPort can be IPv4Only which means that even if we can auto discover an
IPv6 address, we should not publish it because it would have an ORPort of 0.

Fixes #40054

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21 08:12:47 -04:00
Daniel Pinto
d75e7daaab Fix seccomp sandbox rules for openat #27315
The need for casting negative syscall arguments depends on the
glibc version. This affects the rules for the openat syscall which
uses the constant AT_FDCWD that is defined as a negative number.
This commit adds logic to only apply the cast when necessary, on
glibc versions from 2.27 onwards.
2020-07-20 22:35:05 +01:00
Daniel Pinto
d28bfb2cd5 Fix seccomp sandbox rules for opening directories #40020
Different versions of glibc use either open or openat for the
opendir function. This commit adds logic to use the correct rule
for each glibc version, namely:
- Until 2.14 open is used
- From 2.15 to to 2.21 openat is used
- From 2.22 to 2.26 open is used
- From 2.27 onwards openat is used
2020-07-20 22:30:13 +01:00
Daniel Pinto
c79b4397d3 Fix seccomp sandbox rules for openat #27315
The need for casting negative syscall arguments depends on the
glibc version. This affects the rules for the openat syscall which
uses the constant AT_FDCWD that is defined as a negative number.
This commit adds logic to only apply the cast when necessary, on
glibc versions from 2.27 onwards.
2020-07-20 22:30:00 +01:00
Nick Mathewson
f5d773c600 Merge remote-tracking branch 'tor-gitlab/mr/51' 2020-07-20 16:50:32 -04:00
Nick Mathewson
d6570eaf5d Merge remote-tracking branch 'tor-gitlab/mr/59' 2020-07-20 16:37:11 -04:00
David Goulet
a576f37cfe relay: Don't log at warn level when we find an address
Dirauth code use the warn log severity when calling find_my_address() which
made it that every time we would find an address, it would log a warning.

These are not needed below info level and thus set them to info level. An IP
change is set to notice by default.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
75434a1df1 relay: Use flags in relay_find_addr_to_publish()
Instead of a boolean saying "cache_only" add the concept of flags so we add
semantic through out the code and allow ourselves to have more options in the
future.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
230293c169 control: With GETINFO, don't trigger an address resolve
Tell the relay find address interface to only use the cache so we don't
trigger an address resolve everytime the "GETINFO address" is called.

Related #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
433a1949e8 relay: Handle dir address suggestion with new interface
We now use relay_address_new_suggestion() when a suggested address is received
from a directory.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
0b89eba7d5 addr: Use false/true with relay_find_addr_to_publish()
Previous development introduced the error of using 0/1 for a boolean
parameter. Fix that everywhere

Related #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
a37a027e61 test: Unit test for relay_find_addr_to_publish()
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
c98cffbc07 test: Unit test for relay_address_new_suggestion()
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
8178a34b80 relay: Remove router_pick_published_address()
Unused at this commit.

Closes #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
4a41761101 test: Move unit tests to new find address interface
Remove use of router_pick_published_address() and use
relay_find_addr_to_publish instead.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
75a2e7fcb7 control: GETINFO address/ use new find address API
At the moment, this command only returns the IPv4. Do so by using the new
relay_find_addr_to_publish().

New commands to return IPv4 and IPv6 will be done with the work in tor#40039.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
1a347b4790 relay: Deciding to fetch from authority, use new find address API
Use the new relay_has_address_set() interface when deciding if we need to
fetch directory information from an authority as a relay.

If no IPv4 address is found, we'll proceed with a fetch so we can learn our
address in the HTTP header or NETINFO cell that a trusted authority will send
us back.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
35871e46e8 relay: Don't lookup our address before rebuilding our descriptor
Tor periodic events have moved to a role base model where relays have specific
events. One of those is to rebuild the descriptor and that is ran every
minute.

This removes the call to router_rebuild_descriptor() from
router_get_my_routerinfo_with_err() because that is the only code path that
can call for a rebuild every second.

Instead, when we mark the descriptor as dirty, immediately reschedule the
descriptor check periodic event so it can be rebuilt that way instead of
randomly when router_get_my_routerinfo_with_err() is called.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
502f3f5afe relay: Publish IPv4/IPv6 from resolved address cache
When a relay builds a new descriptor, use the new relay_find_addr_to_publish()
interface to find the address to publish per family.

This commit also make the check for address consistency to also work for a
configured IPv6 for which before it was IPv4 only.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
9f61a6bdc3 pt: Use new address discovery interface when creating extrainfo
In case the transport has no usable address configured (likely 0.0.0.0 or
[::]), attempt to find the IPv4 and on failure, fallback to the IPv6. If none
are found, a log error is emitted and the transport is skiped.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
b239f178a2 addr: New function to find address to publish
In order for a relay to find which address to publish in its descriptor,
router_pick_published_address() is used. However, that function only supports
AF_INET and uses the directory server suggested address discovery mechanism.

This new function uses a new interface so that the caller can request an
address family and get the tor_addr_t object. Furthermore, it drops the use of
directory servers address discovery (tor#33244) and instead uses the new
suggested cache that is populated at the moment from data in the NETINFO cell
coming from the directory authorities.

At this commit, function is unused.

Related to #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:54:13 -04:00
David Goulet
c18e52af7c addr: Continue discovery if Address exits but not for wanted family
Commit b14b1f2b1d was a mistake.

In case an Address statement is missing for the wanted family but another one
exists for another family, simply continue the address discovery.

It is not a mistake to be missing an Address statement for a family because
the address could simply be discovered by the next methods. Not all address
family requires a specific Address statement.

However, we do bail if we couldn't find any valid address for the requested
family _and_ a resolve failed meaning we had a hostname but couldn't resolve
it. In that case, we can't know if that hostname would have been for v4 or v6
thus we can't continue the address discovery properly.

Couple unit tests case were removed to match this reality.

Related #40025

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20 14:51:42 -04:00
Daniel Pinto
29307c0625 Add running glibc version to the log. #40047
Also adds the compiled and running glibc version when using the
--library-versions flag.
2020-07-17 18:45:57 +01:00
Nick Mathewson
2225c3c369 Merge branch 'ticket40042_squashed' 2020-07-17 11:44:27 -04:00
Nick Mathewson
11f125ec78 Clean up documentation for connection_t.address 2020-07-17 11:42:49 -04:00
Nick Mathewson
f64cf09eb2 Document some channel_matches_extend_info issues that confused me. 2020-07-17 11:42:49 -04:00
Nick Mathewson
adec471595 Clean up documentation for connection_t.addr a bit more. 2020-07-17 11:42:49 -04:00
Nick Mathewson
7b3bd45cfe or_connection_t: replace real_addr with canonical_orport.
Instead of replacing connection_t.{addr,port} with a canonical
orport, and tracking the truth in real_addr, we now leave
connection_t.addr alone, and put the canonical address in
canonical_orport.

Closes #40042

Closes #33898
2020-07-17 11:42:49 -04:00
Nick Mathewson
44da920670 Add a tor_addr_port_copy() function. 2020-07-17 11:42:49 -04:00
Nick Mathewson
ff68aeb492 When choosing an orport from an extendinfo, pick randomly.
(This is not fully general yet: we only pick randomly among
_supported_ addresses, and each extendinfo contains at most one IPv4
address and at most one IPv6 address, no matter what the extend cell
had.)

This change will help dual-stack relays do IPv6 reachability tests,
in theory, by having them sometimes do IPv4 connections and
sometimes do ipv6 connections.

Closes ticket 33220.
2020-07-17 09:15:08 -04:00
David Goulet
aa9561164a nodelist: Fix possible NULL deref
Found by coverity with CID 1465290. Fix unreleased code.

Fixes #40049

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-16 13:23:03 -04:00
Nick Mathewson
4b24b36289 Remove unneeded generate_ed_link_cert() in tests.
This fixes CID 1465291, which was a complaint that we never actually
checked the return value of this function.  It turns out that this
function was failing, and it didn't matter, because it wasn't
necessary for this test.
2020-07-16 12:59:51 -04:00
Nick Mathewson
7ebfa607b2 Use CONST_TO_* macros in more places.
This is an automated commit made with a python script.

After running the automated script, I had to hand-revert the cases where it
made the conversion functions call themselves.

Additionally, I had to edit a variable declaration in control_bootstrap.c so
that the result of a const cast could be put in a const field.
2020-07-16 12:55:06 -04:00
Nick Mathewson
b3eb409157 Define const variants for our channel_tls_t* casts. 2020-07-16 10:21:38 -04:00
Nick Mathewson
47a48e2f5a Define new CONST_TO_*_CONN() functions for const-to-const casts
These names are analogous to the CONST_TO_*_CIRC() functions we have
for circuits.

Part of #40046.
2020-07-16 10:08:15 -04:00
Nick Mathewson
b0d7b10088 Improve documentation for our TO_*_CONN() cast functions.
Preliminary work for #40046.
2020-07-16 09:57:52 -04:00
Nick Mathewson
10d8555e7d Add unit tests for connection_describe(). 2020-07-16 09:02:10 -04:00
Nick Mathewson
9b5567df4e Improvements to output format for OR connection descriptions.
Only log the 'real_addr' when it is set to something.

Only log the ID when it is set.

When scrubbing the address, don't include a canonical address.
(There should never be a canonical address for a connection with no
ID set.)
2020-07-16 09:02:10 -04:00
Nick Mathewson
ab428ef60b Collapse channel_get_*_remote_addr() into a single function.
Since we can list the real address and the canonical one in a
human-readable format we don't need to pick.
2020-07-16 09:02:10 -04:00
Nick Mathewson
4f4785a8c1 Refactor channel description internals.
Now that we've clarified that these functions only need to describe
the peer in a human-readable way, we can have them delegate to
connection_describe_peer().
2020-07-16 09:02:10 -04:00
Nick Mathewson
f9aafcd64e channelpadding: don't call method pointer directly. 2020-07-16 09:02:10 -04:00
Nick Mathewson
db21e91f4b Remove "ADDR_ONLY" mode from channel_get_*_remote_descr.
This mode was only used in one place, and it caused a dangerous
mingling of functionality.  The method is supposed to _describe_ the
peer's address, not give its actual address.  We already had a
function to get the actual address.
2020-07-16 09:02:10 -04:00
Nick Mathewson
0ccdf05dc5 Minor refactoring on channel_get_remote_addr_if_possible()
* We no longer call this an optional method
* We document that it returns the real address, not a canonical one.
* We have it try harder if the real address hasn't been set yet.
2020-07-16 09:02:10 -04:00
Nick Mathewson
382387882c Update test_rebind.py to expect new format. 2020-07-16 09:02:10 -04:00
Nick Mathewson
9d2867c396 Use connection_describe() for log messages. 2020-07-16 09:02:10 -04:00
Nick Mathewson
aa33b88778 connection_describe_peer(): add nonzero ports to nonscrubbed addrs. 2020-07-16 09:02:10 -04:00
Daniel Pinto
3c70f26dc0 Fix small memory leak in config include tests
Tests that used options_init_from_string were not freeing calling
config_free_all().
2020-07-15 22:01:08 +01:00
Daniel Pinto
49dab42782 Add test for torrc %include functionality and seccomp sandbox
Tests %include with files and folders, modifying and reloading
the config file with sandbox enabled and reponse of SAVECONF and
getinfo config-can-saveconf control commmands.
2020-07-15 22:01:08 +01:00
Daniel Pinto
34fa2c4d0d Add support for patterns on %include #25140
Also adds generic tor_glob function to expand globs.
2020-07-15 22:01:08 +01:00
Nick Mathewson
8fbafd1402 Apply SafeLogging in connection_describe_peer(). 2020-07-15 15:52:02 -04:00
Nick Mathewson
ba7816db5f New functions to describe connections and peers.
These will let us refactor away a lot of code that currently uses
"addr" and "address" for logging purposes.
2020-07-15 15:51:53 -04:00
Nick Mathewson
a7226ca06e Merge remote-tracking branch 'tor-gitlab/mr/50' 2020-07-14 14:50:30 -04:00
Alexander Færøy
623af0155e Update docstring for read_file_to_str() on stripping of CR characters.
See: https://bugs.torproject.org/tpo/core/tor/33781
2020-07-14 17:41:59 +00:00
Alexander Færøy
abe7196c53 Strip '\r' characters when reading text files on Unix.
This patch ensures that we strip "\r" characters on both Windows as well
as Unix when we read text files. This should prevent the issue where
some Tor state files have been moved from a Windows machine, and thus
contains CRLF line ending, to a Unix machine where only \n is needed.

We add a test-case to ensure that we handle this properly on all our
platforms.

See: https://bugs.torproject.org/tpo/core/tor/33781
2020-07-14 17:41:51 +00:00
Alexander Færøy
aba0ff4cb5 Merge remote-tracking branch 'tor-gitlab/merge-requests/48' 2020-07-14 16:07:36 +00:00
David Goulet
c53c0e82b4 Merge branch 'tor-gitlab/mr/49' 2020-07-14 11:35:05 -04:00
Nick Mathewson
2b33e8037e Merge branch 'ticket40033_045_01_squashed' 2020-07-14 10:59:30 -04:00
David Goulet
268d01ada5 Rename blacklist and whitelist wording
Closes #40033

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-14 10:59:18 -04:00
David Goulet
06ccf12258 node: Standardize interface of format_node_description()
Pass the IPv4 before the IPv6 like all our other interfaces.

Changes unreleased code related to #40043.

Closes #40045

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-14 10:49:43 -04:00
Alexander Færøy
1d554e4baf Merge branch 'maint-0.4.4' 2020-07-14 14:48:21 +00:00
Alexander Færøy
07f3345e11 Merge remote-tracking branch 'tor-gitlab/merge-requests/43' into maint-0.4.4 2020-07-14 14:47:48 +00:00
David Goulet
e594195aa2 Merge branch 'tor-gitlab/mr/47' 2020-07-14 10:36:30 -04:00
David Goulet
15860c8846 addr: Use tor_addr_t instead of uint32_t for IPv4
This changes a LOT of code but in the end, behavior is the same.
Unfortunately, many functions had to be changed to accomodate but in majority
of cases, to become simpler.

Functions are also removed specifically those that were there to convert an
IPv4 as a host format to a tor_addr_t. Those are not needed anymore.

The IPv4 address field has been standardized to "ipv4_addr", the ORPort to
"ipv4_orport" (currently IPv6 uses ipv6_orport) and DirPort to "ipv4_dirport".

This is related to Sponsor 55 work that adds IPv6 support for relays and this
work is needed in order to have a common interface between IPv4 and IPv6.

Closes #40043.

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-14 10:36:08 -04:00
David Goulet
852cf9b2e2 conn: Fix doxygen comment in connstats.c
Issue found by our CI:
https://travis-ci.org/github/torproject/tor/jobs/707731598#L6059

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-14 09:09:14 -04:00
David Goulet
456be93956 doc: Move manpages into doc/man/
Closes #40044

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-14 09:02:03 -04:00
Nick Mathewson
02cff32d79 Improve docs for addr, address, and real_addr fields
These fields have a complicated history, some slightly complicated
behavior, and some definitely inadequate documentation.  Before we
go fixing them up, let's document how they work now.
2020-07-13 12:13:41 -04:00
Nick Mathewson
ecb43ce21c Merge branch 'maint-0.4.4' 2020-07-13 10:45:04 -04:00
JeremyRand
0be80fb650 Bug 31812: Change http URL's to https 2020-07-13 10:42:46 -04:00
Nick Mathewson
59133051f9 Update channel_matches_target_addr_for_extend test to current API 2020-07-13 10:10:25 -04:00
MrSquanchee
c84ce716dc Added tests
Added tests for channel_matches_target_addr_for_extend().
Ticket #33919.
2020-07-13 09:46:11 -04:00
Nick Mathewson
8ebbf62940 Add an extra comment about keeping rust and c protover in sync. 2020-07-10 13:32:25 -04:00
Nick Mathewson
6a647be54a Merge remote-tracking branch 'tor-gitlab/mr/42' 2020-07-10 13:20:14 -04:00
Nick Mathewson
0c2bb9eac5 Merge remote-tracking branch 'tor-gitlab/mr/41' 2020-07-10 13:19:28 -04:00
Nick Mathewson
40eb6b19a3 NSS: Tell NSS that our SSL sockets are nonblocking.
Closes ticket 40035.
2020-07-10 13:14:33 -04:00
David Goulet
063cdb3142 Merge branch 'tor-gitlab/mr/39' 2020-07-10 13:12:22 -04:00
David Goulet
401b3a8a3c addr: Remove BUG() that always triggers
Fix on unreleased code.

Logical || in the BUG() made it that it would always trigger the BUG().

Fixes #40034

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-10 13:09:46 -04:00
David Goulet
46b86b22e3 addr: Remove a BUG() that can normally occur
Fix on unreleased code.

The relay_new_address_suggestion() is called when a NETINFO cell is received
thus not only for relay or bridges.

Remove the BUG() that made sure only in server mode we could handle the
suggested address.

Fixes #40032

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-10 13:06:20 -04:00
Nick Mathewson
6fb1637255 Merge remote-tracking branch 'tor-gitlab/mr/29' 2020-07-10 12:53:46 -04:00
Nick Mathewson
0f60a1d33c connstats: use correct formatter for uint32_t.
We have had no reports of negative counts here, so it is probably
safe not to backport this.
2020-07-10 09:50:04 -04:00
Nick Mathewson
dbdf8bebde Collect IPv6 bidi connection statistics 2020-07-10 09:47:55 -04:00
Nick Mathewson
54141d66e2 connstats: extract functions for summarizing a connection's status 2020-07-10 09:36:07 -04:00
Nick Mathewson
0b5e19d223 connstats: extract connection type counts into a structure. 2020-07-10 09:32:30 -04:00
Nick Mathewson
515cc49cb7 connstats: add and clarify some documentation. 2020-07-10 09:27:42 -04:00
Nick Mathewson
3f2de0bcca Change connstats.c identifers to start with conn_stats
This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        rep_hist_conn_stats_init conn_stats_init \
        rep_hist_note_or_conn_bytes conn_stats_note_or_conn_bytes \
        rep_hist_reset_conn_stats conn_stats_reset \
        rep_hist_format_conn_stats conn_stats_format \
        rep_hist_conn_stats_write conn_stats_save \
        rep_hist_conn_stats_term conn_stats_terminate \
        bidi_map_free_all conn_stats_free_all
2020-07-10 09:27:42 -04:00
Nick Mathewson
50bf2520b3 Split bidi connection-stats code into a new C file. 2020-07-10 09:27:42 -04:00
Nick Mathewson
27c5cadf7e Record IPv6 bandwidth history as appropriate. 2020-07-10 09:25:28 -04:00
Nick Mathewson
a81827d99f Make channel_get_addr_if_possible() take a const channel_t.
(There is no reason that looking up the address of a channel should
ever change it.)
2020-07-10 09:25:28 -04:00
Nick Mathewson
c5db7667d6 Add IPv6 read and write history to bwhist, state, and extrainfo.
These values are stored, persisted, and published.  They are not yet
actually filled with anything.
2020-07-10 09:25:28 -04:00
Nick Mathewson
11da5229d1 Refactor bwhist_get_bandwidth_lines()
We've done a lot to improve our internal APIs since we wrote this
code, and it shows. We can just use a buf_t to build up the
bandwidth lines, and save a bunch of stack fiddling.

Additionally, we can use a function to format a single line, and
thereby get rid of the cheezy pattern that does

    for (i=0;i<n;++i) {
        switch (i) {
           ...
        }
        ...
    }
2020-07-10 09:25:28 -04:00
Nick Mathewson
c5eb601e60 Rename private bandwidth-history identifiers to start with "bwhist".
This commit is a simple search-and-replace in bwhist.c
2020-07-10 07:56:21 -04:00
Nick Mathewson
2fc8257ac4 Rename public bandwidth-history identifiers to start with "bwhist".
This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        rep_hist_note_bytes_read bwhist_note_bytes_read \
        rep_hist_note_bytes_written bwhist_note_bytes_written \
        rep_hist_note_dir_bytes_read bwhist_note_dir_bytes_read \
        rep_hist_note_dir_bytes_written bwhist_note_dir_bytes_written \
        rep_hist_get_bandwidth_lines bwhist_get_bandwidth_lines \
        rep_hist_update_state bwhist_update_state \
        rep_hist_load_state bwhist_load_state \
        rep_hist_bandwidth_assess bwhist_bandwidth_assess
2020-07-10 07:54:04 -04:00
Nick Mathewson
8390df917b Split bandwidth history functions into a separate C file.
These are logically independent from the rest of rephist, and make
more sense in isolation.  The next patch will rename them too.
2020-07-10 07:50:17 -04:00
Nick Mathewson
7b24d56acc Merge remote-tracking branch 'tor-gitlab/mr/36' 2020-07-09 14:39:02 -04:00
Nick Mathewson
7207b4f2e4 Merge remote-tracking branch 'tor-gitlab/mr/21' 2020-07-09 14:30:15 -04:00
David Goulet
edb5ef2540 test: Add IPv6 inet_pton double "::" test
Unclear but that somehow failed on Windows once (?) according to ticket #33768
but we are not seeing that failure.

Nevertheless, add a simple unit test.

Closes #33768

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-09 13:39:56 -04:00
David Goulet
7bc54ccba9 addr: Static assert resolved address cache size
This will make sure that we always properly initialize the cache by the exact
size all the time.

Related to #40022

Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-09 13:33:52 -04:00
Nick Mathewson
20e2787352 Bump to 0.4.4.2-alpha-dev 2020-07-09 13:15:45 -04:00
Nick Mathewson
3517d20322 Bump to 0.4.3.6-dev 2020-07-09 13:15:15 -04:00
Nick Mathewson
49b4d1765c Bump to 0.4.2.8-dev 2020-07-09 13:14:48 -04:00
Nick Mathewson
c9751e2611 Bump to 0.3.5.11-dev 2020-07-09 13:12:45 -04:00
Nick Mathewson
3efd604743 Update version to 0.4.4.2-alpha. 2020-07-09 10:31:55 -04:00
Nick Mathewson
7ba849349a Update version to 0.4.3.6. 2020-07-09 10:31:09 -04:00
Nick Mathewson
5aaecf6d07 Update version to 0.4.2.8. 2020-07-09 10:30:37 -04:00
Nick Mathewson
0bb227d170 bump to 0.3.5.11 2020-07-09 10:28:21 -04:00
George Kadianakis
b1a32761be Merge branch 'maint-0.4.4' 2020-07-09 17:08:34 +03:00
George Kadianakis
e500ea2eae Merge branch 'tor-github/pr/1989' into maint-0.4.4 2020-07-09 17:08:07 +03:00
Nick Mathewson
be6b30e642 Merge branch 'maint-0.4.4' 2020-07-09 09:59:54 -04:00
Nick Mathewson
8dd89e4330 Merge remote-tracking branch 'dgoulet/ticket33796_044_01' into maint-0.4.4 2020-07-09 09:59:45 -04:00
Nick Mathewson
af08dad6d1 Merge branch 'maint-0.4.2' into maint-0.4.3 2020-07-09 09:28:53 -04:00
Nick Mathewson
283ce30c53 Merge branch 'maint-0.3.5' into maint-0.4.2 2020-07-09 09:28:53 -04:00