|
@@ -22,6 +22,7 @@ extern or_options_t options;
|
|
|
|
|
|
|
|
|
*/
|
|
|
+static tor_mutex_t *key_lock=NULL;
|
|
|
static time_t onionkey_set_at=0;
|
|
|
static crypto_pk_env_t *onionkey=NULL;
|
|
|
static crypto_pk_env_t *lastonionkey=NULL;
|
|
@@ -31,8 +32,10 @@ static crypto_pk_env_t *identitykey=NULL;
|
|
|
* to update onionkey correctly, call rotate_onion_key().
|
|
|
*/
|
|
|
void set_onion_key(crypto_pk_env_t *k) {
|
|
|
+ tor_mutex_acquire(key_lock);
|
|
|
onionkey = k;
|
|
|
onionkey_set_at = time(NULL);
|
|
|
+ tor_mutex_release(key_lock);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -50,6 +53,18 @@ crypto_pk_env_t *get_previous_onion_key(void) {
|
|
|
return lastonionkey;
|
|
|
}
|
|
|
|
|
|
+void dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
|
|
|
+{
|
|
|
+ tor_assert(key && last);
|
|
|
+ tor_mutex_acquire(key_lock);
|
|
|
+ *key = crypto_pk_dup_key(onionkey);
|
|
|
+ if (lastonionkey)
|
|
|
+ *last = crypto_pk_dup_key(lastonionkey);
|
|
|
+ else
|
|
|
+ *last = NULL;
|
|
|
+ tor_mutex_release(key_lock);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
* when the process launched, or the time of the most recent key rotation since
|
|
|
* the process launched.
|
|
@@ -96,13 +111,13 @@ void rotate_onion_key(void)
|
|
|
log(LOG_ERR, "Couldn't write generated key to %s.", fname);
|
|
|
goto error;
|
|
|
}
|
|
|
+ tor_mutex_acquire(key_lock);
|
|
|
if (lastonionkey)
|
|
|
crypto_free_pk_env(lastonionkey);
|
|
|
-
|
|
|
- */
|
|
|
log_fn(LOG_INFO, "Rotating onion key");
|
|
|
lastonionkey = onionkey;
|
|
|
set_onion_key(prkey);
|
|
|
+ tor_mutex_release(key_lock);
|
|
|
return;
|
|
|
error:
|
|
|
log_fn(LOG_WARN, "Couldn't rotate onion key.");
|
|
@@ -171,6 +186,9 @@ int init_keys(void) {
|
|
|
const char *tmp, *mydesc;
|
|
|
crypto_pk_env_t *prkey;
|
|
|
|
|
|
+ if (!key_lock)
|
|
|
+ key_lock = tor_mutex_new();
|
|
|
+
|
|
|
|
|
|
if (!options.ORPort) {
|
|
|
tor_assert(!options.DirPort);
|
|
@@ -418,7 +436,7 @@ int router_rebuild_descriptor(void) {
|
|
|
ri->socks_port = options.SocksPort;
|
|
|
ri->dir_port = options.DirPort;
|
|
|
ri->published_on = time(NULL);
|
|
|
- ri->onion_pkey = crypto_pk_dup_key(get_onion_key());
|
|
|
+ ri->onion_pkey = crypto_pk_dup_key(get_onion_key());
|
|
|
ri->identity_pkey = crypto_pk_dup_key(get_identity_key());
|
|
|
get_platform_str(platform, sizeof(platform));
|
|
|
ri->platform = tor_strdup(platform);
|