summaryrefslogtreecommitdiffstats
path: root/apps/pkcs8.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/pkcs8.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/pkcs8.c')
-rw-r--r--apps/pkcs8.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/apps/pkcs8.c b/apps/pkcs8.c
index e94a232f22..919b8f1370 100644
--- a/apps/pkcs8.c
+++ b/apps/pkcs8.c
@@ -115,6 +115,7 @@ int pkcs8_main(int argc, char **argv)
OPTION_CHOICE o;
int nocrypt = 0, ret = 1, iter = PKCS12_DEFAULT_ITER, p8_broken = PKCS8_OK;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, topk8 = 0, pbe_nid = -1;
+ int private = 0;
unsigned long scrypt_N = 0, scrypt_r = 0, scrypt_p = 0;
prog = opt_init(argc, argv, pkcs8_options);
@@ -217,6 +218,7 @@ int pkcs8_main(int argc, char **argv)
}
argc = opt_num_rest();
argv = opt_rest();
+ private = 1;
if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
BIO_printf(bio_err, "Error getting passwords\n");
@@ -232,9 +234,10 @@ int pkcs8_main(int argc, char **argv)
in = bio_open_default(infile, "rb");
if (in == NULL)
goto end;
- out = bio_open_default(outfile, "wb");
+ out = bio_open_owner(outfile, "wb", private);
if (out == NULL)
goto end;
+
if (topk8) {
pkey = load_key(infile, informat, 1, passin, e, "key");
if (!pkey)
@@ -245,6 +248,7 @@ int pkcs8_main(int argc, char **argv)
goto end;
}
if (nocrypt) {
+ assert(private);
if (outformat == FORMAT_PEM)
PEM_write_bio_PKCS8_PRIV_KEY_INFO(out, p8inf);
else if (outformat == FORMAT_ASN1)
@@ -289,6 +293,7 @@ int pkcs8_main(int argc, char **argv)
goto end;
}
app_RAND_write_file(NULL);
+ assert(private);
if (outformat == FORMAT_PEM)
PEM_write_bio_PKCS8(out, p8);
else if (outformat == FORMAT_ASN1)
@@ -373,6 +378,7 @@ int pkcs8_main(int argc, char **argv)
}
}
+ assert(private);
if (outformat == FORMAT_PEM)
PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL, passout);
else if (outformat == FORMAT_ASN1)