summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/PEM_X509_INFO_read_bio.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/man/PEM_X509_INFO_read_bio.3')
-rw-r--r--src/lib/libcrypto/man/PEM_X509_INFO_read_bio.3173
1 files changed, 173 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/PEM_X509_INFO_read_bio.3 b/src/lib/libcrypto/man/PEM_X509_INFO_read_bio.3
new file mode 100644
index 0000000000..7d34951df0
--- /dev/null
+++ b/src/lib/libcrypto/man/PEM_X509_INFO_read_bio.3
@@ -0,0 +1,173 @@
1.\" $OpenBSD: PEM_X509_INFO_read_bio.3,v 1.1 2025/07/17 10:31:50 schwarze Exp $
2.\"
3.\" Copyright (c) 2020 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: July 17 2025 $
18.Dt PEM_X509_INFO_READ_BIO 3
19.Os
20.Sh NAME
21.Nm PEM_X509_INFO_read_bio
22.Nd PEM and DER decode X.509 certificates, private keys, and revocation lists
23.Sh SYNOPSIS
24.Lb libcrypto
25.In openssl/pem.h
26.Ft STACK_OF(X509_INFO) *
27.Fo PEM_X509_INFO_read_bio
28.Fa "BIO *in_bp"
29.Fa "STACK_OF(X509_INFO) *sk"
30.Fa "pem_password_cb *cb"
31.Fa "void *u"
32.Fc
33.Sh DESCRIPTION
34This function reads zero or more objects
35related to X.509 certificates from
36.Fa in_bp ,
37performs both PEM and DER decoding,
38and wraps the resulting objects in newly allocated
39.Vt X509_INFO
40containers.
41.Pp
42Setting
43.Fa sk
44to
45.Dv NULL
46is recommended, in which case
47a new stack is allocated, populated, and returned.
48If an existing
49.Fa sk
50is passed in, the created
51.Vt X509_INFO
52objects are pushed onto that stack.
53.Pp
54For PEM decoding,
55.Xr PEM_read_bio 3
56is used internally, implying that any non-PEM data
57before, between, and after the objects is silently discarded.
58.Pp
59For subsequent DER decoding,
60the decoding function and the field of the
61.Vt X509_INFO
62structure to store the new object in
63are selected according to the PEM type name:
64.Bl -column "TRUSTED CERTIFICATE" "d2i_PrivateKey()" "revocation list"
65.It PEM type name Ta decoder Ta Vt X509_INFO No field
66.It CERTIFICATE Ta Xr d2i_X509 3 Ta certificate
67.It X509 CERTIFICATE Ta Xr d2i_X509 3 Ta certificate
68.It TRUSTED CERTIFICATE Ta Xr d2i_X509_AUX 3 Ta certificate
69.It X509 CRL Ta Xr d2i_X509_CRL 3 Ta revocation list
70.It RSA PRIVATE KEY Ta Xr d2i_PrivateKey 3 Ta private key
71.It DSA PRIVATE KEY Ta Xr d2i_PrivateKey 3 Ta private key
72.It EC PRIVATE KEY Ta Xr d2i_PrivateKey 3 Ta private key
73.El
74.Pp
75Whenever the selected field is already occupied, another new
76.Vt X509_INFO
77container is allocated and pushed onto the stack.
78Depending on the sequence of objects in the input, this can result
79in several partially populated
80.Vt X509_INFO
81containers being pushed onto the stack.
82.Pp
83PEM objects of types not listed in the above table are silently skipped.
84.Pp
85Encrypted certificates and revocation lists are decrypted by calling
86.Xr PEM_do_header 3
87internally, passing through the optional arguments
88.Fa cb
89and
90.Fa u .
91Encrypted private keys are not decrypted.
92Instead, the encrypted form is stored as read.
93All the same,
94.Xr PEM_get_EVP_CIPHER_INFO 3
95is called internally to check that PEM headers, if there are any,
96are valid and specify an encryption the library is prepared to handle.
97.Pp
98If any error occurs, objects that had already been read
99during the same call are deleted again and
100.Fa sk
101is left unchanged.
102.Sh RETURN VALUES
103This function returns a pointer to the stack
104the objects read were pushed onto or
105.Dv NULL
106if an error occurs.
107It fails if
108.Xr PEM_read_bio 3 ,
109.Xr PEM_get_EVP_CIPHER_INFO 3 ,
110.Xr PEM_do_header 3 ,
111or DER decoding fails or if memory is exhausted.
112.Sh ERRORS
113Diagnostics that can be retrieved with
114.Xr ERR_get_error 3 ,
115.Xr ERR_GET_REASON 3 ,
116and
117.Xr ERR_reason_error_string 3
118include:
119.Bl -tag -width Ds
120.It Dv ERR_R_ASN1_LIB Qq "ASN1 lib"
121DER decoding of a PEM object failed.
122.It Dv ERR_R_MALLOC_FAILURE Qq "malloc failure"
123.Fn PEM_X509_INFO_read_bio
124failed to allocate a new
125.Vt X509_INFO ,
126.Vt STACK_OF(X509_INFO) ,
127or
128.Vt X509_PKEY
129object.
130.El
131.Pp
132Additional types of errors can result from
133.Xr PEM_read_bio 3 ,
134.Xr PEM_get_EVP_CIPHER_INFO 3 ,
135and
136.Xr PEM_do_header 3 .
137.Pp
138After this function failed due to memory exhaustion,
139.Xr ERR_get_error 3
140may sometimes return 0 anyway.
141.Sh SEE ALSO
142.Xr BIO_new 3 ,
143.Xr d2i_PrivateKey 3 ,
144.Xr d2i_X509 3 ,
145.Xr d2i_X509_CRL 3 ,
146.Xr EVP_PKEY_new 3 ,
147.Xr PEM_read 3 ,
148.Xr PEM_read_bio_PrivateKey 3 ,
149.Xr STACK_OF 3 ,
150.Xr X509_CRL_new 3 ,
151.Xr X509_INFO_new 3 ,
152.Xr X509_LOOKUP_new 3 ,
153.Xr X509_new 3
154.Sh HISTORY
155.Fn PEM_X509_INFO_read_bio
156first appeared in SSLeay 0.6.0 and has been available since
157.Ox 2.4 .
158.Sh CAVEATS
159It is not an error
160if the input does not contain any objects of the desired types.
161In that case, nothing is added to
162.Fa sk ,
163or if
164.Fa sk
165is
166.Dv NULL ,
167a newly allocated, empty stack is returned.
168The only way to detect this situation is by comparing
169the number of objects on the stack before and after the call.
170.Sh BUGS
171When reaching the end of the input, this function calls
172.Xr ERR_clear_error 3 ,
173which may hide errors that occurred before calling it.