diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-05-03 12:56:16 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-05-04 08:36:50 -0400 |
commit | 3af9704e459fab0120694a46924b27460237cb1a (patch) | |
tree | 89d449afa226b26e4304973e02411e4b23553967 /src/test/test_consdiffmgr.c | |
parent | c8baa9b78362e372cfb5e2d3fcc6100d20d00229 (diff) | |
download | tor-3af9704e459fab0120694a46924b27460237cb1a.tar.gz tor-3af9704e459fab0120694a46924b27460237cb1a.zip |
bug#22143/prop#140: in consdiffmgr, store and use digest-as-signed
We need to index diffs by the digest-as-signed of their source
consensus, so that we can find them even from consensuses whose
signatures are encoded differently.
Diffstat (limited to 'src/test/test_consdiffmgr.c')
-rw-r--r-- | src/test/test_consdiffmgr.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c index 31ce6ce901..0e44ed2ba2 100644 --- a/src/test/test_consdiffmgr.c +++ b/src/test/test_consdiffmgr.c @@ -10,6 +10,7 @@ #include "consdiffmgr.h" #include "cpuworker.h" #include "networkstatus.h" +#include "routerparse.h" #include "workqueue.h" #include "test.h" @@ -66,6 +67,7 @@ fake_ns_body_new(consensus_flavor_t flav, time_t valid_after) format_iso_time(valid_after_string, valid_after); char *random_stuff = crypto_random_hostname(3, 25, "junk ", ""); + char *random_stuff2 = crypto_random_hostname(3, 10, "", ""); char *consensus; tor_asprintf(&consensus, @@ -74,11 +76,15 @@ fake_ns_body_new(consensus_flavor_t flav, time_t valid_after) "valid-after %s\n" "r name ccccccccccccccccc etc\nsample\n" "r name eeeeeeeeeeeeeeeee etc\nbar\n" - "%s\n", + "%s\n" + "directory-signature hello-there\n" + "directory-signature %s\n", flavor_string, valid_after_string, - random_stuff); + random_stuff, + random_stuff2); tor_free(random_stuff); + tor_free(random_stuff2); return consensus; } @@ -139,7 +145,10 @@ lookup_diff_from(consensus_cache_entry_t **out, const char *str1) { uint8_t digest[DIGEST256_LEN]; - crypto_digest256((char*)digest, str1, strlen(str1), DIGEST_SHA3_256); + if (router_get_networkstatus_v3_sha3_as_signed(digest, str1)<0) { + TT_FAIL(("Unable to compute sha3-as-signed")); + return CONSDIFF_NOT_FOUND; + } return consdiffmgr_find_diff_from(out, flav, DIGEST_SHA3_256, digest, sizeof(digest), NO_METHOD); @@ -152,8 +161,9 @@ lookup_apply_and_verify_diff(consensus_flavor_t flav, { consensus_cache_entry_t *ent = NULL; consdiff_status_t status = lookup_diff_from(&ent, flav, str1); - if (ent == NULL || status != CONSDIFF_AVAILABLE) + if (ent == NULL || status != CONSDIFF_AVAILABLE) { return -1; + } consensus_cache_entry_incref(ent); size_t size; @@ -299,7 +309,7 @@ test_consdiffmgr_add(void *arg) ns_tmp->valid_after = 86400 * 100; /* A few months into 1970 */ r = consdiffmgr_add_consensus(dummy, ns_tmp); tt_int_op(r, OP_EQ, -1); - expect_single_log_msg_containing("it's too old."); + expect_log_msg_containing("it's too old."); /* Try looking up a consensuses. */ ent = cdm_cache_lookup_consensus(FLAV_NS, now-60); @@ -352,8 +362,7 @@ test_consdiffmgr_make_diffs(void *arg) ns = fake_ns_new(FLAV_MICRODESC, now-3600); md_ns_body = fake_ns_body_new(FLAV_MICRODESC, now-3600); r = consdiffmgr_add_consensus(md_ns_body, ns); - crypto_digest256((char*)md_ns_sha3, md_ns_body, strlen(md_ns_body), - DIGEST_SHA3_256); + router_get_networkstatus_v3_sha3_as_signed(md_ns_sha3, md_ns_body); networkstatus_vote_free(ns); tt_int_op(r, OP_EQ, 0); |