|
@@ -148,6 +148,51 @@ dup_onion_keys(crypto_pk_t **key, crypto_pk_t **last)
|
|
|
tor_mutex_release(key_lock);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * last_curve25519_onion_key and lastonionkey to all zero's and NULL
|
|
|
+ * respectively.
|
|
|
+ *
|
|
|
+ * This function does not perform any grace period checks for the old onion
|
|
|
+ * keys.
|
|
|
+ */
|
|
|
+void
|
|
|
+expire_old_onion_keys(void)
|
|
|
+{
|
|
|
+ char *fname = NULL;
|
|
|
+
|
|
|
+ tor_mutex_acquire(key_lock);
|
|
|
+
|
|
|
+
|
|
|
+ if (lastonionkey) {
|
|
|
+ crypto_pk_free(lastonionkey);
|
|
|
+ lastonionkey = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * construct_ntor_key_map() below. */
|
|
|
+ memset(&last_curve25519_onion_key, 0, sizeof(last_curve25519_onion_key));
|
|
|
+
|
|
|
+ tor_mutex_release(key_lock);
|
|
|
+
|
|
|
+ fname = get_datadir_fname2("keys", "secret_onion_key.old");
|
|
|
+ if (file_status(fname) == FN_FILE) {
|
|
|
+ if (tor_unlink(fname) != 0) {
|
|
|
+ log_warn(LD_FS, "Couldn't unlink old onion key file %s: %s",
|
|
|
+ fname, strerror(errno));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tor_free(fname);
|
|
|
+
|
|
|
+ fname = get_datadir_fname2("keys", "secret_onion_key_ntor.old");
|
|
|
+ if (file_status(fname) == FN_FILE) {
|
|
|
+ if (tor_unlink(fname) != 0) {
|
|
|
+ log_warn(LD_FS, "Couldn't unlink old ntor onion key file %s: %s",
|
|
|
+ fname, strerror(errno));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tor_free(fname);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
* be called from the main thread. */
|
|
|
static const curve25519_keypair_t *
|
|
@@ -683,6 +728,47 @@ v3_authority_check_key_expiry(void)
|
|
|
last_warned = now;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * network consesus parameter "onion-key-rotation-days". Always returns a value
|
|
|
+ * between <b>MIN_ONION_KEY_LIFETIME_DAYS</b> and
|
|
|
+ * <b>MAX_ONION_KEY_LIFETIME_DAYS</b>.
|
|
|
+ */
|
|
|
+static int
|
|
|
+get_onion_key_rotation_days_(void)
|
|
|
+{
|
|
|
+ return networkstatus_get_param(NULL,
|
|
|
+ "onion-key-rotation-days",
|
|
|
+ DEFAULT_ONION_KEY_LIFETIME_DAYS,
|
|
|
+ MIN_ONION_KEY_LIFETIME_DAYS,
|
|
|
+ MAX_ONION_KEY_LIFETIME_DAYS);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * by the network consesus parameter "onion-key-rotation-days", but the value
|
|
|
+ * is converted to seconds.
|
|
|
+ */
|
|
|
+int
|
|
|
+get_onion_key_lifetime(void)
|
|
|
+{
|
|
|
+ return get_onion_key_rotation_days_()*24*60*60;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * the network consesus parameter "onion-key-grace-period-days", but the value
|
|
|
+ * is converted to seconds.
|
|
|
+ */
|
|
|
+int
|
|
|
+get_onion_key_grace_period(void)
|
|
|
+{
|
|
|
+ int grace_period;
|
|
|
+ grace_period = networkstatus_get_param(NULL,
|
|
|
+ "onion-key-grace-period-days",
|
|
|
+ DEFAULT_ONION_KEY_GRACE_PERIOD_DAYS,
|
|
|
+ MIN_ONION_KEY_GRACE_PERIOD_DAYS,
|
|
|
+ get_onion_key_rotation_days_());
|
|
|
+ return grace_period*24*60*60;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
* on success, and -1 on failure. */
|
|
|
int
|
|
@@ -928,7 +1014,7 @@ init_keys(void)
|
|
|
|
|
|
* or it's a holdover from 0.1.2.4-alpha-dev or earlier. In either case,
|
|
|
* start the clock ticking now so that we will eventually rotate it even
|
|
|
- * if we don't stay up for a full MIN_ONION_KEY_LIFETIME. */
|
|
|
+ * if we don't stay up for the full lifetime of an onion key. */
|
|
|
state->LastRotatedOnionKey = onionkey_set_at = now;
|
|
|
or_state_mark_dirty(state, options->AvoidDiskWrites ?
|
|
|
time(NULL)+3600 : 0);
|
|
@@ -2760,7 +2846,7 @@ router_dump_router_to_string(routerinfo_t *router,
|
|
|
make_ntor_onion_key_crosscert(ntor_keypair,
|
|
|
&router->cache_info.signing_key_cert->signing_key,
|
|
|
router->cache_info.published_on,
|
|
|
- MIN_ONION_KEY_LIFETIME, &sign);
|
|
|
+ get_onion_key_lifetime(), &sign);
|
|
|
if (!cert) {
|
|
|
log_warn(LD_BUG,"make_ntor_onion_key_crosscert failed!");
|
|
|
goto err;
|