pem_oth.c revision 160814
1139749Simp/* crypto/pem/pem_oth.c */
2130407Sdfr/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3130407Sdfr * All rights reserved.
4130407Sdfr *
5130407Sdfr * This package is an SSL implementation written
6130407Sdfr * by Eric Young (eay@cryptsoft.com).
7130407Sdfr * The implementation was written so as to conform with Netscapes SSL.
8130407Sdfr *
9130407Sdfr * This library is free for commercial and non-commercial use as long as
10130407Sdfr * the following conditions are aheared to.  The following conditions
11130407Sdfr * apply to all code found in this distribution, be it the RC4, RSA,
12130407Sdfr * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13130407Sdfr * included with this distribution is covered by the same copyright terms
14130407Sdfr * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15130407Sdfr *
16130407Sdfr * Copyright remains Eric Young's, and as such any Copyright notices in
17130407Sdfr * the code are not to be removed.
18130407Sdfr * If this package is used in a product, Eric Young should be given attribution
19130407Sdfr * as the author of the parts of the library used.
20130407Sdfr * This can be in the form of a textual message at program startup or
21130407Sdfr * in documentation (online or textual) provided with the package.
22130407Sdfr *
23130407Sdfr * Redistribution and use in source and binary forms, with or without
24130407Sdfr * modification, are permitted provided that the following conditions
25130407Sdfr * are met:
26130407Sdfr * 1. Redistributions of source code must retain the copyright
27130407Sdfr *    notice, this list of conditions and the following disclaimer.
28130407Sdfr * 2. Redistributions in binary form must reproduce the above copyright
29130407Sdfr *    notice, this list of conditions and the following disclaimer in the
30130407Sdfr *    documentation and/or other materials provided with the distribution.
31130407Sdfr * 3. All advertising materials mentioning features or use of this software
32130407Sdfr *    must display the following acknowledgement:
33130407Sdfr *    "This product includes cryptographic software written by
34130407Sdfr *     Eric Young (eay@cryptsoft.com)"
35130407Sdfr *    The word 'cryptographic' can be left out if the rouines from the library
36130407Sdfr *    being used are not cryptographic related :-).
37130407Sdfr * 4. If you include any Windows specific code (or a derivative thereof) from
38130407Sdfr *    the apps directory (application code) you must include an acknowledgement:
39150968Sglebius *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40150968Sglebius *
41130407Sdfr * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42150968Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43130407Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44130407Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45130407Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46130407Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47130407Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48130407Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49130407Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50130407Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51130407Sdfr * SUCH DAMAGE.
52130407Sdfr *
53130407Sdfr * The licence and distribution terms for any publically available version or
54130407Sdfr * derivative of this code cannot be changed.  i.e. this code cannot simply be
55130407Sdfr * copied and put under another distribution licence
56130407Sdfr * [including the GNU Public Licence.]
57130407Sdfr */
58130407Sdfr
59130407Sdfr#include <stdio.h>
60130407Sdfr#include "cryptlib.h"
61147256Sbrooks#include <openssl/buffer.h>
62130407Sdfr#include <openssl/objects.h>
63130407Sdfr#include <openssl/evp.h>
64130407Sdfr#include <openssl/rand.h>
65130407Sdfr#include <openssl/x509.h>
66130407Sdfr#include <openssl/pem.h>
67130407Sdfr
68130407Sdfr/* Handle 'other' PEMs: not private keys */
69130411Sdfr
70130407Sdfrvoid *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
71130407Sdfr			pem_password_cb *cb, void *u)
72130407Sdfr	{
73130407Sdfr	const unsigned char *p=NULL;
74130407Sdfr	unsigned char *data=NULL;
75130407Sdfr	long len;
76130407Sdfr	char *ret=NULL;
77130407Sdfr
78130407Sdfr	if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
79130407Sdfr		return NULL;
80130407Sdfr	p = data;
81130407Sdfr	ret=d2i(x,&p,len);
82130407Sdfr	if (ret == NULL)
83130407Sdfr		PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
84130407Sdfr	OPENSSL_free(data);
85130407Sdfr	return(ret);
86130407Sdfr	}
87130407Sdfr