summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbcook <>2015-09-13 12:41:01 +0000
committerbcook <>2015-09-13 12:41:01 +0000
commite2751f37728059d10cda50d45e3365a1110f26ff (patch)
treea928062f329b4a2f81c6d2b9910fde8181243c7a
parent2555ca7b86c3ba095a21111d3f7d00e279de8e4d (diff)
downloadopenbsd-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.c77
-rw-r--r--src/usr.bin/openssl/apps.h13
-rw-r--r--src/usr.bin/openssl/apps_posix.c20
-rw-r--r--src/usr.bin/openssl/openssl.c6
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
157static UI_METHOD *ui_method = NULL; 156UI_METHOD *ui_method = NULL;
158 157
159static int set_table_opts(unsigned long *flags, const char *arg, 158static 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
300static int 299int
301ui_open(UI *ui) 300ui_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
306static int 305int
307ui_read(UI *ui, UI_STRING *uis) 306ui_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
330static int 326int
331ui_write(UI *ui, UI_STRING *uis) 327ui_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
352static int 345int
353ui_close(UI *ui) 346ui_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
358int 351int
359setup_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
369void
370destroy_ui_method(void)
371{
372 if (ui_method) {
373 UI_destroy_method(ui_method);
374 ui_method = NULL;
375 }
376}
377
378int
379password_callback(char *buf, int bufsiz, int verify, void *arg) 352password_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
143int password_callback(char *buf, int bufsiz, int verify, void *cb_data); 144int password_callback(char *buf, int bufsiz, int verify, void *cb_data);
144 145
145int setup_ui_method(void); 146int setup_ui(void);
146void destroy_ui_method(void); 147void destroy_ui(void);
148
149extern UI_METHOD *ui_method;
150int ui_open(UI *ui);
151int ui_read(UI *ui, UI_STRING *uis);
152int ui_write(UI *ui, UI_STRING *uis);
153int ui_close(UI *ui);
147 154
148int should_retry(int i); 155int should_retry(int i);
149int args_from_file(char *file, int *argc, char **argv[]); 156int 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
146int
147setup_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
157void
158destroy_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
411static void 411static void
412openssl_shutdown(void) 412openssl_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();