Stop spurious "unable to load config info" errors in req
[openssl.git] / apps / dgst.c
index a6b2e30..7989a1d 100644 (file)
@@ -66,7 +66,6 @@
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
-#include <openssl/engine.h>
 
 #undef BUFSIZE
 #define BUFSIZE        1024*8
@@ -225,23 +224,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());
@@ -289,52 +272,19 @@ int MAIN(int argc, char **argv)
 
        if(keyfile)
                {
-               if (keyform == FORMAT_PEM)
-                       {
-                       BIO *keybio;
-                       keybio = BIO_new_file(keyfile, "r");
-                       if(!keybio)
-                               {
-                               BIO_printf(bio_err,
-                                       "Error opening key file %s\n",
-                                       keyfile);
-                               ERR_print_errors(bio_err);
-                               goto end;
-                               }
-                       if(want_pub) 
-                               sigkey = PEM_read_bio_PUBKEY(keybio,
-                                       NULL, NULL, NULL);
-                       else
-                               sigkey = PEM_read_bio_PrivateKey(keybio,
-                                       NULL, NULL, NULL);
-                       BIO_free(keybio);
-                       }
-               else if (keyform == FORMAT_ENGINE)
-                       {
-                       if (!e)
-                               {
-                               BIO_printf(bio_err,"no engine specified\n");
-                               goto end;
-                               }
-                       if (want_pub)
-                               sigkey = ENGINE_load_public_key(e, keyfile, NULL);
-                       else
-                               sigkey = ENGINE_load_private_key(e, keyfile, NULL);
-                       }
+               if (want_pub)
+                       sigkey = load_pubkey(bio_err, keyfile, keyform, NULL,
+                               e, "key file");
                else
+                       sigkey = load_key(bio_err, keyfile, keyform, NULL,
+                               e, "key file");
+               if (!sigkey)
                        {
-                       BIO_printf(bio_err,
-                               "bad input format specified for key file\n");
+                       /* load_[pub]key() has already printed an appropriate
+                          message */
                        goto end;
                        }
-               
-               if(!sigkey) {
-                       BIO_printf(bio_err, "Error reading key file %s\n",
-                                                               keyfile);
-                       ERR_print_errors(bio_err);
-                       goto end;
                }
-       }
 
        if(sigfile && sigkey) {
                BIO *sigbio;
@@ -396,6 +346,7 @@ end:
        EVP_PKEY_free(sigkey);
        if(sigbuf) OPENSSL_free(sigbuf);
        if (bmd != NULL) BIO_free(bmd);
+       apps_shutdown();
        EXIT(err);
        }