apps/apps.c: initialize and de-initialize engine around key loading
authorRichard Levitte <levitte@openssl.org>
Wed, 28 Sep 2016 19:28:00 +0000 (21:28 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 28 Sep 2016 20:00:26 +0000 (22:00 +0200)
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 <steve@openssl.org>
(cherry picked from commit 49e476a5382602d0bad1139d6f1f66ddbc7959d6)

apps/apps.c

index 9fdc3e0097c5576cd3b99a63deb3095f7c5debbd..ff17b35820df0554bbe45cde5ad0b81e1f371591 100644 (file)
@@ -972,7 +972,10 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
         if (!e)
             BIO_printf(err, "no engine specified\n");
         else {
-            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) {
                 BIO_printf(err, "cannot load %s from engine\n", key_descrip);
                 ERR_print_errors(err);