diff options
author | Rich Salz <rsalz@akamai.com> | 2015-05-02 10:01:33 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-06-15 18:26:56 -0400 |
commit | 3b061a00e39d2e4ad524ff01cbdc0c53fe8171ee (patch) | |
tree | 0389af5c46f6c56ab6f88c737f55aa07493dfd39 /apps/pkcs12.c | |
parent | d31fb0b5b341aa7883b487d07e6a56d216224e25 (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/pkcs12.c')
-rw-r--r-- | apps/pkcs12.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 05bb1ad98d..5b14dd5320 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -169,7 +169,7 @@ int pkcs12_main(int argc, char **argv) int cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC; # endif int key_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC; - int ret = 1, macver = 1, noprompt = 0, add_lmk = 0; + int ret = 1, macver = 1, noprompt = 0, add_lmk = 0, private = 0; char *passinarg = NULL, *passoutarg = NULL, *passarg = NULL; char *passin = NULL, *passout = NULL, *inrand = NULL, *macalg = NULL; char *cpass = NULL, *mpass = NULL, *CApath = NULL, *CAfile = NULL; @@ -314,6 +314,7 @@ int pkcs12_main(int argc, char **argv) } argc = opt_num_rest(); argv = opt_rest(); + private = 1; if (passarg) { if (export_cert) @@ -355,8 +356,7 @@ int pkcs12_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; @@ -500,6 +500,7 @@ int pkcs12_main(int argc, char **argv) if (maciter != -1) PKCS12_set_mac(p12, mpass, -1, NULL, 0, maciter, macmd); + assert(private); i2d_PKCS12_bio(out, p12); ret = 0; @@ -545,6 +546,7 @@ int pkcs12_main(int argc, char **argv) } } + assert(private); if (!dump_certs_keys_p12(out, p12, cpass, -1, options, passout, enc)) { BIO_printf(bio_err, "Error outputting keys and certificates\n"); ERR_print_errors(bio_err); |