1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
.\" $OpenBSD: UI_new.3,v 1.9 2019/06/10 09:49:48 schwarze Exp $
.\" full merge up to: OpenSSL 78b19e90 Jan 11 00:12:01 2017 +0100
.\" selective merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800
.\"
.\" This file was written by Richard Levitte <levitte@openssl.org>.
.\" Copyright (c) 2001, 2016, 2017 The OpenSSL Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: June 10 2019 $
.Dt UI_NEW 3
.Os
.Sh NAME
.Nm UI_new ,
.Nm UI_new_method ,
.Nm UI_free ,
.Nm UI_add_input_string ,
.Nm UI_dup_input_string ,
.Nm UI_add_verify_string ,
.Nm UI_dup_verify_string ,
.Nm UI_add_input_boolean ,
.Nm UI_dup_input_boolean ,
.Nm UI_add_info_string ,
.Nm UI_dup_info_string ,
.Nm UI_add_error_string ,
.Nm UI_dup_error_string ,
.Nm UI_construct_prompt ,
.Nm UI_add_user_data ,
.Nm UI_get0_user_data ,
.Nm UI_get0_result ,
.Nm UI_process ,
.Nm UI_ctrl ,
.Nm UI_set_default_method ,
.Nm UI_get_default_method ,
.Nm UI_get_method ,
.Nm UI_set_method ,
.Nm UI_OpenSSL
.Nd New User Interface
.Sh SYNOPSIS
.In openssl/ui.h
.Ft UI *
.Fn UI_new void
.Ft UI *
.Fo UI_new_method
.Fa "const UI_METHOD *method"
.Fc
.Ft void
.Fo UI_free
.Fa "UI *ui"
.Fc
.Ft int
.Fo UI_add_input_string
.Fa "UI *ui"
.Fa "const char *prompt"
.Fa "int flags"
.Fa "char *result_buf"
.Fa "int minsize"
.Fa "int maxsize"
.Fc
.Ft int
.Fo UI_dup_input_string
.Fa "UI *ui"
.Fa "const char *prompt"
.Fa "int flags"
.Fa "char *result_buf"
.Fa "int minsize"
.Fa "int maxsize"
.Fc
.Ft int
.Fo UI_add_verify_string
.Fa "UI *ui"
.Fa "const char *prompt"
.Fa "int flags"
.Fa "char *result_buf"
.Fa "int minsize"
.Fa "int maxsize"
.Fa "const char *test_buf"
.Fc
.Ft int
.Fo UI_dup_verify_string
.Fa "UI *ui"
.Fa "const char *prompt"
.Fa "int flags"
.Fa "char *result_buf"
.Fa "int minsize"
.Fa "int maxsize"
.Fa "const char *test_buf"
.Fc
.Ft int
.Fo UI_add_input_boolean
.Fa "UI *ui"
.Fa "const char *prompt"
.Fa "const char *action_desc"
.Fa "const char *ok_chars"
.Fa "const char *cancel_chars"
.Fa "int flags"
.Fa "char *result_buf"
.Fc
.Ft int
.Fo UI_dup_input_boolean
.Fa "UI *ui"
.Fa "const char *prompt"
.Fa "const char *action_desc"
.Fa "const char *ok_chars"
.Fa "const char *cancel_chars"
.Fa "int flags"
.Fa "char *result_buf"
.Fc
.Ft int
.Fo UI_add_info_string
.Fa "UI *ui"
.Fa "const char *text"
.Fc
.Ft int
.Fo UI_dup_info_string
.Fa "UI *ui"
.Fa "const char *text"
.Fc
.Ft int
.Fo UI_add_error_string
.Fa "UI *ui"
.Fa "const char *text"
.Fc
.Ft int
.Fo UI_dup_error_string
.Fa "UI *ui"
.Fa "const char *text"
.Fc
.Fd /* These are the possible flags. They can be OR'ed together. */
.Fd #define UI_INPUT_FLAG_ECHO 0x01
.Fd #define UI_INPUT_FLAG_DEFAULT_PWD 0x02
.Ft char *
.Fo UI_construct_prompt
.Fa "UI *ui_method"
.Fa "const char *object_desc"
.Fa "const char *object_name"
.Fc
.Ft void *
.Fo UI_add_user_data
.Fa "UI *ui"
.Fa "void *user_data"
.Fc
.Ft void *
.Fo UI_get0_user_data
.Fa "UI *ui"
.Fc
.Ft const char *
.Fo UI_get0_result
.Fa "UI *ui"
.Fa "int i"
.Fc
.Ft int
.Fo UI_process
.Fa "UI *ui"
.Fc
.Ft int
.Fo UI_ctrl
.Fa "UI *ui"
.Fa "int cmd"
.Fa "long i"
.Fa "void *p"
.Fa "void (*f)()"
.Fc
.Fd #define UI_CTRL_PRINT_ERRORS 1
.Fd #define UI_CTRL_IS_REDOABLE 2
.Ft void
.Fo UI_set_default_method
.Fa "const UI_METHOD *meth"
.Fc
.Ft const UI_METHOD *
.Fo UI_get_default_method
.Fa void
.Fc
.Ft const UI_METHOD *
.Fo UI_get_method
.Fa "UI *ui"
.Fc
.Ft const UI_METHOD *
.Fo UI_set_method
.Fa "UI *ui"
.Fa "const UI_METHOD *meth"
.Fc
.Ft UI_METHOD *
.Fo UI_OpenSSL
.Fa void
.Fc
.Sh DESCRIPTION
UI stands for User Interface, and is a general purpose set of routines
to prompt the user for text-based information.
Through user-written methods (see
.Xr UI_create_method 3 ) ,
prompting can be done in any way imaginable, be it plain text prompting,
through dialog boxes or from a cell phone.
.Pp
All the functions work through a context of the type
.Vt UI .
This context contains all the information needed to prompt correctly
as well as a reference to a
.Vt UI_METHOD ,
which is an ordered vector of functions that carry out the actual
prompting.
.Pp
The first thing to do is to create a
.Vt UI
with
.Fn UI_new
or
.Fn UI_new_method ,
then add information to it with the
.Fn UI_add_*
or
.Fn UI_dup_*
functions.
Also, user-defined random data can be passed down to the underlying
method through calls to
.Fn UI_add_user_data .
The default UI method doesn't care about these data, but other methods
might.
Finally, use
.Fn UI_process
to actually perform the prompting and
.Fn UI_get0_result
to find the result to the prompt.
.Pp
A
.Vt 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
.Fn UI_add_*
and
.Fn UI_dup_*
functions, and has to be used to get the corresponding result with
.Fn UI_get0_result .
.Pp
The functions are as follows:
.Pp
.Fn UI_new
creates a new
.Vt UI
using the default UI method.
When done with this UI, it should be freed using
.Fn UI_free .
.Pp
.Fn UI_new_method
creates a new
.Vt UI
using the given UI method.
When done with this UI, it should be freed using
.Fn UI_free .
.Pp
.Fn 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.
.Pp
.Fn UI_free
removes
.Fa ui
from memory, along with all other pieces of memory that are connected
to it, like duplicated input strings, results and others.
If
.Fa ui
is a
.Dv NULL
pointer, no action occurs.
.Pp
.Fn UI_add_input_string
and
.Fn UI_add_verify_string
add a prompt to
.Fa 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).
.Fn 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.
.Pp
.Fn UI_add_input_boolean
adds a prompt to
.Fa 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 really divided in two, one part being the
descriptive text (given through the
.Fa prompt
argument) and one describing the possible answers (given through the
.Fa action_desc
argument).
.Pp
.Fn UI_add_info_string
and
.Fn 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 builtin method, there's no technical difference between them.
Other methods may make a difference between them, however.
.Pp
The flags currently supported are
.Dv UI_INPUT_FLAG_ECHO ,
which is relevant for
.Fn 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
.Dv 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).
.Pp
.Fn UI_dup_input_string ,
.Fn UI_dup_verify_string ,
.Fn UI_dup_input_boolean ,
.Fn UI_dup_info_string ,
and
.Fn UI_dup_error_string
are basically the same as their
.Fn UI_add_*
counterparts, except that they make their own copies of all strings.
.Pp
.Fn UI_construct_prompt
is a helper function that can be used to create a prompt from two pieces
of information: a description and a name.
The default constructor (if there is none provided by the method used)
creates a string "Enter
.Em description
for
.Em name Ns :".
With the description "pass phrase" and the file name "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.
.Pp
.Fn UI_add_user_data
adds a user data pointer for the method to use at any time.
The builtin UI method doesn't care about this info.
Note that several calls to this function doesn't add data -
the previous blob is replaced with the one given as argument.
.Pp
.Fn UI_get0_user_data
retrieves the data that has last been given to the
.Fa ui
with
.Fn UI_add_user_data .
.Pp
.Fn UI_get0_result
returns a pointer to the result buffer associated with the information
indexed by
.Fa i .
.Pp
.Fn 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, or 0 on success.
.Pp
.Fn UI_ctrl
adds extra control for the application author.
For now, it understands two commands:
.Dv UI_CTRL_PRINT_ERRORS ,
which makes
.Fn UI_process
print the OpenSSL error stack as part of processing the
.Fa ui ,
and
.Dv UI_CTRL_IS_REDOABLE ,
which returns a flag saying if the used
.Fa ui
can be used again or not.
.Pp
.Fn 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.
.Pp
.Fn UI_get_default_method
returns a pointer to the current default UI method.
.Pp
.Fn UI_get_method
returns the UI method associated with a given
.Fa ui .
.Pp
.Fn UI_set_method
changes the UI method associated with a given
.Fa ui .
.Sh RETURN VALUES
.Fn UI_new
and
.Fn UI_new_method
return a valid
.Vt UI
structure or
.Dv NULL
if an error occurred.
.Pp
.Fn UI_add_input_string ,
.Fn UI_dup_input_string ,
.Fn UI_add_verify_string ,
.Fn UI_dup_verify_string ,
.Fn UI_add_input_boolean ,
.Fn UI_dup_input_boolean ,
.Fn UI_add_info_string ,
.Fn UI_dup_info_string ,
.Fn UI_add_error_string ,
and
.Fn UI_dup_error_string
return a positive number on success or a number
less than or equal to zero otherwise.
.Pp
.Fn UI_construct_prompt
and
.Fn UI_get0_result
return a string or
.Dv NULL
if an error occurred.
.Pp
.Fn UI_add_user_data
and
.Fn UI_get0_user_data
return a pointer to the user data that was contained in
.Fa ui
before the call.
In particular,
.Dv NULL
is a valid return value.
.Pp
.Fn UI_process
returns 0 on success or a negative value on error.
.Pp
.Fn UI_ctrl
returns a mask on success or \-1 on error.
.Pp
.Fn UI_get_default_method
and
.Fn UI_OpenSSL
always return a pointer to a valid
.Vt UI_METHOD
structure.
.Pp
.Fn UI_get_method
and
.Fn UI_set_method
return a pointer to the
.Vt UI_METHOD
structure that is installed in
.Fa ui
after the call.
The OpenSSL documentation says that they can fail and return
.Dv NULL ,
but currently, this can only happen when and after
.Fn UI_set_method
is called with an explicit
.Dv NULL
argument.
.Sh SEE ALSO
.Xr crypto 3 ,
.Xr des_read_pw 3 ,
.Xr UI_create_method 3 ,
.Xr UI_get_string_type 3 ,
.Xr UI_UTIL_read_pw 3
.Sh HISTORY
These functions first appeared in OpenSSL 0.9.7
and have been available since
.Ox 3.2 .
.Sh AUTHORS
.An Richard Levitte Aq Mt richard@levitte.org
for the OpenSSL project.
|