diff options
author | schwarze <> | 2020-06-12 11:37:42 +0000 |
---|---|---|
committer | schwarze <> | 2020-06-12 11:37:42 +0000 |
commit | 2cba49230cf52f81752d62f2b58037520c8f0941 (patch) | |
tree | 4a14a7bce99ded95ff18678d951d99cd5a455738 /src/lib/libcrypto/man/PEM_ASN1_read.3 | |
parent | a62588f56a55f2f2d239f35e37ce930a37347a40 (diff) | |
download | openbsd-2cba49230cf52f81752d62f2b58037520c8f0941.tar.gz openbsd-2cba49230cf52f81752d62f2b58037520c8f0941.tar.bz2 openbsd-2cba49230cf52f81752d62f2b58037520c8f0941.zip |
document PEM_ASN1_read(3) and PEM_ASN1_read_bio(3);
tweaks and OK tb@
Diffstat (limited to 'src/lib/libcrypto/man/PEM_ASN1_read.3')
-rw-r--r-- | src/lib/libcrypto/man/PEM_ASN1_read.3 | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/PEM_ASN1_read.3 b/src/lib/libcrypto/man/PEM_ASN1_read.3 new file mode 100644 index 0000000000..cea0c2df68 --- /dev/null +++ b/src/lib/libcrypto/man/PEM_ASN1_read.3 | |||
@@ -0,0 +1,171 @@ | |||
1 | .\" $OpenBSD: PEM_ASN1_read.3,v 1.1 2020/06/12 11:37:42 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: June 12 2020 $ | ||
18 | .Dt PEM_ASN1_READ 3 | ||
19 | .Os | ||
20 | .Sh NAME | ||
21 | .Nm d2i_of_void , | ||
22 | .Nm PEM_ASN1_read , | ||
23 | .Nm PEM_ASN1_read_bio | ||
24 | .Nd PEM and DER decode an arbitrary ASN.1 value | ||
25 | .Sh SYNOPSIS | ||
26 | .In openssl/pem.h | ||
27 | .Ft typedef void * | ||
28 | .Fo d2i_of_void | ||
29 | .Fa "void **val_out" | ||
30 | .Fa "const unsigned char **der_in" | ||
31 | .Fa "long length" | ||
32 | .Fc | ||
33 | .Ft void * | ||
34 | .Fo PEM_ASN1_read | ||
35 | .Fa "d2i_of_void *d2i" | ||
36 | .Fa "const char *name" | ||
37 | .Fa "FILE *in_fp" | ||
38 | .Fa "void **val_out" | ||
39 | .Fa "pem_password_cb *cb" | ||
40 | .Fa "void *u" | ||
41 | .Fc | ||
42 | .Ft void * | ||
43 | .Fo PEM_ASN1_read_bio | ||
44 | .Fa "d2i_of_void *d2i" | ||
45 | .Fa "const char *name" | ||
46 | .Fa "BIO *in_bp" | ||
47 | .Fa "void **val_out" | ||
48 | .Fa "pem_password_cb *cb" | ||
49 | .Fa "void *u" | ||
50 | .Fc | ||
51 | .Sh DESCRIPTION | ||
52 | These functions read one object from | ||
53 | .Fa in_fp | ||
54 | or | ||
55 | .Fa in_bp | ||
56 | and perform both PEM and DER decoding. | ||
57 | They are needed when more specific decoding functions | ||
58 | like those documented in | ||
59 | .Xr PEM_read_bio_PrivateKey 3 | ||
60 | and | ||
61 | .Xr PEM_read_SSL_SESSION 3 | ||
62 | are inadequate for the type | ||
63 | .Fa name . | ||
64 | .Pp | ||
65 | For PEM decoding, | ||
66 | .Xr PEM_bytes_read_bio 3 | ||
67 | is called internally. | ||
68 | Consequently, the first object of type | ||
69 | .Fa name | ||
70 | is returned and preceding objects of other types are discarded. | ||
71 | If necessary, data is decrypted, using | ||
72 | .Fa cb | ||
73 | and/or | ||
74 | .Fa u | ||
75 | if they are not | ||
76 | .Dv NULL , | ||
77 | as described in the | ||
78 | .Xr pem_password_cb 3 | ||
79 | manual page. | ||
80 | .Pp | ||
81 | For subsequent DER decoding, pass a | ||
82 | .Fa d2i | ||
83 | callback function that is adequate for the type | ||
84 | .Fa name , | ||
85 | typically returning a pointer of a type more specific than | ||
86 | .Ft void * . | ||
87 | For example, | ||
88 | .Xr d2i_ASN1_TYPE 3 | ||
89 | can always be used and its manual page describes the required | ||
90 | behaviour of the callback function to be passed. | ||
91 | Normally, passing a more specific function is more useful; | ||
92 | candidate functions can be found with | ||
93 | .Ql man -k Nm~^d2i_ . | ||
94 | .Pp | ||
95 | For the | ||
96 | .Fa name | ||
97 | argument, the | ||
98 | .Dv PEM_STRING_* | ||
99 | string constants defined in | ||
100 | .In openssl/pem.h | ||
101 | can be used. | ||
102 | .Pp | ||
103 | The | ||
104 | .Fa val_out | ||
105 | argument is useless and its many dangers are described in detail in the | ||
106 | .Xr d2i_ASN1_TYPE 3 | ||
107 | manual page. | ||
108 | To reduce the risk of bugs, always passing | ||
109 | .Dv NULL | ||
110 | is recommended. | ||
111 | .Sh RETURN VALUES | ||
112 | These functions return a pointer to the decoded object or | ||
113 | .Dv NULL | ||
114 | if an error occurs. | ||
115 | They fail if | ||
116 | .Xr PEM_bytes_read_bio 3 | ||
117 | fails, for example because of invalid syntax in the input, an unknown | ||
118 | encryption, or an invalid passphrase entered by the user. | ||
119 | They also fail if | ||
120 | .Fa d2i | ||
121 | returns | ||
122 | .Dv NULL , | ||
123 | for example due to DER decoding errors. | ||
124 | .Pp | ||
125 | .Fn PEM_ASN1_read | ||
126 | may also fail if memory is exhausted. | ||
127 | .Sh EXAMPLES | ||
128 | Typical usage of | ||
129 | .Fn PEM_ASN1_read | ||
130 | is demonstrated by the implementation of the more specific function | ||
131 | to PEM and DER decode an X.509 certificate: | ||
132 | .Bd -literal -offset 2n | ||
133 | X509 * | ||
134 | PEM_read_X509(FILE *fp, X509 **val_out, pem_password_cb *cb, void *u) | ||
135 | { | ||
136 | return PEM_ASN1_read((d2i_of_void *)d2i_X509, PEM_STRING_X509, | ||
137 | fp, (void **)val_out, cb, u); | ||
138 | } | ||
139 | .Ed | ||
140 | .Sh ERRORS | ||
141 | Diagnostics that can be retrieved with | ||
142 | .Xr ERR_get_error 3 , | ||
143 | .Xr ERR_GET_REASON 3 , | ||
144 | and | ||
145 | .Xr ERR_reason_error_string 3 | ||
146 | include: | ||
147 | .Bl -tag -width Ds | ||
148 | .It Dv ERR_R_BUF_LIB Qq "BUF lib" | ||
149 | .Fn PEM_ASN1_read | ||
150 | failed to set up a temporary BIO, | ||
151 | for example because memory was exhausted. | ||
152 | .It Dv ERR_R_ASN1_LIB Qq "ASN1 lib" | ||
153 | .Fa d2i | ||
154 | returned | ||
155 | .Dv NULL , | ||
156 | for example due to a DER syntax error. | ||
157 | .El | ||
158 | .Pp | ||
159 | Additional types of errors can result from | ||
160 | .Xr PEM_bytes_read_bio 3 . | ||
161 | .Sh SEE ALSO | ||
162 | .Xr BIO_new 3 , | ||
163 | .Xr d2i_ASN1_TYPE 3 , | ||
164 | .Xr PEM_bytes_read_bio 3 , | ||
165 | .Xr PEM_read 3 , | ||
166 | .Xr PEM_read_bio_PrivateKey 3 , | ||
167 | .Xr PEM_read_SSL_SESSION 3 | ||
168 | .Sh HISTORY | ||
169 | These functions first appeared in SSLeay 0.5.1 | ||
170 | and have been available since | ||
171 | .Ox 2.4 . | ||