xref: /openbsd-src/lib/libcrypto/pem/pem_oth.c (revision 4a925a6a8d19d7b7ed705f131daa4c3c08f0db82)
1*4a925a6aSbeck /* $OpenBSD: pem_oth.c,v 1.9 2023/07/07 13:40:44 beck Exp $ */
2da347917Sbeck /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3da347917Sbeck  * All rights reserved.
4da347917Sbeck  *
5da347917Sbeck  * This package is an SSL implementation written
6da347917Sbeck  * by Eric Young (eay@cryptsoft.com).
7da347917Sbeck  * The implementation was written so as to conform with Netscapes SSL.
8da347917Sbeck  *
9da347917Sbeck  * This library is free for commercial and non-commercial use as long as
10da347917Sbeck  * the following conditions are aheared to.  The following conditions
11da347917Sbeck  * apply to all code found in this distribution, be it the RC4, RSA,
12da347917Sbeck  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13da347917Sbeck  * included with this distribution is covered by the same copyright terms
14da347917Sbeck  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15da347917Sbeck  *
16da347917Sbeck  * Copyright remains Eric Young's, and as such any Copyright notices in
17da347917Sbeck  * the code are not to be removed.
18da347917Sbeck  * If this package is used in a product, Eric Young should be given attribution
19da347917Sbeck  * as the author of the parts of the library used.
20da347917Sbeck  * This can be in the form of a textual message at program startup or
21da347917Sbeck  * in documentation (online or textual) provided with the package.
22da347917Sbeck  *
23da347917Sbeck  * Redistribution and use in source and binary forms, with or without
24da347917Sbeck  * modification, are permitted provided that the following conditions
25da347917Sbeck  * are met:
26da347917Sbeck  * 1. Redistributions of source code must retain the copyright
27da347917Sbeck  *    notice, this list of conditions and the following disclaimer.
28da347917Sbeck  * 2. Redistributions in binary form must reproduce the above copyright
29da347917Sbeck  *    notice, this list of conditions and the following disclaimer in the
30da347917Sbeck  *    documentation and/or other materials provided with the distribution.
31da347917Sbeck  * 3. All advertising materials mentioning features or use of this software
32da347917Sbeck  *    must display the following acknowledgement:
33da347917Sbeck  *    "This product includes cryptographic software written by
34da347917Sbeck  *     Eric Young (eay@cryptsoft.com)"
35da347917Sbeck  *    The word 'cryptographic' can be left out if the rouines from the library
36da347917Sbeck  *    being used are not cryptographic related :-).
37da347917Sbeck  * 4. If you include any Windows specific code (or a derivative thereof) from
38da347917Sbeck  *    the apps directory (application code) you must include an acknowledgement:
39da347917Sbeck  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40da347917Sbeck  *
41da347917Sbeck  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42da347917Sbeck  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43da347917Sbeck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44da347917Sbeck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45da347917Sbeck  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46da347917Sbeck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47da347917Sbeck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48da347917Sbeck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49da347917Sbeck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50da347917Sbeck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51da347917Sbeck  * SUCH DAMAGE.
52da347917Sbeck  *
53da347917Sbeck  * The licence and distribution terms for any publically available version or
54da347917Sbeck  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55da347917Sbeck  * copied and put under another distribution licence
56da347917Sbeck  * [including the GNU Public Licence.]
57da347917Sbeck  */
58da347917Sbeck 
59da347917Sbeck #include <stdio.h>
60b6ab114eSjsing 
61da347917Sbeck #include <openssl/buffer.h>
62b6ab114eSjsing #include <openssl/err.h>
63da347917Sbeck #include <openssl/evp.h>
64b6ab114eSjsing #include <openssl/objects.h>
65b6ab114eSjsing #include <openssl/pem.h>
66da347917Sbeck #include <openssl/x509.h>
67da347917Sbeck 
68da347917Sbeck /* Handle 'other' PEMs: not private keys */
69da347917Sbeck 
70a8b5ceceSjsing void *
PEM_ASN1_read_bio(d2i_of_void * d2i,const char * name,BIO * bp,void ** x,pem_password_cb * cb,void * u)71a8b5ceceSjsing PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
72da347917Sbeck     pem_password_cb *cb, void *u)
73da347917Sbeck {
745650a0e1Sdjm 	const unsigned char *p = NULL;
755650a0e1Sdjm 	unsigned char *data = NULL;
76da347917Sbeck 	long len;
77da347917Sbeck 	char *ret = NULL;
78da347917Sbeck 
79da347917Sbeck 	if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
80da347917Sbeck 		return NULL;
81da347917Sbeck 	p = data;
82da347917Sbeck 	ret = d2i(x, &p, len);
83da347917Sbeck 	if (ret == NULL)
845067ae9fSbeck 		PEMerror(ERR_R_ASN1_LIB);
856f3a6cb1Sbeck 	free(data);
86da347917Sbeck 	return (ret);
87da347917Sbeck }
88*4a925a6aSbeck LCRYPTO_ALIAS(PEM_ASN1_read_bio);
89