sl@0
|
1 |
/* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */
|
sl@0
|
2 |
/* Written by Richard Levitte (richard@levitte.org) and others
|
sl@0
|
3 |
* for the OpenSSL project 2001.
|
sl@0
|
4 |
*/
|
sl@0
|
5 |
/* ====================================================================
|
sl@0
|
6 |
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
9 |
* modification, are permitted provided that the following conditions
|
sl@0
|
10 |
* are met:
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
13 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
16 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
17 |
* the documentation and/or other materials provided with the
|
sl@0
|
18 |
* distribution.
|
sl@0
|
19 |
*
|
sl@0
|
20 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
21 |
* software must display the following acknowledgment:
|
sl@0
|
22 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
23 |
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
sl@0
|
24 |
*
|
sl@0
|
25 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
26 |
* endorse or promote products derived from this software without
|
sl@0
|
27 |
* prior written permission. For written permission, please contact
|
sl@0
|
28 |
* openssl-core@openssl.org.
|
sl@0
|
29 |
*
|
sl@0
|
30 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
31 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
32 |
* permission of the OpenSSL Project.
|
sl@0
|
33 |
*
|
sl@0
|
34 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
35 |
* acknowledgment:
|
sl@0
|
36 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
37 |
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
sl@0
|
38 |
*
|
sl@0
|
39 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
40 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
41 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
42 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
43 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
44 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
45 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
46 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
47 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
48 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
49 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
50 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
51 |
* ====================================================================
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
54 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
55 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
56 |
*
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
|
sl@0
|
59 |
/* The lowest level part of this file was previously in crypto/des/read_pwd.c,
|
sl@0
|
60 |
* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
61 |
* All rights reserved.
|
sl@0
|
62 |
*
|
sl@0
|
63 |
* This package is an SSL implementation written
|
sl@0
|
64 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
65 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
66 |
*
|
sl@0
|
67 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
68 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
69 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
70 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
71 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
72 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
73 |
*
|
sl@0
|
74 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
75 |
* the code are not to be removed.
|
sl@0
|
76 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
77 |
* as the author of the parts of the library used.
|
sl@0
|
78 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
79 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
80 |
*
|
sl@0
|
81 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
82 |
* modification, are permitted provided that the following conditions
|
sl@0
|
83 |
* are met:
|
sl@0
|
84 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
85 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
86 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
87 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
88 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
89 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
90 |
* must display the following acknowledgement:
|
sl@0
|
91 |
* "This product includes cryptographic software written by
|
sl@0
|
92 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
93 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
94 |
* being used are not cryptographic related :-).
|
sl@0
|
95 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
96 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
97 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
98 |
*
|
sl@0
|
99 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
100 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
101 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
102 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
103 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
104 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
105 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
106 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
107 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
108 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
109 |
* SUCH DAMAGE.
|
sl@0
|
110 |
*
|
sl@0
|
111 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
112 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
113 |
* copied and put under another distribution licence
|
sl@0
|
114 |
* [including the GNU Public Licence.]
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
/*
|
sl@0
|
117 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
118 |
*/
|
sl@0
|
119 |
|
sl@0
|
120 |
|
sl@0
|
121 |
#include <openssl/e_os2.h>
|
sl@0
|
122 |
|
sl@0
|
123 |
/* need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc
|
sl@0
|
124 |
* [maybe others?], because it masks interfaces not discussed in standard,
|
sl@0
|
125 |
* sigaction and fileno included. -pedantic would be more appropriate for
|
sl@0
|
126 |
* the intended purposes, but we can't prevent users from adding -ansi.
|
sl@0
|
127 |
*/
|
sl@0
|
128 |
|
sl@0
|
129 |
#define _POSIX_C_SOURCE 1
|
sl@0
|
130 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
131 |
#undef _POSIX_C_SOURCE
|
sl@0
|
132 |
#endif
|
sl@0
|
133 |
#ifndef SYMBIAN
|
sl@0
|
134 |
#include <signal.h>
|
sl@0
|
135 |
#endif
|
sl@0
|
136 |
#include <stdio.h>
|
sl@0
|
137 |
#include <string.h>
|
sl@0
|
138 |
#include <errno.h>
|
sl@0
|
139 |
|
sl@0
|
140 |
|
sl@0
|
141 |
#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
|
sl@0
|
142 |
# ifdef OPENSSL_UNISTD
|
sl@0
|
143 |
# include OPENSSL_UNISTD
|
sl@0
|
144 |
# else
|
sl@0
|
145 |
# include <unistd.h>
|
sl@0
|
146 |
# endif
|
sl@0
|
147 |
/* If unistd.h defines _POSIX_VERSION, we conclude that we
|
sl@0
|
148 |
* are on a POSIX system and have sigaction and termios. */
|
sl@0
|
149 |
# if defined(_POSIX_VERSION) && !defined(SYMBIAN)
|
sl@0
|
150 |
# define SIGACTION
|
sl@0
|
151 |
# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
|
sl@0
|
152 |
# define TERMIOS
|
sl@0
|
153 |
# endif
|
sl@0
|
154 |
|
sl@0
|
155 |
# endif
|
sl@0
|
156 |
#endif
|
sl@0
|
157 |
|
sl@0
|
158 |
#ifdef WIN16TTY
|
sl@0
|
159 |
# undef OPENSSL_SYS_WIN16
|
sl@0
|
160 |
# undef WIN16
|
sl@0
|
161 |
# undef _WINDOWS
|
sl@0
|
162 |
# include <graph.h>
|
sl@0
|
163 |
#endif
|
sl@0
|
164 |
|
sl@0
|
165 |
/* 06-Apr-92 Luke Brennan Support for VMS */
|
sl@0
|
166 |
#include "ui_locl.h"
|
sl@0
|
167 |
#include "cryptlib.h"
|
sl@0
|
168 |
|
sl@0
|
169 |
#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
|
sl@0
|
170 |
# include <starlet.h>
|
sl@0
|
171 |
# ifdef __DECC
|
sl@0
|
172 |
# pragma message disable DOLLARID
|
sl@0
|
173 |
# endif
|
sl@0
|
174 |
#endif
|
sl@0
|
175 |
|
sl@0
|
176 |
#ifndef SYMBIAN
|
sl@0
|
177 |
#ifdef WIN_CONSOLE_BUG
|
sl@0
|
178 |
# include <windows.h>
|
sl@0
|
179 |
#ifndef OPENSSL_SYS_WINCE
|
sl@0
|
180 |
# include <wincon.h>
|
sl@0
|
181 |
#endif
|
sl@0
|
182 |
#endif
|
sl@0
|
183 |
#endif
|
sl@0
|
184 |
|
sl@0
|
185 |
/* There are 5 types of terminal interface supported,
|
sl@0
|
186 |
* TERMIO, TERMIOS, VMS, MSDOS and SGTTY
|
sl@0
|
187 |
*/
|
sl@0
|
188 |
|
sl@0
|
189 |
#if defined(__sgi) && !defined(TERMIOS)
|
sl@0
|
190 |
# define TERMIOS
|
sl@0
|
191 |
# undef TERMIO
|
sl@0
|
192 |
# undef SGTTY
|
sl@0
|
193 |
#endif
|
sl@0
|
194 |
|
sl@0
|
195 |
#if defined(linux) && !defined(TERMIO)
|
sl@0
|
196 |
# undef TERMIOS
|
sl@0
|
197 |
# define TERMIO
|
sl@0
|
198 |
# undef SGTTY
|
sl@0
|
199 |
#endif
|
sl@0
|
200 |
|
sl@0
|
201 |
#ifdef _LIBC
|
sl@0
|
202 |
# undef TERMIOS
|
sl@0
|
203 |
# define TERMIO
|
sl@0
|
204 |
# undef SGTTY
|
sl@0
|
205 |
#endif
|
sl@0
|
206 |
|
sl@0
|
207 |
#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
|
sl@0
|
208 |
# undef TERMIOS
|
sl@0
|
209 |
# undef TERMIO
|
sl@0
|
210 |
# define SGTTY
|
sl@0
|
211 |
#endif
|
sl@0
|
212 |
|
sl@0
|
213 |
#if defined(OPENSSL_SYS_VXWORKS)
|
sl@0
|
214 |
#undef TERMIOS
|
sl@0
|
215 |
#undef TERMIO
|
sl@0
|
216 |
#undef SGTTY
|
sl@0
|
217 |
#endif
|
sl@0
|
218 |
|
sl@0
|
219 |
#if defined(OPENSSL_SYS_NETWARE)
|
sl@0
|
220 |
#undef TERMIOS
|
sl@0
|
221 |
#undef TERMIO
|
sl@0
|
222 |
#undef SGTTY
|
sl@0
|
223 |
#endif
|
sl@0
|
224 |
|
sl@0
|
225 |
#if defined(SYMBIAN)
|
sl@0
|
226 |
#undef TERMIOS
|
sl@0
|
227 |
#undef TERMIO
|
sl@0
|
228 |
#undef SGTTY
|
sl@0
|
229 |
#endif
|
sl@0
|
230 |
|
sl@0
|
231 |
#ifdef TERMIOS
|
sl@0
|
232 |
# include <termios.h>
|
sl@0
|
233 |
# define TTY_STRUCT struct termios
|
sl@0
|
234 |
# define TTY_FLAGS c_lflag
|
sl@0
|
235 |
# define TTY_get(tty,data) tcgetattr(tty,data)
|
sl@0
|
236 |
# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
|
sl@0
|
237 |
#endif
|
sl@0
|
238 |
|
sl@0
|
239 |
#ifdef TERMIO
|
sl@0
|
240 |
# include <termio.h>
|
sl@0
|
241 |
# define TTY_STRUCT struct termio
|
sl@0
|
242 |
# define TTY_FLAGS c_lflag
|
sl@0
|
243 |
# define TTY_get(tty,data) ioctl(tty,TCGETA,data)
|
sl@0
|
244 |
# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
|
sl@0
|
245 |
#endif
|
sl@0
|
246 |
|
sl@0
|
247 |
#ifdef SGTTY
|
sl@0
|
248 |
# include <sgtty.h>
|
sl@0
|
249 |
# define TTY_STRUCT struct sgttyb
|
sl@0
|
250 |
# define TTY_FLAGS sg_flags
|
sl@0
|
251 |
# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
|
sl@0
|
252 |
# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
|
sl@0
|
253 |
#endif
|
sl@0
|
254 |
|
sl@0
|
255 |
#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
|
sl@0
|
256 |
# include <sys/ioctl.h>
|
sl@0
|
257 |
#endif
|
sl@0
|
258 |
|
sl@0
|
259 |
#ifdef OPENSSL_SYS_MSDOS
|
sl@0
|
260 |
# include <conio.h>
|
sl@0
|
261 |
#endif
|
sl@0
|
262 |
|
sl@0
|
263 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
264 |
# include <ssdef.h>
|
sl@0
|
265 |
# include <iodef.h>
|
sl@0
|
266 |
# include <ttdef.h>
|
sl@0
|
267 |
# include <descrip.h>
|
sl@0
|
268 |
struct IOSB {
|
sl@0
|
269 |
short iosb$w_value;
|
sl@0
|
270 |
short iosb$w_count;
|
sl@0
|
271 |
long iosb$l_info;
|
sl@0
|
272 |
};
|
sl@0
|
273 |
#endif
|
sl@0
|
274 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
275 |
#include "libcrypto_wsd_macros.h"
|
sl@0
|
276 |
#include "libcrypto_wsd.h"
|
sl@0
|
277 |
#endif
|
sl@0
|
278 |
|
sl@0
|
279 |
#ifdef OPENSSL_SYS_SUNOS
|
sl@0
|
280 |
typedef int sig_atomic_t;
|
sl@0
|
281 |
#endif
|
sl@0
|
282 |
|
sl@0
|
283 |
#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) || defined(OPENSSL_SYS_NETWARE)
|
sl@0
|
284 |
/*
|
sl@0
|
285 |
* This one needs work. As a matter of fact the code is unoperational
|
sl@0
|
286 |
* and this is only a trick to get it compiled.
|
sl@0
|
287 |
* <appro@fy.chalmers.se>
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
# define TTY_STRUCT int
|
sl@0
|
290 |
#endif
|
sl@0
|
291 |
|
sl@0
|
292 |
#ifndef NX509_SIG
|
sl@0
|
293 |
# define NX509_SIG 32
|
sl@0
|
294 |
#endif
|
sl@0
|
295 |
|
sl@0
|
296 |
|
sl@0
|
297 |
/* Define globals. They are protected by a lock */
|
sl@0
|
298 |
#ifdef SIGACTION
|
sl@0
|
299 |
static struct sigaction savsig[NX509_SIG];
|
sl@0
|
300 |
#else
|
sl@0
|
301 |
static void (*savsig[NX509_SIG])(int );
|
sl@0
|
302 |
#endif
|
sl@0
|
303 |
|
sl@0
|
304 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
305 |
static struct IOSB iosb;
|
sl@0
|
306 |
static $DESCRIPTOR(terminal,"TT");
|
sl@0
|
307 |
static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
|
sl@0
|
308 |
static long status;
|
sl@0
|
309 |
static unsigned short channel = 0;
|
sl@0
|
310 |
#else
|
sl@0
|
311 |
#ifndef SYMBIAN
|
sl@0
|
312 |
#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
|
sl@0
|
313 |
static TTY_STRUCT tty_orig,tty_new;
|
sl@0
|
314 |
#endif
|
sl@0
|
315 |
#endif
|
sl@0
|
316 |
#endif
|
sl@0
|
317 |
#ifndef EMULATOR
|
sl@0
|
318 |
static FILE *tty_in, *tty_out;
|
sl@0
|
319 |
static int is_a_tty;
|
sl@0
|
320 |
#else
|
sl@0
|
321 |
GET_STATIC_VAR_FROM_TLS(tty_in,ui_openssl,FILE *)
|
sl@0
|
322 |
#define tty_in (*GET_WSD_VAR_NAME(tty_in,ui_openssl, s)())
|
sl@0
|
323 |
|
sl@0
|
324 |
GET_STATIC_VAR_FROM_TLS(tty_out,ui_openssl,FILE *)
|
sl@0
|
325 |
#define tty_out (*GET_WSD_VAR_NAME(tty_out,ui_openssl, s)())
|
sl@0
|
326 |
|
sl@0
|
327 |
GET_STATIC_VAR_FROM_TLS(is_a_tty,ui_openssl,int)
|
sl@0
|
328 |
#define is_a_tty (*GET_WSD_VAR_NAME(is_a_tty,ui_openssl, s)())
|
sl@0
|
329 |
|
sl@0
|
330 |
#endif
|
sl@0
|
331 |
/* Declare static functions */
|
sl@0
|
332 |
#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
|
sl@0
|
333 |
static void read_till_nl(FILE *);
|
sl@0
|
334 |
static void recsig(int);
|
sl@0
|
335 |
static void pushsig(void);
|
sl@0
|
336 |
static void popsig(void);
|
sl@0
|
337 |
#endif
|
sl@0
|
338 |
#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
|
sl@0
|
339 |
static int noecho_fgets(char *buf, int size, FILE *tty);
|
sl@0
|
340 |
#endif
|
sl@0
|
341 |
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
|
sl@0
|
342 |
|
sl@0
|
343 |
static int read_string(UI *ui, UI_STRING *uis);
|
sl@0
|
344 |
static int write_string(UI *ui, UI_STRING *uis);
|
sl@0
|
345 |
|
sl@0
|
346 |
static int open_console(UI *ui);
|
sl@0
|
347 |
static int echo_console(UI *ui);
|
sl@0
|
348 |
static int noecho_console(UI *ui);
|
sl@0
|
349 |
static int close_console(UI *ui);
|
sl@0
|
350 |
|
sl@0
|
351 |
#ifndef EMULATOR
|
sl@0
|
352 |
static UI_METHOD ui_openssl =
|
sl@0
|
353 |
{
|
sl@0
|
354 |
"OpenSSL default user interface",
|
sl@0
|
355 |
open_console,
|
sl@0
|
356 |
write_string,
|
sl@0
|
357 |
NULL, /* No flusher is needed for command lines */
|
sl@0
|
358 |
read_string,
|
sl@0
|
359 |
close_console,
|
sl@0
|
360 |
NULL
|
sl@0
|
361 |
};
|
sl@0
|
362 |
#else
|
sl@0
|
363 |
GET_STATIC_VAR_FROM_TLS(ui_openssl,ui_openssl,UI_METHOD)
|
sl@0
|
364 |
#define ui_openssl (*GET_WSD_VAR_NAME(ui_openssl,ui_openssl, s)())
|
sl@0
|
365 |
const UI_METHOD temp_s_ui_openssl =
|
sl@0
|
366 |
{
|
sl@0
|
367 |
"OpenSSL default user interface",
|
sl@0
|
368 |
open_console,
|
sl@0
|
369 |
write_string,
|
sl@0
|
370 |
NULL, /* No flusher is needed for command lines */
|
sl@0
|
371 |
read_string,
|
sl@0
|
372 |
close_console,
|
sl@0
|
373 |
NULL
|
sl@0
|
374 |
};
|
sl@0
|
375 |
|
sl@0
|
376 |
#endif
|
sl@0
|
377 |
/* The method with all the built-in thingies */
|
sl@0
|
378 |
EXPORT_C UI_METHOD *UI_OpenSSL(void)
|
sl@0
|
379 |
{
|
sl@0
|
380 |
return &ui_openssl;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
/* The following function makes sure that info and error strings are printed
|
sl@0
|
384 |
before any prompt. */
|
sl@0
|
385 |
static int write_string(UI *ui, UI_STRING *uis)
|
sl@0
|
386 |
{
|
sl@0
|
387 |
switch (UI_get_string_type(uis))
|
sl@0
|
388 |
{
|
sl@0
|
389 |
case UIT_ERROR:
|
sl@0
|
390 |
case UIT_INFO:
|
sl@0
|
391 |
fputs(UI_get0_output_string(uis), tty_out);
|
sl@0
|
392 |
fflush(tty_out);
|
sl@0
|
393 |
break;
|
sl@0
|
394 |
default:
|
sl@0
|
395 |
break;
|
sl@0
|
396 |
}
|
sl@0
|
397 |
return 1;
|
sl@0
|
398 |
}
|
sl@0
|
399 |
|
sl@0
|
400 |
static int read_string(UI *ui, UI_STRING *uis)
|
sl@0
|
401 |
{
|
sl@0
|
402 |
int ok = 0;
|
sl@0
|
403 |
|
sl@0
|
404 |
switch (UI_get_string_type(uis))
|
sl@0
|
405 |
{
|
sl@0
|
406 |
case UIT_BOOLEAN:
|
sl@0
|
407 |
fputs(UI_get0_output_string(uis), tty_out);
|
sl@0
|
408 |
fputs(UI_get0_action_string(uis), tty_out);
|
sl@0
|
409 |
fflush(tty_out);
|
sl@0
|
410 |
return read_string_inner(ui, uis,
|
sl@0
|
411 |
UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
|
sl@0
|
412 |
case UIT_PROMPT:
|
sl@0
|
413 |
fputs(UI_get0_output_string(uis), tty_out);
|
sl@0
|
414 |
fflush(tty_out);
|
sl@0
|
415 |
return read_string_inner(ui, uis,
|
sl@0
|
416 |
UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
|
sl@0
|
417 |
case UIT_VERIFY:
|
sl@0
|
418 |
fprintf(tty_out,"Verifying - %s",
|
sl@0
|
419 |
UI_get0_output_string(uis));
|
sl@0
|
420 |
fflush(tty_out);
|
sl@0
|
421 |
if ((ok = read_string_inner(ui, uis,
|
sl@0
|
422 |
UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
|
sl@0
|
423 |
return ok;
|
sl@0
|
424 |
if (strcmp(UI_get0_result_string(uis),
|
sl@0
|
425 |
UI_get0_test_string(uis)) != 0)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
fprintf(tty_out,"Verify failure\n");
|
sl@0
|
428 |
fflush(tty_out);
|
sl@0
|
429 |
return 0;
|
sl@0
|
430 |
}
|
sl@0
|
431 |
break;
|
sl@0
|
432 |
default:
|
sl@0
|
433 |
break;
|
sl@0
|
434 |
}
|
sl@0
|
435 |
return 1;
|
sl@0
|
436 |
}
|
sl@0
|
437 |
|
sl@0
|
438 |
#ifndef SYMBIAN
|
sl@0
|
439 |
#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
|
sl@0
|
440 |
/* Internal functions to read a string without echoing */
|
sl@0
|
441 |
static void read_till_nl(FILE *in)
|
sl@0
|
442 |
{
|
sl@0
|
443 |
#define SIZE 4
|
sl@0
|
444 |
char buf[SIZE+1];
|
sl@0
|
445 |
|
sl@0
|
446 |
do {
|
sl@0
|
447 |
fgets(buf,SIZE,in);
|
sl@0
|
448 |
} while (strchr(buf,'\n') == NULL);
|
sl@0
|
449 |
}
|
sl@0
|
450 |
|
sl@0
|
451 |
static volatile sig_atomic_t intr_signal;
|
sl@0
|
452 |
#endif
|
sl@0
|
453 |
#endif
|
sl@0
|
454 |
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
static int ps;
|
sl@0
|
457 |
int ok;
|
sl@0
|
458 |
char result[BUFSIZ];
|
sl@0
|
459 |
int maxsize = BUFSIZ-1;
|
sl@0
|
460 |
#ifndef SYMBIAN
|
sl@0
|
461 |
#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
|
sl@0
|
462 |
char *p;
|
sl@0
|
463 |
|
sl@0
|
464 |
intr_signal=0;
|
sl@0
|
465 |
ok=0;
|
sl@0
|
466 |
ps=0;
|
sl@0
|
467 |
|
sl@0
|
468 |
pushsig();
|
sl@0
|
469 |
ps=1;
|
sl@0
|
470 |
|
sl@0
|
471 |
if (!echo && !noecho_console(ui))
|
sl@0
|
472 |
goto error;
|
sl@0
|
473 |
ps=2;
|
sl@0
|
474 |
|
sl@0
|
475 |
result[0]='\0';
|
sl@0
|
476 |
#ifdef OPENSSL_SYS_MSDOS
|
sl@0
|
477 |
if (!echo)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
noecho_fgets(result,maxsize,tty_in);
|
sl@0
|
480 |
p=result; /* FIXME: noecho_fgets doesn't return errors */
|
sl@0
|
481 |
}
|
sl@0
|
482 |
else
|
sl@0
|
483 |
p=fgets(result,maxsize,tty_in);
|
sl@0
|
484 |
#else
|
sl@0
|
485 |
p=fgets(result,maxsize,tty_in);
|
sl@0
|
486 |
#endif
|
sl@0
|
487 |
if(!p)
|
sl@0
|
488 |
goto error;
|
sl@0
|
489 |
if (feof(tty_in)) goto error;
|
sl@0
|
490 |
if (ferror(tty_in)) goto error;
|
sl@0
|
491 |
if ((p=(char *)strchr(result,'\n')) != NULL)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
if (strip_nl)
|
sl@0
|
494 |
*p='\0';
|
sl@0
|
495 |
}
|
sl@0
|
496 |
else
|
sl@0
|
497 |
read_till_nl(tty_in);
|
sl@0
|
498 |
if (UI_set_result(ui, uis, result) >= 0)
|
sl@0
|
499 |
ok=1;
|
sl@0
|
500 |
|
sl@0
|
501 |
error:
|
sl@0
|
502 |
if (intr_signal == SIGINT)
|
sl@0
|
503 |
ok=-1;
|
sl@0
|
504 |
if (!echo) fprintf(tty_out,"\n");
|
sl@0
|
505 |
if (ps >= 2 && !echo && !echo_console(ui))
|
sl@0
|
506 |
ok=0;
|
sl@0
|
507 |
|
sl@0
|
508 |
if (ps >= 1)
|
sl@0
|
509 |
popsig();
|
sl@0
|
510 |
#else
|
sl@0
|
511 |
ok=1;
|
sl@0
|
512 |
#endif
|
sl@0
|
513 |
#endif
|
sl@0
|
514 |
OPENSSL_cleanse(result,BUFSIZ);
|
sl@0
|
515 |
return ok;
|
sl@0
|
516 |
}
|
sl@0
|
517 |
|
sl@0
|
518 |
|
sl@0
|
519 |
/* Internal functions to open, handle and close a channel to the console. */
|
sl@0
|
520 |
static int open_console(UI *ui)
|
sl@0
|
521 |
{
|
sl@0
|
522 |
CRYPTO_w_lock(CRYPTO_LOCK_UI);
|
sl@0
|
523 |
is_a_tty = 1;
|
sl@0
|
524 |
|
sl@0
|
525 |
#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE)
|
sl@0
|
526 |
tty_in=stdin;
|
sl@0
|
527 |
tty_out=stderr;
|
sl@0
|
528 |
#else
|
sl@0
|
529 |
# ifdef OPENSSL_SYS_MSDOS
|
sl@0
|
530 |
# define DEV_TTY "con"
|
sl@0
|
531 |
# else
|
sl@0
|
532 |
# define DEV_TTY "/dev/tty"
|
sl@0
|
533 |
# endif
|
sl@0
|
534 |
if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
|
sl@0
|
535 |
tty_in=stdin;
|
sl@0
|
536 |
if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
|
sl@0
|
537 |
tty_out=stderr;
|
sl@0
|
538 |
#endif
|
sl@0
|
539 |
|
sl@0
|
540 |
#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
|
sl@0
|
541 |
if (TTY_get(fileno(tty_in),&tty_orig) == -1)
|
sl@0
|
542 |
{
|
sl@0
|
543 |
#ifdef ENOTTY
|
sl@0
|
544 |
if (errno == ENOTTY)
|
sl@0
|
545 |
is_a_tty=0;
|
sl@0
|
546 |
else
|
sl@0
|
547 |
#endif
|
sl@0
|
548 |
#ifdef EINVAL
|
sl@0
|
549 |
/* Ariel Glenn ariel@columbia.edu reports that solaris
|
sl@0
|
550 |
* can return EINVAL instead. This should be ok */
|
sl@0
|
551 |
if (errno == EINVAL)
|
sl@0
|
552 |
is_a_tty=0;
|
sl@0
|
553 |
else
|
sl@0
|
554 |
#endif
|
sl@0
|
555 |
return 0;
|
sl@0
|
556 |
}
|
sl@0
|
557 |
#endif
|
sl@0
|
558 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
559 |
status = sys$assign(&terminal,&channel,0,0);
|
sl@0
|
560 |
if (status != SS$_NORMAL)
|
sl@0
|
561 |
return 0;
|
sl@0
|
562 |
status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
|
sl@0
|
563 |
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
sl@0
|
564 |
return 0;
|
sl@0
|
565 |
#endif
|
sl@0
|
566 |
return 1;
|
sl@0
|
567 |
}
|
sl@0
|
568 |
|
sl@0
|
569 |
static int noecho_console(UI *ui)
|
sl@0
|
570 |
{
|
sl@0
|
571 |
#ifdef TTY_FLAGS
|
sl@0
|
572 |
memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
|
sl@0
|
573 |
tty_new.TTY_FLAGS &= ~ECHO;
|
sl@0
|
574 |
#endif
|
sl@0
|
575 |
|
sl@0
|
576 |
#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
|
sl@0
|
577 |
if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
|
sl@0
|
578 |
return 0;
|
sl@0
|
579 |
#endif
|
sl@0
|
580 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
581 |
tty_new[0] = tty_orig[0];
|
sl@0
|
582 |
tty_new[1] = tty_orig[1] | TT$M_NOECHO;
|
sl@0
|
583 |
tty_new[2] = tty_orig[2];
|
sl@0
|
584 |
status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
|
sl@0
|
585 |
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
sl@0
|
586 |
return 0;
|
sl@0
|
587 |
#endif
|
sl@0
|
588 |
return 1;
|
sl@0
|
589 |
}
|
sl@0
|
590 |
|
sl@0
|
591 |
static int echo_console(UI *ui)
|
sl@0
|
592 |
{
|
sl@0
|
593 |
#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
|
sl@0
|
594 |
memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
|
sl@0
|
595 |
tty_new.TTY_FLAGS |= ECHO;
|
sl@0
|
596 |
#endif
|
sl@0
|
597 |
|
sl@0
|
598 |
#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
|
sl@0
|
599 |
if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
|
sl@0
|
600 |
return 0;
|
sl@0
|
601 |
#endif
|
sl@0
|
602 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
603 |
tty_new[0] = tty_orig[0];
|
sl@0
|
604 |
tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
|
sl@0
|
605 |
tty_new[2] = tty_orig[2];
|
sl@0
|
606 |
status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
|
sl@0
|
607 |
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
|
sl@0
|
608 |
return 0;
|
sl@0
|
609 |
#endif
|
sl@0
|
610 |
return 1;
|
sl@0
|
611 |
}
|
sl@0
|
612 |
|
sl@0
|
613 |
static int close_console(UI *ui)
|
sl@0
|
614 |
{
|
sl@0
|
615 |
if (tty_in != stdin) fclose(tty_in);
|
sl@0
|
616 |
if (tty_out != stderr) fclose(tty_out);
|
sl@0
|
617 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
618 |
status = sys$dassgn(channel);
|
sl@0
|
619 |
#endif
|
sl@0
|
620 |
CRYPTO_w_unlock(CRYPTO_LOCK_UI);
|
sl@0
|
621 |
|
sl@0
|
622 |
return 1;
|
sl@0
|
623 |
}
|
sl@0
|
624 |
|
sl@0
|
625 |
|
sl@0
|
626 |
#ifndef SYMBIAN
|
sl@0
|
627 |
#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
|
sl@0
|
628 |
/* Internal functions to handle signals and act on them */
|
sl@0
|
629 |
static void pushsig(void)
|
sl@0
|
630 |
{
|
sl@0
|
631 |
#ifndef OPENSSL_SYS_WIN32
|
sl@0
|
632 |
int i;
|
sl@0
|
633 |
#endif
|
sl@0
|
634 |
#ifdef SIGACTION
|
sl@0
|
635 |
struct sigaction sa;
|
sl@0
|
636 |
|
sl@0
|
637 |
memset(&sa,0,sizeof sa);
|
sl@0
|
638 |
sa.sa_handler=recsig;
|
sl@0
|
639 |
#endif
|
sl@0
|
640 |
|
sl@0
|
641 |
#ifdef OPENSSL_SYS_WIN32
|
sl@0
|
642 |
savsig[SIGABRT]=signal(SIGABRT,recsig);
|
sl@0
|
643 |
savsig[SIGFPE]=signal(SIGFPE,recsig);
|
sl@0
|
644 |
savsig[SIGILL]=signal(SIGILL,recsig);
|
sl@0
|
645 |
savsig[SIGINT]=signal(SIGINT,recsig);
|
sl@0
|
646 |
savsig[SIGSEGV]=signal(SIGSEGV,recsig);
|
sl@0
|
647 |
savsig[SIGTERM]=signal(SIGTERM,recsig);
|
sl@0
|
648 |
#else
|
sl@0
|
649 |
for (i=1; i<NX509_SIG; i++)
|
sl@0
|
650 |
{
|
sl@0
|
651 |
#ifdef SIGUSR1
|
sl@0
|
652 |
if (i == SIGUSR1)
|
sl@0
|
653 |
continue;
|
sl@0
|
654 |
#endif
|
sl@0
|
655 |
#ifdef SIGUSR2
|
sl@0
|
656 |
if (i == SIGUSR2)
|
sl@0
|
657 |
continue;
|
sl@0
|
658 |
#endif
|
sl@0
|
659 |
#ifdef SIGKILL
|
sl@0
|
660 |
if (i == SIGKILL) /* We can't make any action on that. */
|
sl@0
|
661 |
continue;
|
sl@0
|
662 |
#endif
|
sl@0
|
663 |
#ifdef SIGACTION
|
sl@0
|
664 |
sigaction(i,&sa,&savsig[i]);
|
sl@0
|
665 |
#else
|
sl@0
|
666 |
savsig[i]=signal(i,recsig);
|
sl@0
|
667 |
#endif
|
sl@0
|
668 |
}
|
sl@0
|
669 |
#endif
|
sl@0
|
670 |
|
sl@0
|
671 |
#ifdef SIGWINCH
|
sl@0
|
672 |
signal(SIGWINCH,SIG_DFL);
|
sl@0
|
673 |
#endif
|
sl@0
|
674 |
}
|
sl@0
|
675 |
|
sl@0
|
676 |
static void popsig(void)
|
sl@0
|
677 |
{
|
sl@0
|
678 |
#ifdef OPENSSL_SYS_WIN32
|
sl@0
|
679 |
signal(SIGABRT,savsig[SIGABRT]);
|
sl@0
|
680 |
signal(SIGFPE,savsig[SIGFPE]);
|
sl@0
|
681 |
signal(SIGILL,savsig[SIGILL]);
|
sl@0
|
682 |
signal(SIGINT,savsig[SIGINT]);
|
sl@0
|
683 |
signal(SIGSEGV,savsig[SIGSEGV]);
|
sl@0
|
684 |
signal(SIGTERM,savsig[SIGTERM]);
|
sl@0
|
685 |
#else
|
sl@0
|
686 |
int i;
|
sl@0
|
687 |
for (i=1; i<NX509_SIG; i++)
|
sl@0
|
688 |
{
|
sl@0
|
689 |
#ifdef SIGUSR1
|
sl@0
|
690 |
if (i == SIGUSR1)
|
sl@0
|
691 |
continue;
|
sl@0
|
692 |
#endif
|
sl@0
|
693 |
#ifdef SIGUSR2
|
sl@0
|
694 |
if (i == SIGUSR2)
|
sl@0
|
695 |
continue;
|
sl@0
|
696 |
#endif
|
sl@0
|
697 |
#ifdef SIGACTION
|
sl@0
|
698 |
sigaction(i,&savsig[i],NULL);
|
sl@0
|
699 |
#else
|
sl@0
|
700 |
signal(i,savsig[i]);
|
sl@0
|
701 |
#endif
|
sl@0
|
702 |
}
|
sl@0
|
703 |
#endif
|
sl@0
|
704 |
}
|
sl@0
|
705 |
|
sl@0
|
706 |
static void recsig(int i)
|
sl@0
|
707 |
{
|
sl@0
|
708 |
intr_signal=i;
|
sl@0
|
709 |
}
|
sl@0
|
710 |
#endif
|
sl@0
|
711 |
#endif
|
sl@0
|
712 |
|
sl@0
|
713 |
/* Internal functions specific for Windows */
|
sl@0
|
714 |
#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
|
sl@0
|
715 |
static int noecho_fgets(char *buf, int size, FILE *tty)
|
sl@0
|
716 |
{
|
sl@0
|
717 |
int i;
|
sl@0
|
718 |
char *p;
|
sl@0
|
719 |
|
sl@0
|
720 |
p=buf;
|
sl@0
|
721 |
for (;;)
|
sl@0
|
722 |
{
|
sl@0
|
723 |
if (size == 0)
|
sl@0
|
724 |
{
|
sl@0
|
725 |
*p='\0';
|
sl@0
|
726 |
break;
|
sl@0
|
727 |
}
|
sl@0
|
728 |
size--;
|
sl@0
|
729 |
#ifdef WIN16TTY
|
sl@0
|
730 |
i=_inchar();
|
sl@0
|
731 |
#else
|
sl@0
|
732 |
i=getch();
|
sl@0
|
733 |
#endif
|
sl@0
|
734 |
if (i == '\r') i='\n';
|
sl@0
|
735 |
*(p++)=i;
|
sl@0
|
736 |
if (i == '\n')
|
sl@0
|
737 |
{
|
sl@0
|
738 |
*p='\0';
|
sl@0
|
739 |
break;
|
sl@0
|
740 |
}
|
sl@0
|
741 |
}
|
sl@0
|
742 |
#ifndef SYMBIAN
|
sl@0
|
743 |
#ifdef WIN_CONSOLE_BUG
|
sl@0
|
744 |
/* Win95 has several evil console bugs: one of these is that the
|
sl@0
|
745 |
* last character read using getch() is passed to the next read: this is
|
sl@0
|
746 |
* usually a CR so this can be trouble. No STDIO fix seems to work but
|
sl@0
|
747 |
* flushing the console appears to do the trick.
|
sl@0
|
748 |
*/
|
sl@0
|
749 |
{
|
sl@0
|
750 |
HANDLE inh;
|
sl@0
|
751 |
inh = GetStdHandle(STD_INPUT_HANDLE);
|
sl@0
|
752 |
FlushConsoleInputBuffer(inh);
|
sl@0
|
753 |
}
|
sl@0
|
754 |
#endif
|
sl@0
|
755 |
#endif
|
sl@0
|
756 |
return(strlen(buf));
|
sl@0
|
757 |
}
|
sl@0
|
758 |
#endif
|
sl@0
|
759 |
|