[openssl] master update

dev at ddvo.net dev at ddvo.net
Thu Sep 10 20:01:48 UTC 2020


The branch master has been updated
       via  d3dbc9b50043fd1b4464b3f2b0ab8c54075099d6 (commit)
       via  591ceeddb349d735480102f1992c868663b2c580 (commit)
       via  f84de16f397b06831ea5569a285518c035285f46 (commit)
      from  9a62ccbe8a73101d2cfcdf7902b6fe10da7602c9 (commit)


- Log -----------------------------------------------------------------
commit d3dbc9b50043fd1b4464b3f2b0ab8c54075099d6
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Mon May 11 15:31:53 2020 +0200

    apps_ui.c: Correct password prompt for ui_method
    
    Reviewed-by: Tomas Mraz <tmraz at fedoraproject.org>
    (Merged from https://github.com/openssl/openssl/pull/12493)

commit 591ceeddb349d735480102f1992c868663b2c580
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Mon May 11 15:32:26 2020 +0200

    apps_ui.c: Correct handling of empty password from -passin
    
    This is done in analogy to commit ca3245a61989009a99931748723d12e30d0a66b2
    
    Reviewed-by: Tomas Mraz <tmraz at fedoraproject.org>
    (Merged from https://github.com/openssl/openssl/pull/12493)

commit f84de16f397b06831ea5569a285518c035285f46
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Tue Aug 4 10:11:02 2020 +0200

    apps_ui.c: Improve error handling and return value of setup_ui_method()
    
    Reviewed-by: Tomas Mraz <tmraz at fedoraproject.org>
    (Merged from https://github.com/openssl/openssl/pull/12493)

-----------------------------------------------------------------------

Summary of changes:
 apps/lib/apps_ui.c   | 29 ++++++++++++++++++++++-------
 apps/openssl.c       |  2 +-
 crypto/ui/ui_lib.c   | 18 ++++++++----------
 doc/man3/UI_new.pod  | 10 ++++++----
 include/openssl/ui.h | 17 +++++++++--------
 test/uitest.c        |  2 +-
 6 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/apps/lib/apps_ui.c b/apps/lib/apps_ui.c
index 13f8670d9f..880e9a4f6d 100644
--- a/apps/lib/apps_ui.c
+++ b/apps/lib/apps_ui.c
@@ -15,7 +15,6 @@
 static UI_METHOD *ui_method = NULL;
 static const UI_METHOD *ui_fallback_method = NULL;
 
-
 static int ui_open(UI *ui)
 {
     int (*opener)(UI *ui) = UI_method_get_opener(ui_fallback_method);
@@ -72,7 +71,8 @@ static int ui_write(UI *ui, UI_STRING *uis)
             {
                 const char *password =
                     ((PW_CB_DATA *)UI_get0_user_data(ui))->password;
-                if (password && password[0] != '\0')
+
+                if (password != NULL)
                     return 1;
             }
             break;
@@ -99,6 +99,19 @@ static int ui_close(UI *ui)
     return 1;
 }
 
+/* object_name defaults to prompt_info from ui user data if present */
+static char *ui_prompt_construct(UI *ui, const char *phrase_desc,
+                                 const char *object_name)
+{
+    PW_CB_DATA *cb_data = (PW_CB_DATA *)UI_get0_user_data(ui);
+
+    if (phrase_desc == NULL)
+        phrase_desc = "pass phrase";
+    if (object_name == NULL && cb_data != NULL)
+        object_name = cb_data->prompt_info;
+    return UI_construct_prompt(NULL, phrase_desc, object_name);
+}
+
 int setup_ui_method(void)
 {
     ui_fallback_method = UI_null();
@@ -106,11 +119,13 @@ int setup_ui_method(void)
     ui_fallback_method = UI_OpenSSL();
 #endif
     ui_method = UI_create_method("OpenSSL application user interface");
-    UI_method_set_opener(ui_method, ui_open);
-    UI_method_set_reader(ui_method, ui_read);
-    UI_method_set_writer(ui_method, ui_write);
-    UI_method_set_closer(ui_method, ui_close);
-    return 0;
+    return ui_method != NULL
+        && 0 == UI_method_set_opener(ui_method, ui_open)
+        && 0 == UI_method_set_reader(ui_method, ui_read)
+        && 0 == UI_method_set_writer(ui_method, ui_write)
+        && 0 == UI_method_set_closer(ui_method, ui_close)
+        && 0 == UI_method_set_prompt_constructor(ui_method,
+                                                 ui_prompt_construct);
 }
 
 void destroy_ui_method(void)
diff --git a/apps/openssl.c b/apps/openssl.c
index 6b2c2b9c6b..b426f594b3 100644
--- a/apps/openssl.c
+++ b/apps/openssl.c
@@ -68,7 +68,7 @@ static int apps_startup(void)
                           | OPENSSL_INIT_LOAD_CONFIG, NULL))
         return 0;
 
-    setup_ui_method();
+    (void)setup_ui_method();
 
     /*
      * NOTE: This is an undocumented feature required for testing only.
diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c
index 85bf8c1f80..8c6dc6dd89 100644
--- a/crypto/ui/ui_lib.c
+++ b/crypto/ui/ui_lib.c
@@ -356,22 +356,22 @@ int UI_dup_error_string(UI *ui, const char *text)
                                    0, 0, NULL);
 }
 
-char *UI_construct_prompt(UI *ui, const char *object_desc,
+char *UI_construct_prompt(UI *ui, const char *phrase_desc,
                           const char *object_name)
 {
     char *prompt = NULL;
 
-    if (ui->meth->ui_construct_prompt != NULL)
-        prompt = ui->meth->ui_construct_prompt(ui, object_desc, object_name);
+    if (ui != NULL && ui->meth != NULL && ui->meth->ui_construct_prompt != NULL)
+        prompt = ui->meth->ui_construct_prompt(ui, phrase_desc, object_name);
     else {
         char prompt1[] = "Enter ";
         char prompt2[] = " for ";
         char prompt3[] = ":";
         int len = 0;
 
-        if (object_desc == NULL)
+        if (phrase_desc == NULL)
             return NULL;
-        len = sizeof(prompt1) - 1 + strlen(object_desc);
+        len = sizeof(prompt1) - 1 + strlen(phrase_desc);
         if (object_name != NULL)
             len += sizeof(prompt2) - 1 + strlen(object_name);
         len += sizeof(prompt3) - 1;
@@ -381,7 +381,7 @@ char *UI_construct_prompt(UI *ui, const char *object_desc,
             return NULL;
         }
         OPENSSL_strlcpy(prompt, prompt1, len + 1);
-        OPENSSL_strlcat(prompt, object_desc, len + 1);
+        OPENSSL_strlcat(prompt, phrase_desc, len + 1);
         if (object_name != NULL) {
             OPENSSL_strlcat(prompt, prompt2, len + 1);
             OPENSSL_strlcat(prompt, object_name, len + 1);
@@ -690,10 +690,8 @@ int UI_method_set_data_duplicator(UI_METHOD *method,
 
 int UI_method_set_prompt_constructor(UI_METHOD *method,
                                      char *(*prompt_constructor) (UI *ui,
-                                                                  const char
-                                                                  *object_desc,
-                                                                  const char
-                                                                  *object_name))
+                                                                  const char *,
+                                                                  const char *))
 {
     if (method != NULL) {
         method->ui_construct_prompt = prompt_constructor;
diff --git a/doc/man3/UI_new.pod b/doc/man3/UI_new.pod
index 0615e2766c..c3852587eb 100644
--- a/doc/man3/UI_new.pod
+++ b/doc/man3/UI_new.pod
@@ -44,7 +44,7 @@ UI_get_method, UI_set_method, UI_OpenSSL, UI_null - user interface
  int UI_dup_error_string(UI *ui, const char *text);
 
  char *UI_construct_prompt(UI *ui_method,
-        const char *object_desc, const char *object_name);
+                           const char *phrase_desc, const char *object_name);
 
  void *UI_add_user_data(UI *ui, void *user_data);
  int UI_dup_user_data(UI *ui, void *user_data);
@@ -149,10 +149,12 @@ as their UI_add counterparts, except that they make their own copies
 of all strings.
 
 UI_construct_prompt() is a helper function that can be used to create
-a prompt from two pieces of information: an description and a name.
+a prompt from two pieces of information: a phrase description I<phrase_desc>
+and an object name I<object_name>, where the latter may be NULL.
 The default constructor (if there is none provided by the method used)
-creates a string "Enter I<description> for I<name>:".  With the
-description "pass phrase" and the filename "foo.key", that becomes
+creates a string "Enter I<phrase_desc> for I<object_name>:"
+where the " for I<object_name>" part is left out if I<object_name> is NULL.
+With the description "pass phrase" and the filename "foo.key", that becomes
 "Enter pass phrase for foo.key:".  Other methods may create whatever
 string and may include encodings that will be processed by the other
 method functions.
diff --git a/include/openssl/ui.h b/include/openssl/ui.h
index fa55d92ac8..f68a4e90a8 100644
--- a/include/openssl/ui.h
+++ b/include/openssl/ui.h
@@ -138,25 +138,26 @@ int UI_dup_error_string(UI *ui, const char *text);
 # define UI_INPUT_FLAG_USER_BASE 16
 
 /*-
- * The following function helps construct a prompt.  object_desc is a
- * textual short description of the object, for example "pass phrase",
- * and object_name is the name of the object (might be a card name or
- * a file name.
+ * The following function helps construct a prompt.
+ * phrase_desc is a textual short description of the phrase to enter,
+ * for example "pass phrase", and
+ * object_name is the name of the object
+ * (which might be a card name or a file name) or NULL.
  * The returned string shall always be allocated on the heap with
  * OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
  *
  * If the ui_method doesn't contain a pointer to a user-defined prompt
  * constructor, a default string is built, looking like this:
  *
- *       "Enter {object_desc} for {object_name}:"
+ *       "Enter {phrase_desc} for {object_name}:"
  *
- * So, if object_desc has the value "pass phrase" and object_name has
+ * So, if phrase_desc has the value "pass phrase" and object_name has
  * the value "foo.key", the resulting string is:
  *
  *       "Enter pass phrase for foo.key:"
 */
 char *UI_construct_prompt(UI *ui_method,
-                          const char *object_desc, const char *object_name);
+                          const char *phrase_desc, const char *object_name);
 
 /*
  * The following function is used to store a pointer to user-specific data.
@@ -315,7 +316,7 @@ int UI_method_set_data_duplicator(UI_METHOD *method,
 int UI_method_set_prompt_constructor(UI_METHOD *method,
                                      char *(*prompt_constructor) (UI *ui,
                                                                   const char
-                                                                  *object_desc,
+                                                                  *phrase_desc,
                                                                   const char
                                                                   *object_name));
 int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data);
diff --git a/test/uitest.c b/test/uitest.c
index 289f32b6b0..d45d57d9fb 100644
--- a/test/uitest.c
+++ b/test/uitest.c
@@ -78,7 +78,7 @@ static int test_new_ui(void)
     char pass[16];
     int ok = 0;
 
-    setup_ui_method();
+    (void)setup_ui_method();
     if (TEST_int_gt(password_callback(pass, sizeof(pass), 0, &cb_data), 0)
             && TEST_str_eq(pass, cb_data.password))
         ok = 1;


More information about the openssl-commits mailing list