diff options
author | bcook <> | 2015-09-13 12:41:01 +0000 |
---|---|---|
committer | bcook <> | 2015-09-13 12:41:01 +0000 |
commit | e2751f37728059d10cda50d45e3365a1110f26ff (patch) | |
tree | a928062f329b4a2f81c6d2b9910fde8181243c7a | |
parent | 2555ca7b86c3ba095a21111d3f7d00e279de8e4d (diff) | |
download | openbsd-e2751f37728059d10cda50d45e3365a1110f26ff.tar.gz openbsd-e2751f37728059d10cda50d45e3365a1110f26ff.tar.bz2 openbsd-e2751f37728059d10cda50d45e3365a1110f26ff.zip |
Factor out setup_up / destroy_ui functions.
This pulls out and renames setup_ui/destroy_ui so we have something that
can be replaced as-needed, moving the the console setup code for Windows
to app_win.c in -portable, instead of needing a local patch to enable binary
console mode
ui_read/write are also simplified.
Diffstat (limited to '')
-rw-r--r-- | src/usr.bin/openssl/apps.c | 77 | ||||
-rw-r--r-- | src/usr.bin/openssl/apps.h | 13 | ||||
-rw-r--r-- | src/usr.bin/openssl/apps_posix.c | 20 | ||||
-rw-r--r-- | src/usr.bin/openssl/openssl.c | 6 |
4 files changed, 58 insertions, 58 deletions
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index f8cad1a703..c2b786d3f9 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: apps.c,v 1.35 2015/09/11 14:30:23 bcook Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.36 2015/09/13 12:41:01 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -142,7 +142,6 @@ | |||
142 | #include <openssl/pem.h> | 142 | #include <openssl/pem.h> |
143 | #include <openssl/pkcs12.h> | 143 | #include <openssl/pkcs12.h> |
144 | #include <openssl/safestack.h> | 144 | #include <openssl/safestack.h> |
145 | #include <openssl/ui.h> | ||
146 | #include <openssl/x509.h> | 145 | #include <openssl/x509.h> |
147 | #include <openssl/x509v3.h> | 146 | #include <openssl/x509v3.h> |
148 | 147 | ||
@@ -154,7 +153,7 @@ typedef struct { | |||
154 | unsigned long mask; | 153 | unsigned long mask; |
155 | } NAME_EX_TBL; | 154 | } NAME_EX_TBL; |
156 | 155 | ||
157 | static UI_METHOD *ui_method = NULL; | 156 | UI_METHOD *ui_method = NULL; |
158 | 157 | ||
159 | static int set_table_opts(unsigned long *flags, const char *arg, | 158 | static int set_table_opts(unsigned long *flags, const char *arg, |
160 | const NAME_EX_TBL *in_tbl); | 159 | const NAME_EX_TBL *in_tbl); |
@@ -297,85 +296,59 @@ dump_cert_text(BIO *out, X509 *x) | |||
297 | return 0; | 296 | return 0; |
298 | } | 297 | } |
299 | 298 | ||
300 | static int | 299 | int |
301 | ui_open(UI *ui) | 300 | ui_open(UI *ui) |
302 | { | 301 | { |
303 | return UI_method_get_opener(UI_OpenSSL()) (ui); | 302 | return UI_method_get_opener(UI_OpenSSL()) (ui); |
304 | } | 303 | } |
305 | 304 | ||
306 | static int | 305 | int |
307 | ui_read(UI *ui, UI_STRING *uis) | 306 | ui_read(UI *ui, UI_STRING *uis) |
308 | { | 307 | { |
308 | const char *password; | ||
309 | int string_type; | ||
310 | |||
309 | if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && | 311 | if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && |
310 | UI_get0_user_data(ui)) { | 312 | UI_get0_user_data(ui)) { |
311 | switch (UI_get_string_type(uis)) { | 313 | string_type = UI_get_string_type(uis); |
312 | case UIT_PROMPT: | 314 | if (string_type == UIT_PROMPT || string_type == UIT_VERIFY) { |
313 | case UIT_VERIFY: | 315 | password = |
314 | { | 316 | ((PW_CB_DATA *)UI_get0_user_data(ui))->password; |
315 | const char *password = | 317 | if (password && password[0] != '\0') { |
316 | ((PW_CB_DATA *)UI_get0_user_data(ui))->password; | 318 | UI_set_result(ui, uis, password); |
317 | if (password && password[0] != '\0') { | 319 | return 1; |
318 | UI_set_result(ui, uis, password); | ||
319 | return 1; | ||
320 | } | ||
321 | } | 320 | } |
322 | break; | ||
323 | default: | ||
324 | break; | ||
325 | } | 321 | } |
326 | } | 322 | } |
327 | return UI_method_get_reader(UI_OpenSSL()) (ui, uis); | 323 | return UI_method_get_reader(UI_OpenSSL()) (ui, uis); |
328 | } | 324 | } |
329 | 325 | ||
330 | static int | 326 | int |
331 | ui_write(UI *ui, UI_STRING *uis) | 327 | ui_write(UI *ui, UI_STRING *uis) |
332 | { | 328 | { |
329 | const char *password; | ||
330 | int string_type; | ||
331 | |||
333 | if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && | 332 | if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD && |
334 | UI_get0_user_data(ui)) { | 333 | UI_get0_user_data(ui)) { |
335 | switch (UI_get_string_type(uis)) { | 334 | string_type = UI_get_string_type(uis); |
336 | case UIT_PROMPT: | 335 | if (string_type == UIT_PROMPT || string_type == UIT_VERIFY) { |
337 | case UIT_VERIFY: | 336 | password = |
338 | { | 337 | ((PW_CB_DATA *)UI_get0_user_data(ui))->password; |
339 | const char *password = | 338 | if (password && password[0] != '\0') |
340 | ((PW_CB_DATA *)UI_get0_user_data(ui))->password; | 339 | return 1; |
341 | if (password && password[0] != '\0') | ||
342 | return 1; | ||
343 | } | ||
344 | break; | ||
345 | default: | ||
346 | break; | ||
347 | } | 340 | } |
348 | } | 341 | } |
349 | return UI_method_get_writer(UI_OpenSSL()) (ui, uis); | 342 | return UI_method_get_writer(UI_OpenSSL()) (ui, uis); |
350 | } | 343 | } |
351 | 344 | ||
352 | static int | 345 | int |
353 | ui_close(UI *ui) | 346 | ui_close(UI *ui) |
354 | { | 347 | { |
355 | return UI_method_get_closer(UI_OpenSSL()) (ui); | 348 | return UI_method_get_closer(UI_OpenSSL()) (ui); |
356 | } | 349 | } |
357 | 350 | ||
358 | int | 351 | int |
359 | setup_ui_method(void) | ||
360 | { | ||
361 | ui_method = UI_create_method("OpenSSL application user interface"); | ||
362 | UI_method_set_opener(ui_method, ui_open); | ||
363 | UI_method_set_reader(ui_method, ui_read); | ||
364 | UI_method_set_writer(ui_method, ui_write); | ||
365 | UI_method_set_closer(ui_method, ui_close); | ||
366 | return 0; | ||
367 | } | ||
368 | |||
369 | void | ||
370 | destroy_ui_method(void) | ||
371 | { | ||
372 | if (ui_method) { | ||
373 | UI_destroy_method(ui_method); | ||
374 | ui_method = NULL; | ||
375 | } | ||
376 | } | ||
377 | |||
378 | int | ||
379 | password_callback(char *buf, int bufsiz, int verify, void *arg) | 352 | password_callback(char *buf, int bufsiz, int verify, void *arg) |
380 | { | 353 | { |
381 | PW_CB_DATA *cb_tmp = arg; | 354 | PW_CB_DATA *cb_tmp = arg; |
diff --git a/src/usr.bin/openssl/apps.h b/src/usr.bin/openssl/apps.h index f63079179d..bb9fd0dd7a 100644 --- a/src/usr.bin/openssl/apps.h +++ b/src/usr.bin/openssl/apps.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: apps.h,v 1.15 2015/09/11 14:30:23 bcook Exp $ */ | 1 | /* $OpenBSD: apps.h,v 1.16 2015/09/13 12:41:01 bcook Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -120,6 +120,7 @@ | |||
120 | #include <openssl/ossl_typ.h> | 120 | #include <openssl/ossl_typ.h> |
121 | #include <openssl/txt_db.h> | 121 | #include <openssl/txt_db.h> |
122 | #include <openssl/x509.h> | 122 | #include <openssl/x509.h> |
123 | #include <openssl/ui.h> | ||
123 | 124 | ||
124 | #ifndef OPENSSL_NO_OCSP | 125 | #ifndef OPENSSL_NO_OCSP |
125 | #include <openssl/ocsp.h> | 126 | #include <openssl/ocsp.h> |
@@ -142,8 +143,14 @@ typedef struct pw_cb_data { | |||
142 | 143 | ||
143 | int password_callback(char *buf, int bufsiz, int verify, void *cb_data); | 144 | int password_callback(char *buf, int bufsiz, int verify, void *cb_data); |
144 | 145 | ||
145 | int setup_ui_method(void); | 146 | int setup_ui(void); |
146 | void destroy_ui_method(void); | 147 | void destroy_ui(void); |
148 | |||
149 | extern UI_METHOD *ui_method; | ||
150 | int ui_open(UI *ui); | ||
151 | int ui_read(UI *ui, UI_STRING *uis); | ||
152 | int ui_write(UI *ui, UI_STRING *uis); | ||
153 | int ui_close(UI *ui); | ||
147 | 154 | ||
148 | int should_retry(int i); | 155 | int should_retry(int i); |
149 | int args_from_file(char *file, int *argc, char **argv[]); | 156 | int args_from_file(char *file, int *argc, char **argv[]); |
diff --git a/src/usr.bin/openssl/apps_posix.c b/src/usr.bin/openssl/apps_posix.c index c49a23a653..67cd465088 100644 --- a/src/usr.bin/openssl/apps_posix.c +++ b/src/usr.bin/openssl/apps_posix.c | |||
@@ -142,3 +142,23 @@ app_tminterval(int stop, int usertime) | |||
142 | 142 | ||
143 | return (ret); | 143 | return (ret); |
144 | } | 144 | } |
145 | |||
146 | int | ||
147 | setup_ui(void) | ||
148 | { | ||
149 | ui_method = UI_create_method("OpenSSL application user interface"); | ||
150 | UI_method_set_opener(ui_method, ui_open); | ||
151 | UI_method_set_reader(ui_method, ui_read); | ||
152 | UI_method_set_writer(ui_method, ui_write); | ||
153 | UI_method_set_closer(ui_method, ui_close); | ||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | void | ||
158 | destroy_ui(void) | ||
159 | { | ||
160 | if (ui_method) { | ||
161 | UI_destroy_method(ui_method); | ||
162 | ui_method = NULL; | ||
163 | } | ||
164 | } | ||
diff --git a/src/usr.bin/openssl/openssl.c b/src/usr.bin/openssl/openssl.c index 653329f7c6..d0c0ec0551 100644 --- a/src/usr.bin/openssl/openssl.c +++ b/src/usr.bin/openssl/openssl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: openssl.c,v 1.9 2015/09/12 19:34:07 lteo Exp $ */ | 1 | /* $OpenBSD: openssl.c,v 1.10 2015/09/13 12:41:01 bcook Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -405,14 +405,14 @@ openssl_startup(void) | |||
405 | SSL_library_init(); | 405 | SSL_library_init(); |
406 | SSL_load_error_strings(); | 406 | SSL_load_error_strings(); |
407 | 407 | ||
408 | setup_ui_method(); | 408 | setup_ui(); |
409 | } | 409 | } |
410 | 410 | ||
411 | static void | 411 | static void |
412 | openssl_shutdown(void) | 412 | openssl_shutdown(void) |
413 | { | 413 | { |
414 | CONF_modules_unload(1); | 414 | CONF_modules_unload(1); |
415 | destroy_ui_method(); | 415 | destroy_ui(); |
416 | OBJ_cleanup(); | 416 | OBJ_cleanup(); |
417 | EVP_cleanup(); | 417 | EVP_cleanup(); |
418 | CRYPTO_cleanup_all_ex_data(); | 418 | CRYPTO_cleanup_all_ex_data(); |