summaryrefslogtreecommitdiff
path: root/src/or/routerkeys.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-09-01 10:58:53 -0400
committerNick Mathewson <nickm@torproject.org>2015-09-22 09:24:35 -0400
commitbca4211de5464cd159592b359b2f16eb64d3c07f (patch)
tree462b3d2249f6330cf977bd3c0282853e84b45065 /src/or/routerkeys.c
parentd8f031aec2ee84c753ef282577c7f4fcf0123d2f (diff)
downloadtor-bca4211de5464cd159592b359b2f16eb64d3c07f.tar.gz
tor-bca4211de5464cd159592b359b2f16eb64d3c07f.zip
Add a --master-key option
This lets the user override the default location for the master key when used with --keygen Part of 16769.
Diffstat (limited to 'src/or/routerkeys.c')
-rw-r--r--src/or/routerkeys.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/or/routerkeys.c b/src/or/routerkeys.c
index be5c2c33a1..197dbf87a1 100644
--- a/src/or/routerkeys.c
+++ b/src/or/routerkeys.c
@@ -258,6 +258,9 @@ write_secret_key(const ed25519_secret_key_t *key, int encrypted,
*
* If INIT_ED_KEY_SUGGEST_KEYGEN is set, have log messages about failures
* refer to the --keygen option.
+ *
+ * If INIT_ED_KEY_EXPLICIT_FNAME is set, use the provided file name for the
+ * secret key file, encrypted or not.
*/
ed25519_keypair_t *
ed_key_init_from_file(const char *fname, uint32_t flags,
@@ -279,6 +282,7 @@ ed_key_init_from_file(const char *fname, uint32_t flags,
const int norepair = !! (flags & INIT_ED_KEY_NO_REPAIR);
const int split = !! (flags & INIT_ED_KEY_SPLIT);
const int omit_secret = !! (flags & INIT_ED_KEY_OMIT_SECRET);
+ const int explicit_fname = !! (flags & INIT_ED_KEY_EXPLICIT_FNAME);
/* we don't support setting both of these flags at once. */
tor_assert((flags & (INIT_ED_KEY_NO_REPAIR|INIT_ED_KEY_NEEDCERT)) !=
@@ -291,8 +295,13 @@ ed_key_init_from_file(const char *fname, uint32_t flags,
char *got_tag = NULL;
ed25519_keypair_t *keypair = tor_malloc_zero(sizeof(ed25519_keypair_t));
- tor_asprintf(&secret_fname, "%s_secret_key", fname);
- tor_asprintf(&encrypted_secret_fname, "%s_secret_key_encrypted", fname);
+ if (explicit_fname) {
+ secret_fname = tor_strdup(fname);
+ encrypted_secret_fname = tor_strdup(fname);
+ } else {
+ tor_asprintf(&secret_fname, "%s_secret_key", fname);
+ tor_asprintf(&encrypted_secret_fname, "%s_secret_key_encrypted", fname);
+ }
tor_asprintf(&public_fname, "%s_public_key", fname);
tor_asprintf(&cert_fname, "%s_cert", fname);
@@ -729,7 +738,12 @@ load_ed_keys(const or_options_t *options, time_t now)
goto err;
}
tor_free(fname);
- fname = options_get_datadir_fname2(options, "keys", "ed25519_master_id");
+ if (options->master_key_fname) {
+ fname = tor_strdup(options->master_key_fname);
+ flags |= INIT_ED_KEY_EXPLICIT_FNAME;
+ } else {
+ fname = options_get_datadir_fname2(options, "keys", "ed25519_master_id");
+ }
id = ed_key_init_from_file(
fname,
flags,