diff options
author | George Kadianakis <desnacked@gmail.com> | 2011-11-24 22:32:10 +0100 |
---|---|---|
committer | George Kadianakis <desnacked@gmail.com> | 2011-11-24 22:32:10 +0100 |
commit | 2ef68980a778666bcc9b3b492c4acbd7af27fc28 (patch) | |
tree | 8331554dd3964726504e2a165c9113e512d72047 /src | |
parent | cabb8e54c7240aeb20ccfa745d75c5ad4063edb3 (diff) | |
download | tor-2ef68980a778666bcc9b3b492c4acbd7af27fc28.tar.gz tor-2ef68980a778666bcc9b3b492c4acbd7af27fc28.zip |
Move store_dynamic_prime() to crypto.c.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/crypto.c | 40 | ||||
-rw-r--r-- | src/common/crypto.h | 2 | ||||
-rw-r--r-- | src/or/router.c | 52 | ||||
-rw-r--r-- | src/or/router.h | 1 |
4 files changed, 44 insertions, 51 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 72c3dd7c12..a3c292324b 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1849,10 +1849,44 @@ crypto_generate_dynamic_prime(void) return dynamic_prime; } -BIGNUM * -crypto_get_tls_dh_prime(void) +/** Store our dynamic prime to <b>fname</b> for future use. */ +int +router_store_dynamic_prime(const char *fname) { - return dh_param_p_tls; + FILE *fp = NULL; + int retval = -1; + file_status_t fname_status = file_status(fname); + + tor_assert(fname); + + if (fname_status == FN_FILE) { + /* If the fname is a file, then the dynamic prime is already stored. */ + retval = 0; + goto done; + } else if (fname_status != FN_NOENT) { + log_info(LD_GENERAL, "Dynamic prime filename is occupied."); + goto done; + } + + tor_assert(fname_status == FN_NOENT); + + if (!(fp = fopen(fname, "w"))) { + log_notice(LD_GENERAL, "Error while creating dynamic prime file."); + goto done; + } + + if (BN_print_fp(fp, dh_param_p_tls) == 0) { + log_warn(LD_GENERAL, "Error while printing dynamic prime to file."); + goto done; + } + + retval = 0; + + done: + if (fp) + fclose(fp); + + return retval; } /** Set the global TLS Diffie-Hellman modulus. diff --git a/src/common/crypto.h b/src/common/crypto.h index 5b753b83d6..8c99dd7a37 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -97,7 +97,7 @@ void crypto_free_pk_env(crypto_pk_env_t *env); void crypto_set_tls_dh_prime(int use_dynamic_primes, BIGNUM *stored_dynamic_prime); -BIGNUM * crypto_get_tls_dh_prime(void); +int router_store_dynamic_prime(const char *fname); /* convenience function: wraps crypto_create_crypto_env, set_key, and init. */ crypto_cipher_env_t *crypto_create_init_cipher(const char *key, diff --git a/src/or/router.c b/src/or/router.c index 6b38c793ce..dd5b9fff52 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -485,46 +485,6 @@ v3_authority_check_key_expiry(void) } -/** Store <b>dynamic_prime</b> to disk for future use. */ -int -router_store_dynamic_prime(const BIGNUM *dynamic_prime) -{ - FILE *fp = NULL; - char *fname = get_datadir_fname2("keys", "dynamic_prime"); - int retval = -1; - file_status_t fname_status = file_status(fname); - - if (fname_status == FN_FILE) { - /* If the fname is a file, then the dynamic prime is already stored. */ - retval = 0; - goto done; - } else if (fname_status != FN_NOENT) { - log_info(LD_GENERAL, "Dynamic prime filename is occupied."); - goto done; - } - - tor_assert(fname_status == FN_NOENT); - - if (!(fp = fopen(fname, "w"))) { - log_notice(LD_GENERAL, "Error while creating dynamic prime file."); - goto done; - } - - if (BN_print_fp(fp, dynamic_prime) == 0) { - log_warn(LD_GENERAL, "Error while printing dynamic prime to file."); - goto done; - } - - retval = 0; - - done: - if (fp) - fclose(fp); - tor_free(fname); - - return retval; -} - /** Return the dynamic prime stored in the disk. If there is no dynamic prime stored in the disk, return NULL. */ BIGNUM * @@ -722,12 +682,12 @@ init_keys(void) /** 3b. If we use a dynamic prime, store it to disk. */ if (get_options()->DynamicPrimes) { - BIGNUM *dynamic_prime = crypto_get_tls_dh_prime(); - if (dynamic_prime) { - if (router_store_dynamic_prime(dynamic_prime) < 0) - log_notice(LD_GENERAL, "Failed while storing dynamic prime. " - "Make sure your data directory is sane."); - } + const char *fname = get_datadir_fname2("keys", "dynamic_prime"); + if (crypto_store_dynamic_prime(fname)) { + log_notice(LD_GENERAL, "Failed while storing dynamic prime. " + "Make sure your data directory is sane."); + } + tor_free(fname); } /* 4. Build our router descriptor. */ diff --git a/src/or/router.h b/src/or/router.h index 41ff139936..a998335aa3 100644 --- a/src/or/router.h +++ b/src/or/router.h @@ -30,7 +30,6 @@ crypto_pk_env_t *init_key_from_file(const char *fname, int generate, int severity); BIGNUM *router_get_stored_dynamic_prime(void); -int router_store_dynamic_prime(const BIGNUM *dynamic_prime); void v3_authority_check_key_expiry(void); |