From 538404d2186954d58c04c46232f985ddf9675b6f Mon Sep 17 00:00:00 2001 From: David von Oheimb Date: Mon, 28 Aug 2017 19:14:47 +0200 Subject: [PATCH] Add 'methods' parameter to setup_engine() in apps.c for individual method defaults Reviewed-by: Richard Levitte Reviewed-by: David von Oheimb (Merged from https://github.com/openssl/openssl/pull/4277) --- apps/cmp.c | 9 +-------- apps/include/apps.h | 9 +++++---- apps/lib/apps.c | 23 +++++++++++------------ apps/s_server.c | 4 +++- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/apps/cmp.c b/apps/cmp.c index 7a2ce2963d..72ebe34d26 100644 --- a/apps/cmp.c +++ b/apps/cmp.c @@ -61,13 +61,6 @@ static int read_config(void); static CONF *conf = NULL; /* OpenSSL config file context structure */ static OSSL_CMP_CTX *cmp_ctx = NULL; /* the client-side CMP context */ -/* TODO remove when new setup_engine_flags() is in apps/lib/apps.c (PR #4277) */ -static -ENGINE *setup_engine_flags(const char *engine, unsigned int flags, int debug) -{ - return setup_engine(engine, debug); -} - /* the type of cmp command we want to send */ typedef enum { CMP_IR, @@ -2938,7 +2931,7 @@ int cmp_main(int argc, char **argv) } if (opt_engine != NULL) - e = setup_engine_flags(opt_engine, 0 /* not: ENGINE_METHOD_ALL */, 0); + e = setup_engine_methods(opt_engine, 0 /* not: ENGINE_METHOD_ALL */, 0); if (opt_port != NULL) { if (opt_use_mock_srv) { diff --git a/apps/include/apps.h b/apps/include/apps.h index a8da7ac9f4..b051222244 100644 --- a/apps/include/apps.h +++ b/apps/include/apps.h @@ -41,7 +41,7 @@ * this is true for some implementations of the is*() functions, for * example. */ -#define _UC(c) ((unsigned char)(c)) +# define _UC(c) ((unsigned char)(c)) void app_RAND_load_conf(CONF *c, const char *section); void app_RAND_write(void); @@ -126,7 +126,7 @@ __owur int ctx_set_verify_locations(SSL_CTX *ctx, const char *CApath, int noCApath, const char *CAstore, int noCAstore); -#ifndef OPENSSL_NO_CT +# ifndef OPENSSL_NO_CT /* * Sets the file to load the Certificate Transparency log list from. @@ -135,9 +135,10 @@ __owur int ctx_set_verify_locations(SSL_CTX *ctx, */ __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path); -#endif +# endif -ENGINE *setup_engine(const char *engine, int debug); +ENGINE *setup_engine_methods(const char *id, unsigned int methods, int debug); +# define setup_engine(e, debug) setup_engine_methods(e, (unsigned int)-1, debug) void release_engine(ENGINE *e); # ifndef OPENSSL_NO_OCSP diff --git a/apps/lib/apps.c b/apps/lib/apps.c index 8063a0e272..4337cc6c87 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -1115,29 +1115,28 @@ static ENGINE *try_load_engine(const char *engine) } #endif -ENGINE *setup_engine(const char *engine, int debug) +ENGINE *setup_engine_methods(const char *id, unsigned int methods, int debug) { ENGINE *e = NULL; #ifndef OPENSSL_NO_ENGINE - if (engine != NULL) { - if (strcmp(engine, "auto") == 0) { + if (id != NULL) { + if (strcmp(id, "auto") == 0) { BIO_printf(bio_err, "Enabling auto ENGINE support\n"); ENGINE_register_all_complete(); return NULL; } - if ((e = ENGINE_by_id(engine)) == NULL - && (e = try_load_engine(engine)) == NULL) { - BIO_printf(bio_err, "Invalid engine \"%s\"\n", engine); + if ((e = ENGINE_by_id(id)) == NULL + && (e = try_load_engine(id)) == NULL) { + BIO_printf(bio_err, "Invalid engine \"%s\"\n", id); ERR_print_errors(bio_err); return NULL; } - if (debug) { - ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM, 0, bio_err, 0); - } - ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, (void *)get_ui_method(), - 0, 1); - if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) { + if (debug) + (void)ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM, 0, bio_err, 0); + if (!ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, + (void *)get_ui_method(), 0, 1) + || !ENGINE_set_default(e, methods)) { BIO_printf(bio_err, "Cannot use engine \"%s\"\n", ENGINE_get_id(e)); ERR_print_errors(bio_err); ENGINE_free(e); diff --git a/apps/s_server.c b/apps/s_server.c index bbc311befd..09bcc0cfb8 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -1576,7 +1576,9 @@ int s_server_main(int argc, char *argv[]) session_id_prefix = opt_arg(); break; case OPT_ENGINE: - engine = setup_engine(opt_arg(), 1); +#ifndef OPENSSL_NO_ENGINE + engine = setup_engine(opt_arg(), s_debug); +#endif break; case OPT_R_CASES: if (!opt_rand(o)) -- 2.34.1