xref: /openbsd-src/lib/libcrypto/man/PEM_bytes_read_bio.3 (revision 7e22e6914a2c8df19b21b49c51bc487f293d6f2a)
1*7e22e691Sschwarze.\" $OpenBSD: PEM_bytes_read_bio.3,v 1.6 2020/07/23 17:34:53 schwarze Exp $
2a926fd0dSschwarze.\" selective merge up to:
377f706dcSschwarze.\" OpenSSL PEM_bytes_read_bio.pod 7671342e Feb 29 15:47:12 2016 -0600
477f706dcSschwarze.\"
5a926fd0dSschwarze.\" This file is a derived work.
6a926fd0dSschwarze.\" The changes are covered by the following Copyright and license:
7a926fd0dSschwarze.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
8a926fd0dSschwarze.\"
9a926fd0dSschwarze.\" Permission to use, copy, modify, and distribute this software for any
10a926fd0dSschwarze.\" purpose with or without fee is hereby granted, provided that the above
11a926fd0dSschwarze.\" copyright notice and this permission notice appear in all copies.
12a926fd0dSschwarze.\"
13a926fd0dSschwarze.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14a926fd0dSschwarze.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15a926fd0dSschwarze.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16a926fd0dSschwarze.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17a926fd0dSschwarze.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18a926fd0dSschwarze.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19a926fd0dSschwarze.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20a926fd0dSschwarze.\"
21a926fd0dSschwarze.\" The original file was written by Benjamin Kaduk <bkaduk at akamai dot com>.
2277f706dcSschwarze.\" Copyright (c) 2017 The OpenSSL Project.  All rights reserved.
2377f706dcSschwarze.\"
2477f706dcSschwarze.\" Redistribution and use in source and binary forms, with or without
2577f706dcSschwarze.\" modification, are permitted provided that the following conditions
2677f706dcSschwarze.\" are met:
2777f706dcSschwarze.\"
2877f706dcSschwarze.\" 1. Redistributions of source code must retain the above copyright
2977f706dcSschwarze.\"    notice, this list of conditions and the following disclaimer.
3077f706dcSschwarze.\"
3177f706dcSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright
3277f706dcSschwarze.\"    notice, this list of conditions and the following disclaimer in
3377f706dcSschwarze.\"    the documentation and/or other materials provided with the
3477f706dcSschwarze.\"    distribution.
3577f706dcSschwarze.\"
3677f706dcSschwarze.\" 3. All advertising materials mentioning features or use of this
3777f706dcSschwarze.\"    software must display the following acknowledgment:
3877f706dcSschwarze.\"    "This product includes software developed by the OpenSSL Project
3977f706dcSschwarze.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
4077f706dcSschwarze.\"
4177f706dcSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
4277f706dcSschwarze.\"    endorse or promote products derived from this software without
4377f706dcSschwarze.\"    prior written permission. For written permission, please contact
4477f706dcSschwarze.\"    openssl-core@openssl.org.
4577f706dcSschwarze.\"
4677f706dcSschwarze.\" 5. Products derived from this software may not be called "OpenSSL"
4777f706dcSschwarze.\"    nor may "OpenSSL" appear in their names without prior written
4877f706dcSschwarze.\"    permission of the OpenSSL Project.
4977f706dcSschwarze.\"
5077f706dcSschwarze.\" 6. Redistributions of any form whatsoever must retain the following
5177f706dcSschwarze.\"    acknowledgment:
5277f706dcSschwarze.\"    "This product includes software developed by the OpenSSL Project
5377f706dcSschwarze.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
5477f706dcSschwarze.\"
5577f706dcSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
5677f706dcSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5777f706dcSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
5877f706dcSschwarze.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
5977f706dcSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6077f706dcSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6177f706dcSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
6277f706dcSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6377f706dcSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
6477f706dcSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
6577f706dcSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
6677f706dcSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE.
6777f706dcSschwarze.\"
68*7e22e691Sschwarze.Dd $Mdocdate: July 23 2020 $
6977f706dcSschwarze.Dt PEM_BYTES_READ_BIO 3
7077f706dcSschwarze.Os
7177f706dcSschwarze.Sh NAME
7277f706dcSschwarze.Nm PEM_bytes_read_bio
7377f706dcSschwarze.Nd read a PEM-encoded data structure from a BIO
7477f706dcSschwarze.Sh SYNOPSIS
7577f706dcSschwarze.In openssl/pem.h
7677f706dcSschwarze.Ft int
7777f706dcSschwarze.Fo PEM_bytes_read_bio
7877f706dcSschwarze.Fa "unsigned char **pdata"
7977f706dcSschwarze.Fa "long *plen"
8077f706dcSschwarze.Fa "char **pnm"
8177f706dcSschwarze.Fa "const char *name"
82eb87f619Sschwarze.Fa "BIO *in_bp"
8377f706dcSschwarze.Fa "pem_password_cb *cb"
8477f706dcSschwarze.Fa "void *u"
8577f706dcSschwarze.Fc
8677f706dcSschwarze.Sh DESCRIPTION
8777f706dcSschwarze.Fn PEM_bytes_read_bio
88eb87f619Sschwarzereads and PEM decodes the first object of type
8977f706dcSschwarze.Fa name
90eb87f619Sschwarze.Pq e.g. RSA PRIVATE KEY, CERTIFICATE, etc.\&
91eb87f619Sschwarzefrom
92eb87f619Sschwarze.Fa in_bp .
9377f706dcSschwarzeIf multiple PEM-encoded data structures are present in the same stream,
94eb87f619Sschwarzeit skips non-matching data types and continues reading.
95eb87f619SschwarzeBefore reading each PEM object, lines not starting with
96eb87f619Sschwarze.Qq "-----BEGIN "
97eb87f619Sschwarzeare also skipped; see
98eb87f619Sschwarze.Xr PEM_read_bio 3
99eb87f619Sschwarzefor details of PEM parsing.
10077f706dcSschwarze.Pp
10177f706dcSschwarzeThe PEM header may indicate that the following data is encrypted; if so,
102eb87f619Sschwarzethe data is decrypted, optionally using
10377f706dcSschwarze.Fa cb
104eb87f619Sschwarzeand
105eb87f619Sschwarze.Fa u ,
106eb87f619Sschwarzeas described in
10760f0d397Sschwarze.Xr pem_password_cb 3 .
10877f706dcSschwarze.Pp
10977f706dcSschwarzeSome data types have compatibility aliases, such as a file containing
11077f706dcSschwarzeX509 CERTIFICATE matching a request for the deprecated type CERTIFICATE.
11177f706dcSschwarzeThe actual type indicated by the file is returned in
11277f706dcSschwarze.Em *pnm
11377f706dcSschwarzeif
11477f706dcSschwarze.Fa pnm
11577f706dcSschwarzeis
11677f706dcSschwarze.Pf non- Dv NULL .
11777f706dcSschwarzeThe caller must free the storage pointed to by
11877f706dcSschwarze.Em *pnm .
11977f706dcSschwarze.Pp
12077f706dcSschwarzeThe returned data is the DER-encoded form of the requested type, in
12177f706dcSschwarze.Em *pdata
12277f706dcSschwarzewith length
12377f706dcSschwarze.Em *plen .
12477f706dcSschwarzeThe caller must free the storage pointed to by
12577f706dcSschwarze.Em *pdata .
12677f706dcSschwarze.Sh RETURN VALUES
12777f706dcSschwarze.Fn PEM_bytes_read_bio
12877f706dcSschwarzereturns 1 for success or 0 for failure.
12960f0d397Sschwarze.Sh ERRORS
13060f0d397SschwarzeDiagnostics that can be retrieved with
13160f0d397Sschwarze.Xr ERR_get_error 3 ,
13260f0d397Sschwarze.Xr ERR_GET_REASON 3 ,
13360f0d397Sschwarzeand
13460f0d397Sschwarze.Xr ERR_reason_error_string 3
13560f0d397Sschwarzeinclude:
13660f0d397Sschwarze.Bl -tag -width Ds
13760f0d397Sschwarze.It Dv PEM_R_NO_START_LINE Qq no start line
13860f0d397SschwarzeNo more PEM objects were found in the input.
13960f0d397SschwarzeThis can happen when the input contains no PEM objects at all,
14060f0d397Sschwarzeor only objects that do not match the type
14160f0d397Sschwarze.Fa name .
14260f0d397Sschwarze.It Dv PEM_R_NOT_PROC_TYPE Qq not proc type
14360f0d397SschwarzeThe first PEM header does not start with
14460f0d397Sschwarze.Qq "Proc-Type: " .
14560f0d397Sschwarze.It Dv PEM_R_NOT_ENCRYPTED Qq not encrypted
14660f0d397SschwarzeThe Proc-Type header differs from
14760f0d397Sschwarze.Qq 4,ENCRYPTED .
14860f0d397Sschwarze.It Dv PEM_R_SHORT_HEADER Qq short header
14960f0d397SschwarzeThe Proc-Type header is the last header line.
15060f0d397Sschwarze.It Dv PEM_R_NOT_DEK_INFO Qq not dek info
15160f0d397SschwarzeThe second PEM header does not start with
15260f0d397Sschwarze.Qq "DEK-Info: " .
15360f0d397Sschwarze.It Dv PEM_R_UNSUPPORTED_ENCRYPTION Qq unsupported encryption
15460f0d397SschwarzeThe cipher name given in the DEK-Info header is unknown to
15560f0d397Sschwarze.Xr EVP_get_cipherbyname 3 .
15660f0d397Sschwarze.It Dv PEM_R_BAD_IV_CHARS Qq "bad iv chars"
15760f0d397SschwarzeThe word following the cipher name in the DEK-Info header
15860f0d397Sschwarzecontains bytes that are not hexadecimal digits.
15960f0d397SschwarzeThis also happens when the initialization vector is missing or too short.
16060f0d397Sschwarze.It Dv PEM_R_BAD_PASSWORD_READ Qq bad password read
16160f0d397Sschwarze.Fa cb
16260f0d397Sschwarzereported failure.
16360f0d397SschwarzeThis may for example happen when the user mistypes the password.
16460f0d397Sschwarze.It Dv PEM_R_BAD_DECRYPT Qq bad decrypt
16560f0d397Sschwarze.Xr EVP_DecryptInit_ex 3 ,
16660f0d397Sschwarze.Xr EVP_DecryptUpdate 3 ,
16760f0d397Sschwarzeor
16860f0d397Sschwarze.Xr EVP_DecryptFinal_ex 3
16960f0d397Sschwarzefailed.
17060f0d397Sschwarze.El
17160f0d397Sschwarze.Pp
17260f0d397SschwarzeAdditional types of errors can result from
17360f0d397Sschwarze.Xr PEM_read_bio 3 .
17477f706dcSschwarze.Sh SEE ALSO
17560f0d397Sschwarze.Xr PEM_ASN1_read 3 ,
17677f706dcSschwarze.Xr PEM_read 3 ,
177*7e22e691Sschwarze.Xr PEM_read_bio_PrivateKey 3 ,
178*7e22e691Sschwarze.Xr PEM_X509_INFO_read 3
179eb87f619Sschwarze.Sh STANDARDS
180eb87f619SschwarzeRFC 1421: Privacy Enhancement for Internet Electronic Mail (PEM), Part I
18180d1afcdSschwarze.Sh HISTORY
18280d1afcdSschwarze.Fn PEM_bytes_read_bio
18380d1afcdSschwarzefirst appeared in OpenSSL 0.9.7 and has been available since
18480d1afcdSschwarze.Ox 3.2 .
185