Provide an application-common setup function for engines and use it
authorRichard Levitte <levitte@openssl.org>
Mon, 18 Jun 2001 06:22:33 +0000 (06:22 +0000)
committerRichard Levitte <levitte@openssl.org>
Mon, 18 Jun 2001 06:22:33 +0000 (06:22 +0000)
everywhere.

26 files changed:
apps/apps.c
apps/apps.h
apps/ca.c
apps/dgst.c
apps/dh.c
apps/dhparam.c
apps/dsa.c
apps/dsaparam.c
apps/enc.c
apps/gendh.c
apps/gendsa.c
apps/genrsa.c
apps/pkcs12.c
apps/pkcs7.c
apps/pkcs8.c
apps/rand.c
apps/req.c
apps/rsa.c
apps/rsautl.c
apps/s_client.c
apps/s_server.c
apps/smime.c
apps/speed.c
apps/spkac.c
apps/verify.c
apps/x509.c

index 659a3ad7fd03a2b1514ca44fde3f2fb00598c9a7..dd19a4cc3a1ba67941884b23cde1f3a86a4b54f0 100644 (file)
@@ -1037,3 +1037,32 @@ X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath)
        X509_STORE_free(store);
        return NULL;
 }
+
+ENGINE *setup_engine(BIO *err, const char *engine, int debug)
+        {
+        ENGINE *e = NULL;
+
+        if (engine)
+                {
+               if((e = ENGINE_by_id(engine)) == NULL)
+                       {
+                       BIO_printf(err,"invalid engine \"%s\"\n", engine);
+                       return NULL;
+                       }
+               if (debug)
+                       {
+                       ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
+                               0, err, 0);
+                       }
+                ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, UI_OpenSSL(), 0, 1);
+               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
+                       {
+                       BIO_printf(err,"can't use that engine\n");
+                       return NULL;
+                       }
+               BIO_printf(err,"engine \"%s\" set.\n", engine);
+               /* Free our "structural" reference. */
+               ENGINE_free(e);
+               }
+        return e;
+        }
index a2b72f087838bb028185bc604ac03ba80079c6d2..7fbd41769b0e9aad1c0535ecda4db7ba2f02a0fc 100644 (file)
@@ -176,6 +176,7 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
 STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
        const char *pass, ENGINE *e, const char *cert_descrip);
 X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
+ENGINE *setup_engine(BIO *err, const char *engine, int debug);
 
 #define FORMAT_UNDEF    0
 #define FORMAT_ASN1     1
index 921e1f184068a6113452256df762d8ff9101673d..4c67b121b14b29118acb207f969b2127ca596807 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -549,23 +549,7 @@ bad:
 
        ERR_load_crypto_strings();
 
-       if (engine != NULL)
-               {
-               if ((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto err;
-                       }
-               if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto err;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        /*****************************************************************/
        if (configfile == NULL) configfile = getenv("OPENSSL_CONF");
index a010ba071960814cab4251fcee84f01d09b220ea..1fbef6bed21ef28716cd6eb8e64d8aebdb85c594 100644 (file)
@@ -225,23 +225,7 @@ int MAIN(int argc, char **argv)
                goto end;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        in=BIO_new(BIO_s_file());
        bmd=BIO_new(BIO_f_md());
index 6162e442bae86d67353d4517ec9effa17b4f3e94..20581f66495871df3026f067f771efdf14e76362 100644 (file)
--- a/apps/dh.c
+++ b/apps/dh.c
@@ -174,23 +174,7 @@ bad:
 
        ERR_load_crypto_strings();
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        in=BIO_new(BIO_s_file());
        out=BIO_new(BIO_s_file());
index bbc64d5eb08d76c0ca3737b128a1ac43f8c8c503..51aee97d258a23819b3a0de5975d8468fcac1065 100644 (file)
@@ -257,23 +257,7 @@ bad:
 
        ERR_load_crypto_strings();
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if (g && !num)
                num = DEFBITS;
index 6e9e6c7566068876d740f48ad68a8bde8e59d0b3..4f45edac6bf4986db85ceca514e8b23ab4162551 100644 (file)
@@ -198,23 +198,7 @@ bad:
 
        ERR_load_crypto_strings();
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = ENGINE_setup(engine, bio_err);
 
        if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
                BIO_printf(bio_err, "Error getting passwords\n");
index e923f10dbb0e05b524d3f3ccbda8406e1677c121..7ce49d90c3658a03c38cd9698120a80c44c5f430 100644 (file)
@@ -232,23 +232,7 @@ bad:
                        }
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = ENGINE_setup(engine, bio_err);
 
        if (need_rand)
                {
index 332c2ba9dae4194954dd9b6da11c31d5c2a7ffe8..fd25a2122277599b93eb80cd47a947f33e030835 100644 (file)
@@ -285,23 +285,7 @@ bad:
                argv++;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if (bufsize != NULL)
                {
index 0b47867c2036289cb5144b60f29d73bd331e436f..14928d84a3e724b9378ed462463092a9515c5a41 100644 (file)
@@ -143,23 +143,7 @@ bad:
                goto end;
                }
                
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        out=BIO_new(BIO_s_file());
        if (out == NULL)
index 1166be44110dbd34058c497d1bb4b195901c170e..3fdbf3772217e22f60b979803adc4b6e3c532046 100644 (file)
@@ -162,23 +162,7 @@ bad:
                goto end;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = ENGINE_setup(engine, bio_err);
 
        if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) {
                BIO_printf(bio_err, "Error getting password\n");
index d67880811facf4c7a8fafc99dabec7979b11b07b..5d7fca404d2639c973eb3a16dd79c01279efbf46 100644 (file)
@@ -176,23 +176,7 @@ bad:
                goto err;
        }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto err;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto err;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if (outfile == NULL)
                {
index f277956cd96423fedbf2935f090afad259519693..e24a8401e21848bc25078d1d71040b5089175880 100644 (file)
@@ -300,19 +300,7 @@ int MAIN(int argc, char **argv)
        goto end;
     }
 
-    if (engine != NULL) {
-       if((e = ENGINE_by_id(engine)) == NULL) {
-           BIO_printf(bio_err,"invalid engine \"%s\"\n", engine);
-           goto end;
-       }
-       if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
-           BIO_printf(bio_err,"can't use that engine\n");
-           goto end;
-       }
-       BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-       /* Free our "structural" reference. */
-       ENGINE_free(e);
-    }
+    e = setup_engine(bio_err, engine, 0);
 
     if(passarg) {
        if(export_cert) passargout = passarg;
index 63ec8a5744d9e5964de959bfced9109aaffb3950..f3df25fe8b04ef7591bc82a4575321ab8eadf531 100644 (file)
@@ -168,23 +168,7 @@ bad:
 
        ERR_load_crypto_strings();
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        in=BIO_new(BIO_s_file());
        out=BIO_new(BIO_s_file());
index 852a43558415265880de73160dc3322ad91af63d..5e20a2be70b526eecff0c34082cca762ca7d37c9 100644 (file)
@@ -185,23 +185,7 @@ int MAIN(int argc, char **argv)
                return (1);
        }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       return (1);
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       return (1);
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
                BIO_printf(bio_err, "Error getting passwords\n");
index 8a216fbc75b2002fdf0b9195bf9003ff9ae88fa7..10adf0e95d81e3f3810987b9ee169afb145e5769 100644 (file)
@@ -101,23 +101,7 @@ int MAIN(int argc, char **argv)
                goto err;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto err;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto err;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        app_RAND_load_file(NULL, bio_err, (inrand != NULL));
        if (inrand != NULL)
index 429eb9d4a0e781768bb91579d73ca2d7a3ba7bd3..2999d509ba979bd8b982d9e2c3fa30ea35c5cdd7 100644 (file)
@@ -586,23 +586,7 @@ bad:
        if ((in == NULL) || (out == NULL))
                goto end;
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if (keyfile != NULL)
                {
index bdfe2189ba3656f676985fe33ec069d5468dd079..5b671e135ec3b5e85ff746a67431c0c4dbcb0035 100644 (file)
@@ -209,23 +209,7 @@ bad:
 
        ERR_load_crypto_strings();
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
                BIO_printf(bio_err, "Error getting passwords\n");
index 86aa95d38a6b26456bf0e888a6c4a550d57abc6d..56025c5f0cc1719bcca6f5a36543139c85d31e42 100644 (file)
@@ -157,23 +157,7 @@ int MAIN(int argc, char **argv)
                goto end;
        }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
 /* FIXME: seed PRNG only if needed */
        app_RAND_load_file(NULL, bio_err, 0);
index bad59f64683601aa848fad16419faac3b6fba815..009aa83e4eefb466b7690be99268f4f9ada1a682 100644 (file)
@@ -382,28 +382,7 @@ bad:
        OpenSSL_add_ssl_algorithms();
        SSL_load_error_strings();
 
-       if (engine_id != NULL)
-               {
-               if((e = ENGINE_by_id(engine_id)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine\n");
-                       ERR_print_errors(bio_err);
-                       goto end;
-                       }
-               if (c_debug)
-                       {
-                       ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
-                               0, bio_err, 0);
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       ERR_print_errors(bio_err);
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine_id);
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine_id, 1);
 
        ctx=SSL_CTX_new(meth);
        if (ctx == NULL)
index 8d76c8f3fa188cbf0165503981a871e6e68040bd..11971cb8c98c855a07ab4d57dfd20bff517e7282 100644 (file)
@@ -657,28 +657,7 @@ bad:
        SSL_load_error_strings();
        OpenSSL_add_ssl_algorithms();
 
-       if (engine_id != NULL)
-               {
-               if((e = ENGINE_by_id(engine_id)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine\n");
-                       ERR_print_errors(bio_err);
-                       goto end;
-                       }
-               if (s_debug)
-                       {
-                       ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
-                               0, bio_err, 0);
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       ERR_print_errors(bio_err);
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine_id);
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine_id, 1);
 
        ctx=SSL_CTX_new(meth);
        if (ctx == NULL)
index 869933459b53a886b90e6fd1e18a92e5c4239678..1ff4ed02fe8ee681639728d8758b655861f87d4e 100644 (file)
@@ -319,23 +319,7 @@ int MAIN(int argc, char **argv)
                goto end;
        }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if(!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
                BIO_printf(bio_err, "Error getting password\n");
index 27e6c432929d71c2a705fdcabfe7bc44c2b34b1b..dd3270f6eb389185f8692a1936dc4e2137fe94af 100644 (file)
@@ -505,21 +505,8 @@ int MAIN(int argc, char **argv)
                                BIO_printf(bio_err,"no engine given\n");
                                goto end;
                                }
-                       if((e = ENGINE_by_id(*argv)) == NULL)
-                               {
-                               BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                                       *argv);
-                               goto end;
-                               }
-                       if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                               {
-                               BIO_printf(bio_err,"can't use that engine\n");
-                               goto end;
-                               }
-                       BIO_printf(bio_err,"engine \"%s\" set.\n", *argv);
-                       /* Free our "structural" reference. */
-                       ENGINE_free(e);
-                       /* It will be increased again further down.  We just
+                        e = setup_engine(bio_err, *argv, 0);
+                       /* j will be increased again further down.  We just
                           don't want speed to confuse an engine with an
                           algorithm, especially when none is given (which
                           means all of them should be run) */
index 5ac9b14c54b2035c56cb1989d240ff0272ea53b9..538a419345eb0f51d3a045aacd9f0e3935cb4974 100644 (file)
@@ -179,23 +179,7 @@ bad:
                goto end;
        }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if(keyfile) {
                if(strcmp(keyfile, "-")) key = BIO_new_file(keyfile, "r");
index 5b9d719d9f127863efdc0bda75462685012bde95..d5f07c2db46507eebeae66e6bf19fb9ea559533f 100644 (file)
@@ -166,23 +166,7 @@ int MAIN(int argc, char **argv)
                        break;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());
        if (lookup == NULL) abort();
index 5be90740c66e6a1fb01f621d5d98bc54a6d17a78..b2e4ec631f9526967433c21a554645453642503e 100644 (file)
@@ -448,23 +448,7 @@ bad:
                goto end;
                }
 
-       if (engine != NULL)
-               {
-               if((e = ENGINE_by_id(engine)) == NULL)
-                       {
-                       BIO_printf(bio_err,"invalid engine \"%s\"\n",
-                               engine);
-                       goto end;
-                       }
-               if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
-                       {
-                       BIO_printf(bio_err,"can't use that engine\n");
-                       goto end;
-                       }
-               BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
-               /* Free our "structural" reference. */
-               ENGINE_free(e);
-               }
+        e = setup_engine(bio_err, engine, 0);
 
        if (need_rand)
                app_RAND_load_file(NULL, bio_err, 0);