summaryrefslogtreecommitdiffstats
path: root/apps/genrsa.c
diff options
context:
space:
mode:
authorKurt Roeckx <kurt@roeckx.be>2019-04-13 15:52:47 +0200
committerKurt Roeckx <kurt@roeckx.be>2020-09-09 18:32:10 +0200
commit10203a34725ec75136b03d64fd2126b321419ac1 (patch)
tree74fe59f88ef556a8bcadd7673bac64f092c7057b /apps/genrsa.c
parent8ae40cf57d2138af92a3479e23f35037ae8c5c30 (diff)
Support writing RSA keys using the traditional format again
Fixes: #6855 Reviewed-by: Richard Levitte <levitte@openssl.org> GH: #8743
Diffstat (limited to 'apps/genrsa.c')
-rw-r--r--apps/genrsa.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/apps/genrsa.c b/apps/genrsa.c
index 4f589e98c1..04315a559b 100644
--- a/apps/genrsa.c
+++ b/apps/genrsa.c
@@ -38,7 +38,7 @@ typedef enum OPTION_choice {
#endif
OPT_F4, OPT_ENGINE,
OPT_OUT, OPT_PASSOUT, OPT_CIPHER, OPT_PRIMES, OPT_VERBOSE,
- OPT_R_ENUM, OPT_PROV_ENUM
+ OPT_R_ENUM, OPT_PROV_ENUM, OPT_TRADITIONAL
} OPTION_CHOICE;
const OPTIONS genrsa_options[] = {
@@ -62,6 +62,8 @@ const OPTIONS genrsa_options[] = {
{"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
{"primes", OPT_PRIMES, 'p', "Specify number of primes"},
{"verbose", OPT_VERBOSE, '-', "Verbose output"},
+ {"traditional", OPT_TRADITIONAL, '-',
+ "Use traditional format for private keys"},
{"", OPT_CIPHER, '-', "Encrypt the output with any supported cipher"},
OPT_R_OPTIONS,
@@ -88,7 +90,7 @@ int genrsa_main(int argc, char **argv)
char *outfile = NULL, *passoutarg = NULL, *passout = NULL;
char *prog, *hexe, *dece;
OPTION_CHOICE o;
- unsigned char *ebuf = NULL;
+ int traditional = 0;
if (bn == NULL || cb == NULL)
goto end;
@@ -141,6 +143,9 @@ opthelp:
case OPT_VERBOSE:
verbose = 1;
break;
+ case OPT_TRADITIONAL:
+ traditional = 1;
+ break;
}
}
argc = opt_num_rest();
@@ -214,8 +219,14 @@ opthelp:
OPENSSL_free(hexe);
OPENSSL_free(dece);
}
- if (!PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, passout))
- goto end;
+ if (traditional) {
+ if (!PEM_write_bio_PrivateKey_traditional(out, pkey, enc, NULL, 0,
+ NULL, passout))
+ goto end;
+ } else {
+ if (!PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, passout))
+ goto end;
+ }
ret = 0;
end:
@@ -226,7 +237,6 @@ opthelp:
BIO_free_all(out);
release_engine(eng);
OPENSSL_free(passout);
- OPENSSL_free(ebuf);
if (ret != 0)
ERR_print_errors(bio_err);
return ret;