From 7d72dc78ee54cc3b9163ef9b23cf22bb85015552 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Wed, 12 May 2021 11:45:37 -0400 Subject: [PATCH] Add -quiet flag to genpkey Picking up late suggestions to PR #6909 by Philip Prindeville . Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15249) --- apps/genpkey.c | 28 ++++++++++++++++++++-------- doc/man1/openssl-genpkey.pod.in | 5 +++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/apps/genpkey.c b/apps/genpkey.c index f10390e1ba..c187cc2a70 100644 --- a/apps/genpkey.c +++ b/apps/genpkey.c @@ -15,6 +15,8 @@ #include #include +static int quiet; + static int init_keygen_file(EVP_PKEY_CTX **pctx, const char *file, ENGINE *e, OSSL_LIB_CTX *libctx, const char *propq); static int genpkey_cb(EVP_PKEY_CTX *ctx); @@ -23,7 +25,7 @@ typedef enum OPTION_choice { OPT_COMMON, OPT_ENGINE, OPT_OUTFORM, OPT_OUT, OPT_PASS, OPT_PARAMFILE, OPT_ALGORITHM, OPT_PKEYOPT, OPT_GENPARAM, OPT_TEXT, OPT_CIPHER, - OPT_CONFIG, + OPT_QUIET, OPT_CONFIG, OPT_PROV_ENUM } OPTION_CHOICE; @@ -35,6 +37,7 @@ const OPTIONS genpkey_options[] = { #endif {"paramfile", OPT_PARAMFILE, '<', "Parameters file"}, {"algorithm", OPT_ALGORITHM, 's', "The public key algorithm"}, + {"quiet", OPT_QUIET, 's', "Do not output status while generating keys"}, {"pkeyopt", OPT_PKEYOPT, 's', "Set the public key algorithm option as opt:value"}, OPT_CONFIG_OPTION, @@ -111,6 +114,9 @@ int genpkey_main(int argc, char **argv) if (!sk_OPENSSL_STRING_push(keyopt, opt_arg())) goto end; break; + case OPT_QUIET: + quiet = 1; + break; case OPT_GENPARAM: do_param = 1; break; @@ -332,16 +338,22 @@ static int genpkey_cb(EVP_PKEY_CTX *ctx) { char c = '*'; BIO *b = EVP_PKEY_CTX_get_app_data(ctx); - int p; - p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); - if (p == 0) + + if (quiet) + return 1; + + switch (EVP_PKEY_CTX_get_keygen_info(ctx, 0)) { + case 0: c = '.'; - if (p == 1) + break; + case 1: c = '+'; - if (p == 2) - c = '*'; - if (p == 3) + break; + case 3: c = '\n'; + break; + } + BIO_write(b, &c, 1); (void)BIO_flush(b); return 1; diff --git a/doc/man1/openssl-genpkey.pod.in b/doc/man1/openssl-genpkey.pod.in index aa08b01f4f..9cfd9ae441 100644 --- a/doc/man1/openssl-genpkey.pod.in +++ b/doc/man1/openssl-genpkey.pod.in @@ -15,6 +15,7 @@ B B [B<-help>] [B<-out> I] [B<-outform> B|B] +[B<-quiet>] [B<-pass> I] [B<-I>] [B<-paramfile> I] @@ -51,6 +52,10 @@ See L for details. When B<-genparam> is given, B<-outform> is ignored. +=item B<-quiet> + +Do not output "status dots" while generating keys. + =item B<-pass> I The output file password source. For more information about the format of I -- 2.39.5