ENGINE_register_all_complete() will register all implementations of all
[openssl.git] / apps / apps.c
index 9bbf476245c8f783ebbfe723e82f4456a252f57d..1089c8b8a3d6ab7bcbf0dca2032400cdd0f82b95 100644 (file)
@@ -71,6 +71,7 @@
 #include <openssl/pkcs12.h>
 #include <openssl/ui.h>
 #include <openssl/safestack.h>
+#include <openssl/engine.h>
 
 #ifdef OPENSSL_SYS_WINDOWS
 #define strcasecmp _stricmp
@@ -390,7 +391,7 @@ static int ui_read(UI *ui, UI_STRING *uis)
                                ((PW_CB_DATA *)UI_get0_user_data(ui))->password;
                        if (password[0] != '\0')
                                {
-                               UI_set_result(uis, password);
+                               UI_set_result(ui, uis, password);
                                return 1;
                                }
                        }
@@ -459,11 +460,18 @@ int password_callback(char *buf, int bufsiz, int verify,
                        prompt_info = cb_data->prompt_info;
                }
 
+       if (password)
+               {
+               res = strlen(password);
+               if (res > bufsiz)
+                       res = bufsiz;
+               memcpy(buf, password, res);
+               return res;
+               }
+
        ui = UI_new_method(ui_method);
        if (ui)
                {
-               char errstring[80];
-               int errstring_added = 0;
                int ok = 0;
                char *buff = NULL;
                int ui_flags = 0;
@@ -473,44 +481,32 @@ int password_callback(char *buf, int bufsiz, int verify,
                        cb_data->prompt_info);
 
                ui_flags |= UI_INPUT_FLAG_DEFAULT_PWD;
+               UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0);
 
                if (ok >= 0)
-                       ok = UI_add_input_string(ui,prompt,ui_flags,buf,0,BUFSIZ-1);
+                       ok = UI_add_input_string(ui,prompt,ui_flags,buf,
+                               PW_MIN_LENGTH,BUFSIZ-1);
                if (ok >= 0 && verify)
                        {
                        buff = (char *)OPENSSL_malloc(bufsiz);
-                       ok = UI_add_verify_string(ui,prompt,ui_flags,buff,0,BUFSIZ-1,
-                               buf);
+                       ok = UI_add_verify_string(ui,prompt,ui_flags,buff,
+                               PW_MIN_LENGTH,BUFSIZ-1, buf);
                        }
                if (ok >= 0)
-                       for(;;)
+                       do
                                {
-                               res = 0;
-                               ok=UI_process(ui);
-                               if (ok < 0)
-                                       break;
-                               res=strlen(buf);
-                               if (res < PW_MIN_LENGTH)
-                                       {
-                                       if (errstring_added == 0)
-                                               {
-                                               BIO_snprintf(errstring,
-                                                       sizeof(errstring),
-"phrase is too short, needs to be at least %d chars\n", PW_MIN_LENGTH);
-                                               UI_add_error_string(ui,
-                                                       errstring);
-                                               }
-                                       errstring_added = 1;
-                                       }
-                               else
-                                       break;
+                               ok = UI_process(ui);
                                }
+                       while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0));
+
                if (buff)
                        {
-                       memset(buf,0,(unsigned int)bufsiz);
+                       memset(buff,0,(unsigned int)bufsiz);
                        OPENSSL_free(buff);
                        }
 
+               if (ok >= 0)
+                       res = strlen(buf);
                if (ok == -1)
                        {
                        BIO_printf(bio_err, "User interface error\n");
@@ -525,6 +521,7 @@ int password_callback(char *buf, int bufsiz, int verify,
                        res = 0;
                        }
                UI_free(ui);
+               OPENSSL_free(prompt);
                }
        return res;
        }
@@ -604,18 +601,18 @@ static char *app_get_pass(BIO *err, char *arg, int keepbio)
        return BUF_strdup(tpass);
 }
 
-int add_oid_section(BIO *err, LHASH *conf)
+int add_oid_section(BIO *err, CONF *conf)
 {      
        char *p;
        STACK_OF(CONF_VALUE) *sktmp;
        CONF_VALUE *cnf;
        int i;
-       if(!(p=CONF_get_string(conf,NULL,"oid_section")))
+       if(!(p=NCONF_get_string(conf,NULL,"oid_section")))
                {
                ERR_clear_error();
                return 1;
                }
-       if(!(sktmp = CONF_get_section(conf, p))) {
+       if(!(sktmp = NCONF_get_section(conf, p))) {
                BIO_printf(err, "problem loading oid section %s\n", p);
                return 0;
        }
@@ -1153,6 +1150,12 @@ ENGINE *setup_engine(BIO *err, const char *engine, int debug)
 
         if (engine)
                 {
+               if(strcmp(engine, "auto") == 0)
+                       {
+                       BIO_printf(err,"enabling auto ENGINE support\n");
+                       ENGINE_register_all_complete();
+                       return NULL;
+                       }
                if((e = ENGINE_by_id(engine)) == NULL)
                        {
                        BIO_printf(err,"invalid engine \"%s\"\n", engine);
@@ -1169,7 +1172,9 @@ ENGINE *setup_engine(BIO *err, const char *engine, int debug)
                        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);
                }