UI_NEW(3ossl)
β¨ NAME β¨
okay bestie, welcome to the UI_NEW(3ossl) page π this is the whole UI squad β OpenSSL's user-interface girlies β and here's every single one of them, no cap:
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
β 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 π
okay so UI stands for User Interface, and it's a general-purpose little set of routines whose whole job is to prompt the user for text-based information. and the way it prompts? literally whatever you want. through user-written methods (peep UI_create_method(3)) the prompting can be done in any way imaginable β plain text prompting, dialog boxes, even from a cell phone. the range is giving main character energy π¦
every single one of these functions works through a context of the type UI. that context holds everything needed to prompt correctly, plus a reference to a UI_METHOD, which is an ordered vector of functions that actually carry out the prompting. it's the whole blueprint, bestie.
so the first thing you do is create a UI with UI_new() or UI_new_method(), then add info 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 literally does not 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 hold more than one prompt, and they get 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 index 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, which lets a UI have a long lifetime β but it can just as well have a short one. no rules, only vibes β¨
the functions are as follows:
UI_new()β creates a newUIusing the default UI method. when you're done with thisUI, it should be freed usingUI_free().UI_new_method()β creates a newUIusing the given UI method. when you're done with thisUI, it should be freed usingUI_free().UI_OpenSSL()β returns the built-in UI method (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 a UI method 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. ifuiisNULLnothing is done.UI_add_input_string()andUI_add_verify_string()β add a prompt to theUI, plus flags and a result buffer and the desired minimum and maximum sizes of the result, not counting the finalNULcharacter. 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 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. periodt.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 split 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()andUI_add_error_string()β add strings that are shown at the same time as the prompt, either 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.- the flags currently supported are
UI_INPUT_FLAG_ECHO, which is 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), andUI_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_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. it's giving responsible π«Ά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 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:". other methods may create whatever string 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-in UI method doesn't care about this info. note that several calls to this function doesn'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 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.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 the UI, andUI_CTRL_IS_REDOABLE, which returns a flag saying if the used UI can be used again or not.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.UI_get_default_method()β returns a pointer to the current default UI method.UI_get_method()β returns the UI method associated with a givenUI.UI_set_method()β changes the UI method 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) 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 β¨
ngl bestie, that locale/code page thing trips people up constantly β your strings, your responsibility π
π RETURN VALUES π
okay so bestie, when you call these, here's what you get back. no cap, write it down. π
UI_new()andUI_new_method()β give you a validUIstructure, orNULLif something went sideways. π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()β return a positive number when it's giving success, or a value that's less than or equal to0otherwise. so if it's not > 0, it's a no from her. πUI_construct_prompt()β hands you a string, orNULLif an error occurred. π«UI_add_user_data()β returns the user data pointer that was previously set using this function, otherwiseNULL. lowkey just giving you back what you put in. β¨UI_dup_user_data()β returns0on success or-1on error. that's it, that's the vibe. πUI_get0_result()β returns a string, orNULLon error. πUI_get_result_length()β returns a positive integer or0on success; otherwise it returns-1on error. so positive or zero = slay, -1 = not slay. π₯UI_process()β returns0on success or a negative value on error. πUI_ctrl()β returns a mask on success or-1on error. πUI_get_default_method(),UI_get_method(),UI_OpenSSL(),UI_null()andUI_set_method()β return either a validUI_METHODstructure orNULLrespectively. periodt. π
β¨ HISTORY β¨
the UI_dup_user_data() function was added in OpenSSL 1.1.1. so it's not ancient, it's a little baby. πΌ
π 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>. π
and that's the whole page bestie! this was UI_NEW(3ossl) from OpenSSL 3.5.9, dated 2026-09-29. mwah, go slay your UI code. π
β¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms