diff options
author | David Goulet <dgoulet@torproject.org> | 2020-02-04 09:25:55 -0500 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2020-02-06 12:54:54 +0200 |
commit | 9278a24729c92b9f5c670b3e1608e2cdbd8bd9a1 (patch) | |
tree | f91a28a47f591f21eed12563cd5288cd5e75fb11 /src/test/test_hs_cache.c | |
parent | 2c4d7d8c65b3783fa9213cc632d398d0d1b6ef5c (diff) | |
download | tor-9278a24729c92b9f5c670b3e1608e2cdbd8bd9a1.tar.gz tor-9278a24729c92b9f5c670b3e1608e2cdbd8bd9a1.zip |
hs-v3: Remove descriptor when we remove client authorization
When the ONION_CLIENT_AUTH_REMOVE command is given to tor, now also remove the
descriptor associated with the client authorization credentials.
Fixes #33148
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_hs_cache.c')
-rw-r--r-- | src/test/test_hs_cache.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/test_hs_cache.c b/src/test/test_hs_cache.c index 9e0094d250..8ea550b65f 100644 --- a/src/test/test_hs_cache.c +++ b/src/test/test_hs_cache.c @@ -645,6 +645,59 @@ test_client_cache_decrypt(void *arg) UNMOCK(networkstatus_get_live_consensus); } +static void +test_client_cache_remove(void *arg) +{ + int ret; + ed25519_keypair_t service_kp; + hs_descriptor_t *desc1 = NULL; + + (void) arg; + + hs_init(); + + MOCK(networkstatus_get_live_consensus, + mock_networkstatus_get_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. */ + parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", + &mock_ns.valid_after); + parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC", + &mock_ns.fresh_until); + parse_rfc1123_time("Sat, 26 Oct 1985 16:00:00 UTC", + &mock_ns.valid_until); + + /* Generate service keypair */ + tt_int_op(0, OP_EQ, ed25519_keypair_generate(&service_kp, 0)); + + /* Build a descriptor and cache it. */ + { + char *encoded; + desc1 = hs_helper_build_hs_desc_with_ip(&service_kp); + tt_assert(desc1); + ret = hs_desc_encode_descriptor(desc1, &service_kp, NULL, &encoded); + tt_int_op(ret, OP_EQ, 0); + tt_assert(encoded); + + /* Store it */ + ret = hs_cache_store_as_client(encoded, &service_kp.pubkey); + tt_int_op(ret, OP_EQ, HS_DESC_DECODE_OK); + tor_free(encoded); + tt_assert(hs_cache_lookup_as_client(&service_kp.pubkey)); + } + + /* Remove the cached entry. */ + hs_cache_remove_as_client(&service_kp.pubkey); + tt_assert(!hs_cache_lookup_as_client(&service_kp.pubkey)); + + done: + hs_descriptor_free(desc1); + hs_free_all(); + + UNMOCK(networkstatus_get_live_consensus); +} + struct testcase_t hs_cache[] = { /* Encoding tests. */ { "directory", test_directory, TT_FORK, @@ -659,6 +712,8 @@ struct testcase_t hs_cache[] = { NULL, NULL }, { "client_cache_decrypt", test_client_cache_decrypt, TT_FORK, NULL, NULL }, + { "client_cache_remove", test_client_cache_remove, TT_FORK, + NULL, NULL }, END_OF_TESTCASES }; |