summaryrefslogtreecommitdiffstats
path: root/apps/req.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2015-05-02 10:01:33 -0400
committerRich Salz <rsalz@openssl.org>2015-06-15 18:26:56 -0400
commit3b061a00e39d2e4ad524ff01cbdc0c53fe8171ee (patch)
tree0389af5c46f6c56ab6f88c737f55aa07493dfd39 /apps/req.c
parentd31fb0b5b341aa7883b487d07e6a56d216224e25 (diff)
RT2547: Tighten perms on generated privkey files
When generating a private key, try to make the output file be readable only by the owner. Put it in CHANGES file since it might be noticeable. Add "int private" flag to apps that write private keys, and check that it's set whenever we do write a private key. Checked via assert so that this bug (security-related) gets fixed. Thanks to Viktor for help in tracing the code-paths where private keys are written. Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Diffstat (limited to 'apps/req.c')
-rw-r--r--apps/req.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/apps/req.c b/apps/req.c
index 712037dc17..03736cc34b 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -204,8 +204,8 @@ int req_main(int argc, char **argv)
char *template = default_config_file, *keyout = NULL;
const char *keyalg = NULL;
OPTION_CHOICE o;
- int ret = 1, x509 = 0, days = 30, i = 0, newreq = 0, verbose =
- 0, pkey_type = -1;
+ int ret = 1, x509 = 0, days = 30, i = 0, newreq = 0, verbose = 0;
+ int pkey_type = -1, private = 0;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, keyform = FORMAT_PEM;
int modulus = 0, multirdn = 0, verify = 0, noout = 0, text = 0;
int nodes = 0, kludge = 0, newhdr = 0, subject = 0, pubkey = 0;
@@ -375,6 +375,7 @@ int req_main(int argc, char **argv)
}
argc = opt_num_rest();
argv = opt_rest();
+ private = newreq && (pkey == NULL) ? 1 : 0;
if (!app_passwd(passargin, passargout, &passin, &passout)) {
BIO_printf(bio_err, "Error getting passwords\n");
@@ -569,7 +570,7 @@ int req_main(int argc, char **argv)
BIO_printf(bio_err, "writing new private key to stdout\n");
else
BIO_printf(bio_err, "writing new private key to '%s'\n", keyout);
- out = bio_open_default(keyout, "w");
+ out = bio_open_owner(keyout, "w", private);
if (out == NULL)
goto end;
@@ -587,6 +588,7 @@ int req_main(int argc, char **argv)
i = 0;
loop:
+ assert(private);
if (!PEM_write_bio_PrivateKey(out, pkey, cipher,
NULL, 0, NULL, passout)) {
if ((ERR_GET_REASON(ERR_peek_error()) ==