diff options
author | Richard Levitte <levitte@openssl.org> | 2017-07-01 12:14:37 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2017-07-03 07:51:04 +0200 |
commit | 48feaceb53fa6ae924e298b8eba0e247019313e4 (patch) | |
tree | 535524c1e9e1f24c7e0341e7721416c8e5d175eb /apps/apps.c | |
parent | 6e2f49b38429d9df00ed12ade60e3de3b9ba43b3 (diff) |
Remove the possibility to disable the UI module entirely
Instead, make it possible to disable the console reader that's part of
the UI module. This makes it possible to use the UI API and other UI
methods in environments where the console reader isn't useful.
To disable the console reader, configure with 'no-ui-console' /
'disable-ui-console'.
'no-ui' / 'disable-ui' is now an alias for 'no-ui-console' /
'disable-ui-console'.
Fixes #3806
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3820)
Diffstat (limited to 'apps/apps.c')
-rw-r--r-- | apps/apps.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/apps/apps.c b/apps/apps.c index a89d4eb5e6..8b1aab4c4d 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -56,9 +56,8 @@ typedef struct { unsigned long mask; } NAME_EX_TBL; -#if !defined(OPENSSL_NO_UI) || !defined(OPENSSL_NO_ENGINE) static UI_METHOD *ui_method = NULL; -#endif +static const UI_METHOD *ui_fallback_method = NULL; static int set_table_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL * in_tbl); @@ -176,14 +175,19 @@ int dump_cert_text(BIO *out, X509 *x) return 0; } -#ifndef OPENSSL_NO_UI static int ui_open(UI *ui) { - return UI_method_get_opener(UI_OpenSSL())(ui); + int (*opener)(UI *ui) = UI_method_get_opener(ui_fallback_method); + + if (opener) + return opener(ui); + return 1; } static int ui_read(UI *ui, UI_STRING *uis) { + int (*reader)(UI *ui, UI_STRING *uis) = NULL; + if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && UI_get0_user_data(ui)) { switch (UI_get_string_type(uis)) { @@ -205,11 +209,17 @@ static int ui_read(UI *ui, UI_STRING *uis) break; } } - return UI_method_get_reader(UI_OpenSSL())(ui, uis); + + reader = UI_method_get_reader(ui_fallback_method); + if (reader) + return reader(ui, uis); + return 1; } static int ui_write(UI *ui, UI_STRING *uis) { + int (*writer)(UI *ui, UI_STRING *uis) = NULL; + if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && UI_get0_user_data(ui)) { switch (UI_get_string_type(uis)) { @@ -229,16 +239,28 @@ static int ui_write(UI *ui, UI_STRING *uis) break; } } - return UI_method_get_writer(UI_OpenSSL())(ui, uis); + + writer = UI_method_get_reader(ui_fallback_method); + if (writer) + return writer(ui, uis); + return 1; } static int ui_close(UI *ui) { - return UI_method_get_closer(UI_OpenSSL())(ui); + int (*closer)(UI *ui) = UI_method_get_closer(ui_fallback_method); + + if (closer) + return closer(ui); + return 1; } int setup_ui_method(void) { + ui_fallback_method = UI_null(); +#ifndef OPENSSL_NO_UI_CONSOLE + 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); @@ -259,24 +281,13 @@ const UI_METHOD *get_ui_method(void) { return ui_method; } -#endif int password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_tmp) { int res = 0; -#ifndef OPENSSL_NO_UI UI *ui = NULL; -#endif PW_CB_DATA *cb_data = (PW_CB_DATA *)cb_tmp; -#ifdef OPENSSL_NO_UI - if (cb_data != NULL && cb_data->password != NULL) { - res = strlen(cb_data->password); - if (res > bufsiz) - res = bufsiz; - memcpy(buf, cb_data->password, res); - } -#else ui = UI_new_method(ui_method); if (ui) { int ok = 0; @@ -331,7 +342,6 @@ int password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_tmp) UI_free(ui); OPENSSL_free(prompt); } -#endif return res; } |