UI_NEW(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸŽ€ UI_NEW(3) β€” New User Interface πŸŽ€

okay bestie, welcome to UI_NEW(3) from the Library Functions Manual, and this one is literally the whole user-interface crew of libcrypto. like, all of them. every single one. let's go πŸ’…

✨ NAME ✨

UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string, UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean, UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string, UI_add_error_string, UI_dup_error_string, UI_construct_prompt, UI_add_user_data, UI_get0_user_data, UI_get0_result, UI_process, UI_ctrl, UI_set_default_method, UI_get_default_method, UI_get_method, UI_set_method, UI_OpenSSL, UI_null β€” New User Interface

yes that's a lot of names, she's an icon with a big family 🫢


🌸 SYNOPSIS 🌸

library β€œlibcrypto”
#include <openssl/ui.h>

UI *
UI_new(void);

UI *
UI_new_method(const UI_METHOD *method);

void
UI_free(UI *ui);

int
UI_add_input_string(UI *ui, const char *prompt, int flags,
    char *result_buf, int minsize, int maxsize);

int
UI_dup_input_string(UI *ui, const char *prompt, int flags,
    char *result_buf, int minsize, int maxsize);

int
UI_add_verify_string(UI *ui, const char *prompt, int flags,
    char *result_buf, int minsize, int maxsize, const char *test_buf);

int
UI_dup_verify_string(UI *ui, const char *prompt, int flags,
    char *result_buf, int minsize, int maxsize, const char *test_buf);

int
UI_add_input_boolean(UI *ui, const char *prompt,
    const char *action_desc, const char *ok_chars,
    const char *cancel_chars, int flags, char *result_buf);

int
UI_dup_input_boolean(UI *ui, const char *prompt,
    const char *action_desc, const char *ok_chars,
    const char *cancel_chars, int flags, char *result_buf);

int
UI_add_info_string(UI *ui, const char *text);

int
UI_dup_info_string(UI *ui, const char *text);

int
UI_add_error_string(UI *ui, const char *text);

int
UI_dup_error_string(UI *ui, const char *text);

/* These are the possible flags. They can be OR'ed together. */
#define UI_INPUT_FLAG_ECHO         0x01
#define UI_INPUT_FLAG_DEFAULT_PWD  0x02

char *
UI_construct_prompt(UI *ui_method, const char *object_desc,
    const char *object_name);

void *
UI_add_user_data(UI *ui, void *user_data);

void *
UI_get0_user_data(UI *ui);

const char *
UI_get0_result(UI *ui, int i);

int
UI_process(UI *ui);

int
UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());

#define UI_CTRL_PRINT_ERRORS       1
#define UI_CTRL_IS_REDOABLE        2

void
UI_set_default_method(const UI_METHOD *meth);

const UI_METHOD *
UI_get_default_method(void);

const UI_METHOD *
UI_get_method(UI *ui);

const UI_METHOD *
UI_set_method(UI *ui, const UI_METHOD *meth);

const UI_METHOD *
UI_OpenSSL(void);

const UI_METHOD *
UI_null(void);

πŸ’– DESCRIPTION πŸ’–

so UI stands for User Interface (not the CSS framework, focus πŸ’€), and this whole thing is a general purpose set of routines to prompt the user for text-based information. and the way it does that? through user-written methods (peep UI_create_method(3)) β€” so prompting can be done in literally any way imaginable. plain text prompting? slay. dialog boxes? slay. from a cell phone?? also slay, apparently πŸ“±βœ¨

all the functions work through a context of the type UI. this context holds everything needed to prompt correctly, plus a reference to a UI_METHOD, which is an ordered vector of functions that do the actual prompting. think of it as the group chat and the UI_METHOD is the friend who actually sends the message 🫢

so the first thing you do is create a UI with UI_new() or UI_new_method(), then add information to it with the UI_add_*() or UI_dup_*() functions. also, user-defined random data can be passed down to the underlying method through calls to UI_add_user_data(). the default UI method literally does not care about these data, but other methods might πŸ‘€. finally, use UI_process() to actually perform the prompting and UI_get0_result() to find the result to the prompt. main character energy from start to finish.

a UI can contain more than one prompt, and they're performed in the given sequence. each prompt gets an index number which is returned by the UI_add_*() and UI_dup_*() functions, and you have to use that to get the corresponding result with UI_get0_result(). iykyk.

the functions are as follows:

  • UI_new() β€” creates a new UI using the default UI method. when you're done with this UI, it should be freed using UI_free().
  • UI_new_method() β€” creates a new UI using the given UI method. when done, free it with UI_free(). same vibe, different method πŸ’…
  • UI_OpenSSL() β€” returns the built-in UI method. ⚠️ note: not necessarily the default one, since the default can be changed (see further on bestie). this method is the most machine/OS dependent part of OpenSSL and normally generates the most problems when porting. it's giving "works on my machine" 😭
  • UI_null() β€” returns a UI method that does nothing. its whole purpose is to avoid getting internal defaults for passed UI_METHOD pointers.
  • UI_free() β€” removes ui from memory, along with all other pieces of memory connected to it, like duplicated input strings, results and others. if ui is a NULL pointer, no action occurs. no drama, no crash πŸŽ€
  • UI_add_input_string() and UI_add_verify_string() β€” add a prompt to ui, as well as flags and a result buffer and the desired minimum and maximum sizes of the result, not counting the final NUL character. the given information is used to prompt for information (for example a password) and to verify a password β€” i.e. having the user enter it twice and check that the same string was entered twice. UI_add_verify_string() takes an extra argument that should be a pointer to the result buffer of the input string that it's supposed to verify, or verification will fail. so like, actually pass it πŸ™ˆ
  • UI_add_input_boolean() β€” adds a prompt to ui that's supposed to be answered in a boolean way, with a single character for yes and a different character for no. a set of characters that can be used to cancel the prompt is given as well. the prompt itself is really divided in two: one part is the descriptive text (given through the prompt argument) and one describes the possible answers (given through the action_desc argument). two prompts in a trench coat πŸ§₯
  • UI_add_info_string() and UI_add_error_string() β€” add strings that are shown at the same time as the prompt, for extra information or to show an error string. the difference between the two is only conceptual. with the builtin method there's no technical difference between them at all. other methods may make a difference though, so don't @ me πŸ‘€
  • UI_dup_input_string(), UI_dup_verify_string(), UI_dup_input_boolean(), UI_dup_info_string(), and UI_dup_error_string() β€” basically the same as their UI_add_*() counterparts, except that they make their own copies of all strings. copy-paste but make it official πŸ’…

the flags currently supported are:

  • UI_INPUT_FLAG_ECHO β€” relevant for UI_add_input_string(), and will have the user's response be echoed. when prompting for a password, this flag should obviously not be used 🚨
  • UI_INPUT_FLAG_DEFAULT_PWD β€” means that a default password of some sort will be used (completely depending on the application and the UI method).

and the rest of the crew:

  • UI_construct_prompt() β€” a helper function that can be used to create a prompt from two pieces of information: a description and a name. the default constructor (if there is none provided by the method used) creates a string "Enter description for name:". with the description "pass phrase" and the file name "foo.key", that becomes "Enter pass phrase for foo.key:". other methods may create whatever string and may include encodings that will be processed by the other method functions. customizable queen πŸ‘‘
  • UI_add_user_data() β€” adds a user data pointer for the method to use at any time. the builtin UI method doesn't care about this info. ⚠️ note that several calls to this function don't add data β€” the previous blob is replaced with the one given as argument. not a stack, bestie, it's a swap 😭
  • UI_get0_user_data() β€” retrieves the data that has last been given to the ui with UI_add_user_data().
  • UI_get0_result() β€” returns a pointer to the result buffer associated with the information indexed by i.
  • UI_process() β€” goes through the information given so far, does all the printing and prompting, and returns the final status, which is -2 on out-of-band events (Interrupt, Cancel, ...), -1 on error, or 0 on success.
  • UI_ctrl() β€” adds extra control for the application author. for now it understands two commands: UI_CTRL_PRINT_ERRORS, which makes UI_process() print the OpenSSL error stack as part of processing the ui, and UI_CTRL_IS_REDOABLE, which returns a flag saying if the used ui can be used again or not. redoable is a real word now, we don't question it ✨
  • UI_set_default_method() β€” changes the default UI method to the one given. 🚨 this function is not thread-safe and should not be called at the same time as other OpenSSL functions. do not test her.
  • UI_get_default_method() β€” returns a pointer to the current default UI method.
  • UI_get_method() β€” returns the UI method associated with a given ui.
  • UI_set_method() β€” changes the UI method associated with a given ui.

πŸ¦‹ RETURN VALUES πŸ¦‹

  • UI_new() and UI_new_method() return a valid UI structure or NULL if an error occurred.
  • UI_add_input_string(), UI_dup_input_string(), UI_add_verify_string(), UI_dup_verify_string(), UI_add_input_boolean(), UI_dup_input_boolean(), UI_add_info_string(), UI_dup_info_string(), UI_add_error_string(), and UI_dup_error_string() return a positive number on success or a number less than or equal to zero otherwise.
  • UI_construct_prompt() and UI_get0_result() return a string or NULL if an error occurred.
  • UI_add_user_data() and UI_get0_user_data() return a pointer to the user data that was contained in ui before the call. in particular, NULL is a valid return value β€” don't panic, she's fine πŸ™ˆ
  • UI_process() returns 0 on success or a negative value on error.
  • UI_ctrl() returns a mask on success or -1 on error.
  • UI_get_default_method(), UI_OpenSSL() and UI_null() always return a pointer to a valid UI_METHOD structure. always. no cap πŸ’―
  • UI_get_method() and UI_set_method() return a pointer to the UI_METHOD structure that is installed in ui after the call. the OpenSSL documentation says that they can fail and return NULL, but currently this can only happen when and after UI_set_method() is called with an explicit NULL argument. so like, extremely specific circumstances πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

crypto(3), UI_create_method(3), UI_get_string_type(3)

go read those too, bestie, they're part of the lore πŸ“š


🌈 HISTORY 🌈

these functions first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. vintage icons ✨

UI_null() first appeared in OpenSSL 1.1.1 and has been available since OpenBSD 7.3. the baby of the family 🍼


πŸ’œ AUTHORS πŸ’œ

Richard Levitte <richard@levitte.org> for the OpenSSL project.


and that's the whole page, bestie 🫢 this UI_NEW(3) situation is from the Debian build of the Library Functions Manual, dated June 8, 2025 β€” go forth and prompt responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from