summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ui
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2004-03-22 14:57:04 +0000
committercvs2svn <admin@example.com>2004-03-22 14:57:04 +0000
commit8e32b76f8c63e27a8c61f3e7d76a05ce1f419061 (patch)
tree03dad5c33d913f60f2a0a8df81dfdfb65788c5d9 /src/lib/libcrypto/ui
parentc051a3c4a24fa90cc755059f99d5c2e7131d5ca7 (diff)
downloadopenbsd-OPENBSD_3_5_BASE.tar.gz
openbsd-OPENBSD_3_5_BASE.tar.bz2
openbsd-OPENBSD_3_5_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_3_5_BASE'.OPENBSD_3_5_BASE
Diffstat (limited to 'src/lib/libcrypto/ui')
-rw-r--r--src/lib/libcrypto/ui/ui.h387
-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.c902
-rw-r--r--src/lib/libcrypto/ui/ui_locl.h148
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c673
-rw-r--r--src/lib/libcrypto/ui/ui_util.c91
7 files changed, 0 insertions, 2395 deletions
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h
deleted file mode 100644
index 735a2d988e..0000000000
--- a/src/lib/libcrypto/ui/ui.h
+++ /dev/null
@@ -1,387 +0,0 @@
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.h b/src/lib/libcrypto/ui/ui_compat.h
deleted file mode 100644
index b35c9bb7fd..0000000000
--- a/src/lib/libcrypto/ui/ui_compat.h
+++ /dev/null
@@ -1,83 +0,0 @@
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
deleted file mode 100644
index 39a62ae737..0000000000
--- a/src/lib/libcrypto/ui/ui_err.c
+++ /dev/null
@@ -1,111 +0,0 @@
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
deleted file mode 100644
index 33c86d76ef..0000000000
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ /dev/null
@@ -1,902 +0,0 @@
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#include "cryptlib.h"
66
67IMPLEMENT_STACK_OF(UI_STRING_ST)
68
69static const UI_METHOD *default_UI_meth=NULL;
70
71UI *UI_new(void)
72 {
73 return(UI_new_method(NULL));
74 }
75
76UI *UI_new_method(const UI_METHOD *method)
77 {
78 UI *ret;
79
80 ret=(UI *)OPENSSL_malloc(sizeof(UI));
81 if (ret == NULL)
82 {
83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
84 return NULL;
85 }
86 if (method == NULL)
87 ret->meth=UI_get_default_method();
88 else
89 ret->meth=method;
90
91 ret->strings=NULL;
92 ret->user_data=NULL;
93 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
94 return ret;
95 }
96
97static void free_string(UI_STRING *uis)
98 {
99 if (uis->flags & OUT_STRING_FREEABLE)
100 {
101 OPENSSL_free((char *)uis->out_string);
102 switch(uis->type)
103 {
104 case UIT_BOOLEAN:
105 OPENSSL_free((char *)uis->_.boolean_data.action_desc);
106 OPENSSL_free((char *)uis->_.boolean_data.ok_chars);
107 OPENSSL_free((char *)uis->_.boolean_data.cancel_chars);
108 break;
109 default:
110 break;
111 }
112 }
113 OPENSSL_free(uis);
114 }
115
116void UI_free(UI *ui)
117 {
118 if (ui == NULL)
119 return;
120 sk_UI_STRING_pop_free(ui->strings,free_string);
121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
122 OPENSSL_free(ui);
123 }
124
125static int allocate_string_stack(UI *ui)
126 {
127 if (ui->strings == NULL)
128 {
129 ui->strings=sk_UI_STRING_new_null();
130 if (ui->strings == NULL)
131 {
132 return -1;
133 }
134 }
135 return 0;
136 }
137
138static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt,
139 int prompt_freeable, enum UI_string_types type, int input_flags,
140 char *result_buf)
141 {
142 UI_STRING *ret = NULL;
143
144 if (prompt == NULL)
145 {
146 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER);
147 }
148 else if ((type == UIT_PROMPT || type == UIT_VERIFY
149 || type == UIT_BOOLEAN) && result_buf == NULL)
150 {
151 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER);
152 }
153 else if ((ret = (UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING))))
154 {
155 ret->out_string=prompt;
156 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
157 ret->input_flags=input_flags;
158 ret->type=type;
159 ret->result_buf=result_buf;
160 }
161 return ret;
162 }
163
164static int general_allocate_string(UI *ui, const char *prompt,
165 int prompt_freeable, enum UI_string_types type, int input_flags,
166 char *result_buf, int minsize, int maxsize, const char *test_buf)
167 {
168 int ret = -1;
169 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
170 type, input_flags, result_buf);
171
172 if (s)
173 {
174 if (allocate_string_stack(ui) >= 0)
175 {
176 s->_.string_data.result_minsize=minsize;
177 s->_.string_data.result_maxsize=maxsize;
178 s->_.string_data.test_buf=test_buf;
179 ret=sk_UI_STRING_push(ui->strings, s);
180 /* sk_push() returns 0 on error. Let's addapt that */
181 if (ret <= 0) ret--;
182 }
183 else
184 free_string(s);
185 }
186 return ret;
187 }
188
189static int general_allocate_boolean(UI *ui,
190 const char *prompt, const char *action_desc,
191 const char *ok_chars, const char *cancel_chars,
192 int prompt_freeable, enum UI_string_types type, int input_flags,
193 char *result_buf)
194 {
195 int ret = -1;
196 UI_STRING *s;
197 const char *p;
198
199 if (ok_chars == NULL)
200 {
201 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
202 }
203 else if (cancel_chars == NULL)
204 {
205 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
206 }
207 else
208 {
209 for(p = ok_chars; *p; p++)
210 {
211 if (strchr(cancel_chars, *p))
212 {
213 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
214 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
215 }
216 }
217
218 s = general_allocate_prompt(ui, prompt, prompt_freeable,
219 type, input_flags, result_buf);
220
221 if (s)
222 {
223 if (allocate_string_stack(ui) >= 0)
224 {
225 s->_.boolean_data.action_desc = action_desc;
226 s->_.boolean_data.ok_chars = ok_chars;
227 s->_.boolean_data.cancel_chars = cancel_chars;
228 ret=sk_UI_STRING_push(ui->strings, s);
229 /* sk_push() returns 0 on error.
230 Let's addapt that */
231 if (ret <= 0) ret--;
232 }
233 else
234 free_string(s);
235 }
236 }
237 return ret;
238 }
239
240/* Returns the index to the place in the stack or -1 for error. Uses a
241 direct reference to the prompt. */
242int UI_add_input_string(UI *ui, const char *prompt, int flags,
243 char *result_buf, int minsize, int maxsize)
244 {
245 return general_allocate_string(ui, prompt, 0,
246 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
247 }
248
249/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
250int UI_dup_input_string(UI *ui, const char *prompt, int flags,
251 char *result_buf, int minsize, int maxsize)
252 {
253 char *prompt_copy=NULL;
254
255 if (prompt)
256 {
257 prompt_copy=BUF_strdup(prompt);
258 if (prompt_copy == NULL)
259 {
260 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
261 return 0;
262 }
263 }
264
265 return general_allocate_string(ui, prompt_copy, 1,
266 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
267 }
268
269int UI_add_verify_string(UI *ui, const char *prompt, int flags,
270 char *result_buf, int minsize, int maxsize, const char *test_buf)
271 {
272 return general_allocate_string(ui, prompt, 0,
273 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
274 }
275
276int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
277 char *result_buf, int minsize, int maxsize, const char *test_buf)
278 {
279 char *prompt_copy=NULL;
280
281 if (prompt)
282 {
283 prompt_copy=BUF_strdup(prompt);
284 if (prompt_copy == NULL)
285 {
286 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
287 return -1;
288 }
289 }
290
291 return general_allocate_string(ui, prompt_copy, 1,
292 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
293 }
294
295int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
296 const char *ok_chars, const char *cancel_chars,
297 int flags, char *result_buf)
298 {
299 return general_allocate_boolean(ui, prompt, action_desc,
300 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
301 }
302
303int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
304 const char *ok_chars, const char *cancel_chars,
305 int flags, char *result_buf)
306 {
307 char *prompt_copy = NULL;
308 char *action_desc_copy = NULL;
309 char *ok_chars_copy = NULL;
310 char *cancel_chars_copy = NULL;
311
312 if (prompt)
313 {
314 prompt_copy=BUF_strdup(prompt);
315 if (prompt_copy == NULL)
316 {
317 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
318 goto err;
319 }
320 }
321
322 if (action_desc)
323 {
324 action_desc_copy=BUF_strdup(action_desc);
325 if (action_desc_copy == NULL)
326 {
327 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
328 goto err;
329 }
330 }
331
332 if (ok_chars)
333 {
334 ok_chars_copy=BUF_strdup(ok_chars);
335 if (ok_chars_copy == NULL)
336 {
337 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
338 goto err;
339 }
340 }
341
342 if (cancel_chars)
343 {
344 cancel_chars_copy=BUF_strdup(cancel_chars);
345 if (cancel_chars_copy == NULL)
346 {
347 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
348 goto err;
349 }
350 }
351
352 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
353 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
354 result_buf);
355 err:
356 if (prompt_copy) OPENSSL_free(prompt_copy);
357 if (action_desc_copy) OPENSSL_free(action_desc_copy);
358 if (ok_chars_copy) OPENSSL_free(ok_chars_copy);
359 if (cancel_chars_copy) OPENSSL_free(cancel_chars_copy);
360 return -1;
361 }
362
363int UI_add_info_string(UI *ui, const char *text)
364 {
365 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
366 NULL);
367 }
368
369int UI_dup_info_string(UI *ui, const char *text)
370 {
371 char *text_copy=NULL;
372
373 if (text)
374 {
375 text_copy=BUF_strdup(text);
376 if (text_copy == NULL)
377 {
378 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
379 return -1;
380 }
381 }
382
383 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
384 0, 0, NULL);
385 }
386
387int UI_add_error_string(UI *ui, const char *text)
388 {
389 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
390 NULL);
391 }
392
393int UI_dup_error_string(UI *ui, const char *text)
394 {
395 char *text_copy=NULL;
396
397 if (text)
398 {
399 text_copy=BUF_strdup(text);
400 if (text_copy == NULL)
401 {
402 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
403 return -1;
404 }
405 }
406 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
407 0, 0, NULL);
408 }
409
410char *UI_construct_prompt(UI *ui, const char *object_desc,
411 const char *object_name)
412 {
413 char *prompt = NULL;
414
415 if (ui->meth->ui_construct_prompt)
416 prompt = ui->meth->ui_construct_prompt(ui,
417 object_desc, object_name);
418 else
419 {
420 char prompt1[] = "Enter ";
421 char prompt2[] = " for ";
422 char prompt3[] = ":";
423 int len = 0;
424
425 if (object_desc == NULL)
426 return NULL;
427 len = sizeof(prompt1) - 1 + strlen(object_desc);
428 if (object_name)
429 len += sizeof(prompt2) - 1 + strlen(object_name);
430 len += sizeof(prompt3) - 1;
431
432 prompt = (char *)OPENSSL_malloc(len + 1);
433 strlcpy(prompt, prompt1, len + 1);
434 strlcat(prompt, object_desc, len + 1);
435 if (object_name)
436 {
437 strlcat(prompt, prompt2, len + 1);
438 strlcat(prompt, object_name, len + 1);
439 }
440 strlcat(prompt, prompt3, len + 1);
441 }
442 return prompt;
443 }
444
445void *UI_add_user_data(UI *ui, void *user_data)
446 {
447 void *old_data = ui->user_data;
448 ui->user_data = user_data;
449 return old_data;
450 }
451
452void *UI_get0_user_data(UI *ui)
453 {
454 return ui->user_data;
455 }
456
457const char *UI_get0_result(UI *ui, int i)
458 {
459 if (i < 0)
460 {
461 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL);
462 return NULL;
463 }
464 if (i >= sk_UI_STRING_num(ui->strings))
465 {
466 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
467 return NULL;
468 }
469 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
470 }
471
472static int print_error(const char *str, size_t len, UI *ui)
473 {
474 UI_STRING uis;
475
476 memset(&uis, 0, sizeof(uis));
477 uis.type = UIT_ERROR;
478 uis.out_string = str;
479
480 if (ui->meth->ui_write_string
481 && !ui->meth->ui_write_string(ui, &uis))
482 return -1;
483 return 0;
484 }
485
486int UI_process(UI *ui)
487 {
488 int i, ok=0;
489
490 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
491 return -1;
492
493 if (ui->flags & UI_FLAG_PRINT_ERRORS)
494 ERR_print_errors_cb(
495 (int (*)(const char *, size_t, void *))print_error,
496 (void *)ui);
497
498 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
499 {
500 if (ui->meth->ui_write_string
501 && !ui->meth->ui_write_string(ui,
502 sk_UI_STRING_value(ui->strings, i)))
503 {
504 ok=-1;
505 goto err;
506 }
507 }
508
509 if (ui->meth->ui_flush)
510 switch(ui->meth->ui_flush(ui))
511 {
512 case -1: /* Interrupt/Cancel/something... */
513 ok = -2;
514 goto err;
515 case 0: /* Errors */
516 ok = -1;
517 goto err;
518 default: /* Success */
519 ok = 0;
520 break;
521 }
522
523 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
524 {
525 if (ui->meth->ui_read_string)
526 {
527 switch(ui->meth->ui_read_string(ui,
528 sk_UI_STRING_value(ui->strings, i)))
529 {
530 case -1: /* Interrupt/Cancel/something... */
531 ok = -2;
532 goto err;
533 case 0: /* Errors */
534 ok = -1;
535 goto err;
536 default: /* Success */
537 ok = 0;
538 break;
539 }
540 }
541 }
542 err:
543 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
544 return -1;
545 return ok;
546 }
547
548int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
549 {
550 if (ui == NULL)
551 {
552 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER);
553 return -1;
554 }
555 switch(cmd)
556 {
557 case UI_CTRL_PRINT_ERRORS:
558 {
559 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
560 if (i)
561 ui->flags |= UI_FLAG_PRINT_ERRORS;
562 else
563 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
564 return save_flag;
565 }
566 case UI_CTRL_IS_REDOABLE:
567 return !!(ui->flags & UI_FLAG_REDOABLE);
568 default:
569 break;
570 }
571 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
572 return -1;
573 }
574
575int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
576 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
577 {
578 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
579 new_func, dup_func, free_func);
580 }
581
582int UI_set_ex_data(UI *r, int idx, void *arg)
583 {
584 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
585 }
586
587void *UI_get_ex_data(UI *r, int idx)
588 {
589 return(CRYPTO_get_ex_data(&r->ex_data,idx));
590 }
591
592void UI_set_default_method(const UI_METHOD *meth)
593 {
594 default_UI_meth=meth;
595 }
596
597const UI_METHOD *UI_get_default_method(void)
598 {
599 if (default_UI_meth == NULL)
600 {
601 default_UI_meth=UI_OpenSSL();
602 }
603 return default_UI_meth;
604 }
605
606const UI_METHOD *UI_get_method(UI *ui)
607 {
608 return ui->meth;
609 }
610
611const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth)
612 {
613 ui->meth=meth;
614 return ui->meth;
615 }
616
617
618UI_METHOD *UI_create_method(char *name)
619 {
620 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
621
622 if (ui_method)
623 memset(ui_method, 0, sizeof(*ui_method));
624 ui_method->name = BUF_strdup(name);
625 return ui_method;
626 }
627
628/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
629 (that is, it hasn't been allocated using UI_create_method(), you deserve
630 anything Murphy can throw at you and more! You have been warned. */
631void UI_destroy_method(UI_METHOD *ui_method)
632 {
633 OPENSSL_free(ui_method->name);
634 ui_method->name = NULL;
635 OPENSSL_free(ui_method);
636 }
637
638int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
639 {
640 if (method)
641 {
642 method->ui_open_session = opener;
643 return 0;
644 }
645 else
646 return -1;
647 }
648
649int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
650 {
651 if (method)
652 {
653 method->ui_write_string = writer;
654 return 0;
655 }
656 else
657 return -1;
658 }
659
660int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
661 {
662 if (method)
663 {
664 method->ui_flush = flusher;
665 return 0;
666 }
667 else
668 return -1;
669 }
670
671int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
672 {
673 if (method)
674 {
675 method->ui_read_string = reader;
676 return 0;
677 }
678 else
679 return -1;
680 }
681
682int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
683 {
684 if (method)
685 {
686 method->ui_close_session = closer;
687 return 0;
688 }
689 else
690 return -1;
691 }
692
693int (*UI_method_get_opener(UI_METHOD *method))(UI*)
694 {
695 if (method)
696 return method->ui_open_session;
697 else
698 return NULL;
699 }
700
701int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
702 {
703 if (method)
704 return method->ui_write_string;
705 else
706 return NULL;
707 }
708
709int (*UI_method_get_flusher(UI_METHOD *method))(UI*)
710 {
711 if (method)
712 return method->ui_flush;
713 else
714 return NULL;
715 }
716
717int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
718 {
719 if (method)
720 return method->ui_read_string;
721 else
722 return NULL;
723 }
724
725int (*UI_method_get_closer(UI_METHOD *method))(UI*)
726 {
727 if (method)
728 return method->ui_close_session;
729 else
730 return NULL;
731 }
732
733enum UI_string_types UI_get_string_type(UI_STRING *uis)
734 {
735 if (!uis)
736 return UIT_NONE;
737 return uis->type;
738 }
739
740int UI_get_input_flags(UI_STRING *uis)
741 {
742 if (!uis)
743 return 0;
744 return uis->input_flags;
745 }
746
747const char *UI_get0_output_string(UI_STRING *uis)
748 {
749 if (!uis)
750 return NULL;
751 return uis->out_string;
752 }
753
754const char *UI_get0_action_string(UI_STRING *uis)
755 {
756 if (!uis)
757 return NULL;
758 switch(uis->type)
759 {
760 case UIT_PROMPT:
761 case UIT_BOOLEAN:
762 return uis->_.boolean_data.action_desc;
763 default:
764 return NULL;
765 }
766 }
767
768const char *UI_get0_result_string(UI_STRING *uis)
769 {
770 if (!uis)
771 return NULL;
772 switch(uis->type)
773 {
774 case UIT_PROMPT:
775 case UIT_VERIFY:
776 return uis->result_buf;
777 default:
778 return NULL;
779 }
780 }
781
782const char *UI_get0_test_string(UI_STRING *uis)
783 {
784 if (!uis)
785 return NULL;
786 switch(uis->type)
787 {
788 case UIT_VERIFY:
789 return uis->_.string_data.test_buf;
790 default:
791 return NULL;
792 }
793 }
794
795int UI_get_result_minsize(UI_STRING *uis)
796 {
797 if (!uis)
798 return -1;
799 switch(uis->type)
800 {
801 case UIT_PROMPT:
802 case UIT_VERIFY:
803 return uis->_.string_data.result_minsize;
804 default:
805 return -1;
806 }
807 }
808
809int UI_get_result_maxsize(UI_STRING *uis)
810 {
811 if (!uis)
812 return -1;
813 switch(uis->type)
814 {
815 case UIT_PROMPT:
816 case UIT_VERIFY:
817 return uis->_.string_data.result_maxsize;
818 default:
819 return -1;
820 }
821 }
822
823int UI_set_result(UI *ui, UI_STRING *uis, const char *result)
824 {
825 int l = strlen(result);
826
827 ui->flags &= ~UI_FLAG_REDOABLE;
828
829 if (!uis)
830 return -1;
831 switch (uis->type)
832 {
833 case UIT_PROMPT:
834 case UIT_VERIFY:
835 {
836 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1];
837 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1];
838
839 BIO_snprintf(number1, sizeof(number1), "%d",
840 uis->_.string_data.result_minsize);
841 BIO_snprintf(number2, sizeof(number2), "%d",
842 uis->_.string_data.result_maxsize);
843
844 if (l < uis->_.string_data.result_minsize)
845 {
846 ui->flags |= UI_FLAG_REDOABLE;
847 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL);
848 ERR_add_error_data(5,"You must type in ",
849 number1," to ",number2," characters");
850 return -1;
851 }
852 if (l > uis->_.string_data.result_maxsize)
853 {
854 ui->flags |= UI_FLAG_REDOABLE;
855 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE);
856 ERR_add_error_data(5,"You must type in ",
857 number1," to ",number2," characters");
858 return -1;
859 }
860 }
861
862 if (!uis->result_buf)
863 {
864 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
865 return -1;
866 }
867
868 strlcpy(uis->result_buf, result,
869 uis->_.string_data.result_maxsize + 1);
870 break;
871 case UIT_BOOLEAN:
872 {
873 const char *p;
874
875 if (!uis->result_buf)
876 {
877 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
878 return -1;
879 }
880
881 uis->result_buf[0] = '\0';
882 for(p = result; *p; p++)
883 {
884 if (strchr(uis->_.boolean_data.ok_chars, *p))
885 {
886 uis->result_buf[0] =
887 uis->_.boolean_data.ok_chars[0];
888 break;
889 }
890 if (strchr(uis->_.boolean_data.cancel_chars, *p))
891 {
892 uis->result_buf[0] =
893 uis->_.boolean_data.cancel_chars[0];
894 break;
895 }
896 }
897 default:
898 break;
899 }
900 }
901 return 0;
902 }
diff --git a/src/lib/libcrypto/ui/ui_locl.h b/src/lib/libcrypto/ui/ui_locl.h
deleted file mode 100644
index 7d3a75a619..0000000000
--- a/src/lib/libcrypto/ui/ui_locl.h
+++ /dev/null
@@ -1,148 +0,0 @@
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
deleted file mode 100644
index 75318d48a1..0000000000
--- a/src/lib/libcrypto/ui/ui_openssl.c
+++ /dev/null
@@ -1,673 +0,0 @@
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#ifndef OPENSSL_SYS_WINCE
163# include <wincon.h>
164#endif
165#endif
166
167
168/* There are 5 types of terminal interface supported,
169 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
170 */
171
172#if defined(__sgi) && !defined(TERMIOS)
173# define TERMIOS
174# undef TERMIO
175# undef SGTTY
176#endif
177
178#if defined(linux) && !defined(TERMIO)
179# undef TERMIOS
180# define TERMIO
181# undef SGTTY
182#endif
183
184#ifdef _LIBC
185# undef TERMIOS
186# define TERMIO
187# undef SGTTY
188#endif
189
190#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
191# undef TERMIOS
192# undef TERMIO
193# define SGTTY
194#endif
195
196#if defined(OPENSSL_SYS_VXWORKS)
197#undef TERMIOS
198#undef TERMIO
199#undef SGTTY
200#endif
201
202#ifdef TERMIOS
203# include <termios.h>
204# define TTY_STRUCT struct termios
205# define TTY_FLAGS c_lflag
206# define TTY_get(tty,data) tcgetattr(tty,data)
207# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
208#endif
209
210#ifdef TERMIO
211# include <termio.h>
212# define TTY_STRUCT struct termio
213# define TTY_FLAGS c_lflag
214# define TTY_get(tty,data) ioctl(tty,TCGETA,data)
215# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
216#endif
217
218#ifdef SGTTY
219# include <sgtty.h>
220# define TTY_STRUCT struct sgttyb
221# define TTY_FLAGS sg_flags
222# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
223# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
224#endif
225
226#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
227# include <sys/ioctl.h>
228#endif
229
230#ifdef OPENSSL_SYS_MSDOS
231# include <conio.h>
232#endif
233
234#ifdef OPENSSL_SYS_VMS
235# include <ssdef.h>
236# include <iodef.h>
237# include <ttdef.h>
238# include <descrip.h>
239struct IOSB {
240 short iosb$w_value;
241 short iosb$w_count;
242 long iosb$l_info;
243 };
244#endif
245
246#ifdef OPENSSL_SYS_SUNOS
247 typedef int sig_atomic_t;
248#endif
249
250#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
251/*
252 * This one needs work. As a matter of fact the code is unoperational
253 * and this is only a trick to get it compiled.
254 * <appro@fy.chalmers.se>
255 */
256# define TTY_STRUCT int
257#endif
258
259#ifndef NX509_SIG
260# define NX509_SIG 32
261#endif
262
263
264/* Define globals. They are protected by a lock */
265#ifdef SIGACTION
266static struct sigaction savsig[NX509_SIG];
267#else
268static void (*savsig[NX509_SIG])(int );
269#endif
270
271#ifdef OPENSSL_SYS_VMS
272static struct IOSB iosb;
273static $DESCRIPTOR(terminal,"TT");
274static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
275static long status;
276static unsigned short channel = 0;
277#else
278#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
279static TTY_STRUCT tty_orig,tty_new;
280#endif
281#endif
282static FILE *tty_in, *tty_out;
283static int is_a_tty;
284
285/* Declare static functions */
286#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
287static void read_till_nl(FILE *);
288static void recsig(int);
289static void pushsig(void);
290static void popsig(void);
291#endif
292#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
293static int noecho_fgets(char *buf, int size, FILE *tty);
294#endif
295static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
296
297static int read_string(UI *ui, UI_STRING *uis);
298static int write_string(UI *ui, UI_STRING *uis);
299
300static int open_console(UI *ui);
301static int echo_console(UI *ui);
302static int noecho_console(UI *ui);
303static int close_console(UI *ui);
304
305static UI_METHOD ui_openssl =
306 {
307 "OpenSSL default user interface",
308 open_console,
309 write_string,
310 NULL, /* No flusher is needed for command lines */
311 read_string,
312 close_console,
313 NULL
314 };
315
316/* The method with all the built-in thingies */
317UI_METHOD *UI_OpenSSL(void)
318 {
319 return &ui_openssl;
320 }
321
322/* The following function makes sure that info and error strings are printed
323 before any prompt. */
324static int write_string(UI *ui, UI_STRING *uis)
325 {
326 switch (UI_get_string_type(uis))
327 {
328 case UIT_ERROR:
329 case UIT_INFO:
330 fputs(UI_get0_output_string(uis), tty_out);
331 fflush(tty_out);
332 break;
333 default:
334 break;
335 }
336 return 1;
337 }
338
339static int read_string(UI *ui, UI_STRING *uis)
340 {
341 int ok = 0;
342
343 switch (UI_get_string_type(uis))
344 {
345 case UIT_BOOLEAN:
346 fputs(UI_get0_output_string(uis), tty_out);
347 fputs(UI_get0_action_string(uis), tty_out);
348 fflush(tty_out);
349 return read_string_inner(ui, uis,
350 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
351 case UIT_PROMPT:
352 fputs(UI_get0_output_string(uis), tty_out);
353 fflush(tty_out);
354 return read_string_inner(ui, uis,
355 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
356 case UIT_VERIFY:
357 fprintf(tty_out,"Verifying - %s",
358 UI_get0_output_string(uis));
359 fflush(tty_out);
360 if ((ok = read_string_inner(ui, uis,
361 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
362 return ok;
363 if (strcmp(UI_get0_result_string(uis),
364 UI_get0_test_string(uis)) != 0)
365 {
366 fprintf(tty_out,"Verify failure\n");
367 fflush(tty_out);
368 return 0;
369 }
370 break;
371 default:
372 break;
373 }
374 return 1;
375 }
376
377
378#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
379/* Internal functions to read a string without echoing */
380static void read_till_nl(FILE *in)
381 {
382#define SIZE 4
383 char buf[SIZE+1];
384
385 do {
386 fgets(buf,SIZE,in);
387 } while (strchr(buf,'\n') == NULL);
388 }
389
390static volatile sig_atomic_t intr_signal;
391#endif
392
393static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
394 {
395 static int ps;
396 int ok;
397 char result[BUFSIZ];
398 int maxsize = BUFSIZ-1;
399#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
400 char *p;
401
402 intr_signal=0;
403 ok=0;
404 ps=0;
405
406 pushsig();
407 ps=1;
408
409 if (!echo && !noecho_console(ui))
410 goto error;
411 ps=2;
412
413 result[0]='\0';
414#ifdef OPENSSL_SYS_MSDOS
415 if (!echo)
416 {
417 noecho_fgets(result,maxsize,tty_in);
418 p=result; /* FIXME: noecho_fgets doesn't return errors */
419 }
420 else
421 p=fgets(result,maxsize,tty_in);
422#else
423 p=fgets(result,maxsize,tty_in);
424#endif
425 if(!p)
426 goto error;
427 if (feof(tty_in)) goto error;
428 if (ferror(tty_in)) goto error;
429 if ((p=(char *)strchr(result,'\n')) != NULL)
430 {
431 if (strip_nl)
432 *p='\0';
433 }
434 else
435 read_till_nl(tty_in);
436 if (UI_set_result(ui, uis, result) >= 0)
437 ok=1;
438
439error:
440 if (intr_signal == SIGINT)
441 ok=-1;
442 if (!echo) fprintf(tty_out,"\n");
443 if (ps >= 2 && !echo && !echo_console(ui))
444 ok=0;
445
446 if (ps >= 1)
447 popsig();
448#else
449 ok=1;
450#endif
451
452 OPENSSL_cleanse(result,BUFSIZ);
453 return ok;
454 }
455
456
457/* Internal functions to open, handle and close a channel to the console. */
458static int open_console(UI *ui)
459 {
460 CRYPTO_w_lock(CRYPTO_LOCK_UI);
461 is_a_tty = 1;
462
463#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS)
464 tty_in=stdin;
465 tty_out=stderr;
466#else
467# ifdef OPENSSL_SYS_MSDOS
468# define DEV_TTY "con"
469# else
470# define DEV_TTY "/dev/tty"
471# endif
472 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
473 tty_in=stdin;
474 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
475 tty_out=stderr;
476#endif
477
478#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
479 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
480 {
481#ifdef ENOTTY
482 if (errno == ENOTTY)
483 is_a_tty=0;
484 else
485#endif
486#ifdef EINVAL
487 /* Ariel Glenn ariel@columbia.edu reports that solaris
488 * can return EINVAL instead. This should be ok */
489 if (errno == EINVAL)
490 is_a_tty=0;
491 else
492#endif
493 return 0;
494 }
495#endif
496#ifdef OPENSSL_SYS_VMS
497 status = sys$assign(&terminal,&channel,0,0);
498 if (status != SS$_NORMAL)
499 return 0;
500 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
501 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
502 return 0;
503#endif
504 return 1;
505 }
506
507static int noecho_console(UI *ui)
508 {
509#ifdef TTY_FLAGS
510 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
511 tty_new.TTY_FLAGS &= ~ECHO;
512#endif
513
514#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
515 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
516 return 0;
517#endif
518#ifdef OPENSSL_SYS_VMS
519 tty_new[0] = tty_orig[0];
520 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
521 tty_new[2] = tty_orig[2];
522 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
523 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
524 return 0;
525#endif
526 return 1;
527 }
528
529static int echo_console(UI *ui)
530 {
531#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
532 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
533 tty_new.TTY_FLAGS |= ECHO;
534#endif
535
536#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
537 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
538 return 0;
539#endif
540#ifdef OPENSSL_SYS_VMS
541 tty_new[0] = tty_orig[0];
542 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
543 tty_new[2] = tty_orig[2];
544 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
545 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
546 return 0;
547#endif
548 return 1;
549 }
550
551static int close_console(UI *ui)
552 {
553 if (tty_in != stdin) fclose(tty_in);
554 if (tty_out != stderr) fclose(tty_out);
555#ifdef OPENSSL_SYS_VMS
556 status = sys$dassgn(channel);
557#endif
558 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
559
560 return 1;
561 }
562
563
564#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
565/* Internal functions to handle signals and act on them */
566static void pushsig(void)
567 {
568 int i;
569#ifdef SIGACTION
570 struct sigaction sa;
571
572 memset(&sa,0,sizeof sa);
573 sa.sa_handler=recsig;
574#endif
575
576 for (i=1; i<NX509_SIG; i++)
577 {
578#ifdef SIGUSR1
579 if (i == SIGUSR1)
580 continue;
581#endif
582#ifdef SIGUSR2
583 if (i == SIGUSR2)
584 continue;
585#endif
586#ifdef SIGKILL
587 if (i == SIGKILL) /* We can't make any action on that. */
588 continue;
589#endif
590#ifdef SIGACTION
591 sigaction(i,&sa,&savsig[i]);
592#else
593 savsig[i]=signal(i,recsig);
594#endif
595 }
596
597#ifdef SIGWINCH
598 signal(SIGWINCH,SIG_DFL);
599#endif
600 }
601
602static void popsig(void)
603 {
604 int i;
605
606 for (i=1; i<NX509_SIG; i++)
607 {
608#ifdef SIGUSR1
609 if (i == SIGUSR1)
610 continue;
611#endif
612#ifdef SIGUSR2
613 if (i == SIGUSR2)
614 continue;
615#endif
616#ifdef SIGACTION
617 sigaction(i,&savsig[i],NULL);
618#else
619 signal(i,savsig[i]);
620#endif
621 }
622 }
623
624static void recsig(int i)
625 {
626 intr_signal=i;
627 }
628#endif
629
630/* Internal functions specific for Windows */
631#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
632static int noecho_fgets(char *buf, int size, FILE *tty)
633 {
634 int i;
635 char *p;
636
637 p=buf;
638 for (;;)
639 {
640 if (size == 0)
641 {
642 *p='\0';
643 break;
644 }
645 size--;
646#ifdef WIN16TTY
647 i=_inchar();
648#else
649 i=getch();
650#endif
651 if (i == '\r') i='\n';
652 *(p++)=i;
653 if (i == '\n')
654 {
655 *p='\0';
656 break;
657 }
658 }
659#ifdef WIN_CONSOLE_BUG
660/* Win95 has several evil console bugs: one of these is that the
661 * last character read using getch() is passed to the next read: this is
662 * usually a CR so this can be trouble. No STDIO fix seems to work but
663 * flushing the console appears to do the trick.
664 */
665 {
666 HANDLE inh;
667 inh = GetStdHandle(STD_INPUT_HANDLE);
668 FlushConsoleInputBuffer(inh);
669 }
670#endif
671 return(strlen(buf));
672 }
673#endif
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
deleted file mode 100644
index 46bc8c1a9a..0000000000
--- a/src/lib/libcrypto/ui/ui_util.c
+++ /dev/null
@@ -1,91 +0,0 @@
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 OPENSSL_cleanse(buff,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 if (size < 1)
75 return -1;
76
77 ui = UI_new();
78 if (ui)
79 {
80 ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
81 if (ok >= 0 && verify)
82 ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1,
83 buf);
84 if (ok >= 0)
85 ok=UI_process(ui);
86 UI_free(ui);
87 }
88 if (ok > 0)
89 ok = 0;
90 return(ok);
91 }