Signal an error if the entered output password didn't match itself.
[oweals/openssl.git] / apps / pkcs8.c
index cfc4851e00a6ddd3a8904cfc94bcdc40f3c6152c..8464c439967cc02fa43e2fc2171e286848d82b75 100644 (file)
@@ -62,9 +62,7 @@
 #include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/pkcs12.h>
-#include <openssl/engine.h>
 
-#include "apps.h"
 #define PROG pkcs8_main
 
 int MAIN(int, char **);
@@ -84,13 +82,16 @@ int MAIN(int argc, char **argv)
        int nocrypt = 0;
        X509_SIG *p8;
        PKCS8_PRIV_KEY_INFO *p8inf;
-       EVP_PKEY *pkey;
+       EVP_PKEY *pkey=NULL;
        char pass[50], *passin = NULL, *passout = NULL, *p8pass = NULL;
        int badarg = 0;
        char *engine=NULL;
 
        if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
 
+       if (!load_config(bio_err, NULL))
+               goto end;
+
        informat=FORMAT_PEM;
        outformat=FORMAT_PEM;
 
@@ -220,7 +221,8 @@ int MAIN(int argc, char **argv)
        if (topk8)
                {
                BIO_free(in); /* Not needed in this section */
-               pkey = load_key(bio_err, infile, informat, passin, e, "key");
+               pkey = load_key(bio_err, infile, informat, 1,
+                       passin, e, "key");
                if (!pkey) {
                        return (1);
                }
@@ -242,7 +244,8 @@ int MAIN(int argc, char **argv)
                        if(passout) p8pass = passout;
                        else {
                                p8pass = pass;
-                               EVP_read_pw_string(pass, 50, "Enter Encryption Password:", 1);
+                               if (EVP_read_pw_string(pass, 50, "Enter Encryption Password:", 1))
+                                       return (1);
                        }
                        app_RAND_load_file(NULL, bio_err, 0);
                        if (!(p8 = PKCS8_encrypt(pbe_nid, cipher,
@@ -348,6 +351,7 @@ int MAIN(int argc, char **argv)
                        return (1);
        }
 
+       end:
        EVP_PKEY_free(pkey);
        BIO_free_all(out);
        BIO_free(in);