diff options
Diffstat (limited to 'src/usr.bin/openssl/apps.c')
-rw-r--r-- | src/usr.bin/openssl/apps.c | 77 |
1 files changed, 25 insertions, 52 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; |