diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-07-14 10:23:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-07-14 10:23:07 -0400 |
commit | 0a6997d78bdbf485f42acfa95558a91db3381d70 (patch) | |
tree | 3e648ed80e454ac04550dc2870dc16672f34205f /src/or/routerkeys.c | |
parent | b566cb9e84b095289a1c662e953218c9a7d1f77d (diff) | |
download | tor-0a6997d78bdbf485f42acfa95558a91db3381d70.tar.gz tor-0a6997d78bdbf485f42acfa95558a91db3381d70.zip |
Preserve errno when loading encrypted ed25519 keys.
Diffstat (limited to 'src/or/routerkeys.c')
-rw-r--r-- | src/or/routerkeys.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/or/routerkeys.c b/src/or/routerkeys.c index d075c67e6a..97a586dc56 100644 --- a/src/or/routerkeys.c +++ b/src/or/routerkeys.c @@ -21,6 +21,7 @@ read_encrypted_secret_key(ed25519_secret_key_t *out, char pwbuf[256]; uint8_t encrypted_key[256]; char *tag = NULL; + int saved_errno = 0; ssize_t encrypted_len = crypto_read_tagged_contents_from_file(fname, ENC_KEY_HEADER, @@ -28,6 +29,7 @@ read_encrypted_secret_key(ed25519_secret_key_t *out, encrypted_key, sizeof(encrypted_key)); if (encrypted_len < 0) { + saved_errno = errno; log_info(LD_OR, "%s is missing", fname); r = 0; goto done; @@ -46,6 +48,7 @@ read_encrypted_secret_key(ed25519_secret_key_t *out, pwbuf, pwlen); if (r == UNPWBOX_CORRUPTED) { log_err(LD_OR, "%s is corrupted.", fname); + saved_errno = EINVAL; goto done; } else if (r == UNPWBOX_OKAY) { break; @@ -57,6 +60,7 @@ read_encrypted_secret_key(ed25519_secret_key_t *out, if (secret_len != ED25519_SECKEY_LEN) { log_err(LD_OR, "%s is corrupted.", fname); + saved_errno = EINVAL; goto done; } memcpy(out->seckey, secret, ED25519_SECKEY_LEN); @@ -70,6 +74,8 @@ read_encrypted_secret_key(ed25519_secret_key_t *out, memwipe(secret, 0, secret_len); tor_free(secret); } + if (saved_errno) + errno = saved_errno; return r; } |