From 04b0263974c7ad1327e7a193884cf31d55f7949a Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 11 Jan 2021 16:01:22 -0500 Subject: hs-v3: Require reasonably live consensus Some days before this commit, the network experienced a DDoS on the directory authorities that prevented them to generate a consensus for more than 5 hours straight. That in turn entirely disabled onion service v3, client and service side, due to the subsystem requiring a live consensus to function properly. We know require a reasonably live consensus which means that the HSv3 subsystem will to its job for using the best consensus tor can find. If the entire network is using an old consensus, than this should be alright. If the service happens to use a live consensus while a client is not, it should still work because the client will use the current SRV it sees which might be the previous SRV for the service for which it still publish descriptors for. If the service is using an old one and somehow can't get a new one while clients are on a new one, then reachability issues might arise. However, this is a situation we already have at the moment since the service will simply not work if it doesn't have a live consensus while a client has one. Fixes #40237 Signed-off-by: David Goulet --- src/test/test_hs_client.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/test/test_hs_client.c') diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c index 2f2bb45581..53ee3c53d2 100644 --- a/src/test/test_hs_client.c +++ b/src/test/test_hs_client.c @@ -62,16 +62,18 @@ static networkstatus_t mock_ns; /* Always return NULL. */ static networkstatus_t * -mock_networkstatus_get_live_consensus_false(time_t now) +mock_networkstatus_get_reasonably_live_consensus_false(time_t now, int flavor) { (void) now; + (void) flavor; return NULL; } static networkstatus_t * -mock_networkstatus_get_live_consensus(time_t now) +mock_networkstatus_get_reasonably_live_consensus(time_t now, int flavor) { (void) now; + (void) flavor; return &mock_ns; } @@ -340,8 +342,8 @@ test_client_pick_intro(void *arg) ed25519_keypair_t service_kp; hs_descriptor_t *desc = NULL; - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); (void) arg; @@ -565,15 +567,15 @@ test_descriptor_fetch(void *arg) get_options_mutable()->FetchHidServDescriptors = 1; /* 2. We don't have a live consensus. */ - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus_false); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus_false); ret = hs_client_refetch_hsdesc(&service_pk); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); tt_int_op(ret, OP_EQ, HS_CLIENT_FETCH_MISSING_INFO); /* From now on, return a live consensus. */ - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); /* 3. Not enough dir information. */ MOCK(router_have_minimum_dir_info, @@ -615,7 +617,7 @@ test_descriptor_fetch(void *arg) done: connection_free_minimal(ENTRY_TO_CONN(ec)); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); UNMOCK(router_have_minimum_dir_info); hs_free_all(); } @@ -808,8 +810,8 @@ test_desc_has_arrived_cleanup(void *arg) hs_init(); - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); MOCK(connection_mark_unattached_ap_, mock_connection_mark_unattached_ap_); MOCK(router_have_minimum_dir_info, @@ -880,7 +882,7 @@ test_desc_has_arrived_cleanup(void *arg) tor_free(desc_str); hs_free_all(); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); UNMOCK(connection_mark_unattached_ap_); UNMOCK(router_have_minimum_dir_info); } @@ -900,8 +902,8 @@ test_close_intro_circuits_new_desc(void *arg) /* This is needed because of the client cache expiration timestamp is based * on having a consensus. See cached_client_descriptor_has_expired(). */ - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); /* Set consensus time */ parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", @@ -968,7 +970,7 @@ test_close_intro_circuits_new_desc(void *arg) tt_int_op(ret, OP_EQ, 0); tt_assert(encoded); - hs_cache_store_as_client(encoded, &service_kp.pubkey); + ret = hs_cache_store_as_client(encoded, &service_kp.pubkey); tt_int_op(ret, OP_EQ, 0); tor_free(encoded); tt_assert(hs_cache_lookup_as_client(&service_kp.pubkey)); @@ -983,7 +985,7 @@ test_close_intro_circuits_new_desc(void *arg) hs_descriptor_free(desc1); hs_descriptor_free(desc2); hs_free_all(); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); } struct testcase_t hs_client_tests[] = { -- cgit v1.2.3-54-g00ecf From 0485c7ddba8c3474d1be8972caa9505b09d65644 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 12 Jan 2021 10:50:01 -0500 Subject: tests: Fix unit tests after merge of #40237 --- src/test/test_hs_cache.c | 12 ++++++------ src/test/test_hs_client.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/test/test_hs_client.c') diff --git a/src/test/test_hs_cache.c b/src/test/test_hs_cache.c index e3be0e77ec..a1df2b0eea 100644 --- a/src/test/test_hs_cache.c +++ b/src/test/test_hs_cache.c @@ -587,8 +587,8 @@ test_client_cache_decrypt(void *arg) /* Initialize HSDir cache subsystem */ hs_init(); - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); /* Set consensus time */ parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", @@ -643,7 +643,7 @@ test_client_cache_decrypt(void *arg) hs_free_all(); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); } static void @@ -657,8 +657,8 @@ test_client_cache_remove(void *arg) hs_init(); - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); /* Set consensus time. Lookup will not return the entry if it has expired * and it is checked against the consensus valid_after time. */ @@ -696,7 +696,7 @@ test_client_cache_remove(void *arg) hs_descriptor_free(desc1); hs_free_all(); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); } struct testcase_t hs_cache[] = { diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c index 32a79a7f49..e797fdedd0 100644 --- a/src/test/test_hs_client.c +++ b/src/test/test_hs_client.c @@ -1121,8 +1121,8 @@ test_close_intro_circuits_cache_clean(void *arg) /* This is needed because of the client cache expiration timestamp is based * on having a consensus. See cached_client_descriptor_has_expired(). */ - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); /* Set consensus time */ parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", @@ -1187,7 +1187,7 @@ test_close_intro_circuits_cache_clean(void *arg) hs_descriptor_free(desc1); hs_free_all(); rend_cache_free_all(); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); } static void @@ -1204,8 +1204,8 @@ test_socks_hs_errors(void *arg) (void) arg; - MOCK(networkstatus_get_live_consensus, - mock_networkstatus_get_live_consensus); + MOCK(networkstatus_get_reasonably_live_consensus, + mock_networkstatus_get_reasonably_live_consensus); MOCK(connection_mark_unattached_ap_, mock_connection_mark_unattached_ap_no_close); MOCK(read_file_to_str, mock_read_file_to_str); @@ -1285,7 +1285,7 @@ test_socks_hs_errors(void *arg) hs_free_all(); - UNMOCK(networkstatus_get_live_consensus); + UNMOCK(networkstatus_get_reasonably_live_consensus); UNMOCK(connection_mark_unattached_ap_); UNMOCK(read_file_to_str); UNMOCK(tor_listdir); -- cgit v1.2.3-54-g00ecf