projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
SRP memory leak fix
[oweals/openssl.git]
/
apps
/
genpkey.c
diff --git
a/apps/genpkey.c
b/apps/genpkey.c
index 5130b40a82cf00862f04eb86f91021af480e03fd..d80983350a86b5e3ee86d08a1747a2cc2049f3bd 100644
(file)
--- a/
apps/genpkey.c
+++ b/
apps/genpkey.c
@@
-89,6
+89,7
@@
OPTIONS genpkey_options[] = {
#ifndef OPENSSL_NO_ENGINE
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
#endif
#ifndef OPENSSL_NO_ENGINE
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
#endif
+ /* This is deliberately last. */
{OPT_HELP_STR, 1, 1,
"Order of options may be important! See the documentation.\n"},
{NULL}
{OPT_HELP_STR, 1, 1,
"Order of options may be important! See the documentation.\n"},
{NULL}
@@
-104,6
+105,7
@@
int genpkey_main(int argc, char **argv)
const EVP_CIPHER *cipher = NULL;
OPTION_CHOICE o;
int outformat = FORMAT_PEM, text = 0, ret = 1, rv, do_param = 0;
const EVP_CIPHER *cipher = NULL;
OPTION_CHOICE o;
int outformat = FORMAT_PEM, text = 0, ret = 1, rv, do_param = 0;
+ int private = 0;
prog = opt_init(argc, argv, genpkey_options);
while ((o = opt_next()) != OPT_EOF) {
prog = opt_init(argc, argv, genpkey_options);
while ((o = opt_next()) != OPT_EOF) {
@@
-124,15
+126,12
@@
int genpkey_main(int argc, char **argv)
case OPT_OUT:
outfile = opt_arg();
break;
case OPT_OUT:
outfile = opt_arg();
break;
-
case OPT_PASS:
passarg = opt_arg();
break;
case OPT_PASS:
passarg = opt_arg();
break;
-#ifndef OPENSSL_NO_ENGINE
case OPT_ENGINE:
e = setup_engine(opt_arg(), 0);
break;
case OPT_ENGINE:
e = setup_engine(opt_arg(), 0);
break;
-#endif
case OPT_PARAMFILE:
if (do_param == 1)
goto opthelp;
case OPT_PARAMFILE:
if (do_param == 1)
goto opthelp;
@@
-172,6
+171,7
@@
int genpkey_main(int argc, char **argv)
}
argc = opt_num_rest();
argv = opt_rest();
}
argc = opt_num_rest();
argv = opt_rest();
+ private = do_param ? 0 : 1;
if (ctx == NULL)
goto opthelp;
if (ctx == NULL)
goto opthelp;
@@
-181,7
+181,10
@@
int genpkey_main(int argc, char **argv)
goto end;
}
goto end;
}
- out = bio_open_default(outfile, "wb");
+ if (!app_load_modules(NULL))
+ goto end;
+
+ out = bio_open_owner(outfile, outformat, private);
if (out == NULL)
goto end;
if (out == NULL)
goto end;
@@
-204,11
+207,13
@@
int genpkey_main(int argc, char **argv)
if (do_param)
rv = PEM_write_bio_Parameters(out, pkey);
if (do_param)
rv = PEM_write_bio_Parameters(out, pkey);
- else if (outformat == FORMAT_PEM)
+ else if (outformat == FORMAT_PEM) {
+ assert(private);
rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, NULL, pass);
rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, NULL, pass);
- else if (outformat == FORMAT_ASN1)
+ } else if (outformat == FORMAT_ASN1) {
+ assert(private);
rv = i2d_PrivateKey_bio(out, pkey);
rv = i2d_PrivateKey_bio(out, pkey);
- else {
+
}
else {
BIO_printf(bio_err, "Bad format specified for key\n");
goto end;
}
BIO_printf(bio_err, "Bad format specified for key\n");
goto end;
}
@@
-237,8
+242,7
@@
int genpkey_main(int argc, char **argv)
EVP_PKEY_CTX_free(ctx);
BIO_free_all(out);
BIO_free(in);
EVP_PKEY_CTX_free(ctx);
BIO_free_all(out);
BIO_free(in);
- if (pass)
- OPENSSL_free(pass);
+ OPENSSL_free(pass);
return ret;
}
return ret;
}