"FALLBACK" handling was a hack that was thrown out long ago in the
[openssl.git] / apps / genrsa.c
index c263956c03e7c3f28fc5aa0e323d154a296dd22c..b5ae1beacf1fee70fdeaf42b6460a51080656df2 100644 (file)
@@ -69,7 +69,7 @@
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
-#include <openssl/engine.h>
+#include <openssl/rand.h>
 
 #define DEFBITS        512
 #undef PROG
@@ -86,7 +86,7 @@ int MAIN(int argc, char **argv)
        RSA *rsa=NULL;
        int i,num=DEFBITS;
        long l;
-       EVP_CIPHER *enc=NULL;
+       const EVP_CIPHER *enc=NULL;
        unsigned long f4=RSA_F4;
        char *outfile=NULL;
        char *passargout = NULL, *passout = NULL;
@@ -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)
                {
@@ -242,8 +226,14 @@ bad:
                l+=rsa->e->d[i];
                }
        BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l);
-       if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL, passout))
+       {
+       PW_CB_DATA cb_data;
+       cb_data.password = passout;
+       cb_data.prompt_info = outfile;
+       if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,
+               (pem_password_cb *)password_callback,&cb_data))
                goto err;
+       }
 
        ret=0;
 err:
@@ -252,6 +242,7 @@ err:
        if(passout) OPENSSL_free(passout);
        if (ret != 0)
                ERR_print_errors(bio_err);
+       apps_shutdown();
        EXIT(ret);
        }