summaryrefslogtreecommitdiffstats
path: root/apps/dsaparam.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/dsaparam.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/dsaparam.c')
-rw-r--r--apps/dsaparam.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 27170a22a2..8d48313d2b 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -58,7 +58,6 @@
#include <openssl/opensslconf.h> /* for OPENSSL_NO_DSA */
#ifndef OPENSSL_NO_DSA
-# include <assert.h>
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
@@ -118,9 +117,8 @@ int dsaparam_main(int argc, char **argv)
BIO *in = NULL, *out = NULL;
BN_GENCB *cb = NULL;
int numbits = -1, num = 0, genkey = 0, need_rand = 0, non_fips_allow = 0;
- int informat = FORMAT_PEM, outformat = FORMAT_PEM, noout = 0, C = 0, ret =
- 1;
- int i, text = 0;
+ int informat = FORMAT_PEM, outformat = FORMAT_PEM, noout = 0, C = 0;
+ int ret = 1, i, text = 0, private = 0;
# ifdef GENCB_TEST
int timebomb = 0;
# endif
@@ -195,11 +193,12 @@ int dsaparam_main(int argc, char **argv)
numbits = num;
need_rand = 1;
}
+ private = genkey ? 1 : 0;
in = bio_open_default(infile, "r");
if (in == NULL)
goto end;
- out = bio_open_default(outfile, "w");
+ out = bio_open_owner(outfile, "w", private);
if (out == NULL)
goto end;
@@ -320,6 +319,7 @@ int dsaparam_main(int argc, char **argv)
DSA_free(dsakey);
goto end;
}
+ assert(private);
if (outformat == FORMAT_ASN1)
i = i2d_DSAPrivateKey_bio(out, dsakey);
else