diff options
Diffstat (limited to 'src/lib/libcrypto/man/CRYPTO_set_ex_data.3')
-rw-r--r-- | src/lib/libcrypto/man/CRYPTO_set_ex_data.3 | 564 |
1 files changed, 0 insertions, 564 deletions
diff --git a/src/lib/libcrypto/man/CRYPTO_set_ex_data.3 b/src/lib/libcrypto/man/CRYPTO_set_ex_data.3 deleted file mode 100644 index c22fb22352..0000000000 --- a/src/lib/libcrypto/man/CRYPTO_set_ex_data.3 +++ /dev/null | |||
@@ -1,564 +0,0 @@ | |||
1 | .\" $OpenBSD: CRYPTO_set_ex_data.3,v 1.15 2023/09/18 14:49:43 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org> | ||
4 | .\" | ||
5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
7 | .\" copyright notice and this permission notice appear in all copies. | ||
8 | .\" | ||
9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | .\" | ||
17 | .Dd $Mdocdate: September 18 2023 $ | ||
18 | .Dt CRYPTO_SET_EX_DATA 3 | ||
19 | .Os | ||
20 | .Sh NAME | ||
21 | .Nm CRYPTO_get_ex_new_index , | ||
22 | .Nm CRYPTO_EX_new , | ||
23 | .Nm CRYPTO_EX_free , | ||
24 | .Nm CRYPTO_EX_dup , | ||
25 | .Nm CRYPTO_new_ex_data , | ||
26 | .Nm CRYPTO_set_ex_data , | ||
27 | .Nm CRYPTO_get_ex_data , | ||
28 | .Nm CRYPTO_free_ex_data | ||
29 | .Nd low-level functions for application specific data | ||
30 | .Sh SYNOPSIS | ||
31 | .In openssl/crypto.h | ||
32 | .Ft int | ||
33 | .Fo CRYPTO_get_ex_new_index | ||
34 | .Fa "int class_index" | ||
35 | .Fa "long argl" | ||
36 | .Fa "void *argp" | ||
37 | .Fa "CRYPTO_EX_new *new_func" | ||
38 | .Fa "CRYPTO_EX_dup *dup_func" | ||
39 | .Fa "CRYPTO_EX_free *free_func" | ||
40 | .Fc | ||
41 | .Ft typedef int | ||
42 | .Fo CRYPTO_EX_new | ||
43 | .Fa "void *parent" | ||
44 | .Fa "void *data" | ||
45 | .Fa "CRYPTO_EX_DATA *ad" | ||
46 | .Fa "int idx" | ||
47 | .Fa "long argl" | ||
48 | .Fa "void *argp" | ||
49 | .Fc | ||
50 | .Ft typedef void | ||
51 | .Fo CRYPTO_EX_free | ||
52 | .Fa "void *parent" | ||
53 | .Fa "void *data" | ||
54 | .Fa "CRYPTO_EX_DATA *ad" | ||
55 | .Fa "int idx" | ||
56 | .Fa "long argl" | ||
57 | .Fa "void *argp" | ||
58 | .Fc | ||
59 | .Ft typedef int | ||
60 | .Fo CRYPTO_EX_dup | ||
61 | .Fa "CRYPTO_EX_DATA *to" | ||
62 | .Fa "const CRYPTO_EX_DATA *from" | ||
63 | .Fa "void *datap" | ||
64 | .Fa "int idx" | ||
65 | .Fa "long argl" | ||
66 | .Fa "void *argp" | ||
67 | .Fc | ||
68 | .Ft int | ||
69 | .Fo CRYPTO_new_ex_data | ||
70 | .Fa "int class_index" | ||
71 | .Fa "void *parent" | ||
72 | .Fa "CRYPTO_EX_DATA *ad" | ||
73 | .Fc | ||
74 | .Ft int | ||
75 | .Fo CRYPTO_set_ex_data | ||
76 | .Fa "CRYPTO_EX_DATA *ad" | ||
77 | .Fa "int idx" | ||
78 | .Fa "void *data" | ||
79 | .Fc | ||
80 | .Ft void * | ||
81 | .Fo CRYPTO_get_ex_data | ||
82 | .Fa "CRYPTO_EX_DATA *ad" | ||
83 | .Fa "int idx" | ||
84 | .Fc | ||
85 | .Ft void | ||
86 | .Fo CRYPTO_free_ex_data | ||
87 | .Fa "int class_index" | ||
88 | .Fa "void *parent" | ||
89 | .Fa "CRYPTO_EX_DATA *ad" | ||
90 | .Fc | ||
91 | .Sh DESCRIPTION | ||
92 | The library implements the functions documented in the | ||
93 | .Xr RSA_get_ex_new_index 3 | ||
94 | manual page and similar functions for other parent object types | ||
95 | using the functions documented in the present manual page. | ||
96 | Application programs almost never need | ||
97 | to call the functions documented here directly. | ||
98 | .Pp | ||
99 | .Fn CRYPTO_get_ex_new_index | ||
100 | behaves in the same way as | ||
101 | .Xr RSA_get_ex_new_index 3 | ||
102 | except that the parent object type that the new | ||
103 | .Fa idx | ||
104 | is reserved for is not part of the function name | ||
105 | but instead specified by the additional | ||
106 | .Fa class_index | ||
107 | argument receiving one of the | ||
108 | .Dv CRYPTO_EX_INDEX_* | ||
109 | constants defined in | ||
110 | .In openssl/crypto.h . | ||
111 | The recommendation given in | ||
112 | .Xr RSA_get_ex_new_index 3 | ||
113 | to set the | ||
114 | .Fa argl | ||
115 | argument to 0 and the last four arguments all to | ||
116 | .Dv NULL | ||
117 | applies. | ||
118 | The library passes the | ||
119 | .Fa argl | ||
120 | and | ||
121 | .Fa argp | ||
122 | arguments through to the callback functions for the respective | ||
123 | .Fa idx , | ||
124 | but ignores them otherwise. | ||
125 | .Pp | ||
126 | If a function pointer is passed for the | ||
127 | .Fa new_func | ||
128 | argument, that function is called for the returned | ||
129 | .Fa idx | ||
130 | whenever a new parent object is allocated with | ||
131 | .Xr RSA_new 3 | ||
132 | or a similar function. | ||
133 | .Pp | ||
134 | If a function pointer is passed for the | ||
135 | .Fa free_func | ||
136 | argument, that function is called for the returned | ||
137 | .Fa idx | ||
138 | when a parent object is freed with | ||
139 | .Xr RSA_free 3 | ||
140 | or a similar function. | ||
141 | .Pp | ||
142 | The arguments of | ||
143 | .Fa new_func | ||
144 | and | ||
145 | .Fa free_func | ||
146 | are as follows: | ||
147 | .Pp | ||
148 | .Bl -tag -width Ds -compact | ||
149 | .It Fa parent | ||
150 | the parent object that contains the | ||
151 | .Fa data | ||
152 | .It Fa data | ||
153 | the | ||
154 | .Fa data | ||
155 | previously set by | ||
156 | .Fn CRYPTO_set_ex_data | ||
157 | at | ||
158 | .Fa idx | ||
159 | in | ||
160 | .Fa parent | ||
161 | .It Fa ad | ||
162 | the | ||
163 | .Vt CRYPTO_EX_DATA | ||
164 | subobject of the | ||
165 | .Fa parent | ||
166 | object | ||
167 | .It Fa idx | ||
168 | return value of | ||
169 | .Fn CRYPTO_get_ex_new_index | ||
170 | that set this callback | ||
171 | .It Fa argl | ||
172 | the | ||
173 | .Fa argl | ||
174 | passed to | ||
175 | .Fn CRYPTO_get_ex_new_index | ||
176 | for this | ||
177 | .Fa idx | ||
178 | .It Fa argp | ||
179 | the | ||
180 | .Fa argp | ||
181 | passed to | ||
182 | .Fn CRYPTO_get_ex_new_index | ||
183 | for this | ||
184 | .Fa idx | ||
185 | .El | ||
186 | .Pp | ||
187 | If a function pointer is passed for the | ||
188 | .Fa dup_func , | ||
189 | that function is supposed to be called for the returned | ||
190 | .Fa idx | ||
191 | whenever a parent object of the respective type is copied. | ||
192 | Actually, the only functions doing that are | ||
193 | .Xr BIO_dup_chain 3 , | ||
194 | .Xr EC_KEY_copy 3 , | ||
195 | and | ||
196 | .Xr SSL_dup 3 , | ||
197 | and the TLS 1.3 network stack does it internally when duplicating a | ||
198 | .Vt SSL_SESSION | ||
199 | object after receiving a new session ticket message. | ||
200 | Most other object types supporting ex_data do not support | ||
201 | copying in the first place, whereas | ||
202 | .Xr DSA_dup_DH 3 | ||
203 | and | ||
204 | .Xr X509_dup 3 | ||
205 | simply ignore | ||
206 | .Fa dup_func . | ||
207 | .Pp | ||
208 | The arguments of | ||
209 | .Fa dup_func | ||
210 | are as follows: | ||
211 | .Pp | ||
212 | .Bl -tag -width Ds -compact | ||
213 | .It Fa to | ||
214 | the | ||
215 | .Vt CRYPTO_EX_DATA | ||
216 | subobject of the new parent object | ||
217 | .It Fa from | ||
218 | the | ||
219 | .Vt CRYPTO_EX_DATA | ||
220 | subobject of the original parent object | ||
221 | .It Fa datap | ||
222 | a pointer to a copy of the pointer to the original ex_data | ||
223 | .It Fa idx | ||
224 | return value of | ||
225 | .Fn CRYPTO_get_ex_new_index | ||
226 | that set this callback | ||
227 | .It Fa argl | ||
228 | the | ||
229 | .Fa argl | ||
230 | passed to | ||
231 | .Fn CRYPTO_get_ex_new_index | ||
232 | for this | ||
233 | .Fa idx | ||
234 | .It Fa argp | ||
235 | the | ||
236 | .Fa argp | ||
237 | passed to | ||
238 | .Fn CRYPTO_get_ex_new_index | ||
239 | for this | ||
240 | .Fa idx | ||
241 | .El | ||
242 | .Pp | ||
243 | Inside | ||
244 | .Fa dup_func , | ||
245 | the | ||
246 | .Fa data | ||
247 | pointer contained in the original parent object being copied | ||
248 | can be accessed by casting and dereferencing | ||
249 | .Fa datap , | ||
250 | for example: | ||
251 | .Pp | ||
252 | .Dl char *orig_data = *(char **)datap; | ||
253 | .Pp | ||
254 | If the original data is copied, for example in a manner similar to | ||
255 | .Bd -literal -offset indent | ||
256 | char *new_data; | ||
257 | if ((new_data = strdup(orig_data)) == NULL) | ||
258 | return 0; | ||
259 | .Ed | ||
260 | .Pp | ||
261 | then the pointer to the newly allocated memory needs to be passed | ||
262 | back to the caller in the | ||
263 | .Fa datap | ||
264 | argument, for example: | ||
265 | .Bd -literal -offset indent | ||
266 | *(char **)datap = new_data; | ||
267 | return 1; | ||
268 | .Ed | ||
269 | .Pp | ||
270 | Calling | ||
271 | .Fn CRYPTO_set_ex_data to idx new_data | ||
272 | from inside | ||
273 | .Fa dup_func | ||
274 | has no effect because the code calling | ||
275 | .Fa dup_func | ||
276 | unconditionally calls | ||
277 | .Fn CRYPTO_set_ex_data to idx *datap | ||
278 | after | ||
279 | .Fa dup_func | ||
280 | returns successfully. | ||
281 | Consequently, if | ||
282 | .Fa dup_func | ||
283 | does not change | ||
284 | .Pf * Fa datap , | ||
285 | the new parent object ends up containing a pointer to the same memory | ||
286 | as the original parent object and any memory allocated in | ||
287 | .Fa dup_func | ||
288 | is leaked. | ||
289 | .Pp | ||
290 | When multiple callback functions are called, | ||
291 | they are called in increasing order of their | ||
292 | .Fa idx | ||
293 | value. | ||
294 | .Pp | ||
295 | .Fn CRYPTO_new_ex_data | ||
296 | is an internal function that initializes the | ||
297 | .Fa ad | ||
298 | subobject of the | ||
299 | .Fa parent | ||
300 | object, with the type of the parent object specified by the | ||
301 | .Fa class_index | ||
302 | argument. | ||
303 | Initialization includes calling the respective | ||
304 | .Fa new_func | ||
305 | callbacks for all reserved | ||
306 | .Fa idx | ||
307 | values that have such callbacks configured. | ||
308 | Despite its name, | ||
309 | .Fn CRYPTO_new_ex_data | ||
310 | does not create a new object but requires that | ||
311 | .Fa ad | ||
312 | points to an already allocated but still uninitialized object. | ||
313 | .Pp | ||
314 | .Fn CRYPTO_set_ex_data | ||
315 | and | ||
316 | .Fn CRYPTO_get_ex_data | ||
317 | behave in the same way as | ||
318 | .Xr RSA_set_ex_data 3 | ||
319 | and | ||
320 | .Xr RSA_get_ex_data 3 , | ||
321 | respectively, except that they do not accept a pointer | ||
322 | to the parent object but instead require a pointer to the | ||
323 | .Vt CRYPTO_EX_DATA | ||
324 | subobject of that parent object. | ||
325 | .Pp | ||
326 | .Fn CRYPTO_free_ex_data | ||
327 | is an internal function that frees any memory used inside the | ||
328 | .Fa ad | ||
329 | subobject of the | ||
330 | .Fa parent | ||
331 | object, with the type of the parent object specified by the | ||
332 | .Fa class_index | ||
333 | argument. | ||
334 | This includes calling the respective | ||
335 | .Fa free_func | ||
336 | callbacks for all reserved | ||
337 | .Fa idx | ||
338 | values that have such callbacks configured. | ||
339 | Despite its name, | ||
340 | .Fn CRYPTO_free_ex_data | ||
341 | does not free | ||
342 | .Fa ad | ||
343 | itself. | ||
344 | .Sh RETURN VALUES | ||
345 | .Fn CRYPTO_get_ex_new_index | ||
346 | returns a new index equal to or greater than 1 | ||
347 | or \-1 if memory allocation fails. | ||
348 | .Pp | ||
349 | .Fn CRYPTO_EX_new | ||
350 | and | ||
351 | .Fn CRYPTO_EX_dup | ||
352 | functions are supposed to return 1 on success or 0 on failure. | ||
353 | .Pp | ||
354 | .Fn CRYPTO_new_ex_data | ||
355 | and | ||
356 | .Fn CRYPTO_set_ex_data | ||
357 | return 1 on success or 0 if memory allocation fails. | ||
358 | .Pp | ||
359 | .Fn CRYPTO_get_ex_data | ||
360 | returns the application specific data or | ||
361 | .Dv NULL | ||
362 | if the parent object that contains | ||
363 | .Fa ad | ||
364 | does not contain application specific data at the given | ||
365 | .Fa idx . | ||
366 | .Sh ERRORS | ||
367 | After failure of | ||
368 | .Fn CRYPTO_get_ex_new_index , | ||
369 | .Fn CRYPTO_new_ex_data , | ||
370 | or | ||
371 | .Fn CRYPTO_set_ex_data , | ||
372 | the following diagnostic can be retrieved with | ||
373 | .Xr ERR_get_error 3 , | ||
374 | .Xr ERR_GET_REASON 3 , | ||
375 | and | ||
376 | .Xr ERR_reason_error_string 3 : | ||
377 | .Bl -tag -width Ds | ||
378 | .It Dv ERR_R_MALLOC_FAILURE Qq "malloc failure" | ||
379 | Memory allocation failed. | ||
380 | .El | ||
381 | .Pp | ||
382 | In a few unusual failure cases, | ||
383 | .Xr ERR_get_error 3 | ||
384 | may report different errors caused by | ||
385 | .Xr OPENSSL_init_crypto 3 | ||
386 | or even none at all. | ||
387 | .Pp | ||
388 | Even though it cannot indicate failure, | ||
389 | .Fn CRYPTO_free_ex_data | ||
390 | may occasionally also set an error code that can be retrieved with | ||
391 | .Xr ERR_get_error 3 . | ||
392 | .Pp | ||
393 | .Fn CRYPTO_get_ex_data | ||
394 | does not distinguish success from failure. | ||
395 | Consequently, after | ||
396 | .Fn CRYPTO_get_ex_data | ||
397 | returns | ||
398 | .Dv NULL , | ||
399 | .Xr ERR_get_error 3 | ||
400 | returns 0 unless there is still an earlier error in the queue. | ||
401 | .Sh SEE ALSO | ||
402 | .Xr BIO_get_ex_new_index 3 , | ||
403 | .Xr DH_get_ex_new_index 3 , | ||
404 | .Xr DSA_get_ex_new_index 3 , | ||
405 | .Xr RSA_get_ex_new_index 3 , | ||
406 | .Xr SSL_CTX_get_ex_new_index 3 , | ||
407 | .Xr SSL_get_ex_new_index 3 , | ||
408 | .Xr SSL_SESSION_get_ex_new_index 3 , | ||
409 | .Xr X509_STORE_CTX_get_ex_new_index 3 , | ||
410 | .Xr X509_STORE_get_ex_new_index 3 | ||
411 | .Sh HISTORY | ||
412 | .Fn CRYPTO_get_ex_new_index , | ||
413 | .Fn CRYPTO_new_ex_data , | ||
414 | .Fn CRYPTO_set_ex_data , | ||
415 | .Fn CRYPTO_get_ex_data , | ||
416 | and | ||
417 | .Fn CRYPTO_free_ex_data | ||
418 | first appeared in SSLeay 0.9.0 and have been available since | ||
419 | .Ox 2.4 . | ||
420 | .Pp | ||
421 | .Fn CRYPTO_EX_new , | ||
422 | .Fn CRYPTO_EX_free , | ||
423 | and | ||
424 | .Fn CRYPTO_EX_dup | ||
425 | first appeared in OpenSSL 0.9.5 and have been available since | ||
426 | .Ox 2.7 . | ||
427 | .Sh CAVEATS | ||
428 | If an program installs callback functions, the last call to | ||
429 | .Fn CRYPTO_get_ex_new_index | ||
430 | installing a function of a certain type for a certain | ||
431 | .Fa class_index | ||
432 | needs to be complete before the first object of that | ||
433 | .Fa class_index | ||
434 | can be created, freed, or copied, respectively. | ||
435 | Otherwise, incomplete initialization or cleanup will result. | ||
436 | .Pp | ||
437 | At the time | ||
438 | .Fa new_func | ||
439 | is called, the | ||
440 | .Fa parent | ||
441 | object is only partially initialized, | ||
442 | so trying to access any data in it is strongly discouraged. | ||
443 | The | ||
444 | .Fa data | ||
445 | argument is typically | ||
446 | .Dv NULL | ||
447 | in | ||
448 | .Fa new_func . | ||
449 | .Pp | ||
450 | At the time | ||
451 | .Fa free_func | ||
452 | is called, the | ||
453 | .Fa parent | ||
454 | object is already mostly deconstructed | ||
455 | and part of its content may have been cleared and freed. | ||
456 | Consequently, trying to access any data in | ||
457 | .Fa parent | ||
458 | is strongly discouraged. | ||
459 | According to the OpenSSL API documentation, the library code calling | ||
460 | .Fa free_func | ||
461 | would even be permitted to pass a | ||
462 | .Dv NULL | ||
463 | pointer for the | ||
464 | .Fa parent | ||
465 | argument. | ||
466 | .Pp | ||
467 | .Fn CRYPTO_set_ex_data | ||
468 | and | ||
469 | .Fn CRYPTO_get_ex_data | ||
470 | cannot reasonably be used outside the callback functions | ||
471 | because no API function provides access to any pointers of the type | ||
472 | .Vt CRYPTO_EX_DATA * . | ||
473 | .Pp | ||
474 | Inside | ||
475 | .Fa new_func , | ||
476 | calling | ||
477 | .Fn CRYPTO_get_ex_data | ||
478 | makes no sense because it always returns | ||
479 | .Dv NULL , | ||
480 | and calling | ||
481 | .Fn CRYPTO_set_ex_data | ||
482 | makes no sense because | ||
483 | .Fa new_func | ||
484 | does not have access to any meaningful | ||
485 | .Fa data | ||
486 | it could store, and the absence of application specific data at any given | ||
487 | .Fa idx | ||
488 | is already sufficiently indicated by the default return value | ||
489 | .Dv NULL | ||
490 | of | ||
491 | .Fn CRYPTO_get_ex_data , | ||
492 | .Xr RSA_get_ex_data 3 , | ||
493 | and similar functions. | ||
494 | .Pp | ||
495 | Inside | ||
496 | .Fa free_func , | ||
497 | calling | ||
498 | .Fn CRYPTO_get_ex_data | ||
499 | makes no sense because the return value is already available in | ||
500 | .Fa data , | ||
501 | and calling | ||
502 | .Fn CRYPTO_set_ex_data | ||
503 | makes no sense because the parent object, including any ex_data | ||
504 | contained in it, is already being deconstructed and will no longer | ||
505 | exist by the time application code regains control. | ||
506 | .Pp | ||
507 | Inside | ||
508 | .Fa dup_func , | ||
509 | calling | ||
510 | .Fn CRYPTO_get_ex_data | ||
511 | makes no sense because the return value for | ||
512 | .Fa from | ||
513 | is already available as | ||
514 | .Pf * Fa datap , | ||
515 | and the return value for | ||
516 | .Fa to | ||
517 | is | ||
518 | .Dv NULL . | ||
519 | Calling | ||
520 | .Fn CRYPTO_set_ex_data | ||
521 | makes no sense because changing | ||
522 | .Fa from | ||
523 | would cause an undesirable side effect in this context | ||
524 | and trying to change | ||
525 | .Fa to | ||
526 | is ineffective as explained above. | ||
527 | .Pp | ||
528 | Consequently, application code can never use | ||
529 | .Fn CRYPTO_set_ex_data | ||
530 | or | ||
531 | .Fn CRYPTO_get_ex_data | ||
532 | in a meaningful way. | ||
533 | .Pp | ||
534 | The fact that the functions documented in the present manual page | ||
535 | are part of the public API might create the impression | ||
536 | that application programs could add ex_data support | ||
537 | to additional object types not offering it by default. | ||
538 | However, for built-in object types not offering ex_support, this | ||
539 | is not possible because such objects do not contain the required | ||
540 | .Vt CRYPTO_EX_DATA | ||
541 | subobject. | ||
542 | .Pp | ||
543 | It is theoretically possible to add ex_data support to an | ||
544 | application-defined object type by adding a | ||
545 | .Vt CRYPTO_EX_DATA | ||
546 | field to the struct declaration, a call to | ||
547 | .Fn CRYPTO_new_ex_data | ||
548 | to the object constructor, and a call to | ||
549 | .Fn CRYPTO_free_ex_data | ||
550 | to the object destructor. | ||
551 | The OpenSSL documentation mentions that the constant | ||
552 | .Dv CRYPTO_EX_INDEX_APP | ||
553 | is reserved for this very purpose. | ||
554 | However, doing this would hardly be useful. | ||
555 | It is much more straightforward to just add | ||
556 | all the required data fields to the struct declaration itself. | ||
557 | .Sh BUGS | ||
558 | If | ||
559 | .Fa new_func | ||
560 | or | ||
561 | .Fa dup_func | ||
562 | fails, the failure is silently ignored by the library, potentially | ||
563 | resulting in an incompletely initialized object. | ||
564 | The application program cannot detect this kind of failure. | ||