make sure .rnd exists
[openssl.git] / apps / pkcs8.c
index 852a43558415265880de73160dc3322ad91af63d..c0becce9033776af57798a59529eb74cb8ba23ea 100644 (file)
@@ -62,7 +62,6 @@
 #include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/pkcs12.h>
-#include <openssl/engine.h>
 
 #include "apps.h"
 #define PROG pkcs8_main
@@ -185,23 +184,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");
@@ -233,21 +216,13 @@ int MAIN(int argc, char **argv)
                }
 #endif
        }
-       if (topk8) {
-               if(informat == FORMAT_PEM)
-                       pkey = PEM_read_bio_PrivateKey(in, NULL, NULL, passin);
-               else if(informat == FORMAT_ASN1)
-                       pkey = d2i_PrivateKey_bio(in, NULL);
-               else {
-                       BIO_printf(bio_err, "Bad format specified for key\n");
-                       return (1);
-               }
+       if (topk8)
+               {
+               BIO_free(in); /* Not needed in this section */
+               pkey = load_key(bio_err, infile, informat, passin, e, "key");
                if (!pkey) {
-                       BIO_printf(bio_err, "Error reading key\n", outfile);
-                       ERR_print_errors(bio_err);
                        return (1);
                }
-               BIO_free(in);
                if (!(p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken))) {
                        BIO_printf(bio_err, "Error converting key\n", outfile);
                        ERR_print_errors(bio_err);