mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Store the sha3 of a networkstatus as part of the networkstatus_t
Also store it in the cached_dir_t.
This commit is contained in:
@@ -1212,6 +1212,8 @@ void
|
||||
dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
|
||||
const char *flavor_name,
|
||||
const common_digests_t *digests,
|
||||
// XXXX rename after 22143
|
||||
const uint8_t *sha3_full_digest,
|
||||
time_t published)
|
||||
{
|
||||
cached_dir_t *new_networkstatus;
|
||||
@@ -1221,6 +1223,8 @@ dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
|
||||
|
||||
new_networkstatus = new_cached_dir(tor_strdup(networkstatus), published);
|
||||
memcpy(&new_networkstatus->digests, digests, sizeof(common_digests_t));
|
||||
memcpy(&new_networkstatus->digest_sha3_full, sha3_full_digest,
|
||||
DIGEST256_LEN);
|
||||
old_networkstatus = strmap_set(cached_consensuses, flavor_name,
|
||||
new_networkstatus);
|
||||
if (old_networkstatus)
|
||||
|
||||
@@ -118,6 +118,7 @@ cached_dir_t *dirserv_get_consensus(const char *flavor_name);
|
||||
void dirserv_set_cached_consensus_networkstatus(const char *consensus,
|
||||
const char *flavor_name,
|
||||
const common_digests_t *digests,
|
||||
const uint8_t *sha3_as_signed,
|
||||
time_t published);
|
||||
void dirserv_clear_old_networkstatuses(time_t cutoff);
|
||||
int dirserv_get_routerdesc_spool(smartlist_t *spools_out, const char *key,
|
||||
|
||||
@@ -1981,6 +1981,7 @@ networkstatus_set_current_consensus(const char *consensus,
|
||||
dirserv_set_cached_consensus_networkstatus(consensus,
|
||||
flavor,
|
||||
&c->digests,
|
||||
c->digest_full_sha3,
|
||||
c->valid_after);
|
||||
if (server_mode(get_options())) {
|
||||
consdiffmgr_add_consensus(consensus, c);
|
||||
|
||||
@@ -1938,6 +1938,7 @@ typedef struct cached_dir_t {
|
||||
size_t dir_z_len; /**< Length of <b>dir_z</b>. */
|
||||
time_t published; /**< When was this object published. */
|
||||
common_digests_t digests; /**< Digests of this object (networkstatus only) */
|
||||
uint8_t digest_sha3_full[DIGEST256_LEN]; /**< sha3 digest (also ns only) */
|
||||
int refcnt; /**< Reference count for this cached_dir_t. */
|
||||
} cached_dir_t;
|
||||
|
||||
@@ -2638,6 +2639,9 @@ typedef struct networkstatus_t {
|
||||
|
||||
/** Digests of this document, as signed. */
|
||||
common_digests_t digests;
|
||||
/** A SHA3-256 digest of the document, including signatures: used for
|
||||
* consensus diffs */
|
||||
uint8_t digest_full_sha3[DIGEST256_LEN];
|
||||
|
||||
/** List of router statuses, sorted by identity digest. For a vote,
|
||||
* the elements are vote_routerstatus_t; for a consensus, the elements
|
||||
|
||||
@@ -3384,6 +3384,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
networkstatus_voter_info_t *voter = NULL;
|
||||
networkstatus_t *ns = NULL;
|
||||
common_digests_t ns_digests;
|
||||
uint8_t sha3_full[DIGEST256_LEN];
|
||||
const char *cert, *end_of_header, *end_of_footer, *s_dup = s;
|
||||
directory_token_t *tok;
|
||||
struct in_addr in;
|
||||
@@ -3397,7 +3398,10 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
if (eos_out)
|
||||
*eos_out = NULL;
|
||||
|
||||
if (router_get_networkstatus_v3_hashes(s, &ns_digests)) {
|
||||
// XXXX replace SHA3_full with as_signed digest once #22143 is merged.
|
||||
// XXXX Merge #22143 before this!
|
||||
if (router_get_networkstatus_v3_hashes(s, &ns_digests) ||
|
||||
crypto_digest256((char *)sha3_full, s, strlen(s), DIGEST_SHA3_256)<0) {
|
||||
log_warn(LD_DIR, "Unable to compute digest of network-status");
|
||||
goto err;
|
||||
}
|
||||
@@ -3414,6 +3418,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
|
||||
ns = tor_malloc_zero(sizeof(networkstatus_t));
|
||||
memcpy(&ns->digests, &ns_digests, sizeof(ns_digests));
|
||||
memcpy(&ns->digest_full_sha3, sha3_full, sizeof(sha3_full));
|
||||
|
||||
tok = find_by_keyword(tokens, K_NETWORK_STATUS_VERSION);
|
||||
tor_assert(tok);
|
||||
|
||||
@@ -1773,10 +1773,14 @@ status_vote_current_consensus_ns_test(char **header, char **body,
|
||||
size_t *body_len)
|
||||
{
|
||||
common_digests_t digests;
|
||||
uint8_t sha3[DIGEST256_LEN];
|
||||
dir_connection_t *conn = NULL;
|
||||
|
||||
#define NETWORK_STATUS "some network status string"
|
||||
memset(&digests, 0x60, sizeof(digests));
|
||||
memset(sha3, 0x06, sizeof(sha3));
|
||||
dirserv_set_cached_consensus_networkstatus(NETWORK_STATUS, "ns", &digests,
|
||||
sha3,
|
||||
time(NULL));
|
||||
|
||||
MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
||||
|
||||
Reference in New Issue
Block a user