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