diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-12-03 13:37:13 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-12-03 13:37:13 -0500 |
commit | c0f1517d87d0c858ba8472eb85fd31df73f4b4d1 (patch) | |
tree | 9495237315e5f0bc8d3efabab8e4f0aaa7a71ef5 /src | |
parent | ee8f451bf1a8a0d01bb990ddf96f810a254394eb (diff) | |
download | tor-c0f1517d87d0c858ba8472eb85fd31df73f4b4d1.tar.gz tor-c0f1517d87d0c858ba8472eb85fd31df73f4b4d1.zip |
Don't crash when accountingmax is set in non-server Tors
We use a hash of the identity key to seed a prng to tell when an
accounting period should end. But thanks to the bug998 changes,
clients no longer have server-identity keys to use as a long-term seed
in accounting calculations. In any case, their identity keys (as used
in TLS) were never never fixed. So we can just set the wakeup time
from a random seed instead there. Still open is whether everybody
should be random.
This patch fixes bug 2235, which was introduced in 0.2.2.18-alpha.
Diagnosed with help from boboper on irc.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/hibernate.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/or/hibernate.c b/src/or/hibernate.c index e9be5930d1..356f9a0f55 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -529,14 +529,19 @@ accounting_set_wakeup_time(void) } } - format_iso_time(buf, interval_start_time); - crypto_pk_get_digest(get_server_identity_key(), digest); - - d_env = crypto_new_digest_env(); - crypto_digest_add_bytes(d_env, buf, ISO_TIME_LEN); - crypto_digest_add_bytes(d_env, digest, DIGEST_LEN); - crypto_digest_get_digest(d_env, digest, DIGEST_LEN); - crypto_free_digest_env(d_env); + if (server_identity_key_is_set()) { + format_iso_time(buf, interval_start_time); + + crypto_pk_get_digest(get_server_identity_key(), digest); + + d_env = crypto_new_digest_env(); + crypto_digest_add_bytes(d_env, buf, ISO_TIME_LEN); + crypto_digest_add_bytes(d_env, digest, DIGEST_LEN); + crypto_digest_get_digest(d_env, digest, DIGEST_LEN); + crypto_free_digest_env(d_env); + } else { + crypto_rand(digest, DIGEST_LEN); + } if (!expected_bandwidth_usage) { char buf1[ISO_TIME_LEN+1]; |