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