From 688e8e9bb9d00c4383aab58d7b947c6f3205fb65 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 18 Apr 2004 03:20:30 +0000 Subject: [PATCH] {flagday} actually rotate onion keys. svn:r1662 --- branches/tor-0_0_6incompat/src/or/config.c | 4 ++++ branches/tor-0_0_6incompat/src/or/main.c | 18 +++++++++++++++++- branches/tor-0_0_6incompat/src/or/or.h | 3 +++ branches/tor-0_0_6incompat/src/or/router.c | 8 +++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/branches/tor-0_0_6incompat/src/or/config.c b/branches/tor-0_0_6incompat/src/or/config.c index 93adb5437e..824e5643cb 100644 --- a/branches/tor-0_0_6incompat/src/or/config.c +++ b/branches/tor-0_0_6incompat/src/or/config.c @@ -655,6 +655,10 @@ int getconfig(int argc, char **argv, or_options_t *options) { log(LOG_WARN,"DirFetchPostPeriod option must be positive."); result = -1; } + if(options->DirFetchPostPeriod > MIN_ONION_KEY_LIFETIME/2) { + log(LOG_WARN,"DirFetchPostPeriod is too large; clipping."); + options->DirFetchPostPeriod = MIN_ONION_KEY_LIFETIME/2; + } if(options->KeepalivePeriod < 1) { log(LOG_WARN,"KeepalivePeriod option must be positive."); diff --git a/branches/tor-0_0_6incompat/src/or/main.c b/branches/tor-0_0_6incompat/src/or/main.c index 6c508cd611..8254e85271 100644 --- a/branches/tor-0_0_6incompat/src/or/main.c +++ b/branches/tor-0_0_6incompat/src/or/main.c @@ -339,7 +339,22 @@ static void run_scheduled_events(time_t now) { static time_t last_uploaded_services = 0; int i; - /* 1. Every DirFetchPostPeriod seconds, we get a new directory and upload + + /* 1a. Every MIN_ONION_KEY_LIFETIME seconds, rotate the onion keys, + * shut down and restart all cpuworkers, and update the directory if + * necessary. + */ + if (options.ORPort && get_onion_key_set_at()+MIN_ONION_KEY_LIFETIME < now) { + rotate_onion_key(); + cpuworkers_rotate(); + if (router_rebuild_descriptor()<0) { + log_fn(LOG_WARN, "Couldn't rebuild router descriptor"); + } + router_rebuild_descriptor(); + router_upload_dir_desc_to_dirservers(); + } + + /* 1b. Every DirFetchPostPeriod seconds, we get a new directory and upload * our descriptor (if any). */ if(time_to_fetch_directory < now) { /* it's time to fetch a new directory and/or post our descriptor */ @@ -363,6 +378,7 @@ static void run_scheduled_events(time_t now) { time_to_fetch_directory = now + options.DirFetchPostPeriod; } + /* 2. Every second, we examine pending circuits and prune the * ones which have been pending for more than a few seconds. * We do this before step 3, so it can try building more if diff --git a/branches/tor-0_0_6incompat/src/or/or.h b/branches/tor-0_0_6incompat/src/or/or.h index b9cd482361..af073d4e40 100644 --- a/branches/tor-0_0_6incompat/src/or/or.h +++ b/branches/tor-0_0_6incompat/src/or/or.h @@ -109,6 +109,8 @@ #define MAX_DNS_ENTRY_AGE (15*60) #endif +#define MIN_ONION_KEY_LIFETIME (120*60) + #define CIRC_ID_TYPE_LOWER 0 #define CIRC_ID_TYPE_HIGHER 1 @@ -963,6 +965,7 @@ cpath_build_state_t *onion_new_cpath_build_state(uint8_t purpose, void set_onion_key(crypto_pk_env_t *k); crypto_pk_env_t *get_onion_key(void); crypto_pk_env_t *get_previous_onion_key(void); +time_t get_onion_key_set_at(void); void set_identity_key(crypto_pk_env_t *k); crypto_pk_env_t *get_identity_key(void); int init_keys(void); diff --git a/branches/tor-0_0_6incompat/src/or/router.c b/branches/tor-0_0_6incompat/src/or/router.c index c0a30a95ef..ea96174fd2 100644 --- a/branches/tor-0_0_6incompat/src/or/router.c +++ b/branches/tor-0_0_6incompat/src/or/router.c @@ -11,12 +11,14 @@ extern or_options_t options; /* command-line and config-file options */ /************************************************************/ /* private keys */ +static time_t onionkey_set_at=0; static crypto_pk_env_t *onionkey=NULL; static crypto_pk_env_t *lastonionkey=NULL; static crypto_pk_env_t *identitykey=NULL; void set_onion_key(crypto_pk_env_t *k) { onionkey = k; + onionkey_set_at = time(NULL); } crypto_pk_env_t *get_onion_key(void) { @@ -28,6 +30,10 @@ crypto_pk_env_t *get_previous_onion_key(void) { return lastonionkey; } +time_t get_onion_key_set_at(void) { + return onionkey_set_at; +} + void set_identity_key(crypto_pk_env_t *k) { identitykey = k; } @@ -68,7 +74,7 @@ void rotate_onion_key(void) /* XXXX WINDOWS on windows, we need to protect this next bit with a lock. */ lastonionkey = onionkey; - onionkey = prkey; + set_onion_key(prkey); if (router_rebuild_descriptor() <0) { goto error; }