From: Richard Levitte Date: Wed, 28 Sep 2016 19:28:00 +0000 (+0200) Subject: apps/apps.c: initialize and de-initialize engine around key loading X-Git-Tag: OpenSSL_1_1_1-pre1~3441 X-Git-Url: https://git.openssl.org/?p=openssl.git;a=commitdiff_plain;h=49e476a5382602d0bad1139d6f1f66ddbc7959d6;hp=56e36bdaef442536681bce2a1579385c0279bec8 apps/apps.c: initialize and de-initialize engine around key loading Before loading a key from an engine, it may need to be initialized. When done loading the key, we must de-initialize the engine. (if the engine is already initialized somehow, only the reference counter will be incremented then decremented) Reviewed-by: Stephen Henson --- diff --git a/apps/apps.c b/apps/apps.c index b2877480a0..68f2f2710a 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -700,7 +700,10 @@ EVP_PKEY *load_key(const char *file, int format, int maybe_stdin, BIO_printf(bio_err, "no engine specified\n"); else { #ifndef OPENSSL_NO_ENGINE - pkey = ENGINE_load_private_key(e, file, ui_method, &cb_data); + if (ENGINE_init(e)) { + pkey = ENGINE_load_private_key(e, file, ui_method, &cb_data); + ENGINE_finish(e); + } if (pkey == NULL) { BIO_printf(bio_err, "cannot load %s from engine\n", key_descrip); ERR_print_errors(bio_err);