pem_oth.c revision 160814
1111072Sjake/* crypto/pem/pem_oth.c */
2111072Sjake/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3167308Smarius * All rights reserved.
4111072Sjake *
5111072Sjake * This package is an SSL implementation written
6111072Sjake * by Eric Young (eay@cryptsoft.com).
7111072Sjake * The implementation was written so as to conform with Netscapes SSL.
8111072Sjake *
9111072Sjake * This library is free for commercial and non-commercial use as long as
10111072Sjake * the following conditions are aheared to.  The following conditions
11111072Sjake * apply to all code found in this distribution, be it the RC4, RSA,
12111072Sjake * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13111072Sjake * included with this distribution is covered by the same copyright terms
14111072Sjake * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15111072Sjake *
16111072Sjake * Copyright remains Eric Young's, and as such any Copyright notices in
17111072Sjake * the code are not to be removed.
18111072Sjake * If this package is used in a product, Eric Young should be given attribution
19111072Sjake * as the author of the parts of the library used.
20111072Sjake * This can be in the form of a textual message at program startup or
21111072Sjake * in documentation (online or textual) provided with the package.
22111072Sjake *
23111072Sjake * Redistribution and use in source and binary forms, with or without
24111072Sjake * modification, are permitted provided that the following conditions
25111072Sjake * are met:
26111072Sjake * 1. Redistributions of source code must retain the copyright
27111072Sjake *    notice, this list of conditions and the following disclaimer.
28143129Smarius * 2. Redistributions in binary form must reproduce the above copyright
29143129Smarius *    notice, this list of conditions and the following disclaimer in the
30143129Smarius *    documentation and/or other materials provided with the distribution.
31111072Sjake * 3. All advertising materials mentioning features or use of this software
32111072Sjake *    must display the following acknowledgement:
33111072Sjake *    "This product includes cryptographic software written by
34111072Sjake *     Eric Young (eay@cryptsoft.com)"
35111072Sjake *    The word 'cryptographic' can be left out if the rouines from the library
36167308Smarius *    being used are not cryptographic related :-).
37111123Sjake * 4. If you include any Windows specific code (or a derivative thereof) from
38111072Sjake *    the apps directory (application code) you must include an acknowledgement:
39143826Smarius *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40133589Smarius *
41152684Smarius * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42111072Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43111072Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44111072Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45111072Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46111072Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47111072Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48111072Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49111072Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50111072Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51111072Sjake * SUCH DAMAGE.
52111072Sjake *
53111072Sjake * The licence and distribution terms for any publically available version or
54152684Smarius * derivative of this code cannot be changed.  i.e. this code cannot simply be
55111072Sjake * copied and put under another distribution licence
56111072Sjake * [including the GNU Public Licence.]
57111072Sjake */
58167308Smarius
59172066Smarius#include <stdio.h>
60167308Smarius#include "cryptlib.h"
61167308Smarius#include <openssl/buffer.h>
62167308Smarius#include <openssl/objects.h>
63167308Smarius#include <openssl/evp.h>
64167308Smarius#include <openssl/rand.h>
65167308Smarius#include <openssl/x509.h>
66167308Smarius#include <openssl/pem.h>
67167308Smarius
68167308Smarius/* Handle 'other' PEMs: not private keys */
69167308Smarius
70167308Smariusvoid *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
71167308Smarius			pem_password_cb *cb, void *u)
72225931Smarius	{
73167308Smarius	const unsigned char *p=NULL;
74167308Smarius	unsigned char *data=NULL;
75167308Smarius	long len;
76172066Smarius	char *ret=NULL;
77172066Smarius
78178443Smarius	if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
79178443Smarius		return NULL;
80143826Smarius	p = data;
81152684Smarius	ret=d2i(x,&p,len);
82111123Sjake	if (ret == NULL)
83167308Smarius		PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
84167308Smarius	OPENSSL_free(data);
85167308Smarius	return(ret);
86167308Smarius	}
87167308Smarius