UI_NEW(3SSL)
π UI_NEW π β the OpenSSL UI crew, bestie edition
okay so this is UI_NEW(3SSL) from the OpenSSL family, and honestly? it's giving β¨*user interface toolkit*β¨. no cap. let's get into it π«Ά
πΈ NAME πΈ
Your whole girl gang of functions, fr fr:
UIUI_newUI_new_methodUI_freeUI_add_input_stringUI_dup_input_stringUI_add_verify_stringUI_dup_verify_stringUI_add_input_booleanUI_dup_input_booleanUI_add_info_stringUI_dup_info_stringUI_add_error_stringUI_dup_error_stringUI_construct_promptUI_add_user_dataUI_dup_user_dataUI_get0_user_dataUI_get0_resultUI_get_result_lengthUI_processUI_ctrlUI_set_default_methodUI_get_default_methodUI_get_methodUI_set_methodUI_OpenSSLUI_null
β¦and they're all about one thing: the user interface. π
β¨ 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 π¦
UI stands for User Interface, and it's a general-purpose lil toolkit for asking the user for text-based info. and the way it asks? literally anything you want, bestie β through methods you write yourself (peep UI_create_method(3)). plain text prompt? sure. dialog boxes? iconic. straight up from a cell phone? why not, main character energy. π±
everything here works through a context of type UI. that context holds literally everything needed to prompt correctly, plus a reference to a UI_METHOD β which is an ordered vector of functions that carry out the actual prompting. yes, an ordered vector. she's organized. π
so the flow is:
- make a
UIwithUI_new()orUI_new_method() - feed it info with the
UI_addorUI_dupfunctions - optionally pass user-defined random data down to the underlying method with
UI_add_user_data()orUI_dup_user_data()β the defaultUImethod does not care about these data, but other methods might π - call
UI_process()to actually do the prompting - grab the answer with
UI_get0_result()and its length withUI_get_result_length()
a UI can hold more than one prompt, and they get performed in the given sequence. each prompt gets an index number β returned by the UI_add and UI_dup functions β and you have to use that index to fetch the matching result with UI_get0_result() and UI_get_result_length(). no skipping, bestie.
fun fact: UI_process() can be called more than once on the same UI, so a UI can live a long life. or a short one. both are valid. we support all lifespans here. π
the functions are as follows:
UI_new()β creates a newUIusing the defaultUImethod. when you're done with thisUI, free it withUI_free(). periodt.UI_new_method()β creates a newUIusing the givenUImethod. when you're done with thisUI, free it withUI_free().UI_OpenSSL()β returns the built-inUImethod. β οΈ note: not necessarily the default one, since the default can be changed (more on that further down). this method is the most machine/OS dependent part of OpenSSL and normally generates the most problems when porting. she's high maintenance but we love her. πUI_null()β returns aUImethod that does nothing. its whole job is to avoid getting internal defaults for passedUI_METHODpointers.UI_free()β removes aUIfrom memory, along with all the other pieces of memory connected to it, like duplicated input strings, results and others. ifuiisNULL, nothing is done. no drama. πUI_add_input_string()andUI_add_verify_string()β add a prompt to theUI, plus flags, a result buffer, and the desired minimum and maximum sizes of the result (not counting the final NUL character). the given info is used to prompt for information, for example a password, and to verify a password β i.e. having the user enter it twice and checking 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 it's supposed to verify, or verification will fail. fr fr, don't forget it.UI_add_input_boolean()β adds a prompt 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 split in two: one part is the descriptive text (thepromptargument) and one describes the possible answers (theaction_descargument). two-for-one, love that for us. πUI_add_info_string()andUI_add_error_string()β add strings that are shown at the same time as the prompt, for extra info 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, though. π
the flags currently supported are:
UI_INPUT_FLAG_ECHOβ relevant forUI_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 theUImethod.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 they make their own copies of all strings. dupe, but make it legal. β¨UI_construct_prompt()β a helper that builds a prompt out of two pieces of info: a phrase descriptionphrase_descand an object nameobject_name, where the latter may beNULL. the default constructor (if the method used doesn't provide one) creates a string"Enter phrase_desc for object_name:"where the" for object_name"part is left out ifobject_nameisNULL. with the description"pass phrase"and the filename"foo.key", that becomes"Enter pass phrase for foo.key:". iconic. other methods may create whatever string they want and may include encodings that will be processed by the other method functions. πUI_add_user_data()β sets the user data pointer for the method to use at any time. the built-inUImethod doesn't care about this info, ngl. β οΈ note that several calls to this function don't add data β it replaces the previous pointer with the one given as argument. the return value is the previously set user data pointer if it was set usingUI_add_user_data()and thus the caller owns it, otherwiseNULL.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 and a destructor 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 all the information given so far, does all the printing and prompting, and returns the final status:-2on out-of-band events (Interrupt, Cancel, ...) π-1on error0on success β¨
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 theUIUI_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. don't do it, bestie. π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() generates are assumed to be encoded according to the current locale, or (for Windows) the code page. for applications having different demands, these strings need to be converted appropriately by the caller β that's on you, babes. π
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. π¦
π RETURN VALUES π
okay so this is the part where we find out what you actually get back from all these lil functions, and bestie, the vibes vary wildly. some of them hand you a whole pointer, some hand you a number, some hand you a string, and some just hit you with a -1 and ghost you π
UI_new()andUI_new_method()β give you a validUIstructure, orNULLif something went sideways. so either you got a UI or you got nothing, no in-between π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()β these all return a positive number when it works out, or a value that's less than or equal to 0 when it doesn't. so like,1and up = slay,0or below = πUI_construct_prompt()β returns a string, orNULLif an error happened. no string, no party β¨UI_add_user_data()β returns the user data pointer that you previously set with this exact function. and if you never set one?NULL. that's it, that's the whole deal π«ΆUI_dup_user_data()β returns0on success or-1on error. tiny range, huge stakes π₯UI_get0_result()β returns a string, orNULLon error. (ngl the0in the name is giving "I'm just showing you the pointer, I'm not making a copy" energy, iykyk π)UI_get_result_length()β returns a positive integer or0on success; otherwise it returns-1on error. yes the wording is lowkey cursed but that's literally what it says, fr fr βUI_process()β returns0on success or a negative value on error.0is the good one here, don't let the number gaslight you πUI_ctrl()β returns a mask on success or-1on error πUI_get_default_method(),UI_get_method(),UI_OpenSSL(),UI_null()andUI_set_method()β each of these returns either a validUI_METHODstructure orNULL. that's the vibe check: struct or nothing π¦
π HISTORY π
so the UI_dup_user_data() function is the baby of the family β it was added in OpenSSL 1.1.1. everything else was already here being iconic π
π COPYRIGHT π
Copyright 2001-2026 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>.
real talk though: don't sleep on that license, bestie. "you may not use this file except in compliance with the License" is the legal equivalent of read the room π
and that's a wrap on UI_NEW(3SSL) π«Ά this lil masterpiece is from OpenSSL 4.0.3, dated 2026-09-29. go forth and UI_process() responsibly, mwah πβ¨πΈ
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms