summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/ui/ui.h351
1 files changed, 188 insertions, 163 deletions
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h
index 8035fc2baa..5ca65b0a36 100644
--- a/src/lib/libcrypto/ui/ui.h
+++ b/src/lib/libcrypto/ui/ui.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui.h,v 1.11 2018/06/02 04:45:21 tb Exp $ */ 1/* $OpenBSD: ui.h,v 1.12 2020/09/24 19:20:32 tb Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -76,59 +76,62 @@ extern "C" {
76/* typedef struct ui_method_st UI_METHOD; */ 76/* typedef struct ui_method_st UI_METHOD; */
77 77
78 78
79/* All the following functions return -1 or NULL on error and in some cases 79/*
80 (UI_process()) -2 if interrupted or in some other way cancelled. 80 * All the following functions return -1 or NULL on error and in some cases
81 When everything is fine, they return 0, a positive value or a non-NULL 81 * (UI_process()) -2 if interrupted or in some other way cancelled.
82 pointer, all depending on their purpose. */ 82 * When everything is fine, they return 0, a positive value or a non-NULL
83 * pointer, all depending on their purpose.
84 */
83 85
84/* Creators and destructor. */ 86/* Creators and destructor. */
85UI *UI_new(void); 87UI *UI_new(void);
86UI *UI_new_method(const UI_METHOD *method); 88UI *UI_new_method(const UI_METHOD *method);
87void UI_free(UI *ui); 89void UI_free(UI *ui);
88 90
89/* The following functions are used to add strings to be printed and prompt 91/*
90 strings to prompt for data. The names are UI_{add,dup}_<function>_string 92 * The following functions are used to add strings to be printed and prompt
91 and UI_{add,dup}_input_boolean. 93 * strings to prompt for data. The names are UI_{add,dup}_<function>_string
92 94 * and UI_{add,dup}_input_boolean.
93 UI_{add,dup}_<function>_string have the following meanings: 95 *
94 add add a text or prompt string. The pointers given to these 96 * UI_{add,dup}_<function>_string have the following meanings:
95 functions are used verbatim, no copying is done. 97 * add add a text or prompt string. The pointers given to these
96 dup make a copy of the text or prompt string, then add the copy 98 * functions are used verbatim, no copying is done.
97 to the collection of strings in the user interface. 99 * dup make a copy of the text or prompt string, then add the copy
98 <function> 100 * to the collection of strings in the user interface.
99 The function is a name for the functionality that the given 101 * <function>
100 string shall be used for. It can be one of: 102 * The function is a name for the functionality that the given
101 input use the string as data prompt. 103 * string shall be used for. It can be one of:
102 verify use the string as verification prompt. This 104 * input use the string as data prompt.
103 is used to verify a previous input. 105 * verify use the string as verification prompt. This
104 info use the string for informational output. 106 * is used to verify a previous input.
105 error use the string for error output. 107 * info use the string for informational output.
106 Honestly, there's currently no difference between info and error for the 108 * error use the string for error output.
107 moment. 109 * Honestly, there's currently no difference between info and error for the
108 110 * moment.
109 UI_{add,dup}_input_boolean have the same semantics for "add" and "dup", 111 *
110 and are typically used when one wants to prompt for a yes/no response. 112 * UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
111 113 * and are typically used when one wants to prompt for a yes/no response.
112 114 *
113 All of the functions in this group take a UI and a prompt string. 115 * All of the functions in this group take a UI and a prompt string.
114 The string input and verify addition functions also take a flag argument, 116 * The string input and verify addition functions also take a flag argument,
115 a buffer for the result to end up with, a minimum input size and a maximum 117 * a buffer for the result to end up in, a minimum input size and a maximum
116 input size (the result buffer MUST be large enough to be able to contain 118 * input size (the result buffer MUST be large enough to be able to contain
117 the maximum number of characters). Additionally, the verify addition 119 * the maximum number of characters). Additionally, the verify addition
118 functions takes another buffer to compare the result against. 120 * functions takes another buffer to compare the result against.
119 The boolean input functions take an action description string (which should 121 * The boolean input functions take an action description string (which should
120 be safe to ignore if the expected user action is obvious, for example with 122 * be safe to ignore if the expected user action is obvious, for example with
121 a dialog box with an OK button and a Cancel button), a string of acceptable 123 * a dialog box with an OK button and a Cancel button), a string of acceptable
122 characters to mean OK and to mean Cancel. The two last strings are checked 124 * characters to mean OK and to mean Cancel. The two last strings are checked
123 to make sure they don't have common characters. Additionally, the same 125 * to make sure they don't have common characters. Additionally, the same
124 flag argument as for the string input is taken, as well as a result buffer. 126 * flag argument as for the string input is taken, as well as a result buffer.
125 The result buffer is required to be at least one byte long. Depending on 127 * The result buffer is required to be at least one byte long. Depending on
126 the answer, the first character from the OK or the Cancel character strings 128 * the answer, the first character from the OK or the Cancel character strings
127 will be stored in the first byte of the result buffer. No NUL will be 129 * will be stored in the first byte of the result buffer. No NUL will be
128 added, so the result is *not* a string. 130 * added, so the result is *not* a string.
129 131 *
130 On success, the all return an index of the added information. That index 132 * On success, the functions all return an index of the added information.
131 is usefull when retrieving results with UI_get0_result(). */ 133 * That index is useful when retrieving results with UI_get0_result().
134 */
132int UI_add_input_string(UI *ui, const char *prompt, int flags, 135int UI_add_input_string(UI *ui, const char *prompt, int flags,
133 char *result_buf, int minsize, int maxsize); 136 char *result_buf, int minsize, int maxsize);
134int UI_dup_input_string(UI *ui, const char *prompt, int flags, 137int UI_dup_input_string(UI *ui, const char *prompt, int flags,
@@ -151,55 +154,60 @@ int UI_dup_error_string(UI *ui, const char *text);
151/* These are the possible flags. They can be or'ed together. */ 154/* These are the possible flags. They can be or'ed together. */
152/* Use to have echoing of input */ 155/* Use to have echoing of input */
153#define UI_INPUT_FLAG_ECHO 0x01 156#define UI_INPUT_FLAG_ECHO 0x01
154/* Use a default password. Where that password is found is completely 157/*
155 up to the application, it might for example be in the user data set 158 * Use a default password. Where that password is found is completely
156 with UI_add_user_data(). It is not recommended to have more than 159 * up to the application, it might for example be in the user data set
157 one input in each UI being marked with this flag, or the application 160 * with UI_add_user_data(). It is not recommended to have more than
158 might get confused. */ 161 * one input in each UI being marked with this flag, or the application
162 * might get confused.
163 */
159#define UI_INPUT_FLAG_DEFAULT_PWD 0x02 164#define UI_INPUT_FLAG_DEFAULT_PWD 0x02
160 165
161/* The user of these routines may want to define flags of their own. The core 166/*
162 UI won't look at those, but will pass them on to the method routines. They 167 * Users of these routines may want to define flags of their own. The core
163 must use higher bits so they don't get confused with the UI bits above. 168 * UI won't look at those, but will pass them on to the method routines. They
164 UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good 169 * must use higher bits so they don't get confused with the UI bits above.
165 example of use is this: 170 * UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good
166 171 * example of use is this:
167 #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE) 172 *
168 173 * #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE)
169*/ 174 */
170#define UI_INPUT_FLAG_USER_BASE 16 175#define UI_INPUT_FLAG_USER_BASE 16
171 176
172 177
173/* The following function helps construct a prompt. object_desc is a 178/*
174 textual short description of the object, for example "pass phrase", 179 * The following function helps construct a prompt. object_desc is a
175 and object_name is the name of the object (might be a card name or 180 * textual short description of the object, for example "pass phrase",
176 a file name. 181 * and object_name is the name of the object (might be a card name or
177 The returned string shall always be allocated on the heap with 182 * a file name.
178 malloc(), and need to be free'd with free(). 183 * The returned string shall always be allocated on the heap with
179 184 * malloc(), and need to be free'd with free().
180 If the ui_method doesn't contain a pointer to a user-defined prompt 185 *
181 constructor, a default string is built, looking like this: 186 * If the ui_method doesn't contain a pointer to a user-defined prompt
182 187 * constructor, a default string is built, looking like this:
183 "Enter {object_desc} for {object_name}:" 188 *
184 189 * "Enter {object_desc} for {object_name}:"
185 So, if object_desc has the value "pass phrase" and object_name has 190 *
186 the value "foo.key", the resulting string is: 191 * So, if object_desc has the value "pass phrase" and object_name has
187 192 * the value "foo.key", the resulting string is:
188 "Enter pass phrase for foo.key:" 193 *
189*/ 194 * "Enter pass phrase for foo.key:"
195 */
190char *UI_construct_prompt(UI *ui_method, const char *object_desc, 196char *UI_construct_prompt(UI *ui_method, const char *object_desc,
191 const char *object_name); 197 const char *object_name);
192 198
193 199
194/* The following function is used to store a pointer to user-specific data. 200/*
195 Any previous such pointer will be returned and replaced. 201 * The following function is used to store a pointer to user-specific data.
196 202 * Any previous such pointer will be returned and replaced.
197 For callback purposes, this function makes a lot more sense than using 203 *
198 ex_data, since the latter requires that different parts of OpenSSL or 204 * For callback purposes, this function makes a lot more sense than using
199 applications share the same ex_data index. 205 * ex_data, since the latter requires that different parts of OpenSSL or
200 206 * applications share the same ex_data index.
201 Note that the UI_OpenSSL() method completely ignores the user data. 207 *
202 Other methods may not, however. */ 208 * Note that the UI_OpenSSL() method completely ignores the user data.
209 * Other methods may not, however.
210 */
203void *UI_add_user_data(UI *ui, void *user_data); 211void *UI_add_user_data(UI *ui, void *user_data);
204/* We need a user data retrieving function as well. */ 212/* We need a user data retrieving function as well. */
205void *UI_get0_user_data(UI *ui); 213void *UI_get0_user_data(UI *ui);
@@ -210,19 +218,25 @@ const char *UI_get0_result(UI *ui, int i);
210/* When all strings have been added, process the whole thing. */ 218/* When all strings have been added, process the whole thing. */
211int UI_process(UI *ui); 219int UI_process(UI *ui);
212 220
213/* Give a user interface parametrised control commands. This can be used to 221/*
214 send down an integer, a data pointer or a function pointer, as well as 222 * Give a user interface parametrised control commands. This can be used to
215 be used to get information from a UI. */ 223 * send down an integer, a data pointer or a function pointer, as well as
224 * be used to get information from a UI.
225 */
216int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); 226int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void));
217 227
218/* The commands */ 228/* The commands */
219/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the 229/*
220 OpenSSL error stack before printing any info or added error messages and 230 * Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
221 before any prompting. */ 231 * OpenSSL error stack before printing any info or added error messages and
232 * before any prompting.
233 */
222#define UI_CTRL_PRINT_ERRORS 1 234#define UI_CTRL_PRINT_ERRORS 1
223/* Check if a UI_process() is possible to do again with the same instance of 235/*
224 a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 236 * Check if a UI_process() is possible to do again with the same instance of
225 if not. */ 237 * a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0
238 * if not.
239 */
226#define UI_CTRL_IS_REDOABLE 2 240#define UI_CTRL_IS_REDOABLE 2
227 241
228 242
@@ -244,56 +258,60 @@ const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
244UI_METHOD *UI_OpenSSL(void); 258UI_METHOD *UI_OpenSSL(void);
245 259
246 260
247/* ---------- For method writers ---------- */ 261/*
248/* A method contains a number of functions that implement the low level 262 * ---------- For method writers ----------
249 of the User Interface. The functions are: 263 * A method contains a number of functions that implement the low level
250 264 * of the User Interface. The functions are:
251 an opener This function starts a session, maybe by opening 265 *
252 a channel to a tty, or by opening a window. 266 * an opener This function starts a session, maybe by opening
253 a writer This function is called to write a given string, 267 * a channel to a tty, or by opening a window.
254 maybe to the tty, maybe as a field label in a 268 * a writer This function is called to write a given string,
255 window. 269 * maybe to the tty, maybe as a field label in a
256 a flusher This function is called to flush everything that 270 * window.
257 has been output so far. It can be used to actually 271 * a flusher This function is called to flush everything that
258 display a dialog box after it has been built. 272 * has been output so far. It can be used to actually
259 a reader This function is called to read a given prompt, 273 * display a dialog box after it has been built.
260 maybe from the tty, maybe from a field in a 274 * a reader This function is called to read a given prompt,
261 window. Note that it's called wth all string 275 * maybe from the tty, maybe from a field in a
262 structures, not only the prompt ones, so it must 276 * window. Note that it's called wth all string
263 check such things itself. 277 * structures, not only the prompt ones, so it must
264 a closer This function closes the session, maybe by closing 278 * check such things itself.
265 the channel to the tty, or closing the window. 279 * a closer This function closes the session, maybe by closing
266 280 * the channel to the tty, or closing the window.
267 All these functions are expected to return: 281 *
268 282 * All these functions are expected to return:
269 0 on error. 283 *
270 1 on success. 284 * 0 on error.
271 -1 on out-of-band events, for example if some prompting has 285 * 1 on success.
272 been canceled (by pressing Ctrl-C, for example). This is 286 * -1 on out-of-band events, for example if some prompting has
273 only checked when returned by the flusher or the reader. 287 * been canceled (by pressing Ctrl-C, for example). This is
274 288 * only checked when returned by the flusher or the reader.
275 The way this is used, the opener is first called, then the writer for all 289 *
276 strings, then the flusher, then the reader for all strings and finally the 290 * The way this is used, the opener is first called, then the writer for all
277 closer. Note that if you want to prompt from a terminal or other command 291 * strings, then the flusher, then the reader for all strings and finally the
278 line interface, the best is to have the reader also write the prompts 292 * closer. Note that if you want to prompt from a terminal or other command
279 instead of having the writer do it. If you want to prompt from a dialog 293 * line interface, the best is to have the reader also write the prompts
280 box, the writer can be used to build up the contents of the box, and the 294 * instead of having the writer do it. If you want to prompt from a dialog
281 flusher to actually display the box and run the event loop until all data 295 * box, the writer can be used to build up the contents of the box, and the
282 has been given, after which the reader only grabs the given data and puts 296 * flusher to actually display the box and run the event loop until all data
283 them back into the UI strings. 297 * has been given, after which the reader only grabs the given data and puts
284 298 * them back into the UI strings.
285 All method functions take a UI as argument. Additionally, the writer and 299 *
286 the reader take a UI_STRING. 300 * All method functions take a UI as argument. Additionally, the writer and
287*/ 301 * the reader take a UI_STRING.
288 302 */
289/* The UI_STRING type is the data structure that contains all the needed info 303
290 about a string or a prompt, including test data for a verification prompt. 304/*
291*/ 305 * The UI_STRING type is the data structure that contains all the needed info
306 * about a string or a prompt, including test data for a verification prompt.
307 */
292typedef struct ui_string_st UI_STRING; 308typedef struct ui_string_st UI_STRING;
293DECLARE_STACK_OF(UI_STRING) 309DECLARE_STACK_OF(UI_STRING)
294 310
295/* The different types of strings that are currently supported. 311/*
296 This is only needed by method authors. */ 312 * The different types of strings that are currently supported.
313 * This is only needed by method authors.
314 */
297enum UI_string_types { 315enum UI_string_types {
298 UIT_NONE = 0, 316 UIT_NONE = 0,
299 UIT_PROMPT, /* Prompt for a string */ 317 UIT_PROMPT, /* Prompt for a string */
@@ -307,28 +325,34 @@ enum UI_string_types {
307UI_METHOD *UI_create_method(const char *name); 325UI_METHOD *UI_create_method(const char *name);
308void UI_destroy_method(UI_METHOD *ui_method); 326void UI_destroy_method(UI_METHOD *ui_method);
309int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)); 327int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
310int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)); 328int UI_method_set_writer(UI_METHOD *method,
329 int (*writer)(UI *ui, UI_STRING *uis));
311int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)); 330int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
312int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)); 331int UI_method_set_reader(UI_METHOD *method,
332 int (*reader)(UI *ui, UI_STRING *uis));
313int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)); 333int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
314int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name)); 334int UI_method_set_prompt_constructor(UI_METHOD *method,
315int (*UI_method_get_opener(const UI_METHOD *method))(UI*); 335 char *(*prompt_constructor)(UI *ui, const char *object_desc,
316int (*UI_method_get_writer(const UI_METHOD *method))(UI*, UI_STRING*); 336 const char *object_name));
317int (*UI_method_get_flusher(const UI_METHOD *method))(UI*); 337int (*UI_method_get_opener(const UI_METHOD *method))(UI *);
318int (*UI_method_get_reader(const UI_METHOD *method))(UI*, UI_STRING*); 338int (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *);
319int (*UI_method_get_closer(const UI_METHOD *method))(UI*); 339int (*UI_method_get_flusher(const UI_METHOD *method))(UI *);
320char * (*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI*, const char*, const char*); 340int (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *);
321 341int (*UI_method_get_closer(const UI_METHOD *method))(UI *);
322/* The following functions are helpers for method writers to access relevant 342char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *,
323 data from a UI_STRING. */ 343 const char *, const char *);
324 344
345/*
346 * The following functions are helpers for method writers to access relevant
347 * data from a UI_STRING.
348 */
325/* Return type of the UI_STRING */ 349/* Return type of the UI_STRING */
326enum UI_string_types UI_get_string_type(UI_STRING *uis); 350enum UI_string_types UI_get_string_type(UI_STRING *uis);
327/* Return input flags of the UI_STRING */ 351/* Return input flags of the UI_STRING */
328int UI_get_input_flags(UI_STRING *uis); 352int UI_get_input_flags(UI_STRING *uis);
329/* Return the actual string to output (the prompt, info or error) */ 353/* Return the actual string to output (the prompt, info or error) */
330const char *UI_get0_output_string(UI_STRING *uis); 354const char *UI_get0_output_string(UI_STRING *uis);
331/* Return the optional action string to output (the boolean promtp instruction) */ 355/* Return the optional action string to output (boolean prompt instruction) */
332const char *UI_get0_action_string(UI_STRING *uis); 356const char *UI_get0_action_string(UI_STRING *uis);
333/* Return the result of a prompt */ 357/* Return the result of a prompt */
334const char *UI_get0_result_string(UI_STRING *uis); 358const char *UI_get0_result_string(UI_STRING *uis);
@@ -341,14 +365,15 @@ int UI_get_result_maxsize(UI_STRING *uis);
341/* Set the result of a UI_STRING. */ 365/* Set the result of a UI_STRING. */
342int UI_set_result(UI *ui, UI_STRING *uis, const char *result); 366int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
343 367
344
345/* A couple of popular utility functions */ 368/* A couple of popular utility functions */
346int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify); 369int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
347int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify); 370 int verify);
348 371int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
372 int verify);
349 373
350/* BEGIN ERROR CODES */ 374/* BEGIN ERROR CODES */
351/* The following lines are auto generated by the script mkerr.pl. Any changes 375/*
376 * The following lines are auto generated by the script mkerr.pl. Any changes
352 * made after this point may be overwritten when the script is next run. 377 * made after this point may be overwritten when the script is next run.
353 */ 378 */
354void ERR_load_UI_strings(void); 379void ERR_load_UI_strings(void);