mirror of
https://github.com/openssl/openssl.git
synced 2025-01-30 14:01:55 +08:00
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)
This commit is contained in:
parent
8c2e588bcf
commit
e1cd94f2dc
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
21
apps/req.c
21
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user