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:

  • 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

…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:

  1. make a UI with UI_new() or UI_new_method()
  2. feed it info with the UI_add or UI_dup functions
  3. optionally pass user-defined random data down to the underlying method with UI_add_user_data() or UI_dup_user_data() β€” the default UI method does not care about these data, but other methods might πŸ‘€
  4. call UI_process() to actually do the prompting
  5. grab the answer with UI_get0_result() and its length with UI_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 new UI using the default UI method. when you're done with this UI, free it with UI_free(). periodt.
  • UI_new_method() β€” creates a new UI using the given UI method. when you're done with this UI, free it with UI_free().
  • UI_OpenSSL() β€” returns the built-in UI method. ⚠️ 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 a UI method that does nothing. its whole job is to avoid getting internal defaults for passed UI_METHOD pointers.
  • UI_free() β€” removes a UI from memory, along with all the other pieces of memory connected to it, like duplicated input strings, results and others. if ui is NULL, nothing is done. no drama. πŸ’…
  • UI_add_input_string() and UI_add_verify_string() β€” add a prompt to the UI, 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 (the prompt argument) and one describes the possible answers (the action_desc argument). two-for-one, love that for us. πŸ“
  • UI_add_info_string() and UI_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 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.
  • 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 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 description phrase_desc and an object name object_name, where the latter may be NULL. 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 if object_name is NULL. 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-in UI method 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 using UI_add_user_data() and thus the caller owns it, otherwise NULL.
  • 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.
  • 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 all the information given so far, does all the printing and prompting, and returns the final status:
    • -2 on out-of-band events (Interrupt, Cancel, ...) 😭
    • -1 on error
    • 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
    • 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. don't do it, bestie. πŸ™
  • 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() 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() and UI_new_method() β€” give you a valid UI structure, or NULL if 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() and UI_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, 1 and up = slay, 0 or below = 😭
  • UI_construct_prompt() β€” returns a string, or NULL if 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() β€” returns 0 on success or -1 on error. tiny range, huge stakes πŸ”₯
  • UI_get0_result() β€” returns a string, or NULL on error. (ngl the 0 in 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 or 0 on success; otherwise it returns -1 on error. yes the wording is lowkey cursed but that's literally what it says, fr fr ⭐
  • UI_process() β€” returns 0 on success or a negative value on error. 0 is the good one here, don't let the number gaslight you πŸ‘‘
  • UI_ctrl() β€” returns a mask on success or -1 on error πŸŽ€
  • UI_get_default_method(), UI_get_method(), UI_OpenSSL(), UI_null() and UI_set_method() β€” each of these returns either a valid UI_METHOD structure or NULL. 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 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