Add -quiet flag to genpkey
authorRich Salz <rsalz@akamai.com>
Wed, 12 May 2021 15:45:37 +0000 (11:45 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 18 May 2021 07:20:26 +0000 (09:20 +0200)
Picking up late suggestions to PR #6909 by Philip Prindeville
<philipp@redfish-solutions.com>.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15249)

apps/genpkey.c
doc/man1/openssl-genpkey.pod.in

index f10390e1ba4fb875d6101c6f7299a308fd24ae56..c187cc2a70fa4ee3ef2e1096acd0ab188fb7ee8f 100644 (file)
@@ -15,6 +15,8 @@
 #include <openssl/err.h>
 #include <openssl/evp.h>
 
+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;
index aa08b01f4f89e6a1fc6ef4a7b2015d99875797cf..9cfd9ae4412df3ff0cf24eee8c0cc1f2592871fd 100644 (file)
@@ -15,6 +15,7 @@ B<openssl> B<genpkey>
 [B<-help>]
 [B<-out> I<filename>]
 [B<-outform> B<DER>|B<PEM>]
+[B<-quiet>]
 [B<-pass> I<arg>]
 [B<-I<cipher>>]
 [B<-paramfile> I<file>]
@@ -51,6 +52,10 @@ See L<openssl-format-options(1)> 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<arg>
 
 The output file password source. For more information about the format of I<arg>