diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ui/ui.h | 397 | ||||
| -rw-r--r-- | src/lib/libcrypto/ui/ui_err.c | 98 | ||||
| -rw-r--r-- | src/lib/libcrypto/ui/ui_lib.c | 907 | ||||
| -rw-r--r-- | src/lib/libcrypto/ui/ui_local.h | 152 | ||||
| -rw-r--r-- | src/lib/libcrypto/ui/ui_null.c | 18 | ||||
| -rw-r--r-- | src/lib/libcrypto/ui/ui_openssl.c | 398 |
6 files changed, 0 insertions, 1970 deletions
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h deleted file mode 100644 index cc400c2d5a..0000000000 --- a/src/lib/libcrypto/ui/ui.h +++ /dev/null | |||
| @@ -1,397 +0,0 @@ | |||
| 1 | /* $OpenBSD: ui.h,v 1.20 2025/03/09 15:25:53 tb 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 | #include <openssl/crypto.h> | ||
| 65 | #include <openssl/safestack.h> | ||
| 66 | #include <openssl/ossl_typ.h> | ||
| 67 | |||
| 68 | #ifdef __cplusplus | ||
| 69 | extern "C" { | ||
| 70 | #endif | ||
| 71 | |||
| 72 | /* Declared already in ossl_typ.h */ | ||
| 73 | /* typedef struct ui_st UI; */ | ||
| 74 | /* typedef struct ui_method_st UI_METHOD; */ | ||
| 75 | |||
| 76 | |||
| 77 | /* | ||
| 78 | * All the following functions return -1 or NULL on error and in some cases | ||
| 79 | * (UI_process()) -2 if interrupted or in some other way cancelled. | ||
| 80 | * When everything is fine, they return 0, a positive value or a non-NULL | ||
| 81 | * pointer, all depending on their purpose. | ||
| 82 | */ | ||
| 83 | |||
| 84 | /* Creators and destructor. */ | ||
| 85 | UI *UI_new(void); | ||
| 86 | UI *UI_new_method(const UI_METHOD *method); | ||
| 87 | void UI_free(UI *ui); | ||
| 88 | |||
| 89 | /* | ||
| 90 | * The following functions are used to add strings to be printed and prompt | ||
| 91 | * strings to prompt for data. The names are UI_{add,dup}_<function>_string | ||
| 92 | * and UI_{add,dup}_input_boolean. | ||
| 93 | * | ||
| 94 | * UI_{add,dup}_<function>_string have the following meanings: | ||
| 95 | * add add a text or prompt string. The pointers given to these | ||
| 96 | * functions are used verbatim, no copying is done. | ||
| 97 | * dup make a copy of the text or prompt string, then add the copy | ||
| 98 | * to the collection of strings in the user interface. | ||
| 99 | * <function> | ||
| 100 | * The function is a name for the functionality that the given | ||
| 101 | * string shall be used for. It can be one of: | ||
| 102 | * input use the string as data prompt. | ||
| 103 | * verify use the string as verification prompt. This | ||
| 104 | * is used to verify a previous input. | ||
| 105 | * info use the string for informational output. | ||
| 106 | * error use the string for error output. | ||
| 107 | * Honestly, there's currently no difference between info and error for the | ||
| 108 | * moment. | ||
| 109 | * | ||
| 110 | * UI_{add,dup}_input_boolean have the same semantics for "add" and "dup", | ||
| 111 | * and are typically used when one wants to prompt for a yes/no response. | ||
| 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 in, 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 functions all return an index of the added information. | ||
| 131 | * That index is useful when retrieving results with UI_get0_result(). | ||
| 132 | */ | ||
| 133 | int UI_add_input_string(UI *ui, const char *prompt, int flags, | ||
| 134 | char *result_buf, int minsize, int maxsize); | ||
| 135 | int UI_dup_input_string(UI *ui, const char *prompt, int flags, | ||
| 136 | char *result_buf, int minsize, int maxsize); | ||
| 137 | int UI_add_verify_string(UI *ui, const char *prompt, int flags, | ||
| 138 | char *result_buf, int minsize, int maxsize, const char *test_buf); | ||
| 139 | int UI_dup_verify_string(UI *ui, const char *prompt, int flags, | ||
| 140 | char *result_buf, int minsize, int maxsize, const char *test_buf); | ||
| 141 | int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, | ||
| 142 | const char *ok_chars, const char *cancel_chars, | ||
| 143 | int flags, char *result_buf); | ||
| 144 | int UI_dup_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); | ||
| 147 | int UI_add_info_string(UI *ui, const char *text); | ||
| 148 | int UI_dup_info_string(UI *ui, const char *text); | ||
| 149 | int UI_add_error_string(UI *ui, const char *text); | ||
| 150 | int UI_dup_error_string(UI *ui, const char *text); | ||
| 151 | |||
| 152 | /* These are the possible flags. They can be or'ed together. */ | ||
| 153 | /* Use to have echoing of input */ | ||
| 154 | #define UI_INPUT_FLAG_ECHO 0x01 | ||
| 155 | /* | ||
| 156 | * Use a default password. Where that password is found is completely | ||
| 157 | * up to the application, it might for example be in the user data set | ||
| 158 | * with UI_add_user_data(). It is not recommended to have more than | ||
| 159 | * one input in each UI being marked with this flag, or the application | ||
| 160 | * might get confused. | ||
| 161 | */ | ||
| 162 | #define UI_INPUT_FLAG_DEFAULT_PWD 0x02 | ||
| 163 | |||
| 164 | /* | ||
| 165 | * Users 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 | #define UI_INPUT_FLAG_USER_BASE 16 | ||
| 174 | |||
| 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 | * malloc(), and need to be free'd with 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 | */ | ||
| 194 | char *UI_construct_prompt(UI *ui_method, const char *object_desc, | ||
| 195 | const char *object_name); | ||
| 196 | |||
| 197 | |||
| 198 | /* | ||
| 199 | * The following function is used to store a pointer to user-specific data. | ||
| 200 | * Any previous such pointer will be returned and replaced. | ||
| 201 | * | ||
| 202 | * For callback purposes, this function makes a lot more sense than using | ||
| 203 | * ex_data, since the latter requires that different parts of OpenSSL or | ||
| 204 | * applications share the same ex_data index. | ||
| 205 | * | ||
| 206 | * Note that the UI_OpenSSL() method completely ignores the user data. | ||
| 207 | * Other methods may not, however. | ||
| 208 | */ | ||
| 209 | void *UI_add_user_data(UI *ui, void *user_data); | ||
| 210 | /* We need a user data retrieving function as well. */ | ||
| 211 | void *UI_get0_user_data(UI *ui); | ||
| 212 | |||
| 213 | /* Return the result associated with a prompt given with the index i. */ | ||
| 214 | const char *UI_get0_result(UI *ui, int i); | ||
| 215 | |||
| 216 | /* When all strings have been added, process the whole thing. */ | ||
| 217 | int UI_process(UI *ui); | ||
| 218 | |||
| 219 | /* | ||
| 220 | * Give a user interface parametrised control commands. This can be used to | ||
| 221 | * send down an integer, a data pointer or a function pointer, as well as | ||
| 222 | * be used to get information from a UI. | ||
| 223 | */ | ||
| 224 | int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); | ||
| 225 | |||
| 226 | /* The commands */ | ||
| 227 | /* | ||
| 228 | * Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the | ||
| 229 | * OpenSSL error stack before printing any info or added error messages and | ||
| 230 | * before any prompting. | ||
| 231 | */ | ||
| 232 | #define UI_CTRL_PRINT_ERRORS 1 | ||
| 233 | /* | ||
| 234 | * Check if a UI_process() is possible to do again with the same instance of | ||
| 235 | * a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 | ||
| 236 | * if not. | ||
| 237 | */ | ||
| 238 | #define UI_CTRL_IS_REDOABLE 2 | ||
| 239 | |||
| 240 | |||
| 241 | /* Some methods may use extra data */ | ||
| 242 | #define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) | ||
| 243 | #define UI_get_app_data(s) UI_get_ex_data(s,0) | ||
| 244 | int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 245 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 246 | int UI_set_ex_data(UI *r, int idx, void *arg); | ||
| 247 | void *UI_get_ex_data(UI *r, int idx); | ||
| 248 | |||
| 249 | /* Use specific methods instead of the built-in one */ | ||
| 250 | void UI_set_default_method(const UI_METHOD *meth); | ||
| 251 | const UI_METHOD *UI_get_default_method(void); | ||
| 252 | const UI_METHOD *UI_get_method(UI *ui); | ||
| 253 | const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); | ||
| 254 | |||
| 255 | /* The method with all the built-in thingies */ | ||
| 256 | const UI_METHOD *UI_OpenSSL(void); | ||
| 257 | |||
| 258 | const UI_METHOD *UI_null(void); | ||
| 259 | |||
| 260 | /* | ||
| 261 | * ---------- For method writers ---------- | ||
| 262 | * A method contains a number of functions that implement the low level | ||
| 263 | * of the User Interface. The functions are: | ||
| 264 | * | ||
| 265 | * an opener This function starts a session, maybe by opening | ||
| 266 | * a channel to a tty, or by opening a window. | ||
| 267 | * a writer This function is called to write a given string, | ||
| 268 | * maybe to the tty, maybe as a field label in a | ||
| 269 | * window. | ||
| 270 | * a flusher This function is called to flush everything that | ||
| 271 | * has been output so far. It can be used to actually | ||
| 272 | * display a dialog box after it has been built. | ||
| 273 | * a reader This function is called to read a given prompt, | ||
| 274 | * maybe from the tty, maybe from a field in a | ||
| 275 | * window. Note that it's called with all string | ||
| 276 | * structures, not only the prompt ones, so it must | ||
| 277 | * check such things itself. | ||
| 278 | * a closer This function closes the session, maybe by closing | ||
| 279 | * the channel to the tty, or closing the window. | ||
| 280 | * | ||
| 281 | * All these functions are expected to return: | ||
| 282 | * | ||
| 283 | * 0 on error. | ||
| 284 | * 1 on success. | ||
| 285 | * -1 on out-of-band events, for example if some prompting has | ||
| 286 | * been canceled (by pressing Ctrl-C, for example). This is | ||
| 287 | * only checked when returned by the flusher or the reader. | ||
| 288 | * | ||
| 289 | * The way this is used, the opener is first called, then the writer for all | ||
| 290 | * strings, then the flusher, then the reader for all strings and finally the | ||
| 291 | * closer. Note that if you want to prompt from a terminal or other command | ||
| 292 | * line interface, the best is to have the reader also write the prompts | ||
| 293 | * instead of having the writer do it. If you want to prompt from a dialog | ||
| 294 | * box, the writer can be used to build up the contents of the box, and the | ||
| 295 | * flusher to actually display the box and run the event loop until all data | ||
| 296 | * has been given, after which the reader only grabs the given data and puts | ||
| 297 | * them back into the UI strings. | ||
| 298 | * | ||
| 299 | * All method functions take a UI as argument. Additionally, the writer and | ||
| 300 | * the reader take a UI_STRING. | ||
| 301 | */ | ||
| 302 | |||
| 303 | /* | ||
| 304 | * The UI_STRING type is the data structure that contains all the needed info | ||
| 305 | * about a string or a prompt, including test data for a verification prompt. | ||
| 306 | */ | ||
| 307 | typedef struct ui_string_st UI_STRING; | ||
| 308 | DECLARE_STACK_OF(UI_STRING) | ||
| 309 | |||
| 310 | /* | ||
| 311 | * The different types of strings that are currently supported. | ||
| 312 | * This is only needed by method authors. | ||
| 313 | */ | ||
| 314 | enum UI_string_types { | ||
| 315 | UIT_NONE = 0, | ||
| 316 | UIT_PROMPT, /* Prompt for a string */ | ||
| 317 | UIT_VERIFY, /* Prompt for a string and verify */ | ||
| 318 | UIT_BOOLEAN, /* Prompt for a yes/no response */ | ||
| 319 | UIT_INFO, /* Send info to the user */ | ||
| 320 | UIT_ERROR /* Send an error message to the user */ | ||
| 321 | }; | ||
| 322 | |||
| 323 | /* Create and manipulate methods */ | ||
| 324 | UI_METHOD *UI_create_method(const char *name); | ||
| 325 | void UI_destroy_method(UI_METHOD *ui_method); | ||
| 326 | int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)); | ||
| 327 | int UI_method_set_writer(UI_METHOD *method, | ||
| 328 | int (*writer)(UI *ui, UI_STRING *uis)); | ||
| 329 | int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)); | ||
| 330 | int UI_method_set_reader(UI_METHOD *method, | ||
| 331 | int (*reader)(UI *ui, UI_STRING *uis)); | ||
| 332 | int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)); | ||
| 333 | int UI_method_set_prompt_constructor(UI_METHOD *method, | ||
| 334 | char *(*prompt_constructor)(UI *ui, const char *object_desc, | ||
| 335 | const char *object_name)); | ||
| 336 | int (*UI_method_get_opener(const UI_METHOD *method))(UI *); | ||
| 337 | int (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *); | ||
| 338 | int (*UI_method_get_flusher(const UI_METHOD *method))(UI *); | ||
| 339 | int (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *); | ||
| 340 | int (*UI_method_get_closer(const UI_METHOD *method))(UI *); | ||
| 341 | char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, | ||
| 342 | const char *, const char *); | ||
| 343 | |||
| 344 | /* | ||
| 345 | * The following functions are helpers for method writers to access relevant | ||
| 346 | * data from a UI_STRING. | ||
| 347 | */ | ||
| 348 | /* Return type of the UI_STRING */ | ||
| 349 | enum UI_string_types UI_get_string_type(UI_STRING *uis); | ||
| 350 | /* Return input flags of the UI_STRING */ | ||
| 351 | int UI_get_input_flags(UI_STRING *uis); | ||
| 352 | /* Return the actual string to output (the prompt, info or error) */ | ||
| 353 | const char *UI_get0_output_string(UI_STRING *uis); | ||
| 354 | /* Return the optional action string to output (boolean prompt instruction) */ | ||
| 355 | const char *UI_get0_action_string(UI_STRING *uis); | ||
| 356 | /* Return the result of a prompt */ | ||
| 357 | const char *UI_get0_result_string(UI_STRING *uis); | ||
| 358 | /* Return the string to test the result against. Only useful with verifies. */ | ||
| 359 | const char *UI_get0_test_string(UI_STRING *uis); | ||
| 360 | /* Return the required minimum size of the result */ | ||
| 361 | int UI_get_result_minsize(UI_STRING *uis); | ||
| 362 | /* Return the required maximum size of the result */ | ||
| 363 | int UI_get_result_maxsize(UI_STRING *uis); | ||
| 364 | /* Set the result of a UI_STRING. */ | ||
| 365 | int UI_set_result(UI *ui, UI_STRING *uis, const char *result); | ||
| 366 | |||
| 367 | void ERR_load_UI_strings(void); | ||
| 368 | |||
| 369 | /* Error codes for the UI functions. */ | ||
| 370 | |||
| 371 | /* Function codes. */ | ||
| 372 | #define UI_F_GENERAL_ALLOCATE_BOOLEAN 108 | ||
| 373 | #define UI_F_GENERAL_ALLOCATE_PROMPT 109 | ||
| 374 | #define UI_F_GENERAL_ALLOCATE_STRING 100 | ||
| 375 | #define UI_F_UI_CTRL 111 | ||
| 376 | #define UI_F_UI_DUP_ERROR_STRING 101 | ||
| 377 | #define UI_F_UI_DUP_INFO_STRING 102 | ||
| 378 | #define UI_F_UI_DUP_INPUT_BOOLEAN 110 | ||
| 379 | #define UI_F_UI_DUP_INPUT_STRING 103 | ||
| 380 | #define UI_F_UI_DUP_VERIFY_STRING 106 | ||
| 381 | #define UI_F_UI_GET0_RESULT 107 | ||
| 382 | #define UI_F_UI_NEW_METHOD 104 | ||
| 383 | #define UI_F_UI_SET_RESULT 105 | ||
| 384 | |||
| 385 | /* Reason codes. */ | ||
| 386 | #define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104 | ||
| 387 | #define UI_R_INDEX_TOO_LARGE 102 | ||
| 388 | #define UI_R_INDEX_TOO_SMALL 103 | ||
| 389 | #define UI_R_NO_RESULT_BUFFER 105 | ||
| 390 | #define UI_R_RESULT_TOO_LARGE 100 | ||
| 391 | #define UI_R_RESULT_TOO_SMALL 101 | ||
| 392 | #define UI_R_UNKNOWN_CONTROL_COMMAND 106 | ||
| 393 | |||
| 394 | #ifdef __cplusplus | ||
| 395 | } | ||
| 396 | #endif | ||
| 397 | #endif | ||
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c deleted file mode 100644 index 656fa42887..0000000000 --- a/src/lib/libcrypto/ui/ui_err.c +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | /* $OpenBSD: ui_err.c,v 1.13 2024/06/24 06:43:23 tb 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 | #include <stdio.h> | ||
| 57 | |||
| 58 | #include <openssl/opensslconf.h> | ||
| 59 | |||
| 60 | #include <openssl/err.h> | ||
| 61 | #include <openssl/ui.h> | ||
| 62 | |||
| 63 | #include "err_local.h" | ||
| 64 | |||
| 65 | #ifndef OPENSSL_NO_ERR | ||
| 66 | |||
| 67 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0) | ||
| 68 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason) | ||
| 69 | |||
| 70 | static const ERR_STRING_DATA UI_str_functs[] = { | ||
| 71 | {ERR_FUNC(0xfff), "CRYPTO_internal"}, | ||
| 72 | {0, NULL} | ||
| 73 | }; | ||
| 74 | |||
| 75 | static const ERR_STRING_DATA UI_str_reasons[] = { | ||
| 76 | {ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS), "common ok and cancel characters"}, | ||
| 77 | {ERR_REASON(UI_R_INDEX_TOO_LARGE), "index too large"}, | ||
| 78 | {ERR_REASON(UI_R_INDEX_TOO_SMALL), "index too small"}, | ||
| 79 | {ERR_REASON(UI_R_NO_RESULT_BUFFER), "no result buffer"}, | ||
| 80 | {ERR_REASON(UI_R_RESULT_TOO_LARGE), "result too large"}, | ||
| 81 | {ERR_REASON(UI_R_RESULT_TOO_SMALL), "result too small"}, | ||
| 82 | {ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND), "unknown control command"}, | ||
| 83 | {0, NULL} | ||
| 84 | }; | ||
| 85 | |||
| 86 | #endif | ||
| 87 | |||
| 88 | void | ||
| 89 | ERR_load_UI_strings(void) | ||
| 90 | { | ||
| 91 | #ifndef OPENSSL_NO_ERR | ||
| 92 | if (ERR_func_error_string(UI_str_functs[0].error) == NULL) { | ||
| 93 | ERR_load_const_strings(UI_str_functs); | ||
| 94 | ERR_load_const_strings(UI_str_reasons); | ||
| 95 | } | ||
| 96 | #endif | ||
| 97 | } | ||
| 98 | LCRYPTO_ALIAS(ERR_load_UI_strings); | ||
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c deleted file mode 100644 index 73d899afcc..0000000000 --- a/src/lib/libcrypto/ui/ui_lib.c +++ /dev/null | |||
| @@ -1,907 +0,0 @@ | |||
| 1 | /* $OpenBSD: ui_lib.c,v 1.51 2023/02/16 08:38:17 tb 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_local.h" | ||
| 68 | |||
| 69 | static const UI_METHOD *default_UI_meth = NULL; | ||
| 70 | |||
| 71 | UI * | ||
| 72 | UI_new(void) | ||
| 73 | { | ||
| 74 | return (UI_new_method(NULL)); | ||
| 75 | } | ||
| 76 | LCRYPTO_ALIAS(UI_new); | ||
| 77 | |||
| 78 | UI * | ||
| 79 | UI_new_method(const UI_METHOD *method) | ||
| 80 | { | ||
| 81 | UI *ret; | ||
| 82 | |||
| 83 | if ((ret = calloc(1, sizeof(UI))) == NULL) { | ||
| 84 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 85 | return NULL; | ||
| 86 | } | ||
| 87 | if ((ret->meth = method) == NULL) | ||
| 88 | ret->meth = UI_get_default_method(); | ||
| 89 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data); | ||
| 90 | |||
| 91 | return ret; | ||
| 92 | } | ||
| 93 | LCRYPTO_ALIAS(UI_new_method); | ||
| 94 | |||
| 95 | static void | ||
| 96 | free_string(UI_STRING *uis) | ||
| 97 | { | ||
| 98 | if (uis == NULL) | ||
| 99 | return; | ||
| 100 | if (uis->flags & OUT_STRING_FREEABLE) { | ||
| 101 | free((char *) uis->out_string); | ||
| 102 | switch (uis->type) { | ||
| 103 | case UIT_BOOLEAN: | ||
| 104 | free((char *)uis->_.boolean_data.action_desc); | ||
| 105 | free((char *)uis->_.boolean_data.ok_chars); | ||
| 106 | free((char *)uis->_.boolean_data.cancel_chars); | ||
| 107 | break; | ||
| 108 | default: | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | free(uis); | ||
| 113 | } | ||
| 114 | |||
| 115 | void | ||
| 116 | UI_free(UI *ui) | ||
| 117 | { | ||
| 118 | if (ui == NULL) | ||
| 119 | return; | ||
| 120 | |||
| 121 | sk_UI_STRING_pop_free(ui->strings, free_string); | ||
| 122 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); | ||
| 123 | free(ui); | ||
| 124 | } | ||
| 125 | LCRYPTO_ALIAS(UI_free); | ||
| 126 | |||
| 127 | static int | ||
| 128 | allocate_string_stack(UI *ui) | ||
| 129 | { | ||
| 130 | if (ui->strings == NULL) { | ||
| 131 | if ((ui->strings = sk_UI_STRING_new_null()) == NULL) { | ||
| 132 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 133 | return -1; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | return 0; | ||
| 137 | } | ||
| 138 | |||
| 139 | static UI_STRING * | ||
| 140 | general_allocate_prompt(const char *prompt, int dup_prompt, | ||
| 141 | enum UI_string_types type, int input_flags, char *result_buf) | ||
| 142 | { | ||
| 143 | UI_STRING *uis = NULL; | ||
| 144 | |||
| 145 | if (prompt == NULL) { | ||
| 146 | UIerror(ERR_R_PASSED_NULL_PARAMETER); | ||
| 147 | goto err; | ||
| 148 | } | ||
| 149 | if ((type == UIT_PROMPT || type == UIT_VERIFY || type == UIT_BOOLEAN) && | ||
| 150 | result_buf == NULL) { | ||
| 151 | UIerror(UI_R_NO_RESULT_BUFFER); | ||
| 152 | goto err; | ||
| 153 | } | ||
| 154 | |||
| 155 | if ((uis = calloc(1, sizeof(UI_STRING))) == NULL) { | ||
| 156 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 157 | goto err; | ||
| 158 | } | ||
| 159 | uis->out_string = prompt; | ||
| 160 | if (dup_prompt) { | ||
| 161 | if ((uis->out_string = strdup(prompt)) == NULL) { | ||
| 162 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 163 | goto err; | ||
| 164 | } | ||
| 165 | uis->flags = OUT_STRING_FREEABLE; | ||
| 166 | } | ||
| 167 | uis->input_flags = input_flags; | ||
| 168 | uis->type = type; | ||
| 169 | uis->result_buf = result_buf; | ||
| 170 | |||
| 171 | return uis; | ||
| 172 | |||
| 173 | err: | ||
| 174 | free_string(uis); | ||
| 175 | return NULL; | ||
| 176 | } | ||
| 177 | |||
| 178 | static int | ||
| 179 | general_allocate_string(UI *ui, const char *prompt, int dup_prompt, | ||
| 180 | enum UI_string_types type, int input_flags, char *result_buf, int minsize, | ||
| 181 | int maxsize, const char *test_buf) | ||
| 182 | { | ||
| 183 | UI_STRING *s; | ||
| 184 | int ret; | ||
| 185 | |||
| 186 | if ((s = general_allocate_prompt(prompt, dup_prompt, type, input_flags, | ||
| 187 | result_buf)) == NULL) | ||
| 188 | goto err; | ||
| 189 | s->_.string_data.result_minsize = minsize; | ||
| 190 | s->_.string_data.result_maxsize = maxsize; | ||
| 191 | s->_.string_data.test_buf = test_buf; | ||
| 192 | |||
| 193 | if (allocate_string_stack(ui) < 0) | ||
| 194 | goto err; | ||
| 195 | if ((ret = sk_UI_STRING_push(ui->strings, s)) <= 0) | ||
| 196 | goto err; | ||
| 197 | |||
| 198 | return ret; | ||
| 199 | |||
| 200 | err: | ||
| 201 | free_string(s); | ||
| 202 | return -1; | ||
| 203 | } | ||
| 204 | |||
| 205 | static int | ||
| 206 | general_allocate_boolean(UI *ui, const char *prompt, const char *action_desc, | ||
| 207 | const char *ok_chars, const char *cancel_chars, int dup_strings, | ||
| 208 | enum UI_string_types type, int input_flags, char *result_buf) | ||
| 209 | { | ||
| 210 | UI_STRING *s = NULL; | ||
| 211 | int ret; | ||
| 212 | |||
| 213 | if (ok_chars == NULL || cancel_chars == NULL) { | ||
| 214 | UIerror(ERR_R_PASSED_NULL_PARAMETER); | ||
| 215 | goto err; | ||
| 216 | } | ||
| 217 | if (ok_chars[strcspn(ok_chars, cancel_chars)] != '\0') { | ||
| 218 | UIerror(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS); | ||
| 219 | goto err; | ||
| 220 | } | ||
| 221 | |||
| 222 | if ((s = general_allocate_prompt(prompt, dup_strings, type, input_flags, | ||
| 223 | result_buf)) == NULL) | ||
| 224 | goto err; | ||
| 225 | |||
| 226 | if (dup_strings) { | ||
| 227 | if (action_desc != NULL) { | ||
| 228 | if ((s->_.boolean_data.action_desc = | ||
| 229 | strdup(action_desc)) == NULL) { | ||
| 230 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 231 | goto err; | ||
| 232 | } | ||
| 233 | } | ||
| 234 | if ((s->_.boolean_data.ok_chars = strdup(ok_chars)) == NULL) { | ||
| 235 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 236 | goto err; | ||
| 237 | } | ||
| 238 | if ((s->_.boolean_data.cancel_chars = strdup(cancel_chars)) == | ||
| 239 | NULL) { | ||
| 240 | UIerror(ERR_R_MALLOC_FAILURE); | ||
| 241 | goto err; | ||
| 242 | } | ||
| 243 | } else { | ||
| 244 | s->_.boolean_data.action_desc = action_desc; | ||
| 245 | s->_.boolean_data.ok_chars = ok_chars; | ||
| 246 | s->_.boolean_data.cancel_chars = cancel_chars; | ||
| 247 | } | ||
| 248 | |||
| 249 | if (allocate_string_stack(ui) < 0) | ||
| 250 | goto err; | ||
| 251 | if ((ret = sk_UI_STRING_push(ui->strings, s)) <= 0) | ||
| 252 | goto err; | ||
| 253 | |||
| 254 | return ret; | ||
| 255 | |||
| 256 | err: | ||
| 257 | free_string(s); | ||
| 258 | return -1; | ||
| 259 | } | ||
| 260 | |||
| 261 | /* | ||
| 262 | * Returns the index to the place in the stack or -1 for error. Uses a | ||
| 263 | * direct reference to the prompt. | ||
| 264 | */ | ||
| 265 | int | ||
| 266 | UI_add_input_string(UI *ui, const char *prompt, int flags, char *result_buf, | ||
| 267 | int minsize, int maxsize) | ||
| 268 | { | ||
| 269 | return general_allocate_string(ui, prompt, 0, UIT_PROMPT, flags, | ||
| 270 | result_buf, minsize, maxsize, NULL); | ||
| 271 | } | ||
| 272 | LCRYPTO_ALIAS(UI_add_input_string); | ||
| 273 | |||
| 274 | /* Same as UI_add_input_string(), excepts it takes a copy of the prompt. */ | ||
| 275 | int | ||
| 276 | UI_dup_input_string(UI *ui, const char *prompt, int flags, char *result_buf, | ||
| 277 | int minsize, int maxsize) | ||
| 278 | { | ||
| 279 | return general_allocate_string(ui, prompt, 1, UIT_PROMPT, flags, | ||
| 280 | result_buf, minsize, maxsize, NULL); | ||
| 281 | } | ||
| 282 | LCRYPTO_ALIAS(UI_dup_input_string); | ||
| 283 | |||
| 284 | int | ||
| 285 | UI_add_verify_string(UI *ui, const char *prompt, int flags, char *result_buf, | ||
| 286 | int minsize, int maxsize, const char *test_buf) | ||
| 287 | { | ||
| 288 | return general_allocate_string(ui, prompt, 0, UIT_VERIFY, flags, | ||
| 289 | result_buf, minsize, maxsize, test_buf); | ||
| 290 | } | ||
| 291 | LCRYPTO_ALIAS(UI_add_verify_string); | ||
| 292 | |||
| 293 | int | ||
| 294 | UI_dup_verify_string(UI *ui, const char *prompt, int flags, | ||
| 295 | char *result_buf, int minsize, int maxsize, const char *test_buf) | ||
| 296 | { | ||
| 297 | return general_allocate_string(ui, prompt, 1, UIT_VERIFY, flags, | ||
| 298 | result_buf, minsize, maxsize, test_buf); | ||
| 299 | } | ||
| 300 | LCRYPTO_ALIAS(UI_dup_verify_string); | ||
| 301 | |||
| 302 | int | ||
| 303 | UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, | ||
| 304 | const char *ok_chars, const char *cancel_chars, int flags, char *result_buf) | ||
| 305 | { | ||
| 306 | return general_allocate_boolean(ui, prompt, action_desc, ok_chars, | ||
| 307 | cancel_chars, 0, UIT_BOOLEAN, flags, result_buf); | ||
| 308 | } | ||
| 309 | LCRYPTO_ALIAS(UI_add_input_boolean); | ||
| 310 | |||
| 311 | int | ||
| 312 | UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, | ||
| 313 | const char *ok_chars, const char *cancel_chars, int flags, char *result_buf) | ||
| 314 | { | ||
| 315 | return general_allocate_boolean(ui, prompt, action_desc, ok_chars, | ||
| 316 | cancel_chars, 1, UIT_BOOLEAN, flags, result_buf); | ||
| 317 | } | ||
| 318 | LCRYPTO_ALIAS(UI_dup_input_boolean); | ||
| 319 | |||
| 320 | int | ||
| 321 | UI_add_info_string(UI *ui, const char *text) | ||
| 322 | { | ||
| 323 | return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0, | ||
| 324 | NULL); | ||
| 325 | } | ||
| 326 | LCRYPTO_ALIAS(UI_add_info_string); | ||
| 327 | |||
| 328 | int | ||
| 329 | UI_dup_info_string(UI *ui, const char *text) | ||
| 330 | { | ||
| 331 | return general_allocate_string(ui, text, 1, UIT_INFO, 0, NULL, 0, 0, | ||
| 332 | NULL); | ||
| 333 | } | ||
| 334 | LCRYPTO_ALIAS(UI_dup_info_string); | ||
| 335 | |||
| 336 | int | ||
| 337 | UI_add_error_string(UI *ui, const char *text) | ||
| 338 | { | ||
| 339 | return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0, | ||
| 340 | NULL); | ||
| 341 | } | ||
| 342 | LCRYPTO_ALIAS(UI_add_error_string); | ||
| 343 | |||
| 344 | int | ||
| 345 | UI_dup_error_string(UI *ui, const char *text) | ||
| 346 | { | ||
| 347 | return general_allocate_string(ui, text, 1, UIT_ERROR, 0, NULL, 0, 0, | ||
| 348 | NULL); | ||
| 349 | } | ||
| 350 | LCRYPTO_ALIAS(UI_dup_error_string); | ||
| 351 | |||
| 352 | char * | ||
| 353 | UI_construct_prompt(UI *ui, const char *object_desc, const char *object_name) | ||
| 354 | { | ||
| 355 | char *prompt; | ||
| 356 | |||
| 357 | if (ui->meth->ui_construct_prompt) | ||
| 358 | return ui->meth->ui_construct_prompt(ui, object_desc, | ||
| 359 | object_name); | ||
| 360 | |||
| 361 | if (object_desc == NULL) | ||
| 362 | return NULL; | ||
| 363 | |||
| 364 | if (object_name == NULL) { | ||
| 365 | if (asprintf(&prompt, "Enter %s:", object_desc) == -1) | ||
| 366 | return (NULL); | ||
| 367 | } else { | ||
| 368 | if (asprintf(&prompt, "Enter %s for %s:", object_desc, | ||
| 369 | object_name) == -1) | ||
| 370 | return (NULL); | ||
| 371 | } | ||
| 372 | |||
| 373 | return prompt; | ||
| 374 | } | ||
| 375 | LCRYPTO_ALIAS(UI_construct_prompt); | ||
| 376 | |||
| 377 | void * | ||
| 378 | UI_add_user_data(UI *ui, void *user_data) | ||
| 379 | { | ||
| 380 | void *old_data = ui->user_data; | ||
| 381 | |||
| 382 | ui->user_data = user_data; | ||
| 383 | |||
| 384 | return old_data; | ||
| 385 | } | ||
| 386 | LCRYPTO_ALIAS(UI_add_user_data); | ||
| 387 | |||
| 388 | void * | ||
| 389 | UI_get0_user_data(UI *ui) | ||
| 390 | { | ||
| 391 | return ui->user_data; | ||
| 392 | } | ||
| 393 | LCRYPTO_ALIAS(UI_get0_user_data); | ||
| 394 | |||
| 395 | const char * | ||
| 396 | UI_get0_result(UI *ui, int i) | ||
| 397 | { | ||
| 398 | if (i < 0) { | ||
| 399 | UIerror(UI_R_INDEX_TOO_SMALL); | ||
| 400 | return NULL; | ||
| 401 | } | ||
| 402 | if (i >= sk_UI_STRING_num(ui->strings)) { | ||
| 403 | UIerror(UI_R_INDEX_TOO_LARGE); | ||
| 404 | return NULL; | ||
| 405 | } | ||
| 406 | return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); | ||
| 407 | } | ||
| 408 | LCRYPTO_ALIAS(UI_get0_result); | ||
| 409 | |||
| 410 | static int | ||
| 411 | print_error(const char *str, size_t len, void *arg) | ||
| 412 | { | ||
| 413 | UI *ui = arg; | ||
| 414 | UI_STRING uis; | ||
| 415 | |||
| 416 | memset(&uis, 0, sizeof(uis)); | ||
| 417 | uis.type = UIT_ERROR; | ||
| 418 | uis.out_string = str; | ||
| 419 | |||
| 420 | if (ui->meth->ui_write_string && | ||
| 421 | !ui->meth->ui_write_string(ui, &uis)) | ||
| 422 | return -1; | ||
| 423 | return 0; | ||
| 424 | } | ||
| 425 | |||
| 426 | int | ||
| 427 | UI_process(UI *ui) | ||
| 428 | { | ||
| 429 | int i, ok = 0; | ||
| 430 | |||
| 431 | if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui)) | ||
| 432 | return -1; | ||
| 433 | |||
| 434 | if (ui->flags & UI_FLAG_PRINT_ERRORS) | ||
| 435 | ERR_print_errors_cb(print_error, ui); | ||
| 436 | |||
| 437 | for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) { | ||
| 438 | if (ui->meth->ui_write_string && | ||
| 439 | !ui->meth->ui_write_string(ui, | ||
| 440 | sk_UI_STRING_value(ui->strings, i))) { | ||
| 441 | ok = -1; | ||
| 442 | goto err; | ||
| 443 | } | ||
| 444 | } | ||
| 445 | |||
| 446 | if (ui->meth->ui_flush) | ||
| 447 | switch (ui->meth->ui_flush(ui)) { | ||
| 448 | case -1: /* Interrupt/Cancel/something... */ | ||
| 449 | ok = -2; | ||
| 450 | goto err; | ||
| 451 | case 0: /* Errors */ | ||
| 452 | ok = -1; | ||
| 453 | goto err; | ||
| 454 | default: /* Success */ | ||
| 455 | ok = 0; | ||
| 456 | break; | ||
| 457 | } | ||
| 458 | |||
| 459 | for (i = 0; i < sk_UI_STRING_num(ui->strings); i++) { | ||
| 460 | if (ui->meth->ui_read_string) { | ||
| 461 | switch (ui->meth->ui_read_string(ui, | ||
| 462 | sk_UI_STRING_value(ui->strings, i))) { | ||
| 463 | case -1: /* Interrupt/Cancel/something... */ | ||
| 464 | ui->flags &= ~UI_FLAG_REDOABLE; | ||
| 465 | ok = -2; | ||
| 466 | goto err; | ||
| 467 | case 0: /* Errors */ | ||
| 468 | ok = -1; | ||
| 469 | goto err; | ||
| 470 | default: /* Success */ | ||
| 471 | ok = 0; | ||
| 472 | break; | ||
| 473 | } | ||
| 474 | } | ||
| 475 | } | ||
| 476 | |||
| 477 | err: | ||
| 478 | if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui)) | ||
| 479 | return -1; | ||
| 480 | return ok; | ||
| 481 | } | ||
| 482 | LCRYPTO_ALIAS(UI_process); | ||
| 483 | |||
| 484 | int | ||
| 485 | UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) | ||
| 486 | { | ||
| 487 | if (ui == NULL) { | ||
| 488 | UIerror(ERR_R_PASSED_NULL_PARAMETER); | ||
| 489 | return -1; | ||
| 490 | } | ||
| 491 | |||
| 492 | switch (cmd) { | ||
| 493 | case UI_CTRL_PRINT_ERRORS: | ||
| 494 | { | ||
| 495 | int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS); | ||
| 496 | if (i) | ||
| 497 | ui->flags |= UI_FLAG_PRINT_ERRORS; | ||
| 498 | else | ||
| 499 | ui->flags &= ~UI_FLAG_PRINT_ERRORS; | ||
| 500 | return save_flag; | ||
| 501 | } | ||
| 502 | case UI_CTRL_IS_REDOABLE: | ||
| 503 | return !!(ui->flags & UI_FLAG_REDOABLE); | ||
| 504 | default: | ||
| 505 | break; | ||
| 506 | } | ||
| 507 | UIerror(UI_R_UNKNOWN_CONTROL_COMMAND); | ||
| 508 | return -1; | ||
| 509 | } | ||
| 510 | LCRYPTO_ALIAS(UI_ctrl); | ||
| 511 | |||
| 512 | int | ||
| 513 | UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 514 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 515 | { | ||
| 516 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp, | ||
| 517 | new_func, dup_func, free_func); | ||
| 518 | } | ||
| 519 | LCRYPTO_ALIAS(UI_get_ex_new_index); | ||
| 520 | |||
| 521 | int | ||
| 522 | UI_set_ex_data(UI *r, int idx, void *arg) | ||
| 523 | { | ||
| 524 | return (CRYPTO_set_ex_data(&r->ex_data, idx, arg)); | ||
| 525 | } | ||
| 526 | LCRYPTO_ALIAS(UI_set_ex_data); | ||
| 527 | |||
| 528 | void * | ||
| 529 | UI_get_ex_data(UI *r, int idx) | ||
| 530 | { | ||
| 531 | return (CRYPTO_get_ex_data(&r->ex_data, idx)); | ||
| 532 | } | ||
| 533 | LCRYPTO_ALIAS(UI_get_ex_data); | ||
| 534 | |||
| 535 | void | ||
| 536 | UI_set_default_method(const UI_METHOD *method) | ||
| 537 | { | ||
| 538 | default_UI_meth = method; | ||
| 539 | } | ||
| 540 | LCRYPTO_ALIAS(UI_set_default_method); | ||
| 541 | |||
| 542 | const UI_METHOD * | ||
| 543 | UI_get_default_method(void) | ||
| 544 | { | ||
| 545 | if (default_UI_meth == NULL) | ||
| 546 | default_UI_meth = UI_OpenSSL(); | ||
| 547 | |||
| 548 | return default_UI_meth; | ||
| 549 | } | ||
| 550 | LCRYPTO_ALIAS(UI_get_default_method); | ||
| 551 | |||
| 552 | const UI_METHOD * | ||
| 553 | UI_get_method(UI *ui) | ||
| 554 | { | ||
| 555 | return ui->meth; | ||
| 556 | } | ||
| 557 | LCRYPTO_ALIAS(UI_get_method); | ||
| 558 | |||
| 559 | const UI_METHOD * | ||
| 560 | UI_set_method(UI *ui, const UI_METHOD *method) | ||
| 561 | { | ||
| 562 | ui->meth = method; | ||
| 563 | |||
| 564 | return ui->meth; | ||
| 565 | } | ||
| 566 | LCRYPTO_ALIAS(UI_set_method); | ||
| 567 | |||
| 568 | UI_METHOD * | ||
| 569 | UI_create_method(const char *name) | ||
| 570 | { | ||
| 571 | UI_METHOD *method = NULL; | ||
| 572 | |||
| 573 | if ((method = calloc(1, sizeof(UI_METHOD))) == NULL) | ||
| 574 | goto err; | ||
| 575 | |||
| 576 | if (name != NULL) { | ||
| 577 | if ((method->name = strdup(name)) == NULL) | ||
| 578 | goto err; | ||
| 579 | } | ||
| 580 | |||
| 581 | return method; | ||
| 582 | |||
| 583 | err: | ||
| 584 | UI_destroy_method(method); | ||
| 585 | |||
| 586 | return NULL; | ||
| 587 | } | ||
| 588 | LCRYPTO_ALIAS(UI_create_method); | ||
| 589 | |||
| 590 | void | ||
| 591 | UI_destroy_method(UI_METHOD *method) | ||
| 592 | { | ||
| 593 | if (method == NULL) | ||
| 594 | return; | ||
| 595 | |||
| 596 | free(method->name); | ||
| 597 | free(method); | ||
| 598 | } | ||
| 599 | LCRYPTO_ALIAS(UI_destroy_method); | ||
| 600 | |||
| 601 | int | ||
| 602 | UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) | ||
| 603 | { | ||
| 604 | if (method == NULL) | ||
| 605 | return -1; | ||
| 606 | |||
| 607 | method->ui_open_session = opener; | ||
| 608 | |||
| 609 | return 0; | ||
| 610 | } | ||
| 611 | LCRYPTO_ALIAS(UI_method_set_opener); | ||
| 612 | |||
| 613 | int | ||
| 614 | UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) | ||
| 615 | { | ||
| 616 | if (method == NULL) | ||
| 617 | return -1; | ||
| 618 | |||
| 619 | method->ui_write_string = writer; | ||
| 620 | |||
| 621 | return 0; | ||
| 622 | } | ||
| 623 | LCRYPTO_ALIAS(UI_method_set_writer); | ||
| 624 | |||
| 625 | int | ||
| 626 | UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) | ||
| 627 | { | ||
| 628 | if (method == NULL) | ||
| 629 | return -1; | ||
| 630 | |||
| 631 | method->ui_flush = flusher; | ||
| 632 | |||
| 633 | return 0; | ||
| 634 | } | ||
| 635 | LCRYPTO_ALIAS(UI_method_set_flusher); | ||
| 636 | |||
| 637 | int | ||
| 638 | UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) | ||
| 639 | { | ||
| 640 | if (method == NULL) | ||
| 641 | return -1; | ||
| 642 | |||
| 643 | method->ui_read_string = reader; | ||
| 644 | |||
| 645 | return 0; | ||
| 646 | } | ||
| 647 | LCRYPTO_ALIAS(UI_method_set_reader); | ||
| 648 | |||
| 649 | int | ||
| 650 | UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) | ||
| 651 | { | ||
| 652 | if (method == NULL) | ||
| 653 | return -1; | ||
| 654 | |||
| 655 | method->ui_close_session = closer; | ||
| 656 | |||
| 657 | return 0; | ||
| 658 | } | ||
| 659 | LCRYPTO_ALIAS(UI_method_set_closer); | ||
| 660 | |||
| 661 | int | ||
| 662 | UI_method_set_prompt_constructor(UI_METHOD *method, | ||
| 663 | char *(*prompt_constructor)(UI *ui, const char *object_desc, | ||
| 664 | const char *object_name)) | ||
| 665 | { | ||
| 666 | if (method == NULL) | ||
| 667 | return -1; | ||
| 668 | |||
| 669 | method->ui_construct_prompt = prompt_constructor; | ||
| 670 | |||
| 671 | return 0; | ||
| 672 | } | ||
| 673 | LCRYPTO_ALIAS(UI_method_set_prompt_constructor); | ||
| 674 | |||
| 675 | int | ||
| 676 | (*UI_method_get_opener(const UI_METHOD * method))(UI *) | ||
| 677 | { | ||
| 678 | if (method == NULL) | ||
| 679 | return NULL; | ||
| 680 | |||
| 681 | return method->ui_open_session; | ||
| 682 | } | ||
| 683 | LCRYPTO_ALIAS(UI_method_get_opener); | ||
| 684 | |||
| 685 | int | ||
| 686 | (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *) | ||
| 687 | { | ||
| 688 | if (method == NULL) | ||
| 689 | return NULL; | ||
| 690 | |||
| 691 | return method->ui_write_string; | ||
| 692 | } | ||
| 693 | LCRYPTO_ALIAS(UI_method_get_writer); | ||
| 694 | |||
| 695 | int | ||
| 696 | (*UI_method_get_flusher(const UI_METHOD *method)) (UI *) | ||
| 697 | { | ||
| 698 | if (method == NULL) | ||
| 699 | return NULL; | ||
| 700 | |||
| 701 | return method->ui_flush; | ||
| 702 | } | ||
| 703 | LCRYPTO_ALIAS(UI_method_get_flusher); | ||
| 704 | |||
| 705 | int | ||
| 706 | (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *) | ||
| 707 | { | ||
| 708 | if (method == NULL) | ||
| 709 | return NULL; | ||
| 710 | |||
| 711 | return method->ui_read_string; | ||
| 712 | } | ||
| 713 | LCRYPTO_ALIAS(UI_method_get_reader); | ||
| 714 | |||
| 715 | int | ||
| 716 | (*UI_method_get_closer(const UI_METHOD *method))(UI *) | ||
| 717 | { | ||
| 718 | if (method == NULL) | ||
| 719 | return NULL; | ||
| 720 | |||
| 721 | return method->ui_close_session; | ||
| 722 | } | ||
| 723 | LCRYPTO_ALIAS(UI_method_get_closer); | ||
| 724 | |||
| 725 | char * | ||
| 726 | (*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *, const char *, | ||
| 727 | const char *) | ||
| 728 | { | ||
| 729 | if (method == NULL) | ||
| 730 | return NULL; | ||
| 731 | |||
| 732 | return method->ui_construct_prompt; | ||
| 733 | } | ||
| 734 | LCRYPTO_ALIAS(UI_method_get_prompt_constructor); | ||
| 735 | |||
| 736 | enum UI_string_types | ||
| 737 | UI_get_string_type(UI_STRING *uis) | ||
| 738 | { | ||
| 739 | if (uis == NULL) | ||
| 740 | return UIT_NONE; | ||
| 741 | |||
| 742 | return uis->type; | ||
| 743 | } | ||
| 744 | LCRYPTO_ALIAS(UI_get_string_type); | ||
| 745 | |||
| 746 | int | ||
| 747 | UI_get_input_flags(UI_STRING *uis) | ||
| 748 | { | ||
| 749 | if (uis == NULL) | ||
| 750 | return 0; | ||
| 751 | |||
| 752 | return uis->input_flags; | ||
| 753 | } | ||
| 754 | LCRYPTO_ALIAS(UI_get_input_flags); | ||
| 755 | |||
| 756 | const char * | ||
| 757 | UI_get0_output_string(UI_STRING *uis) | ||
| 758 | { | ||
| 759 | if (uis == NULL) | ||
| 760 | return NULL; | ||
| 761 | |||
| 762 | return uis->out_string; | ||
| 763 | } | ||
| 764 | LCRYPTO_ALIAS(UI_get0_output_string); | ||
| 765 | |||
| 766 | const char * | ||
| 767 | UI_get0_action_string(UI_STRING *uis) | ||
| 768 | { | ||
| 769 | if (uis == NULL) | ||
| 770 | return NULL; | ||
| 771 | |||
| 772 | switch (uis->type) { | ||
| 773 | case UIT_PROMPT: | ||
| 774 | case UIT_BOOLEAN: | ||
| 775 | return uis->_.boolean_data.action_desc; | ||
| 776 | default: | ||
| 777 | return NULL; | ||
| 778 | } | ||
| 779 | } | ||
| 780 | LCRYPTO_ALIAS(UI_get0_action_string); | ||
| 781 | |||
| 782 | const char * | ||
| 783 | UI_get0_result_string(UI_STRING *uis) | ||
| 784 | { | ||
| 785 | if (uis == NULL) | ||
| 786 | return NULL; | ||
| 787 | |||
| 788 | switch (uis->type) { | ||
| 789 | case UIT_PROMPT: | ||
| 790 | case UIT_VERIFY: | ||
| 791 | return uis->result_buf; | ||
| 792 | default: | ||
| 793 | return NULL; | ||
| 794 | } | ||
| 795 | } | ||
| 796 | LCRYPTO_ALIAS(UI_get0_result_string); | ||
| 797 | |||
| 798 | const char * | ||
| 799 | UI_get0_test_string(UI_STRING *uis) | ||
| 800 | { | ||
| 801 | if (uis == NULL) | ||
| 802 | return NULL; | ||
| 803 | |||
| 804 | switch (uis->type) { | ||
| 805 | case UIT_VERIFY: | ||
| 806 | return uis->_.string_data.test_buf; | ||
| 807 | default: | ||
| 808 | return NULL; | ||
| 809 | } | ||
| 810 | } | ||
| 811 | LCRYPTO_ALIAS(UI_get0_test_string); | ||
| 812 | |||
| 813 | int | ||
| 814 | UI_get_result_minsize(UI_STRING *uis) | ||
| 815 | { | ||
| 816 | if (uis == NULL) | ||
| 817 | return -1; | ||
| 818 | |||
| 819 | switch (uis->type) { | ||
| 820 | case UIT_PROMPT: | ||
| 821 | case UIT_VERIFY: | ||
| 822 | return uis->_.string_data.result_minsize; | ||
| 823 | default: | ||
| 824 | return -1; | ||
| 825 | } | ||
| 826 | } | ||
| 827 | LCRYPTO_ALIAS(UI_get_result_minsize); | ||
| 828 | |||
| 829 | int | ||
| 830 | UI_get_result_maxsize(UI_STRING *uis) | ||
| 831 | { | ||
| 832 | if (uis == NULL) | ||
| 833 | return -1; | ||
| 834 | |||
| 835 | switch (uis->type) { | ||
| 836 | case UIT_PROMPT: | ||
| 837 | case UIT_VERIFY: | ||
| 838 | return uis->_.string_data.result_maxsize; | ||
| 839 | default: | ||
| 840 | return -1; | ||
| 841 | } | ||
| 842 | } | ||
| 843 | LCRYPTO_ALIAS(UI_get_result_maxsize); | ||
| 844 | |||
| 845 | int | ||
| 846 | UI_set_result(UI *ui, UI_STRING *uis, const char *result) | ||
| 847 | { | ||
| 848 | const char *p; | ||
| 849 | int l = strlen(result); | ||
| 850 | |||
| 851 | ui->flags &= ~UI_FLAG_REDOABLE; | ||
| 852 | |||
| 853 | if (uis == NULL) | ||
| 854 | return -1; | ||
| 855 | |||
| 856 | switch (uis->type) { | ||
| 857 | case UIT_PROMPT: | ||
| 858 | case UIT_VERIFY: | ||
| 859 | if (l < uis->_.string_data.result_minsize) { | ||
| 860 | ui->flags |= UI_FLAG_REDOABLE; | ||
| 861 | UIerror(UI_R_RESULT_TOO_SMALL); | ||
| 862 | ERR_asprintf_error_data | ||
| 863 | ("You must type in %d to %d characters", | ||
| 864 | uis->_.string_data.result_minsize, | ||
| 865 | uis->_.string_data.result_maxsize); | ||
| 866 | return -1; | ||
| 867 | } | ||
| 868 | if (l > uis->_.string_data.result_maxsize) { | ||
| 869 | ui->flags |= UI_FLAG_REDOABLE; | ||
| 870 | UIerror(UI_R_RESULT_TOO_LARGE); | ||
| 871 | ERR_asprintf_error_data | ||
| 872 | ("You must type in %d to %d characters", | ||
| 873 | uis->_.string_data.result_minsize, | ||
| 874 | uis->_.string_data.result_maxsize); | ||
| 875 | return -1; | ||
| 876 | } | ||
| 877 | if (!uis->result_buf) { | ||
| 878 | UIerror(UI_R_NO_RESULT_BUFFER); | ||
| 879 | return -1; | ||
| 880 | } | ||
| 881 | strlcpy(uis->result_buf, result, | ||
| 882 | uis->_.string_data.result_maxsize + 1); | ||
| 883 | break; | ||
| 884 | case UIT_BOOLEAN: | ||
| 885 | if (!uis->result_buf) { | ||
| 886 | UIerror(UI_R_NO_RESULT_BUFFER); | ||
| 887 | return -1; | ||
| 888 | } | ||
| 889 | uis->result_buf[0] = '\0'; | ||
| 890 | for (p = result; *p; p++) { | ||
| 891 | if (strchr(uis->_.boolean_data.ok_chars, *p)) { | ||
| 892 | uis->result_buf[0] = | ||
| 893 | uis->_.boolean_data.ok_chars[0]; | ||
| 894 | break; | ||
| 895 | } | ||
| 896 | if (strchr(uis->_.boolean_data.cancel_chars, *p)) { | ||
| 897 | uis->result_buf[0] = | ||
| 898 | uis->_.boolean_data.cancel_chars[0]; | ||
| 899 | break; | ||
| 900 | } | ||
| 901 | } | ||
| 902 | default: | ||
| 903 | break; | ||
| 904 | } | ||
| 905 | return 0; | ||
| 906 | } | ||
| 907 | LCRYPTO_ALIAS(UI_set_result); | ||
diff --git a/src/lib/libcrypto/ui/ui_local.h b/src/lib/libcrypto/ui/ui_local.h deleted file mode 100644 index 460b5600bd..0000000000 --- a/src/lib/libcrypto/ui/ui_local.h +++ /dev/null | |||
| @@ -1,152 +0,0 @@ | |||
| 1 | /* $OpenBSD: ui_local.h,v 1.2 2022/11/26 17:23:18 tb 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_LOCAL_H | ||
| 61 | #define HEADER_UI_LOCAL_H | ||
| 62 | |||
| 63 | #include <openssl/ui.h> | ||
| 64 | #include <openssl/crypto.h> | ||
| 65 | |||
| 66 | __BEGIN_HIDDEN_DECLS | ||
| 67 | |||
| 68 | #ifdef _ | ||
| 69 | #undef _ | ||
| 70 | #endif | ||
| 71 | |||
| 72 | struct ui_method_st { | ||
| 73 | char *name; | ||
| 74 | |||
| 75 | /* All the functions return 1 or non-NULL for success and 0 or NULL | ||
| 76 | for failure */ | ||
| 77 | |||
| 78 | /* Open whatever channel for this, be it the console, an X window | ||
| 79 | or whatever. | ||
| 80 | This function should use the ex_data structure to save | ||
| 81 | intermediate data. */ | ||
| 82 | int (*ui_open_session)(UI *ui); | ||
| 83 | |||
| 84 | int (*ui_write_string)(UI *ui, UI_STRING *uis); | ||
| 85 | |||
| 86 | /* Flush the output. If a GUI dialog box is used, this function can | ||
| 87 | be used to actually display it. */ | ||
| 88 | int (*ui_flush)(UI *ui); | ||
| 89 | |||
| 90 | int (*ui_read_string)(UI *ui, UI_STRING *uis); | ||
| 91 | |||
| 92 | int (*ui_close_session)(UI *ui); | ||
| 93 | |||
| 94 | /* Construct a prompt in a user-defined manner. object_desc is a | ||
| 95 | textual short description of the object, for example "pass phrase", | ||
| 96 | and object_name is the name of the object (might be a card name or | ||
| 97 | a file name. | ||
| 98 | The returned string shall always be allocated on the heap with | ||
| 99 | malloc(), and need to be free'd with free(). */ | ||
| 100 | char *(*ui_construct_prompt)(UI *ui, const char *object_desc, | ||
| 101 | const char *object_name); | ||
| 102 | }; | ||
| 103 | |||
| 104 | struct ui_string_st { | ||
| 105 | enum UI_string_types type; /* Input */ | ||
| 106 | const char *out_string; /* Input */ | ||
| 107 | int input_flags; /* Flags from the user */ | ||
| 108 | |||
| 109 | /* The following parameters are completely irrelevant for UIT_INFO, | ||
| 110 | and can therefore be set to 0 or NULL */ | ||
| 111 | char *result_buf; /* Input and Output: If not NULL, user-defined | ||
| 112 | with size in result_maxsize. Otherwise, it | ||
| 113 | may be allocated by the UI routine, meaning | ||
| 114 | result_minsize is going to be overwritten.*/ | ||
| 115 | union { | ||
| 116 | struct { | ||
| 117 | int result_minsize; /* Input: minimum required | ||
| 118 | size of the result. | ||
| 119 | */ | ||
| 120 | int result_maxsize; /* Input: maximum permitted | ||
| 121 | size of the result */ | ||
| 122 | |||
| 123 | const char *test_buf; /* Input: test string to verify | ||
| 124 | against */ | ||
| 125 | } string_data; | ||
| 126 | struct { | ||
| 127 | const char *action_desc; /* Input */ | ||
| 128 | const char *ok_chars; /* Input */ | ||
| 129 | const char *cancel_chars; /* Input */ | ||
| 130 | } boolean_data; | ||
| 131 | } _; | ||
| 132 | |||
| 133 | #define OUT_STRING_FREEABLE 0x01 | ||
| 134 | int flags; /* flags for internal use */ | ||
| 135 | }; | ||
| 136 | |||
| 137 | struct ui_st { | ||
| 138 | const UI_METHOD *meth; | ||
| 139 | STACK_OF(UI_STRING) *strings; /* We might want to prompt for more | ||
| 140 | than one thing at a time, and | ||
| 141 | with different echoing status. */ | ||
| 142 | void *user_data; | ||
| 143 | CRYPTO_EX_DATA ex_data; | ||
| 144 | |||
| 145 | #define UI_FLAG_REDOABLE 0x0001 | ||
| 146 | #define UI_FLAG_PRINT_ERRORS 0x0100 | ||
| 147 | int flags; | ||
| 148 | }; | ||
| 149 | |||
| 150 | __END_HIDDEN_DECLS | ||
| 151 | |||
| 152 | #endif /* !HEADER_UI_LOCAL_H */ | ||
diff --git a/src/lib/libcrypto/ui/ui_null.c b/src/lib/libcrypto/ui/ui_null.c deleted file mode 100644 index cbc9a5025b..0000000000 --- a/src/lib/libcrypto/ui/ui_null.c +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | /* $OpenBSD: ui_null.c,v 1.2 2023/02/16 08:38:17 tb Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Written by Theo Buehler. Public domain. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "ui_local.h" | ||
| 8 | |||
| 9 | static const UI_METHOD ui_null = { | ||
| 10 | .name = "OpenSSL NULL UI", | ||
| 11 | }; | ||
| 12 | |||
| 13 | const UI_METHOD * | ||
| 14 | UI_null(void) | ||
| 15 | { | ||
| 16 | return &ui_null; | ||
| 17 | } | ||
| 18 | LCRYPTO_ALIAS(UI_null); | ||
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c deleted file mode 100644 index 3ace3a4e75..0000000000 --- a/src/lib/libcrypto/ui/ui_openssl.c +++ /dev/null | |||
| @@ -1,398 +0,0 @@ | |||
| 1 | /* $OpenBSD: ui_openssl.c,v 1.29 2025/03/09 15:25:53 tb 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_local.h" | ||
| 129 | |||
| 130 | #ifndef NX509_SIG | ||
| 131 | #define NX509_SIG 32 | ||
| 132 | #endif | ||
| 133 | |||
| 134 | /* Define globals. They are protected by a lock */ | ||
| 135 | static struct sigaction savsig[NX509_SIG]; | ||
| 136 | |||
| 137 | static struct termios tty_orig; | ||
| 138 | static FILE *tty_in, *tty_out; | ||
| 139 | static int is_a_tty; | ||
| 140 | |||
| 141 | /* Declare static functions */ | ||
| 142 | static int read_till_nl(FILE *); | ||
| 143 | static void recsig(int); | ||
| 144 | static void pushsig(void); | ||
| 145 | static void popsig(void); | ||
| 146 | static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl); | ||
| 147 | |||
| 148 | static int read_string(UI *ui, UI_STRING *uis); | ||
| 149 | static int write_string(UI *ui, UI_STRING *uis); | ||
| 150 | |||
| 151 | static int open_console(UI *ui); | ||
| 152 | static int echo_console(UI *ui); | ||
| 153 | static int noecho_console(UI *ui); | ||
| 154 | static int close_console(UI *ui); | ||
| 155 | |||
| 156 | static const 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 */ | ||
| 165 | const UI_METHOD * | ||
| 166 | UI_OpenSSL(void) | ||
| 167 | { | ||
| 168 | return &ui_openssl; | ||
| 169 | } | ||
| 170 | LCRYPTO_ALIAS(UI_OpenSSL); | ||
| 171 | |||
| 172 | /* The following function makes sure that info and error strings are printed | ||
| 173 | before any prompt. */ | ||
| 174 | static int | ||
| 175 | write_string(UI *ui, UI_STRING *uis) | ||
| 176 | { | ||
| 177 | switch (UI_get_string_type(uis)) { | ||
| 178 | case UIT_ERROR: | ||
| 179 | case UIT_INFO: | ||
| 180 | fputs(UI_get0_output_string(uis), tty_out); | ||
| 181 | fflush(tty_out); | ||
| 182 | break; | ||
| 183 | default: | ||
| 184 | break; | ||
| 185 | } | ||
| 186 | return 1; | ||
| 187 | } | ||
| 188 | |||
| 189 | static int | ||
| 190 | read_string(UI *ui, UI_STRING *uis) | ||
| 191 | { | ||
| 192 | int ok = 0; | ||
| 193 | |||
| 194 | switch (UI_get_string_type(uis)) { | ||
| 195 | case UIT_BOOLEAN: | ||
| 196 | fputs(UI_get0_output_string(uis), tty_out); | ||
| 197 | fputs(UI_get0_action_string(uis), tty_out); | ||
| 198 | fflush(tty_out); | ||
| 199 | return read_string_inner(ui, uis, | ||
| 200 | UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0); | ||
| 201 | case UIT_PROMPT: | ||
| 202 | fputs(UI_get0_output_string(uis), tty_out); | ||
| 203 | fflush(tty_out); | ||
| 204 | return read_string_inner(ui, uis, | ||
| 205 | UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1); | ||
| 206 | case UIT_VERIFY: | ||
| 207 | fprintf(tty_out, "Verifying - %s", | ||
| 208 | UI_get0_output_string(uis)); | ||
| 209 | fflush(tty_out); | ||
| 210 | if ((ok = read_string_inner(ui, uis, UI_get_input_flags(uis) & | ||
| 211 | UI_INPUT_FLAG_ECHO, 1)) <= 0) | ||
| 212 | return ok; | ||
| 213 | if (strcmp(UI_get0_result_string(uis), | ||
| 214 | UI_get0_test_string(uis)) != 0) { | ||
| 215 | fprintf(tty_out, "Verify failure\n"); | ||
| 216 | fflush(tty_out); | ||
| 217 | return 0; | ||
| 218 | } | ||
| 219 | break; | ||
| 220 | default: | ||
| 221 | break; | ||
| 222 | } | ||
| 223 | return 1; | ||
| 224 | } | ||
| 225 | |||
| 226 | |||
| 227 | /* Internal functions to read a string without echoing */ | ||
| 228 | static int | ||
| 229 | read_till_nl(FILE *in) | ||
| 230 | { | ||
| 231 | #define SIZE 4 | ||
| 232 | char buf[SIZE + 1]; | ||
| 233 | |||
| 234 | do { | ||
| 235 | if (!fgets(buf, SIZE, in)) | ||
| 236 | return 0; | ||
| 237 | } while (strchr(buf, '\n') == NULL); | ||
| 238 | return 1; | ||
| 239 | } | ||
| 240 | |||
| 241 | static volatile sig_atomic_t intr_signal; | ||
| 242 | |||
| 243 | static int | ||
| 244 | read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) | ||
| 245 | { | ||
| 246 | static int ps; | ||
| 247 | int ok; | ||
| 248 | char result[BUFSIZ]; | ||
| 249 | int maxsize = BUFSIZ - 1; | ||
| 250 | char *p; | ||
| 251 | |||
| 252 | intr_signal = 0; | ||
| 253 | ok = 0; | ||
| 254 | ps = 0; | ||
| 255 | |||
| 256 | pushsig(); | ||
| 257 | ps = 1; | ||
| 258 | |||
| 259 | if (!echo && !noecho_console(ui)) | ||
| 260 | goto error; | ||
| 261 | ps = 2; | ||
| 262 | |||
| 263 | result[0] = '\0'; | ||
| 264 | p = fgets(result, maxsize, tty_in); | ||
| 265 | if (!p) | ||
| 266 | goto error; | ||
| 267 | if (feof(tty_in)) | ||
| 268 | goto error; | ||
| 269 | if (ferror(tty_in)) | ||
| 270 | goto error; | ||
| 271 | if ((p = strchr(result, '\n')) != NULL) { | ||
| 272 | if (strip_nl) | ||
| 273 | *p = '\0'; | ||
| 274 | } else if (!read_till_nl(tty_in)) | ||
| 275 | goto error; | ||
| 276 | if (UI_set_result(ui, uis, result) >= 0) | ||
| 277 | ok = 1; | ||
| 278 | |||
| 279 | error: | ||
| 280 | if (intr_signal == SIGINT) | ||
| 281 | ok = -1; | ||
| 282 | if (!echo) | ||
| 283 | fprintf(tty_out, "\n"); | ||
| 284 | if (ps >= 2 && !echo && !echo_console(ui)) | ||
| 285 | ok = 0; | ||
| 286 | |||
| 287 | if (ps >= 1) | ||
| 288 | popsig(); | ||
| 289 | |||
| 290 | explicit_bzero(result, BUFSIZ); | ||
| 291 | return ok; | ||
| 292 | } | ||
| 293 | |||
| 294 | |||
| 295 | /* Internal functions to open, handle and close a channel to the console. */ | ||
| 296 | static int | ||
| 297 | open_console(UI *ui) | ||
| 298 | { | ||
| 299 | CRYPTO_w_lock(CRYPTO_LOCK_UI); | ||
| 300 | is_a_tty = 1; | ||
| 301 | |||
| 302 | #define DEV_TTY "/dev/tty" | ||
| 303 | if ((tty_in = fopen(DEV_TTY, "r")) == NULL) | ||
| 304 | tty_in = stdin; | ||
| 305 | if ((tty_out = fopen(DEV_TTY, "w")) == NULL) | ||
| 306 | tty_out = stderr; | ||
| 307 | |||
| 308 | if (tcgetattr(fileno(tty_in), &tty_orig) == -1) { | ||
| 309 | if (errno == ENOTTY) | ||
| 310 | is_a_tty = 0; | ||
| 311 | else | ||
| 312 | /* | ||
| 313 | * Ariel Glenn ariel@columbia.edu reports that | ||
| 314 | * solaris can return EINVAL instead. This should be | ||
| 315 | * ok | ||
| 316 | */ | ||
| 317 | if (errno == EINVAL) | ||
| 318 | is_a_tty = 0; | ||
| 319 | else | ||
| 320 | return 0; | ||
| 321 | } | ||
| 322 | |||
| 323 | return 1; | ||
| 324 | } | ||
| 325 | |||
| 326 | static int | ||
| 327 | noecho_console(UI *ui) | ||
| 328 | { | ||
| 329 | struct termios tty_new = tty_orig; | ||
| 330 | |||
| 331 | tty_new.c_lflag &= ~ECHO; | ||
| 332 | if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_new) == -1)) | ||
| 333 | return 0; | ||
| 334 | return 1; | ||
| 335 | } | ||
| 336 | |||
| 337 | static int | ||
| 338 | echo_console(UI *ui) | ||
| 339 | { | ||
| 340 | if (is_a_tty && (tcsetattr(fileno(tty_in), TCSANOW, &tty_orig) == -1)) | ||
| 341 | return 0; | ||
| 342 | return 1; | ||
| 343 | } | ||
| 344 | |||
| 345 | static int | ||
| 346 | close_console(UI *ui) | ||
| 347 | { | ||
| 348 | if (tty_in != stdin) | ||
| 349 | fclose(tty_in); | ||
| 350 | if (tty_out != stderr) | ||
| 351 | fclose(tty_out); | ||
| 352 | CRYPTO_w_unlock(CRYPTO_LOCK_UI); | ||
| 353 | |||
| 354 | return 1; | ||
| 355 | } | ||
| 356 | |||
| 357 | |||
| 358 | /* Internal functions to handle signals and act on them */ | ||
| 359 | static void | ||
| 360 | pushsig(void) | ||
| 361 | { | ||
| 362 | int i; | ||
| 363 | struct sigaction sa; | ||
| 364 | |||
| 365 | memset(&sa, 0, sizeof sa); | ||
| 366 | sa.sa_handler = recsig; | ||
| 367 | |||
| 368 | for (i = 1; i < NX509_SIG; i++) { | ||
| 369 | if (i == SIGUSR1) | ||
| 370 | continue; | ||
| 371 | if (i == SIGUSR2) | ||
| 372 | continue; | ||
| 373 | if (i == SIGKILL) /* We can't make any action on that. */ | ||
| 374 | continue; | ||
| 375 | sigaction(i, &sa, &savsig[i]); | ||
| 376 | } | ||
| 377 | |||
| 378 | signal(SIGWINCH, SIG_DFL); | ||
| 379 | } | ||
| 380 | |||
| 381 | static void | ||
| 382 | popsig(void) | ||
| 383 | { | ||
| 384 | int i; | ||
| 385 | for (i = 1; i < NX509_SIG; i++) { | ||
| 386 | if (i == SIGUSR1) | ||
| 387 | continue; | ||
| 388 | if (i == SIGUSR2) | ||
| 389 | continue; | ||
| 390 | sigaction(i, &savsig[i], NULL); | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | static void | ||
| 395 | recsig(int i) | ||
| 396 | { | ||
| 397 | intr_signal = i; | ||
| 398 | } | ||
