UI_NEW(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… UI_NEW(3ossl) β€” user interface πŸ’…

OpenSSL manual page, section 3ossl, all about the UI family, bestie. This is the vibe: text-based prompting, but make it customizable. ✨

✨ NAME ✨

  • 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 this is a general purpose set of routines for prompting the user for text-based information. Through user-written methods β€” see UI_create_method(3) β€” prompting can be done in literally any way imaginable: plain text prompting, dialog boxes, or even from a cell phone. Iconic flexibility, no cap. πŸ’…

All the functions work through a context of the type UI. This 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 can just as well have a short lifetime. Main character energy: flexible lifespan. πŸ’–

The functions are as follows:

  • UI_new() β€” creates a new UI using the default UI method. When 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 with this UI, it should be freed using UI_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 passed UI_METHOD pointers.
  • UI_free() β€” removes a UI from memory, along with all other pieces of memory that's connected to it, like duplicated input strings, results and others. If ui is NULL nothing is done. Cleanup slay.
  • UI_add_input_string() and UI_add_verify_string() β€” add a prompt to the 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. No pressure, but verification failing is a whole thing. πŸ’€
  • UI_add_input_boolean() β€” adds a prompt to the 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 divided in two: one part being the descriptive text, given through the prompt argument, and one describing the possible answers, given through the action_desc argument. Two-part prompt, very demure. πŸŽ€
  • 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 built-in method, there's no technical difference between them. Other methods may make a difference between them, however.
  • The flags currently supported β€” UI_INPUT_FLAG_ECHO, which is relevant for UI_add_input_string() and will have the users 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. Password echo? Bestie, no. πŸ™ˆ
  • 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 that, literally.
  • UI_construct_prompt() β€” a helper function that can be used to create a prompt from two pieces of information: a phrase description phrase_desc and an object name object_name, where the latter may be NULL. 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 if object_name is NULL. 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. Prompt glow-up achieved. ✨
  • 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 using UI_add_user_data() and thus the caller owns it, otherwise NULL. Ownership tea. 🫢
  • UI_dup_user_data() β€” duplicates the user data and works as an alternative to UI_add_user_data() when the user data needs to be preserved for a longer duration, perhaps even the lifetime of the application. The UI object takes ownership of this duplicate and will free it whenever it gets replaced or the UI is destroyed. UI_dup_user_data() returns 0 on success, or -1 on memory allocation failure or if the method doesn't have a duplicator and a destructor function. Memory allocation failure? Not cute. 😭
  • UI_get0_user_data() β€” retrieves the data that has last been given to the UI with UI_add_user_data() or UI_dup_user_data().
  • UI_get0_result() β€” returns a pointer to the result buffer associated with the information indexed by i.
  • UI_get_result_length() β€” returns the length of 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 and 0 on success. Status report, bestie. πŸ”₯
  • 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.
  • 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 run this concurrently, fr fr. 🚨
  • 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.

🧚 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. Locale lore, Windows edition. 🌈

πŸ’– RETURN VALUES πŸ’–

okay bestie, this is the part where we find out what you actually get back β€” because every single one of these functions has opinions about what it hands you, and you need to know the vibe check results before you start trusting return values blindly 🫢

  • UI_new() and UI_new_method() β€” they give you a whole valid UI structure (iconic) ✨ or NULL if something went wrong. NULL = error occurred, no cap.
  • 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() β€” the whole girl gang πŸ’… they all return a positive number on success, or a value that is less than or equal to 0 otherwise. so like, 0 is not a win here, bestie, don't get it twisted πŸ™ˆ
  • UI_construct_prompt() β€” returns a string 🌸 or NULL if an error occurred.
  • UI_add_user_data() β€” returns the user data pointer you previously set using this same function, otherwise NULL. it's giving "look what you left here" energy πŸŽ€
  • UI_dup_user_data() β€” returns 0 on success or -1 on error. simple as that, periodt.
  • UI_get0_result() β€” returns a string or NULL on error 😭
  • UI_get_result_length() β€” returns a positive integer or 0 on success; otherwise it returns -1 on error. yes, 0 counts as success here, she's just built different.
  • UI_process() β€” returns 0 on success or a negative value on error. zero is the slay outcome, iykyk πŸ”₯
  • UI_ctrl() β€” returns a mask on success or -1 on error. mask = you ate, -1 = πŸ’€
  • UI_get_default_method(), UI_get_method(), **UI_OpenSSL()**, **UI_null()** and **UI_set_method()** β€” these all return either a valid UI_METHODstructure orNULL`, respectively πŸ‘‘

πŸ¦‹ HISTORY πŸ¦‹

so the lore: the UI_dup_user_data() function was added in OpenSSL 1.1.1. that's it, that's the whole glow-up timeline ⭐


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 of the License in the file LICENSE in the source distribution, or at <https://www.openssl.org/source/license.html> πŸ’œ

fr fr bestie, read the license β€” it's the whole "you may not use this file except in compliance" thing, and we are not about to get in trouble over a missing license read 🌈

and that's a wrap on the page, bestie 🫢 this lil beauty is from OpenSSL 3.5.6, dated 2026-04-07, and it lives at UI_NEW(3ossl) β€” go be iconic with your UIs now πŸ’…βœ¨πŸ‘‘

πŸ“¦ where this page comes from