078d10cadd04f4fc3d6570d3ba871c9cb0e1ac1e
[openssl.git] / crypto / ui / ui_openssl.c
1 /*
2  * Copyright 2001-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include "e_os.h"
11 #include <openssl/e_os2.h>
12 #include <openssl/err.h>
13 #include <openssl/ui.h>
14
15 #ifndef OPENSSL_NO_UI_CONSOLE
16 /*
17  * need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc
18  * [maybe others?], because it masks interfaces not discussed in standard,
19  * sigaction and fileno included. -pedantic would be more appropriate for the
20  * intended purposes, but we can't prevent users from adding -ansi.
21  */
22 # if defined(OPENSSL_SYS_VXWORKS)
23 #  include <sys/types.h>
24 # endif
25
26 # if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
27 #  ifndef _POSIX_C_SOURCE
28 #   define _POSIX_C_SOURCE 2
29 #  endif
30 # endif
31 # include <signal.h>
32 # include <stdio.h>
33 # include <string.h>
34 # include <errno.h>
35
36 # if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
37 #  ifdef OPENSSL_UNISTD
38 #   include OPENSSL_UNISTD
39 #  else
40 #   include <unistd.h>
41 #  endif
42 /*
43  * If unistd.h defines _POSIX_VERSION, we conclude that we are on a POSIX
44  * system and have sigaction and termios.
45  */
46 #  if defined(_POSIX_VERSION)
47
48 #   define SIGACTION
49 #   if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
50 #    define TERMIOS
51 #   endif
52
53 #  endif
54 # endif
55
56 # include "ui_locl.h"
57 # include "internal/cryptlib.h"
58
59 # ifdef OPENSSL_SYS_VMS          /* prototypes for sys$whatever */
60 #  include <starlet.h>
61 #  ifdef __DECC
62 #   pragma message disable DOLLARID
63 #  endif
64 # endif
65
66 # ifdef WIN_CONSOLE_BUG
67 #  include <windows.h>
68 #  ifndef OPENSSL_SYS_WINCE
69 #   include <wincon.h>
70 #  endif
71 # endif
72
73 /*
74  * There are 6 types of terminal interface supported, TERMIO, TERMIOS, VMS,
75  * MSDOS, WIN32 Console and SGTTY.
76  *
77  * If someone defines one of the macros TERMIO, TERMIOS or SGTTY, it will
78  * remain respected.  Otherwise, we default to TERMIOS except for a few
79  * systems that require something different.
80  *
81  * Note: we do not use SGTTY unless it's defined by the configuration.  We
82  * may eventually opt to remove it's use entirely.
83  */
84
85 # if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
86
87 #  if defined(_LIBC)
88 #   undef  TERMIOS
89 #   define TERMIO
90 #   undef  SGTTY
91 /*
92  * We know that VMS, MSDOS, VXWORKS, use entirely other mechanisms.
93  */
94 #  elif !defined(OPENSSL_SYS_VMS) \
95         && !defined(OPENSSL_SYS_MSDOS) \
96         && !defined(OPENSSL_SYS_VXWORKS)
97 #   define TERMIOS
98 #   undef  TERMIO
99 #   undef  SGTTY
100 #  endif
101
102 # endif
103
104 # ifdef TERMIOS
105 #  include <termios.h>
106 #  define TTY_STRUCT             struct termios
107 #  define TTY_FLAGS              c_lflag
108 #  define TTY_get(tty,data)      tcgetattr(tty,data)
109 #  define TTY_set(tty,data)      tcsetattr(tty,TCSANOW,data)
110 # endif
111
112 # ifdef TERMIO
113 #  include <termio.h>
114 #  define TTY_STRUCT             struct termio
115 #  define TTY_FLAGS              c_lflag
116 #  define TTY_get(tty,data)      ioctl(tty,TCGETA,data)
117 #  define TTY_set(tty,data)      ioctl(tty,TCSETA,data)
118 # endif
119
120 # ifdef SGTTY
121 #  include <sgtty.h>
122 #  define TTY_STRUCT             struct sgttyb
123 #  define TTY_FLAGS              sg_flags
124 #  define TTY_get(tty,data)      ioctl(tty,TIOCGETP,data)
125 #  define TTY_set(tty,data)      ioctl(tty,TIOCSETP,data)
126 # endif
127
128 # if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
129 #  include <sys/ioctl.h>
130 # endif
131
132 # ifdef OPENSSL_SYS_MSDOS
133 #  include <conio.h>
134 # endif
135
136 # ifdef OPENSSL_SYS_VMS
137 #  include <ssdef.h>
138 #  include <iodef.h>
139 #  include <ttdef.h>
140 #  include <descrip.h>
141 struct IOSB {
142     short iosb$w_value;
143     short iosb$w_count;
144     long iosb$l_info;
145 };
146 # endif
147
148 # ifndef NX509_SIG
149 #  define NX509_SIG 32
150 # endif
151
152 /* Define globals.  They are protected by a lock */
153 # ifdef SIGACTION
154 static struct sigaction savsig[NX509_SIG];
155 # else
156 static void (*savsig[NX509_SIG]) (int);
157 # endif
158
159 # ifdef OPENSSL_SYS_VMS
160 static struct IOSB iosb;
161 static $DESCRIPTOR(terminal, "TT");
162 static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this
163                                       * will always suffice for the actual
164                                       * structures? */
165 static long status;
166 static unsigned short channel = 0;
167 # elif defined(_WIN32) && !defined(_WIN32_WCE)
168 static DWORD tty_orig, tty_new;
169 # else
170 #  if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
171 static TTY_STRUCT tty_orig, tty_new;
172 #  endif
173 # endif
174 static FILE *tty_in, *tty_out;
175 static int is_a_tty;
176
177 /* Declare static functions */
178 # if !defined(OPENSSL_SYS_WINCE)
179 static int read_till_nl(FILE *);
180 static void recsig(int);
181 static void pushsig(void);
182 static void popsig(void);
183 # endif
184 # if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
185 static int noecho_fgets(char *buf, int size, FILE *tty);
186 # endif
187 static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
188
189 static int read_string(UI *ui, UI_STRING *uis);
190 static int write_string(UI *ui, UI_STRING *uis);
191
192 static int open_console(UI *ui);
193 static int echo_console(UI *ui);
194 static int noecho_console(UI *ui);
195 static int close_console(UI *ui);
196
197 /*
198  * The following function makes sure that info and error strings are printed
199  * before any prompt.
200  */
201 static int write_string(UI *ui, UI_STRING *uis)
202 {
203     switch (UI_get_string_type(uis)) {
204     case UIT_ERROR:
205     case UIT_INFO:
206         fputs(UI_get0_output_string(uis), tty_out);
207         fflush(tty_out);
208         break;
209     case UIT_NONE:
210     case UIT_PROMPT:
211     case UIT_VERIFY:
212     case UIT_BOOLEAN:
213         break;
214     }
215     return 1;
216 }
217
218 static int read_string(UI *ui, UI_STRING *uis)
219 {
220     int ok = 0;
221
222     switch (UI_get_string_type(uis)) {
223     case UIT_BOOLEAN:
224         fputs(UI_get0_output_string(uis), tty_out);
225         fputs(UI_get0_action_string(uis), tty_out);
226         fflush(tty_out);
227         return read_string_inner(ui, uis,
228                                  UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO,
229                                  0);
230     case UIT_PROMPT:
231         fputs(UI_get0_output_string(uis), tty_out);
232         fflush(tty_out);
233         return read_string_inner(ui, uis,
234                                  UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO,
235                                  1);
236     case UIT_VERIFY:
237         fprintf(tty_out, "Verifying - %s", UI_get0_output_string(uis));
238         fflush(tty_out);
239         if ((ok = read_string_inner(ui, uis,
240                                     UI_get_input_flags(uis) &
241                                     UI_INPUT_FLAG_ECHO, 1)) <= 0)
242             return ok;
243         if (strcmp(UI_get0_result_string(uis), UI_get0_test_string(uis)) != 0) {
244             fprintf(tty_out, "Verify failure\n");
245             fflush(tty_out);
246             return 0;
247         }
248         break;
249     case UIT_NONE:
250     case UIT_INFO:
251     case UIT_ERROR:
252         break;
253     }
254     return 1;
255 }
256
257 # if !defined(OPENSSL_SYS_WINCE)
258 /* Internal functions to read a string without echoing */
259 static int read_till_nl(FILE *in)
260 {
261 #  define SIZE 4
262     char buf[SIZE + 1];
263
264     do {
265         if (!fgets(buf, SIZE, in))
266             return 0;
267     } while (strchr(buf, '\n') == NULL);
268     return 1;
269 }
270
271 static volatile sig_atomic_t intr_signal;
272 # endif
273
274 static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
275 {
276     static int ps;
277     int ok;
278     char result[BUFSIZ];
279     int maxsize = BUFSIZ - 1;
280 # if !defined(OPENSSL_SYS_WINCE)
281     char *p = NULL;
282     int echo_eol = !echo;
283
284     intr_signal = 0;
285     ok = 0;
286     ps = 0;
287
288     pushsig();
289     ps = 1;
290
291     if (!echo && !noecho_console(ui))
292         goto error;
293     ps = 2;
294
295     result[0] = '\0';
296 #  if defined(_WIN32)
297     if (is_a_tty) {
298         DWORD numread;
299 #   if defined(CP_UTF8)
300         if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) != 0) {
301             WCHAR wresult[BUFSIZ];
302
303             if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE),
304                          wresult, maxsize, &numread, NULL)) {
305                 if (numread >= 2 &&
306                     wresult[numread-2] == L'\r' &&
307                     wresult[numread-1] == L'\n') {
308                     wresult[numread-2] = L'\n';
309                     numread--;
310                 }
311                 wresult[numread] = '\0';
312                 if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1,
313                                         result, sizeof(result), NULL, 0) > 0)
314                     p = result;
315
316                 OPENSSL_cleanse(wresult, sizeof(wresult));
317             }
318         } else
319 #   endif
320         if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE),
321                          result, maxsize, &numread, NULL)) {
322             if (numread >= 2 &&
323                 result[numread-2] == '\r' && result[numread-1] == '\n') {
324                 result[numread-2] = '\n';
325                 numread--;
326             }
327             result[numread] = '\0';
328             p = result;
329         }
330     } else
331 #  elif defined(OPENSSL_SYS_MSDOS)
332     if (!echo) {
333         noecho_fgets(result, maxsize, tty_in);
334         p = result;             /* FIXME: noecho_fgets doesn't return errors */
335     } else
336 #  endif
337     p = fgets(result, maxsize, tty_in);
338     if (p == NULL)
339         goto error;
340     if (feof(tty_in))
341         goto error;
342     if (ferror(tty_in))
343         goto error;
344     if ((p = (char *)strchr(result, '\n')) != NULL) {
345         if (strip_nl)
346             *p = '\0';
347     } else if (!read_till_nl(tty_in))
348         goto error;
349     if (UI_set_result(ui, uis, result) >= 0)
350         ok = 1;
351
352  error:
353     if (intr_signal == SIGINT)
354         ok = -1;
355     if (echo_eol)
356         fprintf(tty_out, "\n");
357     if (ps >= 2 && !echo && !echo_console(ui))
358         ok = 0;
359
360     if (ps >= 1)
361         popsig();
362 # else
363     ok = 1;
364 # endif
365
366     OPENSSL_cleanse(result, BUFSIZ);
367     return ok;
368 }
369
370 /* Internal functions to open, handle and close a channel to the console.  */
371 static int open_console(UI *ui)
372 {
373     CRYPTO_THREAD_write_lock(ui->lock);
374     is_a_tty = 1;
375
376 # if defined(OPENSSL_SYS_VXWORKS)
377     tty_in = stdin;
378     tty_out = stderr;
379 # elif defined(_WIN32) && !defined(_WIN32_WCE)
380     if ((tty_out = fopen("conout$", "w")) == NULL)
381         tty_out = stderr;
382
383     if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &tty_orig)) {
384         tty_in = stdin;
385     } else {
386         is_a_tty = 0;
387         if ((tty_in = fopen("conin$", "r")) == NULL)
388             tty_in = stdin;
389     }
390 # else
391 #  ifdef OPENSSL_SYS_MSDOS
392 #   define DEV_TTY "con"
393 #  else
394 #   define DEV_TTY "/dev/tty"
395 #  endif
396     if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
397         tty_in = stdin;
398     if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
399         tty_out = stderr;
400 # endif
401
402 # if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
403     if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
404 #  ifdef ENOTTY
405         if (errno == ENOTTY)
406             is_a_tty = 0;
407         else
408 #  endif
409 #  ifdef EINVAL
410             /*
411              * Ariel Glenn reports that solaris can return EINVAL instead.
412              * This should be ok
413              */
414         if (errno == EINVAL)
415             is_a_tty = 0;
416         else
417 #  endif
418 #  ifdef ENODEV
419             /*
420              * MacOS X returns ENODEV (Operation not supported by device),
421              * which seems appropriate.
422              */
423         if (errno == ENODEV)
424             is_a_tty = 0;
425         else
426 #  endif
427             {
428                 char tmp_num[10];
429                 BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%d", errno);
430                 UIerr(UI_F_OPEN_CONSOLE, UI_R_UNKNOWN_TTYGET_ERRNO_VALUE);
431                 ERR_add_error_data(2, "errno=", tmp_num);
432
433                 return 0;
434             }
435     }
436 # endif
437 # ifdef OPENSSL_SYS_VMS
438     status = sys$assign(&terminal, &channel, 0, 0);
439
440     /* if there isn't a TT device, something is very wrong */
441     if (status != SS$_NORMAL) {
442         char tmp_num[12];
443
444         BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status);
445         UIerr(UI_F_OPEN_CONSOLE, UI_R_SYSASSIGN_ERROR);
446         ERR_add_error_data(2, "status=", tmp_num);
447         return 0;
448     }
449
450     status = sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12,
451                       0, 0, 0, 0);
452
453     /* If IO$_SENSEMODE doesn't work, this is not a terminal device */
454     if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
455         is_a_tty = 0;
456 # endif
457     return 1;
458 }
459
460 static int noecho_console(UI *ui)
461 {
462 # ifdef TTY_FLAGS
463     memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
464     tty_new.TTY_FLAGS &= ~ECHO;
465 # endif
466
467 # if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
468     if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
469         return 0;
470 # endif
471 # ifdef OPENSSL_SYS_VMS
472     if (is_a_tty) {
473         tty_new[0] = tty_orig[0];
474         tty_new[1] = tty_orig[1] | TT$M_NOECHO;
475         tty_new[2] = tty_orig[2];
476         status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12,
477                           0, 0, 0, 0);
478         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) {
479             char tmp_num[2][12];
480
481             BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
482                          status);
483             BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
484                          iosb.iosb$w_value);
485             UIerr(UI_F_NOECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
486             ERR_add_error_data(5, "status=", tmp_num[0],
487                                ",", "iosb.iosb$w_value=", tmp_num[1]);
488             return 0;
489         }
490     }
491 # endif
492 # if defined(_WIN32) && !defined(_WIN32_WCE)
493     if (is_a_tty) {
494         tty_new = tty_orig;
495         tty_new &= ~ENABLE_ECHO_INPUT;
496         SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
497     }
498 # endif
499     return 1;
500 }
501
502 static int echo_console(UI *ui)
503 {
504 # if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
505     memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
506     if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
507         return 0;
508 # endif
509 # ifdef OPENSSL_SYS_VMS
510     if (is_a_tty) {
511         tty_new[0] = tty_orig[0];
512         tty_new[1] = tty_orig[1];
513         tty_new[2] = tty_orig[2];
514         status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12,
515                           0, 0, 0, 0);
516         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) {
517             char tmp_num[2][12];
518
519             BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
520                          status);
521             BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
522                          iosb.iosb$w_value);
523             UIerr(UI_F_ECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
524             ERR_add_error_data(5, "status=", tmp_num[0],
525                                ",", "iosb.iosb$w_value=", tmp_num[1]);
526             return 0;
527         }
528     }
529 # endif
530 # if defined(_WIN32) && !defined(_WIN32_WCE)
531     if (is_a_tty) {
532         tty_new = tty_orig;
533         SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
534     }
535 # endif
536     return 1;
537 }
538
539 static int close_console(UI *ui)
540 {
541     if (tty_in != stdin)
542         fclose(tty_in);
543     if (tty_out != stderr)
544         fclose(tty_out);
545 # ifdef OPENSSL_SYS_VMS
546     status = sys$dassgn(channel);
547     if (status != SS$_NORMAL) {
548         char tmp_num[12];
549
550         BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status);
551         UIerr(UI_F_CLOSE_CONSOLE, UI_R_SYSDASSGN_ERROR);
552         ERR_add_error_data(2, "status=", tmp_num);
553         return 0;
554     }
555 # endif
556     CRYPTO_THREAD_unlock(ui->lock);
557
558     return 1;
559 }
560
561 # if !defined(OPENSSL_SYS_WINCE)
562 /* Internal functions to handle signals and act on them */
563 static void pushsig(void)
564 {
565 #  ifndef OPENSSL_SYS_WIN32
566     int i;
567 #  endif
568 #  ifdef SIGACTION
569     struct sigaction sa;
570
571     memset(&sa, 0, sizeof(sa));
572     sa.sa_handler = recsig;
573 #  endif
574
575 #  ifdef OPENSSL_SYS_WIN32
576     savsig[SIGABRT] = signal(SIGABRT, recsig);
577     savsig[SIGFPE] = signal(SIGFPE, recsig);
578     savsig[SIGILL] = signal(SIGILL, recsig);
579     savsig[SIGINT] = signal(SIGINT, recsig);
580     savsig[SIGSEGV] = signal(SIGSEGV, recsig);
581     savsig[SIGTERM] = signal(SIGTERM, recsig);
582 #  else
583     for (i = 1; i < NX509_SIG; i++) {
584 #   ifdef SIGUSR1
585         if (i == SIGUSR1)
586             continue;
587 #   endif
588 #   ifdef SIGUSR2
589         if (i == SIGUSR2)
590             continue;
591 #   endif
592 #   ifdef SIGKILL
593         if (i == SIGKILL)       /* We can't make any action on that. */
594             continue;
595 #   endif
596 #   ifdef SIGACTION
597         sigaction(i, &sa, &savsig[i]);
598 #   else
599         savsig[i] = signal(i, recsig);
600 #   endif
601     }
602 #  endif
603
604 #  ifdef SIGWINCH
605     signal(SIGWINCH, SIG_DFL);
606 #  endif
607 }
608
609 static void popsig(void)
610 {
611 #  ifdef OPENSSL_SYS_WIN32
612     signal(SIGABRT, savsig[SIGABRT]);
613     signal(SIGFPE, savsig[SIGFPE]);
614     signal(SIGILL, savsig[SIGILL]);
615     signal(SIGINT, savsig[SIGINT]);
616     signal(SIGSEGV, savsig[SIGSEGV]);
617     signal(SIGTERM, savsig[SIGTERM]);
618 #  else
619     int i;
620     for (i = 1; i < NX509_SIG; i++) {
621 #   ifdef SIGUSR1
622         if (i == SIGUSR1)
623             continue;
624 #   endif
625 #   ifdef SIGUSR2
626         if (i == SIGUSR2)
627             continue;
628 #   endif
629 #   ifdef SIGACTION
630         sigaction(i, &savsig[i], NULL);
631 #   else
632         signal(i, savsig[i]);
633 #   endif
634     }
635 #  endif
636 }
637
638 static void recsig(int i)
639 {
640     intr_signal = i;
641 }
642 # endif
643
644 /* Internal functions specific for Windows */
645 # if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
646 static int noecho_fgets(char *buf, int size, FILE *tty)
647 {
648     int i;
649     char *p;
650
651     p = buf;
652     for (;;) {
653         if (size == 0) {
654             *p = '\0';
655             break;
656         }
657         size--;
658 #  if defined(_WIN32)
659         i = _getch();
660 #  else
661         i = getch();
662 #  endif
663         if (i == '\r')
664             i = '\n';
665         *(p++) = i;
666         if (i == '\n') {
667             *p = '\0';
668             break;
669         }
670     }
671 #  ifdef WIN_CONSOLE_BUG
672     /*
673      * Win95 has several evil console bugs: one of these is that the last
674      * character read using getch() is passed to the next read: this is
675      * usually a CR so this can be trouble. No STDIO fix seems to work but
676      * flushing the console appears to do the trick.
677      */
678     {
679         HANDLE inh;
680         inh = GetStdHandle(STD_INPUT_HANDLE);
681         FlushConsoleInputBuffer(inh);
682     }
683 #  endif
684     return strlen(buf);
685 }
686 # endif
687
688 static UI_METHOD ui_openssl = {
689     "OpenSSL default user interface",
690     open_console,
691     write_string,
692     NULL,                       /* No flusher is needed for command lines */
693     read_string,
694     close_console,
695     NULL
696 };
697
698 /* The method with all the built-in console thingies */
699 UI_METHOD *UI_OpenSSL(void)
700 {
701     return &ui_openssl;
702 }
703
704 static const UI_METHOD *default_UI_meth = &ui_openssl;
705
706 #else
707
708 static const UI_METHOD *default_UI_meth = NULL;
709
710 #endif
711
712 void UI_set_default_method(const UI_METHOD *meth)
713 {
714     default_UI_meth = meth;
715 }
716
717 const UI_METHOD *UI_get_default_method(void)
718 {
719     return default_UI_meth;
720 }