Add -quiet flag to genpkey

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)
This commit is contained in:
Rich Salz 2021-05-12 11:45:37 -04:00 committed by Tomas Mraz
parent a94d62ab23
commit 7d72dc78ee
2 changed files with 25 additions and 8 deletions

View 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;

View 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>