UI_NEW(3ossl)
π
UI_NEW(3ossl) β OpenSSL user interface, but make it make sense β¨
β¨ NAME β¨
Okay bestie, this is the whole squad: UI, 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_dup_user_data, UI_get0_user_data, UI_get0_result, UI_get_result_length, UI_process, UI_ctrl, UI_set_default_method, UI_get_default_method, UI_get_method, UI_set_method, UI_OpenSSL, UI_null β all here for your user interface needs π«Ά
π SYNOPSIS π
#include <openssl/ui.h>
typedef struct ui_st UI;
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);
char *UI_construct_prompt(UI *ui_method,
const char *phrase_desc, const char *object_name);
void *UI_add_user_data(UI *ui, void *user_data);
int UI_dup_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_get_result_length(UI *ui, int i);
int UI_process(UI *ui);
int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
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);
UI_METHOD *UI_OpenSSL(void);
const UI_METHOD *UI_null(void);
π¦ DESCRIPTION π¦
So UI literally stands for User Interface, and this is a general-purpose set of routines for prompting the user for text-based info. Through user-written methods (see UI_create_method(3)), prompting can be done in any way imaginable β plain text prompting, through dialog boxes, or even from a cell phone. Iconic, honestly.
All the functions work through a context of the type UI. That context contains all the information needed to prompt correctly, plus a reference to a UI_METHOD, which is an ordered vector of functions that carry out the actual prompting.
The first thing to 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() or UI_dup_user_data(). The default UI method doesn't care about these data, but other methods might. Finally, use UI_process() to actually perform the prompting, and UI_get0_result() and UI_get_result_length() to find the result to the prompt and its length.
A UI can contain more than one prompt, which are performed in the given sequence. Each prompt gets an index number which is returned by the UI_add and UI_dup functions, and has to be used to get the corresponding result with UI_get0_result() and UI_get_result_length().
UI_process() can be called more than once on the same UI, thereby allowing a UI to have a long lifetime β but it can just as well have a short lifetime. Lowkey flexible like that π
π The functions, one by one π
UI_new()β creates a newUIusing the defaultUImethod. When you're done with thisUI, it should be freed usingUI_free().UI_new_method()β creates a newUIusing the givenUImethod. When you're done with thisUI, it should be freed usingUI_free().UI_OpenSSL()β returns the built-inUImethod. Note: not necessarily the default one, since the default can be changed. See further on. This method is the most machine/OS dependent part of OpenSSL and normally generates the most problems when porting. πUI_null()β returns aUImethod that does nothing. Its use is to avoid getting internal defaults for passedUI_METHODpointers.UI_free()β removes aUIfrom memory, along with all other pieces of memory that's connected to it, like duplicated input strings, results and others. IfuiisNULL, nothing is done.UI_add_input_string()/UI_add_verify_string()β add a prompt to theUI, as well as flags and a result buffer and the desired minimum and maximum sizes of the result, not counting the finalNULcharacter. 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. No pressure or anything π«UI_add_input_boolean()β adds a prompt to theUIthat'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 divided in two, one part being the descriptive text (given through thepromptargument) and one describing the possible answers (given through theaction_descargument).UI_add_info_string()/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 built-in method, there's no technical difference between them. Other methods may make a difference between them, however.UI_dup_input_string(),UI_dup_verify_string(),UI_dup_input_boolean(),UI_dup_info_string()andUI_dup_error_string()β basically the same as theirUI_addcounterparts, except that they make their own copies of all strings. Copy-paste queen behavior, but make it safe β¨
The flags currently supported are UI_INPUT_FLAG_ECHO, which is 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), and UI_INPUT_FLAG_DEFAULT_PWD, which means that a default password of some sort will be used (completely depending on the application and the UI method).
UI_construct_prompt()β a helper function that can be used to create a prompt from two pieces of information: a phrase descriptionphrase_descand an object nameobject_name, where the latter may beNULL. The default constructor (if there is none provided by the method used) creates a stringEnter phrase_desc for object_name:where thefor object_namepart is left out ifobject_nameisNULL. With the descriptionpass phraseand the filenamefoo.key, that becomesEnter pass phrase for foo.key:. Other methods may create whatever string and may include encodings that will be processed by the other method functions.UI_add_user_data()β adds a user data pointer for the method to use at any time. The built-inUImethod doesn't care about this info. Note that several calls to this function doesn't add data, it replaces the previous blob with the one given as argument.UI_dup_user_data()β duplicates the user data and works as an alternative toUI_add_user_data()when the user data needs to be preserved for a longer duration, perhaps even the lifetime of the application. TheUIobject takes ownership of this duplicate and will free it whenever it gets replaced or theUIis destroyed.UI_dup_user_data()returns0on success, or-1on memory allocation failure or if the method doesn't have a duplicator function.UI_get0_user_data()β retrieves the data that has last been given to theUIwithUI_add_user_data()orUI_dup_user_data().UI_get0_result()β returns a pointer to the result buffer associated with the information indexed byi.UI_get_result_length()β returns the length of the result buffer associated with the information indexed byi.UI_process()β goes through the information given so far, does all the printing and prompting and returns the final status, which is-2on out-of-band events (Interrupt, Cancel, ...),-1on error and0on success. Periodt.UI_ctrl()β adds extra control for the application author. For now, it understands two commands:UI_CTRL_PRINT_ERRORS, which makesUI_process()print the OpenSSL error stack as part of processing theUI, andUI_CTRL_IS_REDOABLE, which returns a flag saying if the usedUIcan be used again or not.UI_set_default_method()β changes the defaultUImethod to the one given. This function is not thread-safe and should not be called at the same time as other OpenSSL functions. β οΈUI_get_default_method()β returns a pointer to the current defaultUImethod.UI_get_method()β returns theUImethod associated with a givenUI.UI_set_method()β changes theUImethod associated with a givenUI.
πΈ NOTES πΈ
The resulting strings that the built in method UI_OpenSSL() generate are assumed to be encoded according to the current locale or (for Windows) code page. For applications having different demands, these strings need to be converted appropriately by the caller. For Windows, if the OPENSSL_WIN32_UTF8 environment variable is set, the built-in method UI_OpenSSL() will produce UTF-8 encoded strings instead. Slay for encoding awareness π
β¨ RETURN VALUES β¨
okay bestie, this is the part where we find out what you actually get back β because not every call is a slay, and the numbers matter, so pay attention π
UI_new()andUI_new_method()β they hand you a validUIstructure, or they give youNULLif something went wrong.NULL= not the vibe, check your error queue π«Ά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()andUI_dup_error_string()β all these girlies return a positive number on success. Anything less than or equal to 0 means it did not go well πUI_construct_prompt()β returns a string, orNULLif an error happened. no string, no prompt, no service πUI_dup_user_data()β returns0on success or-1on error. yes, this one's built different from the rest, zero is the good number here, don't @ me πΈUI_get0_result()β returns a string, orNULLon errorUI_get_result_length()β returns a positive integer or 0 on success; otherwise it returns-1on error. so-1is the only actual "uh oh" signal, the rest are fine πUI_process()β returns0on success or a negative value on errorUI_ctrl()β returns a mask on success or-1on errorUI_get_default_method(),UI_get_method(),UI_OpenSSL(),UI_null()andUI_set_method()β each of these returns either a validUI_METHODstructure orNULL, respectively. respectively bestie, respectively β match them up in order π₯
π HISTORY π
so the lore: UI_dup_user_data() was added in OpenSSL 1.1.1. that's it, that's the whole glow-up timeline β¨
π COPYRIGHT π
Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>. like, fr fr, read the license, it's giving legally binding π
and that's a wrap on UI_NEW(3ossl), bestie β this edition is from OpenSSL 3.5.0, dated 2026-09-25. go forth and prompt responsibly, mwah ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms