summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorPhilip Prindeville <philipp@redfish-solutions.com>2021-12-21 22:00:38 -0700
committerTomas Mraz <tomas@openssl.org>2022-01-21 15:44:28 +0100
commite1cd94f2dca4056ce042c62b89c468dffc088033 (patch)
treeee3ca7b476be8d96f92109f03c419b9fd0d11b27 /apps
parent8c2e588bcf0de61880ec8a956ef57ad6b8a50163 (diff)
Standardize progress callback for dhparam, dsaparam, etc.
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17359)
Diffstat (limited to 'apps')
-rw-r--r--apps/dhparam.c14
-rw-r--r--apps/dsaparam.c23
-rw-r--r--apps/genpkey.c29
-rw-r--r--apps/include/apps.h3
-rw-r--r--apps/lib/s_cb.c13
-rw-r--r--apps/req.c21
6 files changed, 21 insertions, 82 deletions
diff --git a/apps/dhparam.c b/apps/dhparam.c
index 9fe0eedfc2..4a67a52d4a 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -31,7 +31,6 @@
#define DEFBITS 2048
static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh);
-static int gendh_cb(EVP_PKEY_CTX *ctx);
typedef enum OPTION_choice {
OPT_COMMON,
@@ -188,7 +187,7 @@ int dhparam_main(int argc, char **argv)
alg);
goto end;
}
- EVP_PKEY_CTX_set_cb(ctx, gendh_cb);
+ EVP_PKEY_CTX_set_cb(ctx, progress_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
BIO_printf(bio_err,
"Generating %s parameters, %d bit long %sprime\n",
@@ -399,14 +398,3 @@ static EVP_PKEY *dsa_to_dh(EVP_PKEY *dh)
return pkey;
}
-static int gendh_cb(EVP_PKEY_CTX *ctx)
-{
- int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
- BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
- static const char symbols[] = ".+*\n";
- char c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
-
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 08f912340a..708cb9a648 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include "apps.h"
#include <time.h>
#include <string.h>
#include "apps.h"
@@ -25,8 +24,6 @@
static int verbose = 0;
-static int gendsa_cb(EVP_PKEY_CTX *ctx);
-
typedef enum OPTION_choice {
OPT_COMMON,
OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_TEXT,
@@ -160,9 +157,9 @@ int dsaparam_main(int argc, char **argv)
" Your key size is %d! Larger key size may behave not as expected.\n",
OPENSSL_DSA_MAX_MODULUS_BITS, numbits);
- EVP_PKEY_CTX_set_cb(ctx, gendsa_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
if (verbose) {
+ EVP_PKEY_CTX_set_cb(ctx, progress_cb);
BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n",
num);
BIO_printf(bio_err, "This could take some time\n");
@@ -235,21 +232,3 @@ int dsaparam_main(int argc, char **argv)
return ret;
}
-static int gendsa_cb(EVP_PKEY_CTX *ctx)
-{
- static const char symbols[] = ".+*\n";
- int p;
- char c;
- BIO *b;
-
- if (!verbose)
- return 1;
-
- b = EVP_PKEY_CTX_get_app_data(ctx);
- p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
- c = (p >= 0 && (size_t)p < sizeof(symbols) - 1) ? symbols[p] : '?';
-
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
diff --git a/apps/genpkey.c b/apps/genpkey.c
index f4c8f92c34..0f2a97137a 100644
--- a/apps/genpkey.c
+++ b/apps/genpkey.c
@@ -19,8 +19,6 @@ 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);
-
typedef enum OPTION_choice {
OPT_COMMON,
OPT_ENGINE, OPT_OUTFORM, OPT_OUT, OPT_PASS, OPT_PARAMFILE,
@@ -181,7 +179,8 @@ int genpkey_main(int argc, char **argv)
if (out == NULL)
goto end;
- EVP_PKEY_CTX_set_cb(ctx, genpkey_cb);
+ if (!quiet)
+ EVP_PKEY_CTX_set_cb(ctx, progress_cb);
EVP_PKEY_CTX_set_app_data(ctx, bio_err);
pkey = do_param ? app_paramgen(ctx, algname)
@@ -319,27 +318,3 @@ int init_gen_str(EVP_PKEY_CTX **pctx,
}
-static int genpkey_cb(EVP_PKEY_CTX *ctx)
-{
- char c = '*';
- BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
-
- if (quiet)
- return 1;
-
- switch (EVP_PKEY_CTX_get_keygen_info(ctx, 0)) {
- case 0:
- c = '.';
- break;
- case 1:
- c = '+';
- break;
- case 3:
- c = '\n';
- break;
- }
-
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}
diff --git a/apps/include/apps.h b/apps/include/apps.h
index f06d01cd37..b6dbe74fa9 100644
--- a/apps/include/apps.h
+++ b/apps/include/apps.h
@@ -94,6 +94,9 @@ typedef struct args_st {
/* We need both wrap and the "real" function because libcrypto uses both. */
int wrap_password_callback(char *buf, int bufsiz, int verify, void *cb_data);
+/* progress callback for dsaparam, dhparam, req, genpkey, etc. */
+int progress_cb(EVP_PKEY_CTX *ctx);
+
int chopup_args(ARGS *arg, char *buf);
void dump_cert_text(BIO *out, X509 *x);
void print_name(BIO *out, const char *title, const X509_NAME *nm);
diff --git a/apps/lib/s_cb.c b/apps/lib/s_cb.c
index 77ddbc9d7b..d6d49d666c 100644
--- a/apps/lib/s_cb.c
+++ b/apps/lib/s_cb.c
@@ -1574,3 +1574,16 @@ void ssl_print_secure_renegotiation_notes(BIO *bio, SSL *s)
BIO_printf(bio, "This TLS version forbids renegotiation.\n");
}
}
+
+int progress_cb(EVP_PKEY_CTX *ctx)
+{
+ BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
+ int p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
+ static const char symbols[] = ".+*\n";
+ char c = (p >= 0 && (size_t)p <= sizeof(symbols) - 1) ? symbols[p] : '?';
+
+ BIO_write(b, &c, 1);
+ (void)BIO_flush(b);
+ return 1;
+}
+
diff --git a/apps/req.c b/apps/req.c
index eaff69faa4..45de46d393 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -62,7 +62,6 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def,
static int add_DN_object(X509_NAME *n, char *text, const char *def,
char *value, int nid, int n_min, int n_max,
unsigned long chtype, int mval);
-static int genpkey_cb(EVP_PKEY_CTX *ctx);
static int build_data(char *text, const char *def, char *value,
int n_min, int n_max, char *buf, const int buf_size,
const char *desc1, const char *desc2);
@@ -663,7 +662,7 @@ int req_main(int argc, char **argv)
}
}
- EVP_PKEY_CTX_set_cb(genctx, genpkey_cb);
+ EVP_PKEY_CTX_set_cb(genctx, progress_cb);
EVP_PKEY_CTX_set_app_data(genctx, bio_err);
pkey = app_keygen(genctx, keyalgstr, newkey_len, verbose);
@@ -1649,21 +1648,3 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
return gctx;
}
-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)
- c = '.';
- if (p == 1)
- c = '+';
- if (p == 2)
- c = '*';
- if (p == 3)
- c = '\n';
- BIO_write(b, &c, 1);
- (void)BIO_flush(b);
- return 1;
-}