xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/UI_new.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
513d40330SchristosUI,
613d40330SchristosUI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string,
713d40330SchristosUI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean,
813d40330SchristosUI_dup_input_boolean, UI_add_info_string, UI_dup_info_string,
913d40330SchristosUI_add_error_string, UI_dup_error_string, UI_construct_prompt,
1013d40330SchristosUI_add_user_data, UI_dup_user_data, UI_get0_user_data, UI_get0_result,
1113d40330SchristosUI_get_result_length,
1213d40330SchristosUI_process, UI_ctrl, UI_set_default_method, UI_get_default_method,
1313d40330SchristosUI_get_method, UI_set_method, UI_OpenSSL, UI_null - user interface
1413d40330Schristos
1513d40330Schristos=head1 SYNOPSIS
1613d40330Schristos
1713d40330Schristos #include <openssl/ui.h>
1813d40330Schristos
1913d40330Schristos typedef struct ui_st UI;
2013d40330Schristos
2113d40330Schristos UI *UI_new(void);
2213d40330Schristos UI *UI_new_method(const UI_METHOD *method);
2313d40330Schristos void UI_free(UI *ui);
2413d40330Schristos
2513d40330Schristos int UI_add_input_string(UI *ui, const char *prompt, int flags,
2613d40330Schristos                         char *result_buf, int minsize, int maxsize);
2713d40330Schristos int UI_dup_input_string(UI *ui, const char *prompt, int flags,
2813d40330Schristos                         char *result_buf, int minsize, int maxsize);
2913d40330Schristos int UI_add_verify_string(UI *ui, const char *prompt, int flags,
3013d40330Schristos                          char *result_buf, int minsize, int maxsize,
3113d40330Schristos                          const char *test_buf);
3213d40330Schristos int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
3313d40330Schristos                          char *result_buf, int minsize, int maxsize,
3413d40330Schristos                          const char *test_buf);
3513d40330Schristos int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
3613d40330Schristos                          const char *ok_chars, const char *cancel_chars,
3713d40330Schristos                          int flags, char *result_buf);
3813d40330Schristos int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
3913d40330Schristos                          const char *ok_chars, const char *cancel_chars,
4013d40330Schristos                          int flags, char *result_buf);
4113d40330Schristos int UI_add_info_string(UI *ui, const char *text);
4213d40330Schristos int UI_dup_info_string(UI *ui, const char *text);
4313d40330Schristos int UI_add_error_string(UI *ui, const char *text);
4413d40330Schristos int UI_dup_error_string(UI *ui, const char *text);
4513d40330Schristos
4613d40330Schristos char *UI_construct_prompt(UI *ui_method,
47*b0d17251Schristos                           const char *phrase_desc, const char *object_name);
4813d40330Schristos
4913d40330Schristos void *UI_add_user_data(UI *ui, void *user_data);
5013d40330Schristos int UI_dup_user_data(UI *ui, void *user_data);
5113d40330Schristos void *UI_get0_user_data(UI *ui);
5213d40330Schristos
5313d40330Schristos const char *UI_get0_result(UI *ui, int i);
5413d40330Schristos int UI_get_result_length(UI *ui, int i);
5513d40330Schristos
5613d40330Schristos int UI_process(UI *ui);
5713d40330Schristos
5813d40330Schristos int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
5913d40330Schristos
6013d40330Schristos void UI_set_default_method(const UI_METHOD *meth);
6113d40330Schristos const UI_METHOD *UI_get_default_method(void);
6213d40330Schristos const UI_METHOD *UI_get_method(UI *ui);
6313d40330Schristos const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
6413d40330Schristos
6513d40330Schristos UI_METHOD *UI_OpenSSL(void);
6613d40330Schristos const UI_METHOD *UI_null(void);
6713d40330Schristos
6813d40330Schristos=head1 DESCRIPTION
6913d40330Schristos
7013d40330SchristosUI stands for User Interface, and is general purpose set of routines to
7113d40330Schristosprompt the user for text-based information.  Through user-written methods
7213d40330Schristos(see L<UI_create_method(3)>), prompting can be done in any way
7313d40330Schristosimaginable, be it plain text prompting, through dialog boxes or from a
7413d40330Schristoscell phone.
7513d40330Schristos
7613d40330SchristosAll the functions work through a context of the type UI.  This context
7713d40330Schristoscontains all the information needed to prompt correctly as well as a
7813d40330Schristosreference to a UI_METHOD, which is an ordered vector of functions that
7913d40330Schristoscarry out the actual prompting.
8013d40330Schristos
8113d40330SchristosThe first thing to do is to create a UI with UI_new() or UI_new_method(),
8213d40330Schristosthen add information to it with the UI_add or UI_dup functions.  Also,
8313d40330Schristosuser-defined random data can be passed down to the underlying method
8413d40330Schristosthrough calls to UI_add_user_data() or UI_dup_user_data().  The default
8513d40330SchristosUI method doesn't care about these data, but other methods might.  Finally,
8613d40330Schristosuse UI_process() to actually perform the prompting and UI_get0_result()
8713d40330Schristosand UI_get_result_length() to find the result to the prompt and its length.
8813d40330Schristos
8913d40330SchristosA UI can contain more than one prompt, which are performed in the given
9013d40330Schristossequence.  Each prompt gets an index number which is returned by the
9113d40330SchristosUI_add and UI_dup functions, and has to be used to get the corresponding
9213d40330Schristosresult with UI_get0_result() and UI_get_result_length().
9313d40330Schristos
9413d40330SchristosUI_process() can be called more than once on the same UI, thereby allowing
9513d40330Schristosa UI to have a long lifetime, but can just as well have a short lifetime.
9613d40330Schristos
9713d40330SchristosThe functions are as follows:
9813d40330Schristos
9913d40330SchristosUI_new() creates a new UI using the default UI method.  When done with
10013d40330Schristosthis UI, it should be freed using UI_free().
10113d40330Schristos
10213d40330SchristosUI_new_method() creates a new UI using the given UI method.  When done with
10313d40330Schristosthis UI, it should be freed using UI_free().
10413d40330Schristos
10513d40330SchristosUI_OpenSSL() returns the built-in UI method (note: not necessarily the
10613d40330Schristosdefault one, since the default can be changed.  See further on).  This
10713d40330Schristosmethod is the most machine/OS dependent part of OpenSSL and normally
10813d40330Schristosgenerates the most problems when porting.
10913d40330Schristos
11013d40330SchristosUI_null() returns a UI method that does nothing.  Its use is to avoid
11113d40330Schristosgetting internal defaults for passed UI_METHOD pointers.
11213d40330Schristos
11313d40330SchristosUI_free() removes a UI from memory, along with all other pieces of memory
11413d40330Schristosthat's connected to it, like duplicated input strings, results and others.
11513d40330SchristosIf B<ui> is NULL nothing is done.
11613d40330Schristos
11713d40330SchristosUI_add_input_string() and UI_add_verify_string() add a prompt to the UI,
11813d40330Schristosas well as flags and a result buffer and the desired minimum and maximum
11913d40330Schristossizes of the result, not counting the final NUL character.  The given
12013d40330Schristosinformation is used to prompt for information, for example a password,
12113d40330Schristosand to verify a password (i.e. having the user enter it twice and check
12213d40330Schristosthat the same string was entered twice).  UI_add_verify_string() takes
12313d40330Schristosand extra argument that should be a pointer to the result buffer of the
12413d40330Schristosinput string that it's supposed to verify, or verification will fail.
12513d40330Schristos
12613d40330SchristosUI_add_input_boolean() adds a prompt to the UI that's supposed to be answered
12713d40330Schristosin a boolean way, with a single character for yes and a different character
12813d40330Schristosfor no.  A set of characters that can be used to cancel the prompt is given
12913d40330Schristosas well.  The prompt itself is divided in two, one part being the
13013d40330Schristosdescriptive text (given through the I<prompt> argument) and one describing
13113d40330Schristosthe possible answers (given through the I<action_desc> argument).
13213d40330Schristos
13313d40330SchristosUI_add_info_string() and UI_add_error_string() add strings that are shown at
13413d40330Schristosthe same time as the prompt for extra information or to show an error string.
135*b0d17251SchristosThe difference between the two is only conceptual.  With the built-in method,
13613d40330Schristosthere's no technical difference between them.  Other methods may make a
13713d40330Schristosdifference between them, however.
13813d40330Schristos
13913d40330SchristosThe flags currently supported are B<UI_INPUT_FLAG_ECHO>, which is relevant for
14013d40330SchristosUI_add_input_string() and will have the users response be echoed (when
14113d40330Schristosprompting for a password, this flag should obviously not be used, and
14213d40330SchristosB<UI_INPUT_FLAG_DEFAULT_PWD>, which means that a default password of some
14313d40330Schristossort will be used (completely depending on the application and the UI
14413d40330Schristosmethod).
14513d40330Schristos
14613d40330SchristosUI_dup_input_string(), UI_dup_verify_string(), UI_dup_input_boolean(),
14713d40330SchristosUI_dup_info_string() and UI_dup_error_string() are basically the same
14813d40330Schristosas their UI_add counterparts, except that they make their own copies
14913d40330Schristosof all strings.
15013d40330Schristos
15113d40330SchristosUI_construct_prompt() is a helper function that can be used to create
152*b0d17251Schristosa prompt from two pieces of information: a phrase description I<phrase_desc>
153*b0d17251Schristosand an object name I<object_name>, where the latter may be NULL.
15413d40330SchristosThe default constructor (if there is none provided by the method used)
155*b0d17251Schristoscreates a string "Enter I<phrase_desc> for I<object_name>:"
156*b0d17251Schristoswhere the " for I<object_name>" part is left out if I<object_name> is NULL.
157*b0d17251SchristosWith the description "pass phrase" and the filename "foo.key", that becomes
15813d40330Schristos"Enter pass phrase for foo.key:".  Other methods may create whatever
15913d40330Schristosstring and may include encodings that will be processed by the other
16013d40330Schristosmethod functions.
16113d40330Schristos
16213d40330SchristosUI_add_user_data() adds a user data pointer for the method to use at any
163*b0d17251Schristostime.  The built-in UI method doesn't care about this info.  Note that several
16413d40330Schristoscalls to this function doesn't add data, it replaces the previous blob
16513d40330Schristoswith the one given as argument.
16613d40330Schristos
16713d40330SchristosUI_dup_user_data() duplicates the user data and works as an alternative
16813d40330Schristosto UI_add_user_data() when the user data needs to be preserved for a longer
16913d40330Schristosduration, perhaps even the lifetime of the application.  The UI object takes
17013d40330Schristosownership of this duplicate and will free it whenever it gets replaced or
17113d40330Schristosthe UI is destroyed.  UI_dup_user_data() returns 0 on success, or -1 on memory
17213d40330Schristosallocation failure or if the method doesn't have a duplicator function.
17313d40330Schristos
17413d40330SchristosUI_get0_user_data() retrieves the data that has last been given to the
17513d40330SchristosUI with UI_add_user_data() or UI_dup_user_data.
17613d40330Schristos
17713d40330SchristosUI_get0_result() returns a pointer to the result buffer associated with
17813d40330Schristosthe information indexed by I<i>.
17913d40330Schristos
18013d40330SchristosUI_get_result_length() returns the length of the result buffer associated with
18113d40330Schristosthe information indexed by I<i>.
18213d40330Schristos
18313d40330SchristosUI_process() goes through the information given so far, does all the printing
18413d40330Schristosand prompting and returns the final status, which is -2 on out-of-band events
18513d40330Schristos(Interrupt, Cancel, ...), -1 on error and 0 on success.
18613d40330Schristos
18713d40330SchristosUI_ctrl() adds extra control for the application author.  For now, it
18813d40330Schristosunderstands two commands: B<UI_CTRL_PRINT_ERRORS>, which makes UI_process()
18913d40330Schristosprint the OpenSSL error stack as part of processing the UI, and
19013d40330SchristosB<UI_CTRL_IS_REDOABLE>, which returns a flag saying if the used UI can
19113d40330Schristosbe used again or not.
19213d40330Schristos
19313d40330SchristosUI_set_default_method() changes the default UI method to the one given.
19413d40330SchristosThis function is not thread-safe and should not be called at the same time
19513d40330Schristosas other OpenSSL functions.
19613d40330Schristos
19713d40330SchristosUI_get_default_method() returns a pointer to the current default UI method.
19813d40330Schristos
19913d40330SchristosUI_get_method() returns the UI method associated with a given UI.
20013d40330Schristos
20113d40330SchristosUI_set_method() changes the UI method associated with a given UI.
20213d40330Schristos
20313d40330Schristos=head1 NOTES
20413d40330Schristos
20513d40330SchristosThe resulting strings that the built in method UI_OpenSSL() generate
20613d40330Schristosare assumed to be encoded according to the current locale or (for
20713d40330SchristosWindows) code page.
20813d40330SchristosFor applications having different demands, these strings need to be
20913d40330Schristosconverted appropriately by the caller.
210*b0d17251SchristosFor Windows, if the B<OPENSSL_WIN32_UTF8> environment variable is set,
21113d40330Schristosthe built-in method UI_OpenSSL() will produce UTF-8 encoded strings
21213d40330Schristosinstead.
21313d40330Schristos
21413d40330Schristos=head1 RETURN VALUES
21513d40330Schristos
21613d40330SchristosUI_new() and UI_new_method() return a valid B<UI> structure or NULL if an error
21713d40330Schristosoccurred.
21813d40330Schristos
21913d40330SchristosUI_add_input_string(), UI_dup_input_string(), UI_add_verify_string(),
22013d40330SchristosUI_dup_verify_string(), UI_add_input_boolean(), UI_dup_input_boolean(),
22113d40330SchristosUI_add_info_string(), UI_dup_info_string(), UI_add_error_string()
22213d40330Schristosand UI_dup_error_string() return a positive number on success or a value which
22313d40330Schristosis less than or equal to 0 otherwise.
22413d40330Schristos
22513d40330SchristosUI_construct_prompt() returns a string or NULL if an error occurred.
22613d40330Schristos
22713d40330SchristosUI_dup_user_data() returns 0 on success or -1 on error.
22813d40330Schristos
22913d40330SchristosUI_get0_result() returns a string or NULL on error.
23013d40330Schristos
23113d40330SchristosUI_get_result_length() returns a positive integer or 0 on success; otherwise it
23213d40330Schristosreturns -1 on error.
23313d40330Schristos
23413d40330SchristosUI_process() returns 0 on success or a negative value on error.
23513d40330Schristos
23613d40330SchristosUI_ctrl() returns a mask on success or -1 on error.
23713d40330Schristos
238b88c74d5SchristosUI_get_default_method(), UI_get_method(), UI_OpenSSL(), UI_null() and
23913d40330SchristosUI_set_method() return either a valid B<UI_METHOD> structure or NULL
24013d40330Schristosrespectively.
24113d40330Schristos
24213d40330Schristos=head1 HISTORY
24313d40330Schristos
244b88c74d5SchristosThe UI_dup_user_data() function was added in OpenSSL 1.1.1.
24513d40330Schristos
24613d40330Schristos=head1 COPYRIGHT
24713d40330Schristos
248f30e0929SchristosCopyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
24913d40330Schristos
250*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
25113d40330Schristosthis file except in compliance with the License.  You can obtain a copy
25213d40330Schristosin the file LICENSE in the source distribution or at
25313d40330SchristosL<https://www.openssl.org/source/license.html>.
25413d40330Schristos
25513d40330Schristos=cut
256