diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-02-22 12:53:45 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-04-18 11:04:57 -0400 |
commit | cb75519bbf6d89ddaf6a6bb40a01a2dba09ad530 (patch) | |
tree | 1ae075833875a1e5be8e5fded4c2bdbe02f5db99 /src/or/dirserv.c | |
parent | fd93622cc897ede9c52205390bfb71e2e8588259 (diff) | |
download | tor-cb75519bbf6d89ddaf6a6bb40a01a2dba09ad530.tar.gz tor-cb75519bbf6d89ddaf6a6bb40a01a2dba09ad530.zip |
Refactor dirobj signature generation
Now we can compute the hash and signature of a dirobj before
concatenating the smartlist, and we don't need to play silly games
with sigbuf and realloc any more.
Diffstat (limited to 'src/or/dirserv.c')
-rw-r--r-- | src/or/dirserv.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index d5b90b936a..2bbfc9a7c6 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -2911,7 +2911,6 @@ generate_v2_networkstatus_opinion(void) size_t identity_pkey_len; char *status = NULL, *client_versions = NULL, *server_versions = NULL, *identity_pkey = NULL, *hostname = NULL; - size_t status_len; const or_options_t *options = get_options(); char fingerprint[FINGERPRINT_LEN+1]; char published[ISO_TIME_LEN+1]; @@ -3032,23 +3031,21 @@ generate_v2_networkstatus_opinion(void) smartlist_add_asprintf(chunks, "directory-signature %s\n", options->Nickname); - status = smartlist_join_strings(chunks, "", 0, NULL); -#define MAX_V2_OPINION_SIGNATURE_LEN 4096 - status_len = strlen(status) + MAX_V2_OPINION_SIGNATURE_LEN + 1; - status = tor_realloc(status, status_len); - - if (router_get_networkstatus_v2_hash(status, digest)<0) { - log_warn(LD_BUG, "Unable to hash network status"); - goto done; - } + crypto_digest_smartlist(digest, DIGEST_LEN, chunks, "", DIGEST_SHA1); note_crypto_pk_op(SIGN_DIR); - if (router_append_dirobj_signature(status, status_len,digest,DIGEST_LEN, - private_key)<0) { - log_warn(LD_BUG, "Unable to sign router status."); - goto done; + { + char *sig; + if (!(sig = router_get_dirobj_signature(digest,DIGEST_LEN, + private_key))) { + log_warn(LD_BUG, "Unable to sign router status."); + goto done; + } + smartlist_add(chunks, sig); } + status = smartlist_join_strings(chunks, "", 0, NULL); + { networkstatus_v2_t *ns; if (!(ns = networkstatus_v2_parse_from_string(status))) { |