summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-05-11 15:31:53 +0200
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-09-10 22:01:07 +0200
commitd3dbc9b50043fd1b4464b3f2b0ab8c54075099d6 (patch)
treedd14564465fa9c3533407049553a0f76a82ab3ae
parentapps_ui.c: Correct handling of empty password from -passin (diff)
downloadopenssl-d3dbc9b50043fd1b4464b3f2b0ab8c54075099d6.tar.xz
openssl-d3dbc9b50043fd1b4464b3f2b0ab8c54075099d6.zip
apps_ui.c: Correct password prompt for ui_method
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/12493)
-rw-r--r--apps/lib/apps_ui.c13
-rw-r--r--crypto/ui/ui_lib.c18
-rw-r--r--doc/man3/UI_new.pod10
-rw-r--r--include/openssl/ui.h17
4 files changed, 36 insertions, 22 deletions
diff --git a/apps/lib/apps_ui.c b/apps/lib/apps_ui.c
index dd794ec747..880e9a4f6d 100644
--- a/apps/lib/apps_ui.c
+++ b/apps/lib/apps_ui.c
@@ -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();
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);