#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}
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) {
case OPT_OUT:
outfile = opt_arg();
break;
-
case OPT_PASS:
passarg = opt_arg();
break;
}
argc = opt_num_rest();
argv = opt_rest();
+ private = do_param ? 0 : 1;
if (ctx == NULL)
goto opthelp;
goto end;
}
- out = bio_open_default(outfile, "wb");
+ out = bio_open_owner(outfile, outformat, private);
if (out == NULL)
goto end;
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;
}
EVP_PKEY_CTX_free(ctx);
BIO_free_all(out);
BIO_free(in);
- if (pass)
- OPENSSL_free(pass);
+ OPENSSL_free(pass);
return ret;
}