summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/PEM_bytes_read_bio.3
blob: 20ad6b8a4d15c29b4fcb428bda1eef8189c51ea1 (plain)
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
.\" $OpenBSD: PEM_bytes_read_bio.3,v 1.6 2020/07/23 17:34:53 schwarze Exp $
.\" selective merge up to:
.\" OpenSSL PEM_bytes_read_bio.pod 7671342e Feb 29 15:47:12 2016 -0600
.\"
.\" This file is a derived work.
.\" The changes are covered by the following Copyright and license:
.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" The original file was written by Benjamin Kaduk <bkaduk at akamai dot com>.
.\" Copyright (c) 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: July 23 2020 $
.Dt PEM_BYTES_READ_BIO 3
.Os
.Sh NAME
.Nm PEM_bytes_read_bio
.Nd read a PEM-encoded data structure from a BIO
.Sh SYNOPSIS
.In openssl/pem.h
.Ft int
.Fo PEM_bytes_read_bio
.Fa "unsigned char **pdata"
.Fa "long *plen"
.Fa "char **pnm"
.Fa "const char *name"
.Fa "BIO *in_bp"
.Fa "pem_password_cb *cb"
.Fa "void *u"
.Fc
.Sh DESCRIPTION
.Fn PEM_bytes_read_bio
reads and PEM decodes the first object of type
.Fa name
.Pq e.g. RSA PRIVATE KEY, CERTIFICATE, etc.\&
from
.Fa in_bp .
If multiple PEM-encoded data structures are present in the same stream,
it skips non-matching data types and continues reading.
Before reading each PEM object, lines not starting with
.Qq "-----BEGIN "
are also skipped; see
.Xr PEM_read_bio 3
for details of PEM parsing.
.Pp
The PEM header may indicate that the following data is encrypted; if so,
the data is decrypted, optionally using
.Fa cb
and
.Fa u ,
as described in
.Xr pem_password_cb 3 .
.Pp
Some data types have compatibility aliases, such as a file containing
X509 CERTIFICATE matching a request for the deprecated type CERTIFICATE.
The actual type indicated by the file is returned in
.Em *pnm
if
.Fa pnm
is
.Pf non- Dv NULL .
The caller must free the storage pointed to by
.Em *pnm .
.Pp
The returned data is the DER-encoded form of the requested type, in
.Em *pdata
with length
.Em *plen .
The caller must free the storage pointed to by
.Em *pdata .
.Sh RETURN VALUES
.Fn PEM_bytes_read_bio
returns 1 for success or 0 for failure.
.Sh ERRORS
Diagnostics that can be retrieved with
.Xr ERR_get_error 3 ,
.Xr ERR_GET_REASON 3 ,
and
.Xr ERR_reason_error_string 3
include:
.Bl -tag -width Ds
.It Dv PEM_R_NO_START_LINE Qq no start line
No more PEM objects were found in the input.
This can happen when the input contains no PEM objects at all,
or only objects that do not match the type
.Fa name .
.It Dv PEM_R_NOT_PROC_TYPE Qq not proc type
The first PEM header does not start with
.Qq "Proc-Type: " .
.It Dv PEM_R_NOT_ENCRYPTED Qq not encrypted
The Proc-Type header differs from
.Qq 4,ENCRYPTED .
.It Dv PEM_R_SHORT_HEADER Qq short header
The Proc-Type header is the last header line.
.It Dv PEM_R_NOT_DEK_INFO Qq not dek info
The second PEM header does not start with
.Qq "DEK-Info: " .
.It Dv PEM_R_UNSUPPORTED_ENCRYPTION Qq unsupported encryption
The cipher name given in the DEK-Info header is unknown to
.Xr EVP_get_cipherbyname 3 .
.It Dv PEM_R_BAD_IV_CHARS Qq "bad iv chars"
The word following the cipher name in the DEK-Info header
contains bytes that are not hexadecimal digits.
This also happens when the initialization vector is missing or too short.
.It Dv PEM_R_BAD_PASSWORD_READ Qq bad password read
.Fa cb
reported failure.
This may for example happen when the user mistypes the password.
.It Dv PEM_R_BAD_DECRYPT Qq bad decrypt
.Xr EVP_DecryptInit_ex 3 ,
.Xr EVP_DecryptUpdate 3 ,
or
.Xr EVP_DecryptFinal_ex 3
failed.
.El
.Pp
Additional types of errors can result from
.Xr PEM_read_bio 3 .
.Sh SEE ALSO
.Xr PEM_ASN1_read 3 ,
.Xr PEM_read 3 ,
.Xr PEM_read_bio_PrivateKey 3 ,
.Xr PEM_X509_INFO_read 3
.Sh STANDARDS
RFC 1421: Privacy Enhancement for Internet Electronic Mail (PEM), Part I
.Sh HISTORY
.Fn PEM_bytes_read_bio
first appeared in OpenSSL 0.9.7 and has been available since
.Ox 3.2 .