summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ui')
-rw-r--r--src/lib/libcrypto/ui/Makefile.ssl117
-rw-r--r--src/lib/libcrypto/ui/ui.h387
-rw-r--r--src/lib/libcrypto/ui/ui_compat.c67
-rw-r--r--src/lib/libcrypto/ui/ui_compat.h83
-rw-r--r--src/lib/libcrypto/ui/ui_err.c111
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c899
-rw-r--r--src/lib/libcrypto/ui/ui_locl.h148
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c661
-rw-r--r--src/lib/libcrypto/ui/ui_util.c86
9 files changed, 2559 insertions, 0 deletions
diff --git a/src/lib/libcrypto/ui/Makefile.ssl b/src/lib/libcrypto/ui/Makefile.ssl
new file mode 100644
index 0000000000..d51c1ff67a
--- /dev/null
+++ b/src/lib/libcrypto/ui/Makefile.ssl
@@ -0,0 +1,117 @@
1#
2# OpenSSL/crypto/ui/Makefile
3#
4
5DIR= ui
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22#TEST= uitest.c
23TEST=
24APPS=
25
26COMPATSRC= ui_compat.c
27COMPATOBJ= ui_compat.o
28
29LIB=$(TOP)/libcrypto.a
30LIBSRC= ui_err.c ui_lib.c ui_openssl.c ui_util.c $(COMPATSRC)
31LIBOBJ= ui_err.o ui_lib.o ui_openssl.o ui_util.o $(COMPATOBJ)
32
33SRC= $(LIBSRC)
34
35EXHEADER= ui.h ui_compat.h
36HEADER= $(EXHEADER) ui_locl.h
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB)
48 @touch lib
49
50files:
51 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
52
53links:
54 @$(TOP)/util/point.sh Makefile.ssl Makefile
55 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
56 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
57 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
58
59install:
60 @for i in $(EXHEADER) ; \
61 do \
62 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
63 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
64 done;
65
66tags:
67 ctags $(SRC)
68
69tests:
70
71lint:
72 lint -DLINT $(INCLUDES) $(SRC)>fluff
73
74depend:
75 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
76
77dclean:
78 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
79 mv -f Makefile.new $(MAKEFILE)
80
81clean:
82 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
83
84# DO NOT DELETE THIS LINE -- make depend depends on it.
85
86ui_compat.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
87ui_compat.o: ../../include/openssl/opensslconf.h
88ui_compat.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
89ui_compat.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
90ui_compat.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
91ui_compat.o: ui_compat.c
92ui_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
93ui_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94ui_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
95ui_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
96ui_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97ui_err.o: ../../include/openssl/ui.h ui_err.c
98ui_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
99ui_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
100ui_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
101ui_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
102ui_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
103ui_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h ui_lib.c
104ui_lib.o: ui_locl.h
105ui_openssl.o: ../../e_os.h ../../include/openssl/bio.h
106ui_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
107ui_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
108ui_openssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
109ui_openssl.o: ../../include/openssl/opensslv.h
110ui_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
111ui_openssl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
112ui_openssl.o: ../cryptlib.h ui_locl.h ui_openssl.c
113ui_util.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
114ui_util.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
115ui_util.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
116ui_util.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
117ui_util.o: ui_util.c
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h
new file mode 100644
index 0000000000..735a2d988e
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui.h
@@ -0,0 +1,387 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_H
60#define HEADER_UI_H
61
62#include <openssl/crypto.h>
63#include <openssl/safestack.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The UI type is a holder for a specific user interface session. It can
70 contain an illimited number of informational or error strings as well
71 as things to prompt for, both passwords (noecho mode) and others (echo
72 mode), and verification of the same. All of these are called strings,
73 and are further described below. */
74typedef struct ui_st UI;
75
76/* All instances of UI have a reference to a method structure, which is a
77 ordered vector of functions that implement the lower level things to do.
78 There is an instruction on the implementation further down, in the section
79 for method implementors. */
80typedef struct ui_method_st UI_METHOD;
81
82
83/* All the following functions return -1 or NULL on error and in some cases
84 (UI_process()) -2 if interrupted or in some other way cancelled.
85 When everything is fine, they return 0, a positive value or a non-NULL
86 pointer, all depending on their purpose. */
87
88/* Creators and destructor. */
89UI *UI_new(void);
90UI *UI_new_method(const UI_METHOD *method);
91void UI_free(UI *ui);
92
93/* The following functions are used to add strings to be printed and prompt
94 strings to prompt for data. The names are UI_{add,dup}_<function>_string
95 and UI_{add,dup}_input_boolean.
96
97 UI_{add,dup}_<function>_string have the following meanings:
98 add add a text or prompt string. The pointers given to these
99 functions are used verbatim, no copying is done.
100 dup make a copy of the text or prompt string, then add the copy
101 to the collection of strings in the user interface.
102 <function>
103 The function is a name for the functionality that the given
104 string shall be used for. It can be one of:
105 input use the string as data prompt.
106 verify use the string as verification prompt. This
107 is used to verify a previous input.
108 info use the string for informational output.
109 error use the string for error output.
110 Honestly, there's currently no difference between info and error for the
111 moment.
112
113 UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
114 and are typically used when one wants to prompt for a yes/no response.
115
116
117 All of the functions in this group take a UI and a prompt string.
118 The string input and verify addition functions also take a flag argument,
119 a buffer for the result to end up with, a minimum input size and a maximum
120 input size (the result buffer MUST be large enough to be able to contain
121 the maximum number of characters). Additionally, the verify addition
122 functions takes another buffer to compare the result against.
123 The boolean input functions take an action description string (which should
124 be safe to ignore if the expected user action is obvious, for example with
125 a dialog box with an OK button and a Cancel button), a string of acceptable
126 characters to mean OK and to mean Cancel. The two last strings are checked
127 to make sure they don't have common characters. Additionally, the same
128 flag argument as for the string input is taken, as well as a result buffer.
129 The result buffer is required to be at least one byte long. Depending on
130 the answer, the first character from the OK or the Cancel character strings
131 will be stored in the first byte of the result buffer. No NUL will be
132 added, so the result is *not* a string.
133
134 On success, the all return an index of the added information. That index
135 is usefull when retrieving results with UI_get0_result(). */
136int UI_add_input_string(UI *ui, const char *prompt, int flags,
137 char *result_buf, int minsize, int maxsize);
138int UI_dup_input_string(UI *ui, const char *prompt, int flags,
139 char *result_buf, int minsize, int maxsize);
140int UI_add_verify_string(UI *ui, const char *prompt, int flags,
141 char *result_buf, int minsize, int maxsize, const char *test_buf);
142int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
143 char *result_buf, int minsize, int maxsize, const char *test_buf);
144int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
145 const char *ok_chars, const char *cancel_chars,
146 int flags, char *result_buf);
147int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
148 const char *ok_chars, const char *cancel_chars,
149 int flags, char *result_buf);
150int UI_add_info_string(UI *ui, const char *text);
151int UI_dup_info_string(UI *ui, const char *text);
152int UI_add_error_string(UI *ui, const char *text);
153int UI_dup_error_string(UI *ui, const char *text);
154
155/* These are the possible flags. They can be or'ed together. */
156/* Use to have echoing of input */
157#define UI_INPUT_FLAG_ECHO 0x01
158/* Use a default password. Where that password is found is completely
159 up to the application, it might for example be in the user data set
160 with UI_add_user_data(). It is not recommended to have more than
161 one input in each UI being marked with this flag, or the application
162 might get confused. */
163#define UI_INPUT_FLAG_DEFAULT_PWD 0x02
164
165/* The user of these routines may want to define flags of their own. The core
166 UI won't look at those, but will pass them on to the method routines. They
167 must use higher bits so they don't get confused with the UI bits above.
168 UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good
169 example of use is this:
170
171 #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE)
172
173*/
174#define UI_INPUT_FLAG_USER_BASE 16
175
176
177/* The following function helps construct a prompt. object_desc is a
178 textual short description of the object, for example "pass phrase",
179 and object_name is the name of the object (might be a card name or
180 a file name.
181 The returned string shall always be allocated on the heap with
182 OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
183
184 If the ui_method doesn't contain a pointer to a user-defined prompt
185 constructor, a default string is built, looking like this:
186
187 "Enter {object_desc} for {object_name}:"
188
189 So, if object_desc has the value "pass phrase" and object_name has
190 the value "foo.key", the resulting string is:
191
192 "Enter pass phrase for foo.key:"
193*/
194char *UI_construct_prompt(UI *ui_method,
195 const char *object_desc, const char *object_name);
196
197
198/* The following function is used to store a pointer to user-specific data.
199 Any previous such pointer will be returned and replaced.
200
201 For callback purposes, this function makes a lot more sense than using
202 ex_data, since the latter requires that different parts of OpenSSL or
203 applications share the same ex_data index.
204
205 Note that the UI_OpenSSL() method completely ignores the user data.
206 Other methods may not, however. */
207void *UI_add_user_data(UI *ui, void *user_data);
208/* We need a user data retrieving function as well. */
209void *UI_get0_user_data(UI *ui);
210
211/* Return the result associated with a prompt given with the index i. */
212const char *UI_get0_result(UI *ui, int i);
213
214/* When all strings have been added, process the whole thing. */
215int UI_process(UI *ui);
216
217/* Give a user interface parametrised control commands. This can be used to
218 send down an integer, a data pointer or a function pointer, as well as
219 be used to get information from a UI. */
220int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
221
222/* The commands */
223/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
224 OpenSSL error stack before printing any info or added error messages and
225 before any prompting. */
226#define UI_CTRL_PRINT_ERRORS 1
227/* Check if a UI_process() is possible to do again with the same instance of
228 a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0
229 if not. */
230#define UI_CTRL_IS_REDOABLE 2
231
232
233/* Some methods may use extra data */
234#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg)
235#define UI_get_app_data(s) UI_get_ex_data(s,0)
236int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
237 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
238int UI_set_ex_data(UI *r,int idx,void *arg);
239void *UI_get_ex_data(UI *r, int idx);
240
241/* Use specific methods instead of the built-in one */
242void UI_set_default_method(const UI_METHOD *meth);
243const UI_METHOD *UI_get_default_method(void);
244const UI_METHOD *UI_get_method(UI *ui);
245const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
246
247/* The method with all the built-in thingies */
248UI_METHOD *UI_OpenSSL(void);
249
250
251/* ---------- For method writers ---------- */
252/* A method contains a number of functions that implement the low level
253 of the User Interface. The functions are:
254
255 an opener This function starts a session, maybe by opening
256 a channel to a tty, or by opening a window.
257 a writer This function is called to write a given string,
258 maybe to the tty, maybe as a field label in a
259 window.
260 a flusher This function is called to flush everything that
261 has been output so far. It can be used to actually
262 display a dialog box after it has been built.
263 a reader This function is called to read a given prompt,
264 maybe from the tty, maybe from a field in a
265 window. Note that it's called wth all string
266 structures, not only the prompt ones, so it must
267 check such things itself.
268 a closer This function closes the session, maybe by closing
269 the channel to the tty, or closing the window.
270
271 All these functions are expected to return:
272
273 0 on error.
274 1 on success.
275 -1 on out-of-band events, for example if some prompting has
276 been canceled (by pressing Ctrl-C, for example). This is
277 only checked when returned by the flusher or the reader.
278
279 The way this is used, the opener is first called, then the writer for all
280 strings, then the flusher, then the reader for all strings and finally the
281 closer. Note that if you want to prompt from a terminal or other command
282 line interface, the best is to have the reader also write the prompts
283 instead of having the writer do it. If you want to prompt from a dialog
284 box, the writer can be used to build up the contents of the box, and the
285 flusher to actually display the box and run the event loop until all data
286 has been given, after which the reader only grabs the given data and puts
287 them back into the UI strings.
288
289 All method functions take a UI as argument. Additionally, the writer and
290 the reader take a UI_STRING.
291*/
292
293/* The UI_STRING type is the data structure that contains all the needed info
294 about a string or a prompt, including test data for a verification prompt.
295*/
296DECLARE_STACK_OF(UI_STRING)
297typedef struct ui_string_st UI_STRING;
298
299/* The different types of strings that are currently supported.
300 This is only needed by method authors. */
301enum UI_string_types
302 {
303 UIT_NONE=0,
304 UIT_PROMPT, /* Prompt for a string */
305 UIT_VERIFY, /* Prompt for a string and verify */
306 UIT_BOOLEAN, /* Prompt for a yes/no response */
307 UIT_INFO, /* Send info to the user */
308 UIT_ERROR /* Send an error message to the user */
309 };
310
311/* Create and manipulate methods */
312UI_METHOD *UI_create_method(char *name);
313void UI_destroy_method(UI_METHOD *ui_method);
314int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
315int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis));
316int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
317int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));
318int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
319int (*UI_method_get_opener(UI_METHOD *method))(UI*);
320int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
321int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
322int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
323int (*UI_method_get_closer(UI_METHOD *method))(UI*);
324
325/* The following functions are helpers for method writers to access relevant
326 data from a UI_STRING. */
327
328/* Return type of the UI_STRING */
329enum UI_string_types UI_get_string_type(UI_STRING *uis);
330/* Return input flags of the UI_STRING */
331int UI_get_input_flags(UI_STRING *uis);
332/* Return the actual string to output (the prompt, info or error) */
333const char *UI_get0_output_string(UI_STRING *uis);
334/* Return the optional action string to output (the boolean promtp instruction) */
335const char *UI_get0_action_string(UI_STRING *uis);
336/* Return the result of a prompt */
337const char *UI_get0_result_string(UI_STRING *uis);
338/* Return the string to test the result against. Only useful with verifies. */
339const char *UI_get0_test_string(UI_STRING *uis);
340/* Return the required minimum size of the result */
341int UI_get_result_minsize(UI_STRING *uis);
342/* Return the required maximum size of the result */
343int UI_get_result_maxsize(UI_STRING *uis);
344/* Set the result of a UI_STRING. */
345int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
346
347
348/* A couple of popular utility functions */
349int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);
350int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
351
352
353/* BEGIN ERROR CODES */
354/* The following lines are auto generated by the script mkerr.pl. Any changes
355 * made after this point may be overwritten when the script is next run.
356 */
357void ERR_load_UI_strings(void);
358
359/* Error codes for the UI functions. */
360
361/* Function codes. */
362#define UI_F_GENERAL_ALLOCATE_BOOLEAN 108
363#define UI_F_GENERAL_ALLOCATE_PROMPT 109
364#define UI_F_GENERAL_ALLOCATE_STRING 100
365#define UI_F_UI_CTRL 111
366#define UI_F_UI_DUP_ERROR_STRING 101
367#define UI_F_UI_DUP_INFO_STRING 102
368#define UI_F_UI_DUP_INPUT_BOOLEAN 110
369#define UI_F_UI_DUP_INPUT_STRING 103
370#define UI_F_UI_DUP_VERIFY_STRING 106
371#define UI_F_UI_GET0_RESULT 107
372#define UI_F_UI_NEW_METHOD 104
373#define UI_F_UI_SET_RESULT 105
374
375/* Reason codes. */
376#define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104
377#define UI_R_INDEX_TOO_LARGE 102
378#define UI_R_INDEX_TOO_SMALL 103
379#define UI_R_NO_RESULT_BUFFER 105
380#define UI_R_RESULT_TOO_LARGE 100
381#define UI_R_RESULT_TOO_SMALL 101
382#define UI_R_UNKNOWN_CONTROL_COMMAND 106
383
384#ifdef __cplusplus
385}
386#endif
387#endif
diff --git a/src/lib/libcrypto/ui/ui_compat.c b/src/lib/libcrypto/ui/ui_compat.c
new file mode 100644
index 0000000000..13e0f70d90
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_compat.c
@@ -0,0 +1,67 @@
1/* crypto/ui/ui_compat.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui_compat.h>
58
59int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 return UI_UTIL_read_pw_string(buf, length, prompt, verify);
62 }
63
64int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
65 {
66 return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
67 }
diff --git a/src/lib/libcrypto/ui/ui_compat.h b/src/lib/libcrypto/ui/ui_compat.h
new file mode 100644
index 0000000000..b35c9bb7fd
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_compat.h
@@ -0,0 +1,83 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_COMPAT_H
60#define HEADER_UI_COMPAT_H
61
62#include <openssl/opensslconf.h>
63#include <openssl/ui.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The following functions were previously part of the DES section,
70 and are provided here for backward compatibility reasons. */
71
72#define des_read_pw_string(b,l,p,v) \
73 _ossl_old_des_read_pw_string((b),(l),(p),(v))
74#define des_read_pw(b,bf,s,p,v) \
75 _ossl_old_des_read_pw((b),(bf),(s),(p),(v))
76
77int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);
78int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
79
80#ifdef __cplusplus
81}
82#endif
83#endif
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c
new file mode 100644
index 0000000000..39a62ae737
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_err.c
@@ -0,0 +1,111 @@
1/* crypto/ui/ui_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ui.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA UI_str_functs[]=
68 {
69{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_BOOLEAN,0), "GENERAL_ALLOCATE_BOOLEAN"},
70{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_PROMPT,0), "GENERAL_ALLOCATE_PROMPT"},
71{ERR_PACK(0,UI_F_GENERAL_ALLOCATE_STRING,0), "GENERAL_ALLOCATE_STRING"},
72{ERR_PACK(0,UI_F_UI_CTRL,0), "UI_ctrl"},
73{ERR_PACK(0,UI_F_UI_DUP_ERROR_STRING,0), "UI_dup_error_string"},
74{ERR_PACK(0,UI_F_UI_DUP_INFO_STRING,0), "UI_dup_info_string"},
75{ERR_PACK(0,UI_F_UI_DUP_INPUT_BOOLEAN,0), "UI_dup_input_boolean"},
76{ERR_PACK(0,UI_F_UI_DUP_INPUT_STRING,0), "UI_dup_input_string"},
77{ERR_PACK(0,UI_F_UI_DUP_VERIFY_STRING,0), "UI_dup_verify_string"},
78{ERR_PACK(0,UI_F_UI_GET0_RESULT,0), "UI_get0_result"},
79{ERR_PACK(0,UI_F_UI_NEW_METHOD,0), "UI_new_method"},
80{ERR_PACK(0,UI_F_UI_SET_RESULT,0), "UI_set_result"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA UI_str_reasons[]=
85 {
86{UI_R_COMMON_OK_AND_CANCEL_CHARACTERS ,"common ok and cancel characters"},
87{UI_R_INDEX_TOO_LARGE ,"index too large"},
88{UI_R_INDEX_TOO_SMALL ,"index too small"},
89{UI_R_NO_RESULT_BUFFER ,"no result buffer"},
90{UI_R_RESULT_TOO_LARGE ,"result too large"},
91{UI_R_RESULT_TOO_SMALL ,"result too small"},
92{UI_R_UNKNOWN_CONTROL_COMMAND ,"unknown control command"},
93{0,NULL}
94 };
95
96#endif
97
98void ERR_load_UI_strings(void)
99 {
100 static int init=1;
101
102 if (init)
103 {
104 init=0;
105#ifndef OPENSSL_NO_ERR
106 ERR_load_strings(ERR_LIB_UI,UI_str_functs);
107 ERR_load_strings(ERR_LIB_UI,UI_str_reasons);
108#endif
109
110 }
111 }
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
new file mode 100644
index 0000000000..16946cad95
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -0,0 +1,899 @@
1/* crypto/ui/ui_lib.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/e_os2.h>
61#include <openssl/buffer.h>
62#include <openssl/ui.h>
63#include <openssl/err.h>
64#include "ui_locl.h"
65
66IMPLEMENT_STACK_OF(UI_STRING_ST)
67
68static const UI_METHOD *default_UI_meth=NULL;
69
70UI *UI_new(void)
71 {
72 return(UI_new_method(NULL));
73 }
74
75UI *UI_new_method(const UI_METHOD *method)
76 {
77 UI *ret;
78
79 ret=(UI *)OPENSSL_malloc(sizeof(UI));
80 if (ret == NULL)
81 {
82 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
83 return NULL;
84 }
85 if (method == NULL)
86 ret->meth=UI_get_default_method();
87 else
88 ret->meth=method;
89
90 ret->strings=NULL;
91 ret->user_data=NULL;
92 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
93 return ret;
94 }
95
96static void free_string(UI_STRING *uis)
97 {
98 if (uis->flags & OUT_STRING_FREEABLE)
99 {
100 OPENSSL_free((char *)uis->out_string);
101 switch(uis->type)
102 {
103 case UIT_BOOLEAN:
104 OPENSSL_free((char *)uis->_.boolean_data.action_desc);
105 OPENSSL_free((char *)uis->_.boolean_data.ok_chars);
106 OPENSSL_free((char *)uis->_.boolean_data.cancel_chars);
107 break;
108 default:
109 break;
110 }
111 }
112 OPENSSL_free(uis);
113 }
114
115void UI_free(UI *ui)
116 {
117 if (ui == NULL)
118 return;
119 sk_UI_STRING_pop_free(ui->strings,free_string);
120 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
121 OPENSSL_free(ui);
122 }
123
124static int allocate_string_stack(UI *ui)
125 {
126 if (ui->strings == NULL)
127 {
128 ui->strings=sk_UI_STRING_new_null();
129 if (ui->strings == NULL)
130 {
131 return -1;
132 }
133 }
134 return 0;
135 }
136
137static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt,
138 int prompt_freeable, enum UI_string_types type, int input_flags,
139 char *result_buf)
140 {
141 UI_STRING *ret = NULL;
142
143 if (prompt == NULL)
144 {
145 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER);
146 }
147 else if (result_buf == NULL)
148 {
149 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER);
150 }
151 else if ((ret = (UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING))))
152 {
153 ret->out_string=prompt;
154 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
155 ret->input_flags=input_flags;
156 ret->type=type;
157 ret->result_buf=result_buf;
158 }
159 return ret;
160 }
161
162static int general_allocate_string(UI *ui, const char *prompt,
163 int prompt_freeable, enum UI_string_types type, int input_flags,
164 char *result_buf, int minsize, int maxsize, const char *test_buf)
165 {
166 int ret = -1;
167 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
168 type, input_flags, result_buf);
169
170 if (s)
171 {
172 if (allocate_string_stack(ui) >= 0)
173 {
174 s->_.string_data.result_minsize=minsize;
175 s->_.string_data.result_maxsize=maxsize;
176 s->_.string_data.test_buf=test_buf;
177 ret=sk_UI_STRING_push(ui->strings, s);
178 /* sk_push() returns 0 on error. Let's addapt that */
179 if (ret <= 0) ret--;
180 }
181 else
182 free_string(s);
183 }
184 return ret;
185 }
186
187static int general_allocate_boolean(UI *ui,
188 const char *prompt, const char *action_desc,
189 const char *ok_chars, const char *cancel_chars,
190 int prompt_freeable, enum UI_string_types type, int input_flags,
191 char *result_buf)
192 {
193 int ret = -1;
194 UI_STRING *s;
195 const char *p;
196
197 if (ok_chars == NULL)
198 {
199 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
200 }
201 else if (cancel_chars == NULL)
202 {
203 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
204 }
205 else
206 {
207 for(p = ok_chars; *p; p++)
208 {
209 if (strchr(cancel_chars, *p))
210 {
211 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
212 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
213 }
214 }
215
216 s = general_allocate_prompt(ui, prompt, prompt_freeable,
217 type, input_flags, result_buf);
218
219 if (s)
220 {
221 if (allocate_string_stack(ui) >= 0)
222 {
223 s->_.boolean_data.action_desc = action_desc;
224 s->_.boolean_data.ok_chars = ok_chars;
225 s->_.boolean_data.cancel_chars = cancel_chars;
226 ret=sk_UI_STRING_push(ui->strings, s);
227 /* sk_push() returns 0 on error.
228 Let's addapt that */
229 if (ret <= 0) ret--;
230 }
231 else
232 free_string(s);
233 }
234 }
235 return ret;
236 }
237
238/* Returns the index to the place in the stack or 0 for error. Uses a
239 direct reference to the prompt. */
240int UI_add_input_string(UI *ui, const char *prompt, int flags,
241 char *result_buf, int minsize, int maxsize)
242 {
243 return general_allocate_string(ui, prompt, 0,
244 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
245 }
246
247/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
248int UI_dup_input_string(UI *ui, const char *prompt, int flags,
249 char *result_buf, int minsize, int maxsize)
250 {
251 char *prompt_copy=NULL;
252
253 if (prompt)
254 {
255 prompt_copy=BUF_strdup(prompt);
256 if (prompt_copy == NULL)
257 {
258 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
259 return 0;
260 }
261 }
262
263 return general_allocate_string(ui, prompt_copy, 1,
264 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
265 }
266
267int UI_add_verify_string(UI *ui, const char *prompt, int flags,
268 char *result_buf, int minsize, int maxsize, const char *test_buf)
269 {
270 return general_allocate_string(ui, prompt, 0,
271 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
272 }
273
274int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
275 char *result_buf, int minsize, int maxsize, const char *test_buf)
276 {
277 char *prompt_copy=NULL;
278
279 if (prompt)
280 {
281 prompt_copy=BUF_strdup(prompt);
282 if (prompt_copy == NULL)
283 {
284 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
285 return -1;
286 }
287 }
288
289 return general_allocate_string(ui, prompt_copy, 1,
290 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
291 }
292
293int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
294 const char *ok_chars, const char *cancel_chars,
295 int flags, char *result_buf)
296 {
297 return general_allocate_boolean(ui, prompt, action_desc,
298 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
299 }
300
301int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
302 const char *ok_chars, const char *cancel_chars,
303 int flags, char *result_buf)
304 {
305 char *prompt_copy = NULL;
306 char *action_desc_copy = NULL;
307 char *ok_chars_copy = NULL;
308 char *cancel_chars_copy = NULL;
309
310 if (prompt)
311 {
312 prompt_copy=BUF_strdup(prompt);
313 if (prompt_copy == NULL)
314 {
315 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
316 goto err;
317 }
318 }
319
320 if (action_desc)
321 {
322 action_desc_copy=BUF_strdup(action_desc);
323 if (action_desc_copy == NULL)
324 {
325 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
326 goto err;
327 }
328 }
329
330 if (ok_chars)
331 {
332 ok_chars_copy=BUF_strdup(ok_chars);
333 if (ok_chars_copy == NULL)
334 {
335 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
336 goto err;
337 }
338 }
339
340 if (cancel_chars)
341 {
342 cancel_chars_copy=BUF_strdup(cancel_chars);
343 if (cancel_chars_copy == NULL)
344 {
345 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
346 goto err;
347 }
348 }
349
350 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
351 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
352 result_buf);
353 err:
354 if (prompt_copy) OPENSSL_free(prompt_copy);
355 if (action_desc_copy) OPENSSL_free(action_desc_copy);
356 if (ok_chars_copy) OPENSSL_free(ok_chars_copy);
357 if (cancel_chars_copy) OPENSSL_free(cancel_chars_copy);
358 return -1;
359 }
360
361int UI_add_info_string(UI *ui, const char *text)
362 {
363 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
364 NULL);
365 }
366
367int UI_dup_info_string(UI *ui, const char *text)
368 {
369 char *text_copy=NULL;
370
371 if (text)
372 {
373 text_copy=BUF_strdup(text);
374 if (text_copy == NULL)
375 {
376 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
377 return -1;
378 }
379 }
380
381 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
382 0, 0, NULL);
383 }
384
385int UI_add_error_string(UI *ui, const char *text)
386 {
387 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
388 NULL);
389 }
390
391int UI_dup_error_string(UI *ui, const char *text)
392 {
393 char *text_copy=NULL;
394
395 if (text)
396 {
397 text_copy=BUF_strdup(text);
398 if (text_copy == NULL)
399 {
400 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
401 return -1;
402 }
403 }
404 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
405 0, 0, NULL);
406 }
407
408char *UI_construct_prompt(UI *ui, const char *object_desc,
409 const char *object_name)
410 {
411 char *prompt = NULL;
412
413 if (ui->meth->ui_construct_prompt)
414 prompt = ui->meth->ui_construct_prompt(ui,
415 object_desc, object_name);
416 else
417 {
418 char prompt1[] = "Enter ";
419 char prompt2[] = " for ";
420 char prompt3[] = ":";
421 int len = 0;
422
423 if (object_desc == NULL)
424 return NULL;
425 len = sizeof(prompt1) - 1 + strlen(object_desc);
426 if (object_name)
427 len += sizeof(prompt2) - 1 + strlen(object_name);
428 len += sizeof(prompt3) - 1;
429
430 prompt = (char *)OPENSSL_malloc(len + 1);
431 strcpy(prompt, prompt1);
432 strcat(prompt, object_desc);
433 if (object_name)
434 {
435 strcat(prompt, prompt2);
436 strcat(prompt, object_name);
437 }
438 strcat(prompt, prompt3);
439 }
440 return prompt;
441 }
442
443void *UI_add_user_data(UI *ui, void *user_data)
444 {
445 void *old_data = ui->user_data;
446 ui->user_data = user_data;
447 return old_data;
448 }
449
450void *UI_get0_user_data(UI *ui)
451 {
452 return ui->user_data;
453 }
454
455const char *UI_get0_result(UI *ui, int i)
456 {
457 if (i < 0)
458 {
459 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL);
460 return NULL;
461 }
462 if (i >= sk_UI_STRING_num(ui->strings))
463 {
464 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
465 return NULL;
466 }
467 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
468 }
469
470static int print_error(const char *str, size_t len, UI *ui)
471 {
472 UI_STRING uis;
473
474 memset(&uis, 0, sizeof(uis));
475 uis.type = UIT_ERROR;
476 uis.out_string = str;
477
478 if (ui->meth->ui_write_string
479 && !ui->meth->ui_write_string(ui, &uis))
480 return -1;
481 return 0;
482 }
483
484int UI_process(UI *ui)
485 {
486 int i, ok=0;
487
488 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
489 return -1;
490
491 if (ui->flags & UI_FLAG_PRINT_ERRORS)
492 ERR_print_errors_cb(
493 (int (*)(const char *, size_t, void *))print_error,
494 (void *)ui);
495
496 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
497 {
498 if (ui->meth->ui_write_string
499 && !ui->meth->ui_write_string(ui,
500 sk_UI_STRING_value(ui->strings, i)))
501 {
502 ok=-1;
503 goto err;
504 }
505 }
506
507 if (ui->meth->ui_flush)
508 switch(ui->meth->ui_flush(ui))
509 {
510 case -1: /* Interrupt/Cancel/something... */
511 ok = -2;
512 goto err;
513 case 0: /* Errors */
514 ok = -1;
515 goto err;
516 default: /* Success */
517 ok = 0;
518 break;
519 }
520
521 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
522 {
523 if (ui->meth->ui_read_string)
524 {
525 switch(ui->meth->ui_read_string(ui,
526 sk_UI_STRING_value(ui->strings, i)))
527 {
528 case -1: /* Interrupt/Cancel/something... */
529 ok = -2;
530 goto err;
531 case 0: /* Errors */
532 ok = -1;
533 goto err;
534 default: /* Success */
535 ok = 0;
536 break;
537 }
538 }
539 }
540 err:
541 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
542 return -1;
543 return ok;
544 }
545
546int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
547 {
548 if (ui == NULL)
549 {
550 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER);
551 return -1;
552 }
553 switch(cmd)
554 {
555 case UI_CTRL_PRINT_ERRORS:
556 {
557 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
558 if (i)
559 ui->flags |= UI_FLAG_PRINT_ERRORS;
560 else
561 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
562 return save_flag;
563 }
564 case UI_CTRL_IS_REDOABLE:
565 return !!(ui->flags & UI_FLAG_REDOABLE);
566 default:
567 break;
568 }
569 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
570 return -1;
571 }
572
573int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
574 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
575 {
576 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
577 new_func, dup_func, free_func);
578 }
579
580int UI_set_ex_data(UI *r, int idx, void *arg)
581 {
582 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
583 }
584
585void *UI_get_ex_data(UI *r, int idx)
586 {
587 return(CRYPTO_get_ex_data(&r->ex_data,idx));
588 }
589
590void UI_set_default_method(const UI_METHOD *meth)
591 {
592 default_UI_meth=meth;
593 }
594
595const UI_METHOD *UI_get_default_method(void)
596 {
597 if (default_UI_meth == NULL)
598 {
599 default_UI_meth=UI_OpenSSL();
600 }
601 return default_UI_meth;
602 }
603
604const UI_METHOD *UI_get_method(UI *ui)
605 {
606 return ui->meth;
607 }
608
609const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth)
610 {
611 ui->meth=meth;
612 return ui->meth;
613 }
614
615
616UI_METHOD *UI_create_method(char *name)
617 {
618 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
619
620 if (ui_method)
621 memset(ui_method, 0, sizeof(*ui_method));
622 ui_method->name = BUF_strdup(name);
623 return ui_method;
624 }
625
626/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
627 (that is, it hasn't been allocated using UI_create_method(), you deserve
628 anything Murphy can throw at you and more! You have been warned. */
629void UI_destroy_method(UI_METHOD *ui_method)
630 {
631 OPENSSL_free(ui_method->name);
632 ui_method->name = NULL;
633 OPENSSL_free(ui_method);
634 }
635
636int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
637 {
638 if (method)
639 {
640 method->ui_open_session = opener;
641 return 0;
642 }
643 else
644 return -1;
645 }
646
647int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
648 {
649 if (method)
650 {
651 method->ui_write_string = writer;
652 return 0;
653 }
654 else
655 return -1;
656 }
657
658int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
659 {
660 if (method)
661 {
662 method->ui_flush = flusher;
663 return 0;
664 }
665 else
666 return -1;
667 }
668
669int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
670 {
671 if (method)
672 {
673 method->ui_read_string = reader;
674 return 0;
675 }
676 else
677 return -1;
678 }
679
680int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
681 {
682 if (method)
683 {
684 method->ui_close_session = closer;
685 return 0;
686 }
687 else
688 return -1;
689 }
690
691int (*UI_method_get_opener(UI_METHOD *method))(UI*)
692 {
693 if (method)
694 return method->ui_open_session;
695 else
696 return NULL;
697 }
698
699int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
700 {
701 if (method)
702 return method->ui_write_string;
703 else
704 return NULL;
705 }
706
707int (*UI_method_get_flusher(UI_METHOD *method))(UI*)
708 {
709 if (method)
710 return method->ui_flush;
711 else
712 return NULL;
713 }
714
715int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
716 {
717 if (method)
718 return method->ui_read_string;
719 else
720 return NULL;
721 }
722
723int (*UI_method_get_closer(UI_METHOD *method))(UI*)
724 {
725 if (method)
726 return method->ui_close_session;
727 else
728 return NULL;
729 }
730
731enum UI_string_types UI_get_string_type(UI_STRING *uis)
732 {
733 if (!uis)
734 return UIT_NONE;
735 return uis->type;
736 }
737
738int UI_get_input_flags(UI_STRING *uis)
739 {
740 if (!uis)
741 return 0;
742 return uis->input_flags;
743 }
744
745const char *UI_get0_output_string(UI_STRING *uis)
746 {
747 if (!uis)
748 return NULL;
749 return uis->out_string;
750 }
751
752const char *UI_get0_action_string(UI_STRING *uis)
753 {
754 if (!uis)
755 return NULL;
756 switch(uis->type)
757 {
758 case UIT_PROMPT:
759 case UIT_BOOLEAN:
760 return uis->_.boolean_data.action_desc;
761 default:
762 return NULL;
763 }
764 }
765
766const char *UI_get0_result_string(UI_STRING *uis)
767 {
768 if (!uis)
769 return NULL;
770 switch(uis->type)
771 {
772 case UIT_PROMPT:
773 case UIT_VERIFY:
774 return uis->result_buf;
775 default:
776 return NULL;
777 }
778 }
779
780const char *UI_get0_test_string(UI_STRING *uis)
781 {
782 if (!uis)
783 return NULL;
784 switch(uis->type)
785 {
786 case UIT_VERIFY:
787 return uis->_.string_data.test_buf;
788 default:
789 return NULL;
790 }
791 }
792
793int UI_get_result_minsize(UI_STRING *uis)
794 {
795 if (!uis)
796 return -1;
797 switch(uis->type)
798 {
799 case UIT_PROMPT:
800 case UIT_VERIFY:
801 return uis->_.string_data.result_minsize;
802 default:
803 return -1;
804 }
805 }
806
807int UI_get_result_maxsize(UI_STRING *uis)
808 {
809 if (!uis)
810 return -1;
811 switch(uis->type)
812 {
813 case UIT_PROMPT:
814 case UIT_VERIFY:
815 return uis->_.string_data.result_maxsize;
816 default:
817 return -1;
818 }
819 }
820
821int UI_set_result(UI *ui, UI_STRING *uis, const char *result)
822 {
823 int l = strlen(result);
824
825 ui->flags &= ~UI_FLAG_REDOABLE;
826
827 if (!uis)
828 return -1;
829 switch (uis->type)
830 {
831 case UIT_PROMPT:
832 case UIT_VERIFY:
833 {
834 char number1[20];
835 char number2[20];
836
837 BIO_snprintf(number1, sizeof(number1), "%d",
838 uis->_.string_data.result_minsize);
839 BIO_snprintf(number2, sizeof(number2), "%d",
840 uis->_.string_data.result_maxsize);
841
842 if (l < uis->_.string_data.result_minsize)
843 {
844 ui->flags |= UI_FLAG_REDOABLE;
845 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL);
846 ERR_add_error_data(5,"You must type in ",
847 number1," to ",number2," characters");
848 return -1;
849 }
850 if (l > uis->_.string_data.result_maxsize)
851 {
852 ui->flags |= UI_FLAG_REDOABLE;
853 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE);
854 ERR_add_error_data(5,"You must type in ",
855 number1," to ",number2," characters");
856 return -1;
857 }
858 }
859
860 if (!uis->result_buf)
861 {
862 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
863 return -1;
864 }
865
866 strcpy(uis->result_buf, result);
867 break;
868 case UIT_BOOLEAN:
869 {
870 const char *p;
871
872 if (!uis->result_buf)
873 {
874 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
875 return -1;
876 }
877
878 uis->result_buf[0] = '\0';
879 for(p = result; *p; p++)
880 {
881 if (strchr(uis->_.boolean_data.ok_chars, *p))
882 {
883 uis->result_buf[0] =
884 uis->_.boolean_data.ok_chars[0];
885 break;
886 }
887 if (strchr(uis->_.boolean_data.cancel_chars, *p))
888 {
889 uis->result_buf[0] =
890 uis->_.boolean_data.cancel_chars[0];
891 break;
892 }
893 }
894 default:
895 break;
896 }
897 }
898 return 0;
899 }
diff --git a/src/lib/libcrypto/ui/ui_locl.h b/src/lib/libcrypto/ui/ui_locl.h
new file mode 100644
index 0000000000..7d3a75a619
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_locl.h
@@ -0,0 +1,148 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_LOCL_H
60#define HEADER_UI_LOCL_H
61
62#include <openssl/ui.h>
63
64struct ui_method_st
65 {
66 char *name;
67
68 /* All the functions return 1 or non-NULL for success and 0 or NULL
69 for failure */
70
71 /* Open whatever channel for this, be it the console, an X window
72 or whatever.
73 This function should use the ex_data structure to save
74 intermediate data. */
75 int (*ui_open_session)(UI *ui);
76
77 int (*ui_write_string)(UI *ui, UI_STRING *uis);
78
79 /* Flush the output. If a GUI dialog box is used, this function can
80 be used to actually display it. */
81 int (*ui_flush)(UI *ui);
82
83 int (*ui_read_string)(UI *ui, UI_STRING *uis);
84
85 int (*ui_close_session)(UI *ui);
86
87 /* Construct a prompt in a user-defined manner. object_desc is a
88 textual short description of the object, for example "pass phrase",
89 and object_name is the name of the object (might be a card name or
90 a file name.
91 The returned string shall always be allocated on the heap with
92 OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). */
93 char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
94 const char *object_name);
95 };
96
97struct ui_string_st
98 {
99 enum UI_string_types type; /* Input */
100 const char *out_string; /* Input */
101 int input_flags; /* Flags from the user */
102
103 /* The following parameters are completely irrelevant for UIT_INFO,
104 and can therefore be set to 0 or NULL */
105 char *result_buf; /* Input and Output: If not NULL, user-defined
106 with size in result_maxsize. Otherwise, it
107 may be allocated by the UI routine, meaning
108 result_minsize is going to be overwritten.*/
109 union
110 {
111 struct
112 {
113 int result_minsize; /* Input: minimum required
114 size of the result.
115 */
116 int result_maxsize; /* Input: maximum permitted
117 size of the result */
118
119 const char *test_buf; /* Input: test string to verify
120 against */
121 } string_data;
122 struct
123 {
124 const char *action_desc; /* Input */
125 const char *ok_chars; /* Input */
126 const char *cancel_chars; /* Input */
127 } boolean_data;
128 } _;
129
130#define OUT_STRING_FREEABLE 0x01
131 int flags; /* flags for internal use */
132 };
133
134struct ui_st
135 {
136 const UI_METHOD *meth;
137 STACK_OF(UI_STRING) *strings; /* We might want to prompt for more
138 than one thing at a time, and
139 with different echoing status. */
140 void *user_data;
141 CRYPTO_EX_DATA ex_data;
142
143#define UI_FLAG_REDOABLE 0x0001
144#define UI_FLAG_PRINT_ERRORS 0x0100
145 int flags;
146 };
147
148#endif
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
new file mode 100644
index 0000000000..3aa03f74aa
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_openssl.c
@@ -0,0 +1,661 @@
1/* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) and others
3 * for the OpenSSL project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* The lowest level part of this file was previously in crypto/des/read_pwd.c,
60 * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
61 * All rights reserved.
62 *
63 * This package is an SSL implementation written
64 * by Eric Young (eay@cryptsoft.com).
65 * The implementation was written so as to conform with Netscapes SSL.
66 *
67 * This library is free for commercial and non-commercial use as long as
68 * the following conditions are aheared to. The following conditions
69 * apply to all code found in this distribution, be it the RC4, RSA,
70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
71 * included with this distribution is covered by the same copyright terms
72 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 *
74 * Copyright remains Eric Young's, and as such any Copyright notices in
75 * the code are not to be removed.
76 * If this package is used in a product, Eric Young should be given attribution
77 * as the author of the parts of the library used.
78 * This can be in the form of a textual message at program startup or
79 * in documentation (online or textual) provided with the package.
80 *
81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions
83 * are met:
84 * 1. Redistributions of source code must retain the copyright
85 * notice, this list of conditions and the following disclaimer.
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in the
88 * documentation and/or other materials provided with the distribution.
89 * 3. All advertising materials mentioning features or use of this software
90 * must display the following acknowledgement:
91 * "This product includes cryptographic software written by
92 * Eric Young (eay@cryptsoft.com)"
93 * The word 'cryptographic' can be left out if the rouines from the library
94 * being used are not cryptographic related :-).
95 * 4. If you include any Windows specific code (or a derivative thereof) from
96 * the apps directory (application code) you must include an acknowledgement:
97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
103 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
104 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
105 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE.
110 *
111 * The licence and distribution terms for any publically available version or
112 * derivative of this code cannot be changed. i.e. this code cannot simply be
113 * copied and put under another distribution licence
114 * [including the GNU Public Licence.]
115 */
116
117
118#include <openssl/e_os2.h>
119
120#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
121# ifdef OPENSSL_UNISTD
122# include OPENSSL_UNISTD
123# else
124# include <unistd.h>
125# endif
126/* If unistd.h defines _POSIX_VERSION, we conclude that we
127 * are on a POSIX system and have sigaction and termios. */
128# if defined(_POSIX_VERSION)
129
130# define SIGACTION
131# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132# define TERMIOS
133# endif
134
135# endif
136#endif
137
138#ifdef WIN16TTY
139# undef OPENSSL_SYS_WIN16
140# undef WIN16
141# undef _WINDOWS
142# include <graph.h>
143#endif
144
145/* 06-Apr-92 Luke Brennan Support for VMS */
146#include "ui_locl.h"
147#include "cryptlib.h"
148#include <signal.h>
149#include <stdio.h>
150#include <string.h>
151#include <errno.h>
152
153#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
154# include <starlet.h>
155# ifdef __DECC
156# pragma message disable DOLLARID
157# endif
158#endif
159
160#ifdef WIN_CONSOLE_BUG
161# include <windows.h>
162# include <wincon.h>
163#endif
164
165
166/* There are 5 types of terminal interface supported,
167 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
168 */
169
170#if defined(__sgi) && !defined(TERMIOS)
171# define TERMIOS
172# undef TERMIO
173# undef SGTTY
174#endif
175
176#if defined(linux) && !defined(TERMIO)
177# undef TERMIOS
178# define TERMIO
179# undef SGTTY
180#endif
181
182#ifdef _LIBC
183# undef TERMIOS
184# define TERMIO
185# undef SGTTY
186#endif
187
188#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
189# undef TERMIOS
190# undef TERMIO
191# define SGTTY
192#endif
193
194#if defined(OPENSSL_SYS_VSWORKS)
195#undef TERMIOS
196#undef TERMIO
197#undef SGTTY
198#endif
199
200#ifdef TERMIOS
201# include <termios.h>
202# define TTY_STRUCT struct termios
203# define TTY_FLAGS c_lflag
204# define TTY_get(tty,data) tcgetattr(tty,data)
205# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
206#endif
207
208#ifdef TERMIO
209# include <termio.h>
210# define TTY_STRUCT struct termio
211# define TTY_FLAGS c_lflag
212# define TTY_get(tty,data) ioctl(tty,TCGETA,data)
213# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
214#endif
215
216#ifdef SGTTY
217# include <sgtty.h>
218# define TTY_STRUCT struct sgttyb
219# define TTY_FLAGS sg_flags
220# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
221# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
222#endif
223
224#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC)
225# include <sys/ioctl.h>
226#endif
227
228#ifdef OPENSSL_SYS_MSDOS
229# include <conio.h>
230#endif
231
232#ifdef OPENSSL_SYS_VMS
233# include <ssdef.h>
234# include <iodef.h>
235# include <ttdef.h>
236# include <descrip.h>
237struct IOSB {
238 short iosb$w_value;
239 short iosb$w_count;
240 long iosb$l_info;
241 };
242#endif
243
244#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
245/*
246 * This one needs work. As a matter of fact the code is unoperational
247 * and this is only a trick to get it compiled.
248 * <appro@fy.chalmers.se>
249 */
250# define TTY_STRUCT int
251#endif
252
253#ifndef NX509_SIG
254# define NX509_SIG 32
255#endif
256
257
258/* Define globals. They are protected by a lock */
259#ifdef SIGACTION
260static struct sigaction savsig[NX509_SIG];
261#else
262static void (*savsig[NX509_SIG])(int );
263#endif
264
265#ifdef OPENSSL_SYS_VMS
266static struct IOSB iosb;
267static $DESCRIPTOR(terminal,"TT");
268static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
269static long status;
270static unsigned short channel = 0;
271#else
272#ifndef OPENSSL_SYS_MSDOS
273static TTY_STRUCT tty_orig,tty_new;
274#endif
275#endif
276static FILE *tty_in, *tty_out;
277static int is_a_tty;
278
279/* Declare static functions */
280static void read_till_nl(FILE *);
281static void recsig(int);
282static void pushsig(void);
283static void popsig(void);
284#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
285static int noecho_fgets(char *buf, int size, FILE *tty);
286#endif
287static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
288
289static int read_string(UI *ui, UI_STRING *uis);
290static int write_string(UI *ui, UI_STRING *uis);
291
292static int open_console(UI *ui);
293static int echo_console(UI *ui);
294static int noecho_console(UI *ui);
295static int close_console(UI *ui);
296
297static UI_METHOD ui_openssl =
298 {
299 "OpenSSL default user interface",
300 open_console,
301 write_string,
302 NULL, /* No flusher is needed for command lines */
303 read_string,
304 close_console,
305 NULL
306 };
307
308/* The method with all the built-in thingies */
309UI_METHOD *UI_OpenSSL(void)
310 {
311 return &ui_openssl;
312 }
313
314/* The following function makes sure that info and error strings are printed
315 before any prompt. */
316static int write_string(UI *ui, UI_STRING *uis)
317 {
318 switch (UI_get_string_type(uis))
319 {
320 case UIT_ERROR:
321 case UIT_INFO:
322 fputs(UI_get0_output_string(uis), tty_out);
323 fflush(tty_out);
324 break;
325 default:
326 break;
327 }
328 return 1;
329 }
330
331static int read_string(UI *ui, UI_STRING *uis)
332 {
333 int ok = 0;
334
335 switch (UI_get_string_type(uis))
336 {
337 case UIT_BOOLEAN:
338 fputs(UI_get0_output_string(uis), tty_out);
339 fputs(UI_get0_action_string(uis), tty_out);
340 fflush(tty_out);
341 return read_string_inner(ui, uis,
342 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
343 case UIT_PROMPT:
344 fputs(UI_get0_output_string(uis), tty_out);
345 fflush(tty_out);
346 return read_string_inner(ui, uis,
347 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
348 case UIT_VERIFY:
349 fprintf(tty_out,"Verifying - %s",
350 UI_get0_output_string(uis));
351 fflush(tty_out);
352 if ((ok = read_string_inner(ui, uis,
353 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
354 return ok;
355 if (strcmp(UI_get0_result_string(uis),
356 UI_get0_test_string(uis)) != 0)
357 {
358 fprintf(tty_out,"Verify failure\n");
359 fflush(tty_out);
360 return 0;
361 }
362 break;
363 default:
364 break;
365 }
366 return 1;
367 }
368
369
370/* Internal functions to read a string without echoing */
371static void read_till_nl(FILE *in)
372 {
373#define SIZE 4
374 char buf[SIZE+1];
375
376 do {
377 fgets(buf,SIZE,in);
378 } while (strchr(buf,'\n') == NULL);
379 }
380
381static sig_atomic_t intr_signal;
382
383static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
384 {
385 static int ps;
386 int ok;
387 char result[BUFSIZ];
388 int maxsize = BUFSIZ-1;
389 char *p;
390
391#ifndef OPENSSL_SYS_WIN16
392 intr_signal=0;
393 ok=0;
394 ps=0;
395
396 pushsig();
397 ps=1;
398
399 if (!echo && !noecho_console(ui))
400 goto error;
401 ps=2;
402
403 result[0]='\0';
404#ifdef OPENSSL_SYS_MSDOS
405 if (!echo)
406 {
407 noecho_fgets(result,maxsize,tty_in);
408 p=result; /* FIXME: noecho_fgets doesn't return errors */
409 }
410 else
411 p=fgets(result,maxsize,tty_in);
412#else
413 p=fgets(result,maxsize,tty_in);
414#endif
415 if(!p)
416 goto error;
417 if (feof(tty_in)) goto error;
418 if (ferror(tty_in)) goto error;
419 if ((p=(char *)strchr(result,'\n')) != NULL)
420 {
421 if (strip_nl)
422 *p='\0';
423 }
424 else
425 read_till_nl(tty_in);
426 if (UI_set_result(ui, uis, result) >= 0)
427 ok=1;
428
429error:
430 if (intr_signal == SIGINT)
431 ok=-1;
432 if (!echo) fprintf(tty_out,"\n");
433 if (ps >= 2 && !echo && !echo_console(ui))
434 ok=0;
435
436 if (ps >= 1)
437 popsig();
438#else
439 ok=1;
440#endif
441
442 memset(result,0,BUFSIZ);
443 return ok;
444 }
445
446
447/* Internal functions to open, handle and close a channel to the console. */
448static int open_console(UI *ui)
449 {
450 CRYPTO_w_lock(CRYPTO_LOCK_UI);
451 is_a_tty = 1;
452
453#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VSWORKS)
454 tty_in=stdin;
455 tty_out=stderr;
456#else
457# ifdef OPENSSL_SYS_MSDOS
458# define DEV_TTY "con"
459# else
460# define DEV_TTY "/dev/tty"
461# endif
462 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
463 tty_in=stdin;
464 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
465 tty_out=stderr;
466#endif
467
468#if defined(TTY_get) && !defined(VMS)
469 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
470 {
471#ifdef ENOTTY
472 if (errno == ENOTTY)
473 is_a_tty=0;
474 else
475#endif
476#ifdef EINVAL
477 /* Ariel Glenn ariel@columbia.edu reports that solaris
478 * can return EINVAL instead. This should be ok */
479 if (errno == EINVAL)
480 is_a_tty=0;
481 else
482#endif
483 return 0;
484 }
485#endif
486#ifdef OPENSSL_SYS_VMS
487 status = sys$assign(&terminal,&channel,0,0);
488 if (status != SS$_NORMAL)
489 return 0;
490 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
491 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
492 return 0;
493#endif
494 return 1;
495 }
496
497static int noecho_console(UI *ui)
498 {
499#ifdef TTY_FLAGS
500 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
501 tty_new.TTY_FLAGS &= ~ECHO;
502#endif
503
504#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
505 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
506 return 0;
507#endif
508#ifdef OPENSSL_SYS_VMS
509 tty_new[0] = tty_orig[0];
510 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
511 tty_new[2] = tty_orig[2];
512 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
513 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
514 return 0;
515#endif
516 return 1;
517 }
518
519static int echo_console(UI *ui)
520 {
521#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
522 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
523 tty_new.TTY_FLAGS |= ECHO;
524#endif
525
526#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
527 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
528 return 0;
529#endif
530#ifdef OPENSSL_SYS_VMS
531 tty_new[0] = tty_orig[0];
532 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
533 tty_new[2] = tty_orig[2];
534 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
535 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
536 return 0;
537#endif
538 return 1;
539 }
540
541static int close_console(UI *ui)
542 {
543 if (tty_in != stderr) fclose(tty_in);
544 if (tty_out != stderr) fclose(tty_out);
545#ifdef OPENSSL_SYS_VMS
546 status = sys$dassgn(channel);
547#endif
548 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
549
550 return 1;
551 }
552
553
554/* Internal functions to handle signals and act on them */
555static void pushsig(void)
556 {
557 int i;
558#ifdef SIGACTION
559 struct sigaction sa;
560
561 memset(&sa,0,sizeof sa);
562 sa.sa_handler=recsig;
563#endif
564
565 for (i=1; i<NX509_SIG; i++)
566 {
567#ifdef SIGUSR1
568 if (i == SIGUSR1)
569 continue;
570#endif
571#ifdef SIGUSR2
572 if (i == SIGUSR2)
573 continue;
574#endif
575#ifdef SIGKILL
576 if (i == SIGKILL) /* We can't make any action on that. */
577 continue;
578#endif
579#ifdef SIGACTION
580 sigaction(i,&sa,&savsig[i]);
581#else
582 savsig[i]=signal(i,recsig);
583#endif
584 }
585
586#ifdef SIGWINCH
587 signal(SIGWINCH,SIG_DFL);
588#endif
589 }
590
591static void popsig(void)
592 {
593 int i;
594
595 for (i=1; i<NX509_SIG; i++)
596 {
597#ifdef SIGUSR1
598 if (i == SIGUSR1)
599 continue;
600#endif
601#ifdef SIGUSR2
602 if (i == SIGUSR2)
603 continue;
604#endif
605#ifdef SIGACTION
606 sigaction(i,&savsig[i],NULL);
607#else
608 signal(i,savsig[i]);
609#endif
610 }
611 }
612
613static void recsig(int i)
614 {
615 intr_signal=i;
616 }
617
618/* Internal functions specific for Windows */
619#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
620static int noecho_fgets(char *buf, int size, FILE *tty)
621 {
622 int i;
623 char *p;
624
625 p=buf;
626 for (;;)
627 {
628 if (size == 0)
629 {
630 *p='\0';
631 break;
632 }
633 size--;
634#ifdef WIN16TTY
635 i=_inchar();
636#else
637 i=getch();
638#endif
639 if (i == '\r') i='\n';
640 *(p++)=i;
641 if (i == '\n')
642 {
643 *p='\0';
644 break;
645 }
646 }
647#ifdef WIN_CONSOLE_BUG
648/* Win95 has several evil console bugs: one of these is that the
649 * last character read using getch() is passed to the next read: this is
650 * usually a CR so this can be trouble. No STDIO fix seems to work but
651 * flushing the console appears to do the trick.
652 */
653 {
654 HANDLE inh;
655 inh = GetStdHandle(STD_INPUT_HANDLE);
656 FlushConsoleInputBuffer(inh);
657 }
658#endif
659 return(strlen(buf));
660 }
661#endif
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
new file mode 100644
index 0000000000..7c6f7d3a73
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_util.c
@@ -0,0 +1,86 @@
1/* crypto/ui/ui_util.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui.h>
58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 char buff[BUFSIZ];
62 int ret;
63
64 ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
65 memset(buff,0,BUFSIZ);
66 return(ret);
67 }
68
69int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
70 {
71 int ok = 0;
72 UI *ui;
73
74 ui = UI_new();
75 if (ui)
76 {
77 ok = UI_add_input_string(ui,prompt,0,buf,0,BUFSIZ-1);
78 if (ok == 0 && verify)
79 ok = UI_add_verify_string(ui,prompt,0,buff,0,BUFSIZ-1,
80 buf);
81 if (ok == 0)
82 ok=UI_process(ui);
83 UI_free(ui);
84 }
85 return(ok);
86 }