aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-10-21 13:54:12 -0400
committerSebastian Hahn <sebastian@torproject.org>2011-10-26 14:16:54 +0200
commitdc557e8164003d6c09b620333902d7dae3762794 (patch)
tree377ca5140491ebe56d6ed04401e718c9069e8a27
parent2a2301e41117ad8439dbe8039085202fa0d6f6ed (diff)
downloadtor-dc557e8164003d6c09b620333902d7dae3762794.tar
tor-dc557e8164003d6c09b620333902d7dae3762794.tar.gz
Add some asserts to get_{tlsclient|server}_identity_key
We now require that: - Only actual servers should ever call get_server_identity_key - If you're being a client or bridge, the client and server keys should differ. - If you're being a public relay, the client and server keys should be the same.
-rw-r--r--src/or/router.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/or/router.c b/src/or/router.c
index f7a50ae88..96aca8837 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -121,13 +121,32 @@ set_server_identity_key(crypto_pk_env_t *k)
crypto_pk_get_digest(server_identitykey, server_identitykey_digest);
}
+/** Make sure that we have set up our identity keys to match or not match as
+ * appropriate, and die with an assertion if we have not. */
+static void
+assert_identity_keys_ok(void)
+{
+ tor_assert(client_identitykey);
+ if (public_server_mode(get_options())) {
+ /* assert that we have set the client and server keys to be equal */
+ tor_assert(server_identitykey);
+ tor_assert(0==crypto_pk_cmp_keys(client_identitykey, server_identitykey));
+ } else {
+ /* assert that we have set the client and server keys to be unequal */
+ if (server_identitykey)
+ tor_assert(0!=crypto_pk_cmp_keys(client_identitykey, server_identitykey));
+ }
+}
+
/** Returns the current server identity key; requires that the key has
- * been set.
+ * been set, and that we are running as a Tor server.
*/
crypto_pk_env_t *
get_server_identity_key(void)
{
tor_assert(server_identitykey);
+ tor_assert(server_mode(get_options()));
+ assert_identity_keys_ok();
return server_identitykey;
}
@@ -155,6 +174,7 @@ crypto_pk_env_t *
get_tlsclient_identity_key(void)
{
tor_assert(client_identitykey);
+ assert_identity_keys_ok();
return client_identitykey;
}