Debian Codegraph @

upstream/debian-unstable/man3/UI_new.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "UI_NEW 3SSL"
58 .TH UI_NEW 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 UI,
65 UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string,
66 UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean,
67 UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string,
68 UI_add_error_string, UI_dup_error_string, UI_construct_prompt,
69 UI_add_user_data, UI_dup_user_data, UI_get0_user_data, UI_get0_result,
70 UI_get_result_length,
71 UI_process, UI_ctrl, UI_set_default_method, UI_get_default_method,
72 UI_get_method, UI_set_method, UI_OpenSSL, UI_null \- user interface
73 .SH SYNOPSIS
74 .IX Header "SYNOPSIS"
75 .Vb 1
76 \& #include <openssl/ui.h>
77 \&
78 \& typedef struct ui_st UI;
79 \&
80 \& UI *UI_new(void);
81 \& UI *UI_new_method(const UI_METHOD *method);
82 \& void UI_free(UI *ui);
83 \&
84 \& int UI_add_input_string(UI *ui, const char *prompt, int flags,
85 \& char *result_buf, int minsize, int maxsize);
86 \& int UI_dup_input_string(UI *ui, const char *prompt, int flags,
87 \& char *result_buf, int minsize, int maxsize);
88 \& int UI_add_verify_string(UI *ui, const char *prompt, int flags,
89 \& char *result_buf, int minsize, int maxsize,
90 \& const char *test_buf);
91 \& int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
92 \& char *result_buf, int minsize, int maxsize,
93 \& const char *test_buf);
94 \& int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
95 \& const char *ok_chars, const char *cancel_chars,
96 \& int flags, char *result_buf);
97 \& int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
98 \& const char *ok_chars, const char *cancel_chars,
99 \& int flags, char *result_buf);
100 \& int UI_add_info_string(UI *ui, const char *text);
101 \& int UI_dup_info_string(UI *ui, const char *text);
102 \& int UI_add_error_string(UI *ui, const char *text);
103 \& int UI_dup_error_string(UI *ui, const char *text);
104 \&
105 \& char *UI_construct_prompt(UI *ui_method,
106 \& const char *phrase_desc, const char *object_name);
107 \&
108 \& void *UI_add_user_data(UI *ui, void *user_data);
109 \& int UI_dup_user_data(UI *ui, void *user_data);
110 \& void *UI_get0_user_data(UI *ui);
111 \&
112 \& const char *UI_get0_result(UI *ui, int i);
113 \& int UI_get_result_length(UI *ui, int i);
114 \&
115 \& int UI_process(UI *ui);
116 \&
117 \& int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
118 \&
119 \& void UI_set_default_method(const UI_METHOD *meth);
120 \& const UI_METHOD *UI_get_default_method(void);
121 \& const UI_METHOD *UI_get_method(UI *ui);
122 \& const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
123 \&
124 \& UI_METHOD *UI_OpenSSL(void);
125 \& const UI_METHOD *UI_null(void);
126 .Ve
127 .SH DESCRIPTION
128 .IX Header "DESCRIPTION"
129 UI stands for User Interface, and is general purpose set of routines to
130 prompt the user for text-based information. Through user-written methods
131 (see \fBUI_create_method\fR\|(3)), prompting can be done in any way
132 imaginable, be it plain text prompting, through dialog boxes or from a
133 cell phone.
134 .PP
135 All the functions work through a context of the type UI. This context
136 contains all the information needed to prompt correctly as well as a
137 reference to a UI_METHOD, which is an ordered vector of functions that
138 carry out the actual prompting.
139 .PP
140 The first thing to do is to create a UI with \fBUI_new()\fR or \fBUI_new_method()\fR,
141 then add information to it with the UI_add or UI_dup functions. Also,
142 user-defined random data can be passed down to the underlying method
143 through calls to \fBUI_add_user_data()\fR or \fBUI_dup_user_data()\fR. The default
144 UI method doesn't care about these data, but other methods might. Finally,
145 use \fBUI_process()\fR to actually perform the prompting and \fBUI_get0_result()\fR
146 and \fBUI_get_result_length()\fR to find the result to the prompt and its length.
147 .PP
148 A UI can contain more than one prompt, which are performed in the given
149 sequence. Each prompt gets an index number which is returned by the
150 UI_add and UI_dup functions, and has to be used to get the corresponding
151 result with \fBUI_get0_result()\fR and \fBUI_get_result_length()\fR.
152 .PP
153 \&\fBUI_process()\fR can be called more than once on the same UI, thereby allowing
154 a UI to have a long lifetime, but can just as well have a short lifetime.
155 .PP
156 The functions are as follows:
157 .PP
158 \&\fBUI_new()\fR creates a new UI using the default UI method. When done with
159 this UI, it should be freed using \fBUI_free()\fR.
160 .PP
161 \&\fBUI_new_method()\fR creates a new UI using the given UI method. When done with
162 this UI, it should be freed using \fBUI_free()\fR.
163 .PP
164 \&\fBUI_OpenSSL()\fR returns the built-in UI method (note: not necessarily the
165 default one, since the default can be changed. See further on). This
166 method is the most machine/OS dependent part of OpenSSL and normally
167 generates the most problems when porting.
168 .PP
169 \&\fBUI_null()\fR returns a UI method that does nothing. Its use is to avoid
170 getting internal defaults for passed UI_METHOD pointers.
171 .PP
172 \&\fBUI_free()\fR removes a UI from memory, along with all other pieces of memory
173 that's connected to it, like duplicated input strings, results and others.
174 If \fBui\fR is NULL nothing is done.
175 .PP
176 \&\fBUI_add_input_string()\fR and \fBUI_add_verify_string()\fR add a prompt to the UI,
177 as well as flags and a result buffer and the desired minimum and maximum
178 sizes of the result, not counting the final NUL character. The given
179 information is used to prompt for information, for example a password,
180 and to verify a password (i.e. having the user enter it twice and check
181 that the same string was entered twice). \fBUI_add_verify_string()\fR takes
182 and extra argument that should be a pointer to the result buffer of the
183 input string that it's supposed to verify, or verification will fail.
184 .PP
185 \&\fBUI_add_input_boolean()\fR adds a prompt to the UI that's supposed to be answered
186 in a boolean way, with a single character for yes and a different character
187 for no. A set of characters that can be used to cancel the prompt is given
188 as well. The prompt itself is divided in two, one part being the
189 descriptive text (given through the \fIprompt\fR argument) and one describing
190 the possible answers (given through the \fIaction_desc\fR argument).
191 .PP
192 \&\fBUI_add_info_string()\fR and \fBUI_add_error_string()\fR add strings that are shown at
193 the same time as the prompt for extra information or to show an error string.
194 The difference between the two is only conceptual. With the built-in method,
195 there's no technical difference between them. Other methods may make a
196 difference between them, however.
197 .PP
198 The flags currently supported are \fBUI_INPUT_FLAG_ECHO\fR, which is relevant for
199 \&\fBUI_add_input_string()\fR and will have the users response be echoed (when
200 prompting for a password, this flag should obviously not be used, and
201 \&\fBUI_INPUT_FLAG_DEFAULT_PWD\fR, which means that a default password of some
202 sort will be used (completely depending on the application and the UI
203 method).
204 .PP
205 \&\fBUI_dup_input_string()\fR, \fBUI_dup_verify_string()\fR, \fBUI_dup_input_boolean()\fR,
206 \&\fBUI_dup_info_string()\fR and \fBUI_dup_error_string()\fR are basically the same
207 as their UI_add counterparts, except that they make their own copies
208 of all strings.
209 .PP
210 \&\fBUI_construct_prompt()\fR is a helper function that can be used to create
211 a prompt from two pieces of information: a phrase description \fIphrase_desc\fR
212 and an object name \fIobject_name\fR, where the latter may be NULL.
213 The default constructor (if there is none provided by the method used)
214 creates a string "Enter \fIphrase_desc\fR for \fIobject_name\fR:"
215 where the " for \fIobject_name\fR" part is left out if \fIobject_name\fR is NULL.
216 With the description "pass phrase" and the filename "foo.key", that becomes
217 "Enter pass phrase for foo.key:". Other methods may create whatever
218 string and may include encodings that will be processed by the other
219 method functions.
220 .PP
221 \&\fBUI_add_user_data()\fR sets the user data pointer for the method to use at any
222 time. The built-in UI method doesn't care about this info. Note that several
223 calls to this function doesn't add data, it replaces the previous pointer
224 with the one given as argument.
225 The return value is the previously set user data pointer if it was set
226 using \fBUI_add_user_data()\fR and thus the caller owns it, otherwise NULL.
227 .PP
228 \&\fBUI_dup_user_data()\fR duplicates the user data and works as an alternative
229 to \fBUI_add_user_data()\fR when the user data needs to be preserved for a longer
230 duration, perhaps even the lifetime of the application. The UI object takes
231 ownership of this duplicate and will free it whenever it gets replaced or
232 the UI is destroyed. \fBUI_dup_user_data()\fR returns 0 on success, or \-1 on memory
233 allocation failure or if the method doesn't have a duplicator and a destructor
234 function.
235 .PP
236 \&\fBUI_get0_user_data()\fR retrieves the data that has last been given to the
237 UI with \fBUI_add_user_data()\fR or UI_dup_user_data.
238 .PP
239 \&\fBUI_get0_result()\fR returns a pointer to the result buffer associated with
240 the information indexed by \fIi\fR.
241 .PP
242 \&\fBUI_get_result_length()\fR returns the length of the result buffer associated with
243 the information indexed by \fIi\fR.
244 .PP
245 \&\fBUI_process()\fR goes through the information given so far, does all the printing
246 and prompting and returns the final status, which is \-2 on out-of-band events
247 (Interrupt, Cancel, ...), \-1 on error and 0 on success.
248 .PP
249 \&\fBUI_ctrl()\fR adds extra control for the application author. For now, it
250 understands two commands: \fBUI_CTRL_PRINT_ERRORS\fR, which makes \fBUI_process()\fR
251 print the OpenSSL error stack as part of processing the UI, and
252 \&\fBUI_CTRL_IS_REDOABLE\fR, which returns a flag saying if the used UI can
253 be used again or not.
254 .PP
255 \&\fBUI_set_default_method()\fR changes the default UI method to the one given.
256 This function is not thread-safe and should not be called at the same time
257 as other OpenSSL functions.
258 .PP
259 \&\fBUI_get_default_method()\fR returns a pointer to the current default UI method.
260 .PP
261 \&\fBUI_get_method()\fR returns the UI method associated with a given UI.
262 .PP
263 \&\fBUI_set_method()\fR changes the UI method associated with a given UI.
264 .SH NOTES
265 .IX Header "NOTES"
266 The resulting strings that the built in method \fBUI_OpenSSL()\fR generate
267 are assumed to be encoded according to the current locale or (for
268 Windows) code page.
269 For applications having different demands, these strings need to be
270 converted appropriately by the caller.
271 For Windows, if the \fBOPENSSL_WIN32_UTF8\fR environment variable is set,
272 the built-in method \fBUI_OpenSSL()\fR will produce UTF\-8 encoded strings
273 instead.
274 .SH "RETURN VALUES"
275 .IX Header "RETURN VALUES"
276 \&\fBUI_new()\fR and \fBUI_new_method()\fR return a valid \fBUI\fR structure or NULL if an error
277 occurred.
278 .PP
279 \&\fBUI_add_input_string()\fR, \fBUI_dup_input_string()\fR, \fBUI_add_verify_string()\fR,
280 \&\fBUI_dup_verify_string()\fR, \fBUI_add_input_boolean()\fR, \fBUI_dup_input_boolean()\fR,
281 \&\fBUI_add_info_string()\fR, \fBUI_dup_info_string()\fR, \fBUI_add_error_string()\fR
282 and \fBUI_dup_error_string()\fR return a positive number on success or a value which
283 is less than or equal to 0 otherwise.
284 .PP
285 \&\fBUI_construct_prompt()\fR returns a string or NULL if an error occurred.
286 .PP
287 \&\fBUI_add_user_data()\fR returns
288 the user data pointer previously set using this function, otherwise NULL.
289 .PP
290 \&\fBUI_dup_user_data()\fR returns 0 on success or \-1 on error.
291 .PP
292 \&\fBUI_get0_result()\fR returns a string or NULL on error.
293 .PP
294 \&\fBUI_get_result_length()\fR returns a positive integer or 0 on success; otherwise it
295 returns \-1 on error.
296 .PP
297 \&\fBUI_process()\fR returns 0 on success or a negative value on error.
298 .PP
299 \&\fBUI_ctrl()\fR returns a mask on success or \-1 on error.
300 .PP
301 \&\fBUI_get_default_method()\fR, \fBUI_get_method()\fR, \fBUI_OpenSSL()\fR, \fBUI_null()\fR and
302 \&\fBUI_set_method()\fR return either a valid \fBUI_METHOD\fR structure or NULL
303 respectively.
304 .SH HISTORY
305 .IX Header "HISTORY"
306 The \fBUI_dup_user_data()\fR function was added in OpenSSL 1.1.1.
307 .SH COPYRIGHT
308 .IX Header "COPYRIGHT"
309 Copyright 2001\-2026 The OpenSSL Project Authors. All Rights Reserved.
310 .PP
311 Licensed under the Apache License 2.0 (the "License"). You may not use
312 this file except in compliance with the License. You can obtain a copy
313 in the file LICENSE in the source distribution or at
314 <https://www.openssl.org/source/license.html>.