UI_new.3ossl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  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 3ossl"
  58. .TH UI_NEW 3ossl 2025-01-17 3.4.0 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 adds a 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 blob
  224. with the one given as argument.
  225. .PP
  226. \&\fBUI_dup_user_data()\fR duplicates the user data and works as an alternative
  227. to \fBUI_add_user_data()\fR when the user data needs to be preserved for a longer
  228. duration, perhaps even the lifetime of the application. The UI object takes
  229. ownership of this duplicate and will free it whenever it gets replaced or
  230. the UI is destroyed. \fBUI_dup_user_data()\fR returns 0 on success, or \-1 on memory
  231. allocation failure or if the method doesn't have a duplicator function.
  232. .PP
  233. \&\fBUI_get0_user_data()\fR retrieves the data that has last been given to the
  234. UI with \fBUI_add_user_data()\fR or UI_dup_user_data.
  235. .PP
  236. \&\fBUI_get0_result()\fR returns a pointer to the result buffer associated with
  237. the information indexed by \fIi\fR.
  238. .PP
  239. \&\fBUI_get_result_length()\fR returns the length of the result buffer associated with
  240. the information indexed by \fIi\fR.
  241. .PP
  242. \&\fBUI_process()\fR goes through the information given so far, does all the printing
  243. and prompting and returns the final status, which is \-2 on out-of-band events
  244. (Interrupt, Cancel, ...), \-1 on error and 0 on success.
  245. .PP
  246. \&\fBUI_ctrl()\fR adds extra control for the application author. For now, it
  247. understands two commands: \fBUI_CTRL_PRINT_ERRORS\fR, which makes \fBUI_process()\fR
  248. print the OpenSSL error stack as part of processing the UI, and
  249. \&\fBUI_CTRL_IS_REDOABLE\fR, which returns a flag saying if the used UI can
  250. be used again or not.
  251. .PP
  252. \&\fBUI_set_default_method()\fR changes the default UI method to the one given.
  253. This function is not thread-safe and should not be called at the same time
  254. as other OpenSSL functions.
  255. .PP
  256. \&\fBUI_get_default_method()\fR returns a pointer to the current default UI method.
  257. .PP
  258. \&\fBUI_get_method()\fR returns the UI method associated with a given UI.
  259. .PP
  260. \&\fBUI_set_method()\fR changes the UI method associated with a given UI.
  261. .SH NOTES
  262. .IX Header "NOTES"
  263. The resulting strings that the built in method \fBUI_OpenSSL()\fR generate
  264. are assumed to be encoded according to the current locale or (for
  265. Windows) code page.
  266. For applications having different demands, these strings need to be
  267. converted appropriately by the caller.
  268. For Windows, if the \fBOPENSSL_WIN32_UTF8\fR environment variable is set,
  269. the built-in method \fBUI_OpenSSL()\fR will produce UTF\-8 encoded strings
  270. instead.
  271. .SH "RETURN VALUES"
  272. .IX Header "RETURN VALUES"
  273. \&\fBUI_new()\fR and \fBUI_new_method()\fR return a valid \fBUI\fR structure or NULL if an error
  274. occurred.
  275. .PP
  276. \&\fBUI_add_input_string()\fR, \fBUI_dup_input_string()\fR, \fBUI_add_verify_string()\fR,
  277. \&\fBUI_dup_verify_string()\fR, \fBUI_add_input_boolean()\fR, \fBUI_dup_input_boolean()\fR,
  278. \&\fBUI_add_info_string()\fR, \fBUI_dup_info_string()\fR, \fBUI_add_error_string()\fR
  279. and \fBUI_dup_error_string()\fR return a positive number on success or a value which
  280. is less than or equal to 0 otherwise.
  281. .PP
  282. \&\fBUI_construct_prompt()\fR returns a string or NULL if an error occurred.
  283. .PP
  284. \&\fBUI_dup_user_data()\fR returns 0 on success or \-1 on error.
  285. .PP
  286. \&\fBUI_get0_result()\fR returns a string or NULL on error.
  287. .PP
  288. \&\fBUI_get_result_length()\fR returns a positive integer or 0 on success; otherwise it
  289. returns \-1 on error.
  290. .PP
  291. \&\fBUI_process()\fR returns 0 on success or a negative value on error.
  292. .PP
  293. \&\fBUI_ctrl()\fR returns a mask on success or \-1 on error.
  294. .PP
  295. \&\fBUI_get_default_method()\fR, \fBUI_get_method()\fR, \fBUI_OpenSSL()\fR, \fBUI_null()\fR and
  296. \&\fBUI_set_method()\fR return either a valid \fBUI_METHOD\fR structure or NULL
  297. respectively.
  298. .SH HISTORY
  299. .IX Header "HISTORY"
  300. The \fBUI_dup_user_data()\fR function was added in OpenSSL 1.1.1.
  301. .SH COPYRIGHT
  302. .IX Header "COPYRIGHT"
  303. Copyright 2001\-2020 The OpenSSL Project Authors. All Rights Reserved.
  304. .PP
  305. Licensed under the Apache License 2.0 (the "License"). You may not use
  306. this file except in compliance with the License. You can obtain a copy
  307. in the file LICENSE in the source distribution or at
  308. <https://www.openssl.org/source/license.html>.