Home | History | Annotate | Line # | Download | only in man3
      1      1.1  christos =pod
      2      1.1  christos 
      3      1.1  christos =head1 NAME
      4      1.1  christos 
      5      1.1  christos UI,
      6      1.1  christos UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string,
      7      1.1  christos UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean,
      8      1.1  christos UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string,
      9      1.1  christos UI_add_error_string, UI_dup_error_string, UI_construct_prompt,
     10      1.1  christos UI_add_user_data, UI_dup_user_data, UI_get0_user_data, UI_get0_result,
     11      1.1  christos UI_get_result_length,
     12      1.1  christos UI_process, UI_ctrl, UI_set_default_method, UI_get_default_method,
     13      1.1  christos UI_get_method, UI_set_method, UI_OpenSSL, UI_null - user interface
     14      1.1  christos 
     15      1.1  christos =head1 SYNOPSIS
     16      1.1  christos 
     17      1.1  christos  #include <openssl/ui.h>
     18      1.1  christos 
     19      1.1  christos  typedef struct ui_st UI;
     20      1.1  christos 
     21      1.1  christos  UI *UI_new(void);
     22      1.1  christos  UI *UI_new_method(const UI_METHOD *method);
     23      1.1  christos  void UI_free(UI *ui);
     24      1.1  christos 
     25      1.1  christos  int UI_add_input_string(UI *ui, const char *prompt, int flags,
     26      1.1  christos                          char *result_buf, int minsize, int maxsize);
     27      1.1  christos  int UI_dup_input_string(UI *ui, const char *prompt, int flags,
     28      1.1  christos                          char *result_buf, int minsize, int maxsize);
     29      1.1  christos  int UI_add_verify_string(UI *ui, const char *prompt, int flags,
     30      1.1  christos                           char *result_buf, int minsize, int maxsize,
     31      1.1  christos                           const char *test_buf);
     32      1.1  christos  int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
     33      1.1  christos                           char *result_buf, int minsize, int maxsize,
     34      1.1  christos                           const char *test_buf);
     35      1.1  christos  int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
     36      1.1  christos                           const char *ok_chars, const char *cancel_chars,
     37      1.1  christos                           int flags, char *result_buf);
     38      1.1  christos  int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
     39      1.1  christos                           const char *ok_chars, const char *cancel_chars,
     40      1.1  christos                           int flags, char *result_buf);
     41      1.1  christos  int UI_add_info_string(UI *ui, const char *text);
     42      1.1  christos  int UI_dup_info_string(UI *ui, const char *text);
     43      1.1  christos  int UI_add_error_string(UI *ui, const char *text);
     44      1.1  christos  int UI_dup_error_string(UI *ui, const char *text);
     45      1.1  christos 
     46      1.1  christos  char *UI_construct_prompt(UI *ui_method,
     47  1.1.1.4  christos                            const char *phrase_desc, const char *object_name);
     48      1.1  christos 
     49      1.1  christos  void *UI_add_user_data(UI *ui, void *user_data);
     50      1.1  christos  int UI_dup_user_data(UI *ui, void *user_data);
     51      1.1  christos  void *UI_get0_user_data(UI *ui);
     52      1.1  christos 
     53      1.1  christos  const char *UI_get0_result(UI *ui, int i);
     54      1.1  christos  int UI_get_result_length(UI *ui, int i);
     55      1.1  christos 
     56      1.1  christos  int UI_process(UI *ui);
     57      1.1  christos 
     58      1.1  christos  int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
     59      1.1  christos 
     60      1.1  christos  void UI_set_default_method(const UI_METHOD *meth);
     61      1.1  christos  const UI_METHOD *UI_get_default_method(void);
     62      1.1  christos  const UI_METHOD *UI_get_method(UI *ui);
     63      1.1  christos  const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
     64      1.1  christos 
     65      1.1  christos  UI_METHOD *UI_OpenSSL(void);
     66      1.1  christos  const UI_METHOD *UI_null(void);
     67      1.1  christos 
     68      1.1  christos =head1 DESCRIPTION
     69      1.1  christos 
     70      1.1  christos UI stands for User Interface, and is general purpose set of routines to
     71      1.1  christos prompt the user for text-based information.  Through user-written methods
     72      1.1  christos (see L<UI_create_method(3)>), prompting can be done in any way
     73      1.1  christos imaginable, be it plain text prompting, through dialog boxes or from a
     74      1.1  christos cell phone.
     75      1.1  christos 
     76      1.1  christos All the functions work through a context of the type UI.  This context
     77      1.1  christos contains all the information needed to prompt correctly as well as a
     78      1.1  christos reference to a UI_METHOD, which is an ordered vector of functions that
     79      1.1  christos carry out the actual prompting.
     80      1.1  christos 
     81      1.1  christos The first thing to do is to create a UI with UI_new() or UI_new_method(),
     82      1.1  christos then add information to it with the UI_add or UI_dup functions.  Also,
     83      1.1  christos user-defined random data can be passed down to the underlying method
     84      1.1  christos through calls to UI_add_user_data() or UI_dup_user_data().  The default
     85      1.1  christos UI method doesn't care about these data, but other methods might.  Finally,
     86      1.1  christos use UI_process() to actually perform the prompting and UI_get0_result()
     87      1.1  christos and UI_get_result_length() to find the result to the prompt and its length.
     88      1.1  christos 
     89      1.1  christos A UI can contain more than one prompt, which are performed in the given
     90      1.1  christos sequence.  Each prompt gets an index number which is returned by the
     91      1.1  christos UI_add and UI_dup functions, and has to be used to get the corresponding
     92      1.1  christos result with UI_get0_result() and UI_get_result_length().
     93      1.1  christos 
     94      1.1  christos UI_process() can be called more than once on the same UI, thereby allowing
     95      1.1  christos a UI to have a long lifetime, but can just as well have a short lifetime.
     96      1.1  christos 
     97      1.1  christos The functions are as follows:
     98      1.1  christos 
     99      1.1  christos UI_new() creates a new UI using the default UI method.  When done with
    100      1.1  christos this UI, it should be freed using UI_free().
    101      1.1  christos 
    102      1.1  christos UI_new_method() creates a new UI using the given UI method.  When done with
    103      1.1  christos this UI, it should be freed using UI_free().
    104      1.1  christos 
    105      1.1  christos UI_OpenSSL() returns the built-in UI method (note: not necessarily the
    106      1.1  christos default one, since the default can be changed.  See further on).  This
    107      1.1  christos method is the most machine/OS dependent part of OpenSSL and normally
    108      1.1  christos generates the most problems when porting.
    109      1.1  christos 
    110      1.1  christos UI_null() returns a UI method that does nothing.  Its use is to avoid
    111      1.1  christos getting internal defaults for passed UI_METHOD pointers.
    112      1.1  christos 
    113      1.1  christos UI_free() removes a UI from memory, along with all other pieces of memory
    114      1.1  christos that's connected to it, like duplicated input strings, results and others.
    115      1.1  christos If B<ui> is NULL nothing is done.
    116      1.1  christos 
    117      1.1  christos UI_add_input_string() and UI_add_verify_string() add a prompt to the UI,
    118      1.1  christos as well as flags and a result buffer and the desired minimum and maximum
    119      1.1  christos sizes of the result, not counting the final NUL character.  The given
    120      1.1  christos information is used to prompt for information, for example a password,
    121      1.1  christos and to verify a password (i.e. having the user enter it twice and check
    122      1.1  christos that the same string was entered twice).  UI_add_verify_string() takes
    123      1.1  christos and extra argument that should be a pointer to the result buffer of the
    124      1.1  christos input string that it's supposed to verify, or verification will fail.
    125      1.1  christos 
    126      1.1  christos UI_add_input_boolean() adds a prompt to the UI that's supposed to be answered
    127      1.1  christos in a boolean way, with a single character for yes and a different character
    128      1.1  christos for no.  A set of characters that can be used to cancel the prompt is given
    129      1.1  christos as well.  The prompt itself is divided in two, one part being the
    130      1.1  christos descriptive text (given through the I<prompt> argument) and one describing
    131      1.1  christos the possible answers (given through the I<action_desc> argument).
    132      1.1  christos 
    133      1.1  christos UI_add_info_string() and UI_add_error_string() add strings that are shown at
    134      1.1  christos the same time as the prompt for extra information or to show an error string.
    135  1.1.1.4  christos The difference between the two is only conceptual.  With the built-in method,
    136      1.1  christos there's no technical difference between them.  Other methods may make a
    137      1.1  christos difference between them, however.
    138      1.1  christos 
    139      1.1  christos The flags currently supported are B<UI_INPUT_FLAG_ECHO>, which is relevant for
    140      1.1  christos UI_add_input_string() and will have the users response be echoed (when
    141      1.1  christos prompting for a password, this flag should obviously not be used, and
    142      1.1  christos B<UI_INPUT_FLAG_DEFAULT_PWD>, which means that a default password of some
    143      1.1  christos sort will be used (completely depending on the application and the UI
    144      1.1  christos method).
    145      1.1  christos 
    146      1.1  christos UI_dup_input_string(), UI_dup_verify_string(), UI_dup_input_boolean(),
    147      1.1  christos UI_dup_info_string() and UI_dup_error_string() are basically the same
    148      1.1  christos as their UI_add counterparts, except that they make their own copies
    149      1.1  christos of all strings.
    150      1.1  christos 
    151      1.1  christos UI_construct_prompt() is a helper function that can be used to create
    152  1.1.1.4  christos a prompt from two pieces of information: a phrase description I<phrase_desc>
    153  1.1.1.4  christos and an object name I<object_name>, where the latter may be NULL.
    154      1.1  christos The default constructor (if there is none provided by the method used)
    155  1.1.1.4  christos creates a string "Enter I<phrase_desc> for I<object_name>:"
    156  1.1.1.4  christos where the " for I<object_name>" part is left out if I<object_name> is NULL.
    157  1.1.1.4  christos With the description "pass phrase" and the filename "foo.key", that becomes
    158      1.1  christos "Enter pass phrase for foo.key:".  Other methods may create whatever
    159      1.1  christos string and may include encodings that will be processed by the other
    160      1.1  christos method functions.
    161      1.1  christos 
    162      1.1  christos UI_add_user_data() adds a user data pointer for the method to use at any
    163  1.1.1.4  christos time.  The built-in UI method doesn't care about this info.  Note that several
    164      1.1  christos calls to this function doesn't add data, it replaces the previous blob
    165      1.1  christos with the one given as argument.
    166      1.1  christos 
    167      1.1  christos UI_dup_user_data() duplicates the user data and works as an alternative
    168      1.1  christos to UI_add_user_data() when the user data needs to be preserved for a longer
    169      1.1  christos duration, perhaps even the lifetime of the application.  The UI object takes
    170      1.1  christos ownership of this duplicate and will free it whenever it gets replaced or
    171      1.1  christos the UI is destroyed.  UI_dup_user_data() returns 0 on success, or -1 on memory
    172      1.1  christos allocation failure or if the method doesn't have a duplicator function.
    173      1.1  christos 
    174      1.1  christos UI_get0_user_data() retrieves the data that has last been given to the
    175      1.1  christos UI with UI_add_user_data() or UI_dup_user_data.
    176      1.1  christos 
    177      1.1  christos UI_get0_result() returns a pointer to the result buffer associated with
    178      1.1  christos the information indexed by I<i>.
    179      1.1  christos 
    180      1.1  christos UI_get_result_length() returns the length of the result buffer associated with
    181      1.1  christos the information indexed by I<i>.
    182      1.1  christos 
    183      1.1  christos UI_process() goes through the information given so far, does all the printing
    184      1.1  christos and prompting and returns the final status, which is -2 on out-of-band events
    185      1.1  christos (Interrupt, Cancel, ...), -1 on error and 0 on success.
    186      1.1  christos 
    187      1.1  christos UI_ctrl() adds extra control for the application author.  For now, it
    188      1.1  christos understands two commands: B<UI_CTRL_PRINT_ERRORS>, which makes UI_process()
    189      1.1  christos print the OpenSSL error stack as part of processing the UI, and
    190      1.1  christos B<UI_CTRL_IS_REDOABLE>, which returns a flag saying if the used UI can
    191      1.1  christos be used again or not.
    192      1.1  christos 
    193      1.1  christos UI_set_default_method() changes the default UI method to the one given.
    194      1.1  christos This function is not thread-safe and should not be called at the same time
    195      1.1  christos as other OpenSSL functions.
    196      1.1  christos 
    197      1.1  christos UI_get_default_method() returns a pointer to the current default UI method.
    198      1.1  christos 
    199      1.1  christos UI_get_method() returns the UI method associated with a given UI.
    200      1.1  christos 
    201      1.1  christos UI_set_method() changes the UI method associated with a given UI.
    202      1.1  christos 
    203      1.1  christos =head1 NOTES
    204      1.1  christos 
    205      1.1  christos The resulting strings that the built in method UI_OpenSSL() generate
    206      1.1  christos are assumed to be encoded according to the current locale or (for
    207      1.1  christos Windows) code page.
    208      1.1  christos For applications having different demands, these strings need to be
    209      1.1  christos converted appropriately by the caller.
    210  1.1.1.4  christos For Windows, if the B<OPENSSL_WIN32_UTF8> environment variable is set,
    211      1.1  christos the built-in method UI_OpenSSL() will produce UTF-8 encoded strings
    212      1.1  christos instead.
    213      1.1  christos 
    214      1.1  christos =head1 RETURN VALUES
    215      1.1  christos 
    216      1.1  christos UI_new() and UI_new_method() return a valid B<UI> structure or NULL if an error
    217      1.1  christos occurred.
    218      1.1  christos 
    219      1.1  christos UI_add_input_string(), UI_dup_input_string(), UI_add_verify_string(),
    220      1.1  christos UI_dup_verify_string(), UI_add_input_boolean(), UI_dup_input_boolean(),
    221      1.1  christos UI_add_info_string(), UI_dup_info_string(), UI_add_error_string()
    222      1.1  christos and UI_dup_error_string() return a positive number on success or a value which
    223      1.1  christos is less than or equal to 0 otherwise.
    224      1.1  christos 
    225      1.1  christos UI_construct_prompt() returns a string or NULL if an error occurred.
    226      1.1  christos 
    227      1.1  christos UI_dup_user_data() returns 0 on success or -1 on error.
    228      1.1  christos 
    229      1.1  christos UI_get0_result() returns a string or NULL on error.
    230      1.1  christos 
    231      1.1  christos UI_get_result_length() returns a positive integer or 0 on success; otherwise it
    232      1.1  christos returns -1 on error.
    233      1.1  christos 
    234      1.1  christos UI_process() returns 0 on success or a negative value on error.
    235      1.1  christos 
    236      1.1  christos UI_ctrl() returns a mask on success or -1 on error.
    237      1.1  christos 
    238  1.1.1.2  christos UI_get_default_method(), UI_get_method(), UI_OpenSSL(), UI_null() and
    239      1.1  christos UI_set_method() return either a valid B<UI_METHOD> structure or NULL
    240      1.1  christos respectively.
    241      1.1  christos 
    242      1.1  christos =head1 HISTORY
    243      1.1  christos 
    244  1.1.1.2  christos The UI_dup_user_data() function was added in OpenSSL 1.1.1.
    245      1.1  christos 
    246      1.1  christos =head1 COPYRIGHT
    247      1.1  christos 
    248  1.1.1.3  christos Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
    249      1.1  christos 
    250  1.1.1.4  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    251      1.1  christos this file except in compliance with the License.  You can obtain a copy
    252      1.1  christos in the file LICENSE in the source distribution or at
    253      1.1  christos L<https://www.openssl.org/source/license.html>.
    254      1.1  christos 
    255      1.1  christos =cut
    256