X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=apps%2Fgenpkey.c;h=d80983350a86b5e3ee86d08a1747a2cc2049f3bd;hb=d40a1f72b6a298ee34c9de2c96b222d70609ce4c;hp=de14bd3810fe88aefced724540327286253c505c;hpb=b548a1f11c06ccdfa4f52a539912d22d77ee309e;p=oweals%2Fopenssl.git diff --git a/apps/genpkey.c b/apps/genpkey.c index de14bd3810..d80983350a 100644 --- 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 + /* This is deliberately last. */ {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; + int private = 0; prog = opt_init(argc, argv, genpkey_options); while ((o = opt_next()) != OPT_EOF) { @@ -124,7 +126,6 @@ int genpkey_main(int argc, char **argv) case OPT_OUT: outfile = opt_arg(); break; - case OPT_PASS: passarg = opt_arg(); break; @@ -170,6 +171,7 @@ int genpkey_main(int argc, char **argv) } argc = opt_num_rest(); argv = opt_rest(); + private = do_param ? 0 : 1; if (ctx == NULL) goto opthelp; @@ -179,7 +181,10 @@ int genpkey_main(int argc, char **argv) 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; @@ -202,11 +207,13 @@ int genpkey_main(int argc, char **argv) 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); - else if (outformat == FORMAT_ASN1) + } else if (outformat == FORMAT_ASN1) { + assert(private); rv = i2d_PrivateKey_bio(out, pkey); - else { + } else { BIO_printf(bio_err, "Bad format specified for key\n"); goto end; }