diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-12-13 20:22:34 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-01-30 08:37:22 -0500 |
commit | e2aeaeb76c2fd04a8b5934b7682823d77dc6f064 (patch) | |
tree | 3317493ff9a96506017bf4122cf2aaf55f57b120 /src/or | |
parent | 60769e710f1099168f7508fe6834e458ce435ad9 (diff) | |
download | tor-e2aeaeb76c2fd04a8b5934b7682823d77dc6f064.tar.gz tor-e2aeaeb76c2fd04a8b5934b7682823d77dc6f064.zip |
Make a bunch of signature/digest-checking functions mockable
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/routerkeys.c | 12 | ||||
-rw-r--r-- | src/or/routerkeys.h | 4 | ||||
-rw-r--r-- | src/or/routerparse.c | 19 | ||||
-rw-r--r-- | src/or/routerparse.h | 5 |
4 files changed, 27 insertions, 13 deletions
diff --git a/src/or/routerkeys.c b/src/or/routerkeys.c index 51802b15e5..6cc75edfa3 100644 --- a/src/or/routerkeys.c +++ b/src/or/routerkeys.c @@ -1207,12 +1207,12 @@ make_tap_onion_key_crosscert(const crypto_pk_t *onion_key, /** Check whether an RSA-TAP cross-certification is correct. Return 0 if it * is, -1 if it isn't. */ -int -check_tap_onion_key_crosscert(const uint8_t *crosscert, - int crosscert_len, - const crypto_pk_t *onion_pkey, - const ed25519_public_key_t *master_id_pkey, - const uint8_t *rsa_id_digest) +MOCK_IMPL(int, +check_tap_onion_key_crosscert,(const uint8_t *crosscert, + int crosscert_len, + const crypto_pk_t *onion_pkey, + const ed25519_public_key_t *master_id_pkey, + const uint8_t *rsa_id_digest)) { uint8_t *cc = tor_malloc(crypto_pk_keysize(onion_pkey)); int cc_len = diff --git a/src/or/routerkeys.h b/src/or/routerkeys.h index 98894cdc0b..d2027f4bbe 100644 --- a/src/or/routerkeys.h +++ b/src/or/routerkeys.h @@ -57,11 +57,11 @@ uint8_t *make_tap_onion_key_crosscert(const crypto_pk_t *onion_key, const crypto_pk_t *rsa_id_key, int *len_out); -int check_tap_onion_key_crosscert(const uint8_t *crosscert, +MOCK_DECL(int, check_tap_onion_key_crosscert,(const uint8_t *crosscert, int crosscert_len, const crypto_pk_t *onion_pkey, const ed25519_public_key_t *master_id_pkey, - const uint8_t *rsa_id_digest); + const uint8_t *rsa_id_digest)); int load_ed_keys(const or_options_t *options, time_t now); int should_make_new_ed_keys(const or_options_t *options, const time_t now); diff --git a/src/or/routerparse.c b/src/or/routerparse.c index d763a63d84..5fd2e0829c 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -863,8 +863,8 @@ dump_desc_populate_fifo_from_directory(const char *dirname) * type *<b>type</b> to file $DATADIR/unparseable-desc. Do not write more * than one descriptor to disk per minute. If there is already such a * file in the data directory, overwrite it. */ -STATIC void -dump_desc(const char *desc, const char *type) +MOCK_IMPL(STATIC void, +dump_desc,(const char *desc, const char *type)) { tor_assert(desc); tor_assert(type); @@ -4508,13 +4508,24 @@ router_get_hash_impl(const char *s, size_t s_len, char *digest, &start,&end)<0) return -1; + return router_compute_hash_final(digest, start, end-start, alg); +} + +/** Compute the digest of the <b>len</b>-byte directory object at + * <b>start</b>, using <b>alg</b>. Store the result in <b>digest</b>, which + * must be long enough to hold it. */ +MOCK_IMPL(STATIC int, +router_compute_hash_final,(char *digest, + const char *start, size_t len, + digest_algorithm_t alg)) +{ if (alg == DIGEST_SHA1) { - if (crypto_digest(digest, start, end-start) < 0) { + if (crypto_digest(digest, start, len) < 0) { log_warn(LD_BUG,"couldn't compute digest"); return -1; } } else { - if (crypto_digest256(digest, start, end-start, alg) < 0) { + if (crypto_digest256(digest, start, len, alg) < 0) { log_warn(LD_BUG,"couldn't compute digest"); return -1; } diff --git a/src/or/routerparse.h b/src/or/routerparse.h index 9a3fadca1f..a461d6794f 100644 --- a/src/or/routerparse.h +++ b/src/or/routerparse.h @@ -110,7 +110,6 @@ STATIC int routerstatus_parse_guardfraction(const char *guardfraction_str, MOCK_DECL(STATIC dumped_desc_t *, dump_desc_populate_one_file, (const char *dirname, const char *f)); STATIC void dump_desc_populate_fifo_from_directory(const char *dirname); -STATIC void dump_desc(const char *desc, const char *type); STATIC void dump_desc_fifo_cleanup(void); struct memarea_t; STATIC routerstatus_t *routerstatus_parse_entry_from_string( @@ -120,6 +119,10 @@ STATIC routerstatus_t *routerstatus_parse_entry_from_string( vote_routerstatus_t *vote_rs, int consensus_method, consensus_flavor_t flav); +MOCK_DECL(STATIC void,dump_desc,(const char *desc, const char *type)); +MOCK_DECL(STATIC int, router_compute_hash_final,(char *digest, + const char *start, size_t len, + digest_algorithm_t alg)); #endif #define ED_DESC_SIGNATURE_PREFIX "Tor router descriptor signature v1" |