summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/pem/message16
-rw-r--r--src/lib/libcrypto/pem/pem.h670
-rw-r--r--src/lib/libcrypto/pem/pem2.h70
-rw-r--r--src/lib/libcrypto/pem/pem_all.c196
-rw-r--r--src/lib/libcrypto/pem/pem_err.c131
-rw-r--r--src/lib/libcrypto/pem/pem_info.c364
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c762
-rw-r--r--src/lib/libcrypto/pem/pem_oth.c85
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c243
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c140
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c187
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c102
-rw-r--r--src/lib/libcrypto/pem/pem_x509.c69
-rw-r--r--src/lib/libcrypto/pem/pem_xaux.c68
-rw-r--r--src/lib/libcrypto/pem/pkcs7.lis22
15 files changed, 0 insertions, 3125 deletions
diff --git a/src/lib/libcrypto/pem/message b/src/lib/libcrypto/pem/message
deleted file mode 100644
index e8bf9d7592..0000000000
--- a/src/lib/libcrypto/pem/message
+++ /dev/null
@@ -1,16 +0,0 @@
1-----BEGIN PRIVACY-ENHANCED MESSAGE-----
2Proc-Type: 4,ENCRYPTED
3Proc-Type: 4,MIC-ONLY
4Proc-Type: 4,MIC-CLEAR
5Content-Domain: RFC822
6DEK-Info: DES-CBC,0123456789abcdef
7Originator-Certificate
8 xxxx
9Issuer-Certificate
10 xxxx
11MIC-Info: RSA-MD5,RSA,
12 xxxx
13
14
15-----END PRIVACY-ENHANCED MESSAGE-----
16
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
deleted file mode 100644
index 3785fca77d..0000000000
--- a/src/lib/libcrypto/pem/pem.h
+++ /dev/null
@@ -1,670 +0,0 @@
1/* crypto/pem/pem.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_PEM_H
60#define HEADER_PEM_H
61
62#ifndef OPENSSL_NO_BIO
63#include <openssl/bio.h>
64#endif
65#ifndef OPENSSL_NO_STACK
66#include <openssl/stack.h>
67#endif
68#include <openssl/evp.h>
69#include <openssl/x509.h>
70#include <openssl/pem2.h>
71#include <openssl/e_os2.h>
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77#define PEM_BUFSIZE 1024
78
79#define PEM_OBJ_UNDEF 0
80#define PEM_OBJ_X509 1
81#define PEM_OBJ_X509_REQ 2
82#define PEM_OBJ_CRL 3
83#define PEM_OBJ_SSL_SESSION 4
84#define PEM_OBJ_PRIV_KEY 10
85#define PEM_OBJ_PRIV_RSA 11
86#define PEM_OBJ_PRIV_DSA 12
87#define PEM_OBJ_PRIV_DH 13
88#define PEM_OBJ_PUB_RSA 14
89#define PEM_OBJ_PUB_DSA 15
90#define PEM_OBJ_PUB_DH 16
91#define PEM_OBJ_DHPARAMS 17
92#define PEM_OBJ_DSAPARAMS 18
93#define PEM_OBJ_PRIV_RSA_PUBLIC 19
94
95#define PEM_ERROR 30
96#define PEM_DEK_DES_CBC 40
97#define PEM_DEK_IDEA_CBC 45
98#define PEM_DEK_DES_EDE 50
99#define PEM_DEK_DES_ECB 60
100#define PEM_DEK_RSA 70
101#define PEM_DEK_RSA_MD2 80
102#define PEM_DEK_RSA_MD5 90
103
104#define PEM_MD_MD2 NID_md2
105#define PEM_MD_MD5 NID_md5
106#define PEM_MD_SHA NID_sha
107#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
108#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
109#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
110
111#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
112#define PEM_STRING_X509 "CERTIFICATE"
113#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
114#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
115#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
116#define PEM_STRING_X509_CRL "X509 CRL"
117#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
118#define PEM_STRING_PUBLIC "PUBLIC KEY"
119#define PEM_STRING_RSA "RSA PRIVATE KEY"
120#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
121#define PEM_STRING_DSA "DSA PRIVATE KEY"
122#define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
123#define PEM_STRING_PKCS7 "PKCS7"
124#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
125#define PEM_STRING_PKCS8INF "PRIVATE KEY"
126#define PEM_STRING_DHPARAMS "DH PARAMETERS"
127#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
128#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
129
130 /* Note that this structure is initialised by PEM_SealInit and cleaned up
131 by PEM_SealFinal (at least for now) */
132typedef struct PEM_Encode_Seal_st
133 {
134 EVP_ENCODE_CTX encode;
135 EVP_MD_CTX md;
136 EVP_CIPHER_CTX cipher;
137 } PEM_ENCODE_SEAL_CTX;
138
139/* enc_type is one off */
140#define PEM_TYPE_ENCRYPTED 10
141#define PEM_TYPE_MIC_ONLY 20
142#define PEM_TYPE_MIC_CLEAR 30
143#define PEM_TYPE_CLEAR 40
144
145typedef struct pem_recip_st
146 {
147 char *name;
148 X509_NAME *dn;
149
150 int cipher;
151 int key_enc;
152 char iv[8];
153 } PEM_USER;
154
155typedef struct pem_ctx_st
156 {
157 int type; /* what type of object */
158
159 struct {
160 int version;
161 int mode;
162 } proc_type;
163
164 char *domain;
165
166 struct {
167 int cipher;
168 unsigned char iv[8];
169 } DEK_info;
170
171 PEM_USER *originator;
172
173 int num_recipient;
174 PEM_USER **recipient;
175
176#ifndef OPENSSL_NO_STACK
177 STACK *x509_chain; /* certificate chain */
178#else
179 char *x509_chain; /* certificate chain */
180#endif
181 EVP_MD *md; /* signature type */
182
183 int md_enc; /* is the md encrypted or not? */
184 int md_len; /* length of md_data */
185 char *md_data; /* message digest, could be pkey encrypted */
186
187 EVP_CIPHER *dec; /* date encryption cipher */
188 int key_len; /* key length */
189 unsigned char *key; /* key */
190 unsigned char iv[8]; /* the iv */
191
192
193 int data_enc; /* is the data encrypted */
194 int data_len;
195 unsigned char *data;
196 } PEM_CTX;
197
198/* These macros make the PEM_read/PEM_write functions easier to maintain and
199 * write. Now they are all implemented with either:
200 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
201 */
202
203#ifdef OPENSSL_NO_FP_API
204
205#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
206#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
207#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
208
209#else
210
211#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
212type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
213{ \
214return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
215 cb,u)); \
216} \
217
218#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
219int PEM_write_##name(FILE *fp, type *x) \
220{ \
221return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
222 NULL,NULL,0,NULL,NULL)); \
223}
224
225#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
226int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
227 unsigned char *kstr, int klen, pem_password_cb *cb, \
228 void *u) \
229 { \
230 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
231 (char *)x,enc,kstr,klen,cb,u)); \
232 }
233
234#endif
235
236#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
237type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
238{ \
239return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
240 (char **)x,cb,u)); \
241}
242
243#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
244int PEM_write_bio_##name(BIO *bp, type *x) \
245{ \
246return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
247 NULL,NULL,0,NULL,NULL)); \
248}
249
250#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
251int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
252 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
253 { \
254 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
255 (char *)x,enc,kstr,klen,cb,u)); \
256 }
257
258#define IMPLEMENT_PEM_write(name, type, str, asn1) \
259 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
260 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
261
262#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
263 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
264 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
265
266#define IMPLEMENT_PEM_read(name, type, str, asn1) \
267 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
268 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
269
270#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
271 IMPLEMENT_PEM_read(name, type, str, asn1) \
272 IMPLEMENT_PEM_write(name, type, str, asn1)
273
274#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
275 IMPLEMENT_PEM_read(name, type, str, asn1) \
276 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
277
278/* These are the same except they are for the declarations */
279
280#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
281
282#define DECLARE_PEM_read_fp(name, type) /**/
283#define DECLARE_PEM_write_fp(name, type) /**/
284#define DECLARE_PEM_write_cb_fp(name, type) /**/
285
286#else
287
288#define DECLARE_PEM_read_fp(name, type) \
289 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
290
291#define DECLARE_PEM_write_fp(name, type) \
292 int PEM_write_##name(FILE *fp, type *x);
293
294#define DECLARE_PEM_write_cb_fp(name, type) \
295 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
296 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
297
298#endif
299
300#ifndef OPENSSL_NO_BIO
301#define DECLARE_PEM_read_bio(name, type) \
302 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
303
304#define DECLARE_PEM_write_bio(name, type) \
305 int PEM_write_bio_##name(BIO *bp, type *x);
306
307#define DECLARE_PEM_write_cb_bio(name, type) \
308 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
309 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
310
311#else
312
313#define DECLARE_PEM_read_bio(name, type) /**/
314#define DECLARE_PEM_write_bio(name, type) /**/
315#define DECLARE_PEM_write_cb_bio(name, type) /**/
316
317#endif
318
319#define DECLARE_PEM_write(name, type) \
320 DECLARE_PEM_write_bio(name, type) \
321 DECLARE_PEM_write_fp(name, type)
322
323#define DECLARE_PEM_write_cb(name, type) \
324 DECLARE_PEM_write_cb_bio(name, type) \
325 DECLARE_PEM_write_cb_fp(name, type)
326
327#define DECLARE_PEM_read(name, type) \
328 DECLARE_PEM_read_bio(name, type) \
329 DECLARE_PEM_read_fp(name, type)
330
331#define DECLARE_PEM_rw(name, type) \
332 DECLARE_PEM_read(name, type) \
333 DECLARE_PEM_write(name, type)
334
335#define DECLARE_PEM_rw_cb(name, type) \
336 DECLARE_PEM_read(name, type) \
337 DECLARE_PEM_write_cb(name, type)
338
339#ifdef SSLEAY_MACROS
340
341#define PEM_write_SSL_SESSION(fp,x) \
342 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
343 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
344#define PEM_write_X509(fp,x) \
345 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
346 (char *)x, NULL,NULL,0,NULL,NULL)
347#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
348 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
349 NULL,NULL,0,NULL,NULL)
350#define PEM_write_X509_CRL(fp,x) \
351 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
352 fp,(char *)x, NULL,NULL,0,NULL,NULL)
353#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
354 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
355 (char *)x,enc,kstr,klen,cb,u)
356#define PEM_write_RSAPublicKey(fp,x) \
357 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
358 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
359#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
360 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
361 (char *)x,enc,kstr,klen,cb,u)
362#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
363 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
364 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
365 bp,(char *)x,enc,kstr,klen,cb,u)
366#define PEM_write_PKCS7(fp,x) \
367 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
368 (char *)x, NULL,NULL,0,NULL,NULL)
369#define PEM_write_DHparams(fp,x) \
370 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
371 (char *)x,NULL,NULL,0,NULL,NULL)
372
373#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
374 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
375 PEM_STRING_X509,fp, \
376 (char *)x, NULL,NULL,0,NULL,NULL)
377
378#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
379 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
380#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
381 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
382#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
383 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
384#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
385 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
386#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
387 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
388#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
389 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
390#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
391 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
392#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
393 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
394#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
395 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
396#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
397 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
398
399#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
400 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
401 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
402 (char **)x,cb,u)
403
404#define PEM_write_bio_SSL_SESSION(bp,x) \
405 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
406 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
407#define PEM_write_bio_X509(bp,x) \
408 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
409 (char *)x, NULL,NULL,0,NULL,NULL)
410#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
411 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
412 NULL,NULL,0,NULL,NULL)
413#define PEM_write_bio_X509_CRL(bp,x) \
414 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
415 bp,(char *)x, NULL,NULL,0,NULL,NULL)
416#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
417 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
418 bp,(char *)x,enc,kstr,klen,cb,u)
419#define PEM_write_bio_RSAPublicKey(bp,x) \
420 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
421 PEM_STRING_RSA_PUBLIC,\
422 bp,(char *)x,NULL,NULL,0,NULL,NULL)
423#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
424 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
425 bp,(char *)x,enc,kstr,klen,cb,u)
426#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
427 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
428 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
429 bp,(char *)x,enc,kstr,klen,cb,u)
430#define PEM_write_bio_PKCS7(bp,x) \
431 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
432 (char *)x, NULL,NULL,0,NULL,NULL)
433#define PEM_write_bio_DHparams(bp,x) \
434 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
435 bp,(char *)x,NULL,NULL,0,NULL,NULL)
436#define PEM_write_bio_DSAparams(bp,x) \
437 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
438 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
439
440#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
441 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
442 PEM_STRING_X509,bp, \
443 (char *)x, NULL,NULL,0,NULL,NULL)
444
445#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
446 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
447#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
448 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
449#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
450 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
451#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
453#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
455#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
457#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
458 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
459#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
461
462#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
463 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
464#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
465 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
466#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
467 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
468
469#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
470 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
471 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
472 (char **)x,cb,u)
473
474#endif
475
476#if 1
477/* "userdata": new with OpenSSL 0.9.4 */
478typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
479#else
480/* OpenSSL 0.9.3, 0.9.3a */
481typedef int pem_password_cb(char *buf, int size, int rwflag);
482#endif
483
484int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
485int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
486 pem_password_cb *callback,void *u);
487
488#ifndef OPENSSL_NO_BIO
489int PEM_read_bio(BIO *bp, char **name, char **header,
490 unsigned char **data,long *len);
491int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
492 long len);
493int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
494 pem_password_cb *cb, void *u);
495char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
496 pem_password_cb *cb, void *u);
497int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
498 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
499 pem_password_cb *cb, void *u);
500STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
501int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
502 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
503#endif
504
505#ifndef OPENSSL_SYS_WIN16
506int PEM_read(FILE *fp, char **name, char **header,
507 unsigned char **data,long *len);
508int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
509char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
510 pem_password_cb *cb, void *u);
511int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
512 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
513 pem_password_cb *callback, void *u);
514STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
515 pem_password_cb *cb, void *u);
516#endif
517
518int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
519 EVP_MD *md_type, unsigned char **ek, int *ekl,
520 unsigned char *iv, EVP_PKEY **pubk, int npubk);
521void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
522 unsigned char *in, int inl);
523int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
524 unsigned char *out, int *outl, EVP_PKEY *priv);
525
526void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
527void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
528int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
529 unsigned int *siglen, EVP_PKEY *pkey);
530
531int PEM_def_callback(char *buf, int num, int w, void *key);
532void PEM_proc_type(char *buf, int type);
533void PEM_dek_info(char *buf, const char *type, int len, char *str);
534
535#ifndef SSLEAY_MACROS
536
537#include <openssl/symhacks.h>
538
539DECLARE_PEM_rw(X509, X509)
540
541DECLARE_PEM_rw(X509_AUX, X509)
542
543DECLARE_PEM_rw(X509_REQ, X509_REQ)
544DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
545
546DECLARE_PEM_rw(X509_CRL, X509_CRL)
547
548DECLARE_PEM_rw(PKCS7, PKCS7)
549
550DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
551
552DECLARE_PEM_rw(PKCS8, X509_SIG)
553
554DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
555
556#ifndef OPENSSL_NO_RSA
557
558DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
559
560DECLARE_PEM_rw(RSAPublicKey, RSA)
561DECLARE_PEM_rw(RSA_PUBKEY, RSA)
562
563#endif
564
565#ifndef OPENSSL_NO_DSA
566
567DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
568
569DECLARE_PEM_rw(DSA_PUBKEY, DSA)
570
571DECLARE_PEM_rw(DSAparams, DSA)
572
573#endif
574
575#ifndef OPENSSL_NO_DH
576
577DECLARE_PEM_rw(DHparams, DH)
578
579#endif
580
581DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
582
583DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
584
585int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
586 char *kstr, int klen,
587 pem_password_cb *cb, void *u);
588int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
589 char *, int, pem_password_cb *, void *);
590int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
591 char *kstr, int klen,
592 pem_password_cb *cb, void *u);
593int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
594 char *kstr, int klen,
595 pem_password_cb *cb, void *u);
596EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
597
598int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
599 char *kstr, int klen,
600 pem_password_cb *cb, void *u);
601int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
602 char *kstr, int klen,
603 pem_password_cb *cb, void *u);
604int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
605 char *kstr, int klen,
606 pem_password_cb *cb, void *u);
607
608EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
609
610int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
611 char *kstr,int klen, pem_password_cb *cd, void *u);
612
613#endif /* SSLEAY_MACROS */
614
615
616/* BEGIN ERROR CODES */
617/* The following lines are auto generated by the script mkerr.pl. Any changes
618 * made after this point may be overwritten when the script is next run.
619 */
620void ERR_load_PEM_strings(void);
621
622/* Error codes for the PEM functions. */
623
624/* Function codes. */
625#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
626#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
627#define PEM_F_DEF_CALLBACK 100
628#define PEM_F_LOAD_IV 101
629#define PEM_F_PEM_ASN1_READ 102
630#define PEM_F_PEM_ASN1_READ_BIO 103
631#define PEM_F_PEM_ASN1_WRITE 104
632#define PEM_F_PEM_ASN1_WRITE_BIO 105
633#define PEM_F_PEM_DO_HEADER 106
634#define PEM_F_PEM_F_DO_PK8KEY_FP 122
635#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
636#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
637#define PEM_F_PEM_READ 108
638#define PEM_F_PEM_READ_BIO 109
639#define PEM_F_PEM_SEALFINAL 110
640#define PEM_F_PEM_SEALINIT 111
641#define PEM_F_PEM_SIGNFINAL 112
642#define PEM_F_PEM_WRITE 113
643#define PEM_F_PEM_WRITE_BIO 114
644#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
645#define PEM_F_PEM_X509_INFO_READ 115
646#define PEM_F_PEM_X509_INFO_READ_BIO 116
647#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
648
649/* Reason codes. */
650#define PEM_R_BAD_BASE64_DECODE 100
651#define PEM_R_BAD_DECRYPT 101
652#define PEM_R_BAD_END_LINE 102
653#define PEM_R_BAD_IV_CHARS 103
654#define PEM_R_BAD_PASSWORD_READ 104
655#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
656#define PEM_R_NOT_DEK_INFO 105
657#define PEM_R_NOT_ENCRYPTED 106
658#define PEM_R_NOT_PROC_TYPE 107
659#define PEM_R_NO_START_LINE 108
660#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
661#define PEM_R_PUBLIC_KEY_NO_RSA 110
662#define PEM_R_READ_KEY 111
663#define PEM_R_SHORT_HEADER 112
664#define PEM_R_UNSUPPORTED_CIPHER 113
665#define PEM_R_UNSUPPORTED_ENCRYPTION 114
666
667#ifdef __cplusplus
668}
669#endif
670#endif
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h
deleted file mode 100644
index f31790d69c..0000000000
--- a/src/lib/libcrypto/pem/pem2.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * This header only exists to break a circular dependency between pem and err
57 * Ben 30 Jan 1999.
58 */
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64#ifndef HEADER_PEM_H
65void ERR_load_PEM_strings(void);
66#endif
67
68#ifdef __cplusplus
69}
70#endif
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
deleted file mode 100644
index e72b7134ce..0000000000
--- a/src/lib/libcrypto/pem/pem_all.c
+++ /dev/null
@@ -1,196 +0,0 @@
1/* crypto/pem/pem_all.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68#ifndef OPENSSL_NO_RSA
69static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
70#endif
71#ifndef OPENSSL_NO_DSA
72static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
73#endif
74
75IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
76
77IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
78
79IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
80
81IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
82
83IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
84 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
85
86
87#ifndef OPENSSL_NO_RSA
88
89/* We treat RSA or DSA private keys as a special case.
90 *
91 * For private keys we read in an EVP_PKEY structure with
92 * PEM_read_bio_PrivateKey() and extract the relevant private
93 * key: this means can handle "traditional" and PKCS#8 formats
94 * transparently.
95 */
96
97static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa)
98{
99 RSA *rtmp;
100 if(!key) return NULL;
101 rtmp = EVP_PKEY_get1_RSA(key);
102 EVP_PKEY_free(key);
103 if(!rtmp) return NULL;
104 if(rsa) {
105 RSA_free(*rsa);
106 *rsa = rtmp;
107 }
108 return rtmp;
109}
110
111RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
112 void *u)
113{
114 EVP_PKEY *pktmp;
115 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
116 return pkey_get_rsa(pktmp, rsa);
117}
118
119#ifndef OPENSSL_NO_FP_API
120
121RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
122 void *u)
123{
124 EVP_PKEY *pktmp;
125 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
126 return pkey_get_rsa(pktmp, rsa);
127}
128
129#endif
130
131IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
132IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
133IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
134
135#endif
136
137#ifndef OPENSSL_NO_DSA
138
139static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa)
140{
141 DSA *dtmp;
142 if(!key) return NULL;
143 dtmp = EVP_PKEY_get1_DSA(key);
144 EVP_PKEY_free(key);
145 if(!dtmp) return NULL;
146 if(dsa) {
147 DSA_free(*dsa);
148 *dsa = dtmp;
149 }
150 return dtmp;
151}
152
153DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
154 void *u)
155{
156 EVP_PKEY *pktmp;
157 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
158 return pkey_get_dsa(pktmp, dsa);
159}
160
161IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
162IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
163
164#ifndef OPENSSL_NO_FP_API
165
166DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
167 void *u)
168{
169 EVP_PKEY *pktmp;
170 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
171 return pkey_get_dsa(pktmp, dsa);
172}
173
174#endif
175
176IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
177
178#endif
179
180#ifndef OPENSSL_NO_DH
181
182IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
183
184#endif
185
186
187/* The PrivateKey case is not that straightforward.
188 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
189 * does not work, RSA and DSA keys have specific strings.
190 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
191 * appropriate.)
192 */
193IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
194
195IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
196
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
deleted file mode 100644
index 3b39b84d66..0000000000
--- a/src/lib/libcrypto/pem/pem_err.c
+++ /dev/null
@@ -1,131 +0,0 @@
1/* crypto/pem/pem_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pem.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA PEM_str_functs[]=
68 {
69{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_BIO,0), "d2i_PKCS8PrivateKey_bio"},
70{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_FP,0), "d2i_PKCS8PrivateKey_fp"},
71{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"},
72{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"},
73{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"},
74{ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"},
75{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
76{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
77{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
78{ERR_PACK(0,PEM_F_PEM_F_DO_PK8KEY_FP,0), "PEM_F_DO_PK8KEY_FP"},
79{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
80{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
81{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
82{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
83{ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"},
84{ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"},
85{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
86{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
87{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
88{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"},
89{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
90{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
91{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
92{0,NULL}
93 };
94
95static ERR_STRING_DATA PEM_str_reasons[]=
96 {
97{PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"},
98{PEM_R_BAD_DECRYPT ,"bad decrypt"},
99{PEM_R_BAD_END_LINE ,"bad end line"},
100{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
101{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
102{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"},
103{PEM_R_NOT_DEK_INFO ,"not dek info"},
104{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
105{PEM_R_NOT_PROC_TYPE ,"not proc type"},
106{PEM_R_NO_START_LINE ,"no start line"},
107{PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"},
108{PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"},
109{PEM_R_READ_KEY ,"read key"},
110{PEM_R_SHORT_HEADER ,"short header"},
111{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
112{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
113{0,NULL}
114 };
115
116#endif
117
118void ERR_load_PEM_strings(void)
119 {
120 static int init=1;
121
122 if (init)
123 {
124 init=0;
125#ifndef OPENSSL_NO_ERR
126 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs);
127 ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons);
128#endif
129
130 }
131 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
deleted file mode 100644
index 9a6dffb45c..0000000000
--- a/src/lib/libcrypto/pem/pem_info.c
+++ /dev/null
@@ -1,364 +0,0 @@
1/* crypto/pem/pem_info.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
67#ifndef OPENSSL_NO_FP_API
68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
69 {
70 BIO *b;
71 STACK_OF(X509_INFO) *ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
86 {
87 X509_INFO *xi=NULL;
88 char *name=NULL,*header=NULL,**pp;
89 unsigned char *data=NULL,*p;
90 long len,error=0;
91 int ok=0;
92 STACK_OF(X509_INFO) *ret=NULL;
93 unsigned int i,raw;
94 char *(*d2i)();
95
96 if (sk == NULL)
97 {
98 if ((ret=sk_X509_INFO_new_null()) == NULL)
99 {
100 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
101 goto err;
102 }
103 }
104 else
105 ret=sk;
106
107 if ((xi=X509_INFO_new()) == NULL) goto err;
108 for (;;)
109 {
110 raw=0;
111 i=PEM_read_bio(bp,&name,&header,&data,&len);
112 if (i == 0)
113 {
114 error=ERR_GET_REASON(ERR_peek_last_error());
115 if (error == PEM_R_NO_START_LINE)
116 {
117 ERR_clear_error();
118 break;
119 }
120 goto err;
121 }
122start:
123 if ( (strcmp(name,PEM_STRING_X509) == 0) ||
124 (strcmp(name,PEM_STRING_X509_OLD) == 0))
125 {
126 d2i=(char *(*)())d2i_X509;
127 if (xi->x509 != NULL)
128 {
129 if (!sk_X509_INFO_push(ret,xi)) goto err;
130 if ((xi=X509_INFO_new()) == NULL) goto err;
131 goto start;
132 }
133 pp=(char **)&(xi->x509);
134 }
135 else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0))
136 {
137 d2i=(char *(*)())d2i_X509_AUX;
138 if (xi->x509 != NULL)
139 {
140 if (!sk_X509_INFO_push(ret,xi)) goto err;
141 if ((xi=X509_INFO_new()) == NULL) goto err;
142 goto start;
143 }
144 pp=(char **)&(xi->x509);
145 }
146 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
147 {
148 d2i=(char *(*)())d2i_X509_CRL;
149 if (xi->crl != NULL)
150 {
151 if (!sk_X509_INFO_push(ret,xi)) goto err;
152 if ((xi=X509_INFO_new()) == NULL) goto err;
153 goto start;
154 }
155 pp=(char **)&(xi->crl);
156 }
157 else
158#ifndef OPENSSL_NO_RSA
159 if (strcmp(name,PEM_STRING_RSA) == 0)
160 {
161 d2i=(char *(*)())d2i_RSAPrivateKey;
162 if (xi->x_pkey != NULL)
163 {
164 if (!sk_X509_INFO_push(ret,xi)) goto err;
165 if ((xi=X509_INFO_new()) == NULL) goto err;
166 goto start;
167 }
168
169 xi->enc_data=NULL;
170 xi->enc_len=0;
171
172 xi->x_pkey=X509_PKEY_new();
173 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
174 goto err;
175 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
176 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa);
177 if ((int)strlen(header) > 10) /* assume encrypted */
178 raw=1;
179 }
180 else
181#endif
182#ifndef OPENSSL_NO_DSA
183 if (strcmp(name,PEM_STRING_DSA) == 0)
184 {
185 d2i=(char *(*)())d2i_DSAPrivateKey;
186 if (xi->x_pkey != NULL)
187 {
188 if (!sk_X509_INFO_push(ret,xi)) goto err;
189 if ((xi=X509_INFO_new()) == NULL) goto err;
190 goto start;
191 }
192
193 xi->enc_data=NULL;
194 xi->enc_len=0;
195
196 xi->x_pkey=X509_PKEY_new();
197 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
198 goto err;
199 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
200 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa);
201 if ((int)strlen(header) > 10) /* assume encrypted */
202 raw=1;
203 }
204 else
205#endif
206 {
207 d2i=NULL;
208 pp=NULL;
209 }
210
211 if (d2i != NULL)
212 {
213 if (!raw)
214 {
215 EVP_CIPHER_INFO cipher;
216
217 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
218 goto err;
219 if (!PEM_do_header(&cipher,data,&len,cb,u))
220 goto err;
221 p=data;
222 if (d2i(pp,&p,len) == NULL)
223 {
224 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
225 goto err;
226 }
227 }
228 else
229 { /* encrypted RSA data */
230 if (!PEM_get_EVP_CIPHER_INFO(header,
231 &xi->enc_cipher)) goto err;
232 xi->enc_data=(char *)data;
233 xi->enc_len=(int)len;
234 data=NULL;
235 }
236 }
237 else {
238 /* unknown */
239 }
240 if (name != NULL) OPENSSL_free(name);
241 if (header != NULL) OPENSSL_free(header);
242 if (data != NULL) OPENSSL_free(data);
243 name=NULL;
244 header=NULL;
245 data=NULL;
246 }
247
248 /* if the last one hasn't been pushed yet and there is anything
249 * in it then add it to the stack ...
250 */
251 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
252 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
253 {
254 if (!sk_X509_INFO_push(ret,xi)) goto err;
255 xi=NULL;
256 }
257 ok=1;
258err:
259 if (xi != NULL) X509_INFO_free(xi);
260 if (!ok)
261 {
262 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
263 {
264 xi=sk_X509_INFO_value(ret,i);
265 X509_INFO_free(xi);
266 }
267 if (ret != sk) sk_X509_INFO_free(ret);
268 ret=NULL;
269 }
270
271 if (name != NULL) OPENSSL_free(name);
272 if (header != NULL) OPENSSL_free(header);
273 if (data != NULL) OPENSSL_free(data);
274 return(ret);
275 }
276
277
278/* A TJH addition */
279int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
280 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
281 {
282 EVP_CIPHER_CTX ctx;
283 int i,ret=0;
284 unsigned char *data=NULL;
285 const char *objstr=NULL;
286 char buf[PEM_BUFSIZE];
287 unsigned char *iv=NULL;
288
289 if (enc != NULL)
290 {
291 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
292 if (objstr == NULL)
293 {
294 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
295 goto err;
296 }
297 }
298
299 /* now for the fun part ... if we have a private key then
300 * we have to be able to handle a not-yet-decrypted key
301 * being written out correctly ... if it is decrypted or
302 * it is non-encrypted then we use the base code
303 */
304 if (xi->x_pkey!=NULL)
305 {
306 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
307 {
308 /* copy from weirdo names into more normal things */
309 iv=xi->enc_cipher.iv;
310 data=(unsigned char *)xi->enc_data;
311 i=xi->enc_len;
312
313 /* we take the encryption data from the
314 * internal stuff rather than what the
315 * user has passed us ... as we have to
316 * match exactly for some strange reason
317 */
318 objstr=OBJ_nid2sn(
319 EVP_CIPHER_nid(xi->enc_cipher.cipher));
320 if (objstr == NULL)
321 {
322 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
323 goto err;
324 }
325
326 /* create the right magic header stuff */
327 buf[0]='\0';
328 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
329 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
330
331 /* use the normal code to write things out */
332 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
333 if (i <= 0) goto err;
334 }
335 else
336 {
337 /* Add DSA/DH */
338#ifndef OPENSSL_NO_RSA
339 /* normal optionally encrypted stuff */
340 if (PEM_write_bio_RSAPrivateKey(bp,
341 xi->x_pkey->dec_pkey->pkey.rsa,
342 enc,kstr,klen,cb,u)<=0)
343 goto err;
344#endif
345 }
346 }
347
348 /* if we have a certificate then write it out now */
349 if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0))
350 goto err;
351
352 /* we are ignoring anything else that is loaded into the X509_INFO
353 * structure for the moment ... as I don't need it so I'm not
354 * coding it here and Eric can do it when this makes it into the
355 * base library --tjh
356 */
357
358 ret=1;
359
360err:
361 memset((char *)&ctx,0,sizeof(ctx));
362 memset(buf,0,PEM_BUFSIZE);
363 return(ret);
364 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
deleted file mode 100644
index a8db6ffbf5..0000000000
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ /dev/null
@@ -1,762 +0,0 @@
1/* crypto/pem/pem_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67#include <openssl/pkcs12.h>
68#ifndef OPENSSL_NO_DES
69#include <openssl/des.h>
70#endif
71
72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
73
74#define MIN_LENGTH 4
75
76static int load_iv(unsigned char **fromp,unsigned char *to, int num);
77static int check_pem(const char *nm, const char *name);
78
79int PEM_def_callback(char *buf, int num, int w, void *key)
80 {
81#ifdef OPENSSL_NO_FP_API
82 /* We should not ever call the default callback routine from
83 * windows. */
84 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85 return(-1);
86#else
87 int i,j;
88 const char *prompt;
89 if(key) {
90 i=strlen(key);
91 i=(i > num)?num:i;
92 memcpy(buf,key,i);
93 return(i);
94 }
95
96 prompt=EVP_get_pw_prompt();
97 if (prompt == NULL)
98 prompt="Enter PEM pass phrase:";
99
100 for (;;)
101 {
102 i=EVP_read_pw_string(buf,num,prompt,w);
103 if (i != 0)
104 {
105 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
106 memset(buf,0,(unsigned int)num);
107 return(-1);
108 }
109 j=strlen(buf);
110 if (j < MIN_LENGTH)
111 {
112 fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH);
113 }
114 else
115 break;
116 }
117 return(j);
118#endif
119 }
120
121void PEM_proc_type(char *buf, int type)
122 {
123 const char *str;
124
125 if (type == PEM_TYPE_ENCRYPTED)
126 str="ENCRYPTED";
127 else if (type == PEM_TYPE_MIC_CLEAR)
128 str="MIC-CLEAR";
129 else if (type == PEM_TYPE_MIC_ONLY)
130 str="MIC-ONLY";
131 else
132 str="BAD-TYPE";
133
134 strcat(buf,"Proc-Type: 4,");
135 strcat(buf,str);
136 strcat(buf,"\n");
137 }
138
139void PEM_dek_info(char *buf, const char *type, int len, char *str)
140 {
141 static unsigned char map[17]="0123456789ABCDEF";
142 long i;
143 int j;
144
145 strcat(buf,"DEK-Info: ");
146 strcat(buf,type);
147 strcat(buf,",");
148 j=strlen(buf);
149 for (i=0; i<len; i++)
150 {
151 buf[j+i*2] =map[(str[i]>>4)&0x0f];
152 buf[j+i*2+1]=map[(str[i] )&0x0f];
153 }
154 buf[j+i*2]='\n';
155 buf[j+i*2+1]='\0';
156 }
157
158#ifndef OPENSSL_NO_FP_API
159char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
160 pem_password_cb *cb, void *u)
161 {
162 BIO *b;
163 char *ret;
164
165 if ((b=BIO_new(BIO_s_file())) == NULL)
166 {
167 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
168 return(0);
169 }
170 BIO_set_fp(b,fp,BIO_NOCLOSE);
171 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
172 BIO_free(b);
173 return(ret);
174 }
175#endif
176
177static int check_pem(const char *nm, const char *name)
178{
179 /* Normal matching nm and name */
180 if (!strcmp(nm,name)) return 1;
181
182 /* Make PEM_STRING_EVP_PKEY match any private key */
183
184 if(!strcmp(nm,PEM_STRING_PKCS8) &&
185 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
186
187 if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
188 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
189
190 if(!strcmp(nm,PEM_STRING_RSA) &&
191 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
192
193 if(!strcmp(nm,PEM_STRING_DSA) &&
194 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
195
196 /* Permit older strings */
197
198 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
199 !strcmp(name,PEM_STRING_X509)) return 1;
200
201 if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) &&
202 !strcmp(name,PEM_STRING_X509_REQ)) return 1;
203
204 /* Allow normal certs to be read as trusted certs */
205 if(!strcmp(nm,PEM_STRING_X509) &&
206 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
207
208 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
209 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
210
211 /* Some CAs use PKCS#7 with CERTIFICATE headers */
212 if(!strcmp(nm, PEM_STRING_X509) &&
213 !strcmp(name, PEM_STRING_PKCS7)) return 1;
214
215 return 0;
216}
217
218int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
219 pem_password_cb *cb, void *u)
220 {
221 EVP_CIPHER_INFO cipher;
222 char *nm=NULL,*header=NULL;
223 unsigned char *data=NULL;
224 long len;
225 int ret = 0;
226
227 for (;;)
228 {
229 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) {
230 if(ERR_GET_REASON(ERR_peek_error()) ==
231 PEM_R_NO_START_LINE)
232 ERR_add_error_data(2, "Expecting: ", name);
233 return 0;
234 }
235 if(check_pem(nm, name)) break;
236 OPENSSL_free(nm);
237 OPENSSL_free(header);
238 OPENSSL_free(data);
239 }
240 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
241 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
242
243 *pdata = data;
244 *plen = len;
245
246 if (pnm)
247 *pnm = nm;
248
249 ret = 1;
250
251err:
252 if (!pnm) OPENSSL_free(nm);
253 OPENSSL_free(header);
254 if (!ret) OPENSSL_free(data);
255 return ret;
256 }
257
258#ifndef OPENSSL_NO_FP_API
259int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
260 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
261 pem_password_cb *callback, void *u)
262 {
263 BIO *b;
264 int ret;
265
266 if ((b=BIO_new(BIO_s_file())) == NULL)
267 {
268 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
269 return(0);
270 }
271 BIO_set_fp(b,fp,BIO_NOCLOSE);
272 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
273 BIO_free(b);
274 return(ret);
275 }
276#endif
277
278int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
279 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
280 pem_password_cb *callback, void *u)
281 {
282 EVP_CIPHER_CTX ctx;
283 int dsize=0,i,j,ret=0;
284 unsigned char *p,*data=NULL;
285 const char *objstr=NULL;
286 char buf[PEM_BUFSIZE];
287 unsigned char key[EVP_MAX_KEY_LENGTH];
288 unsigned char iv[EVP_MAX_IV_LENGTH];
289
290 if (enc != NULL)
291 {
292 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
293 if (objstr == NULL)
294 {
295 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
296 goto err;
297 }
298 }
299
300 if ((dsize=i2d(x,NULL)) < 0)
301 {
302 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
303 dsize=0;
304 goto err;
305 }
306 /* dzise + 8 bytes are needed */
307 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20);
308 if (data == NULL)
309 {
310 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
311 goto err;
312 }
313 p=data;
314 i=i2d(x,&p);
315
316 if (enc != NULL)
317 {
318 if (kstr == NULL)
319 {
320 if (callback == NULL)
321 klen=PEM_def_callback(buf,PEM_BUFSIZE,1,u);
322 else
323 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
324 if (klen <= 0)
325 {
326 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
327 goto err;
328 }
329#ifdef CHARSET_EBCDIC
330 /* Convert the pass phrase from EBCDIC */
331 ebcdic2ascii(buf, buf, klen);
332#endif
333 kstr=(unsigned char *)buf;
334 }
335 RAND_add(data,i,0);/* put in the RSA key. */
336 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
337 goto err;
338 /* The 'iv' is used as the iv and as a salt. It is
339 * NOT taken from the BytesToKey function */
340 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
341
342 if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE);
343
344 buf[0]='\0';
345 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
346 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
347 /* k=strlen(buf); */
348
349 EVP_CIPHER_CTX_init(&ctx);
350 EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv);
351 EVP_EncryptUpdate(&ctx,data,&j,data,i);
352 EVP_EncryptFinal_ex(&ctx,&(data[j]),&i);
353 EVP_CIPHER_CTX_cleanup(&ctx);
354 i+=j;
355 ret=1;
356 }
357 else
358 {
359 ret=1;
360 buf[0]='\0';
361 }
362 i=PEM_write_bio(bp,name,buf,data,i);
363 if (i <= 0) ret=0;
364err:
365 memset(key,0,sizeof(key));
366 memset(iv,0,sizeof(iv));
367 memset((char *)&ctx,0,sizeof(ctx));
368 memset(buf,0,PEM_BUFSIZE);
369 if (data != NULL)
370 {
371 memset(data,0,(unsigned int)dsize);
372 OPENSSL_free(data);
373 }
374 return(ret);
375 }
376
377int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
378 pem_password_cb *callback,void *u)
379 {
380 int i,j,o,klen;
381 long len;
382 EVP_CIPHER_CTX ctx;
383 unsigned char key[EVP_MAX_KEY_LENGTH];
384 char buf[PEM_BUFSIZE];
385
386 len= *plen;
387
388 if (cipher->cipher == NULL) return(1);
389 if (callback == NULL)
390 klen=PEM_def_callback(buf,PEM_BUFSIZE,0,u);
391 else
392 klen=callback(buf,PEM_BUFSIZE,0,u);
393 if (klen <= 0)
394 {
395 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
396 return(0);
397 }
398#ifdef CHARSET_EBCDIC
399 /* Convert the pass phrase from EBCDIC */
400 ebcdic2ascii(buf, buf, klen);
401#endif
402
403 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
404 (unsigned char *)buf,klen,1,key,NULL);
405
406 j=(int)len;
407 EVP_CIPHER_CTX_init(&ctx);
408 EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0]));
409 EVP_DecryptUpdate(&ctx,data,&i,data,j);
410 o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j);
411 EVP_CIPHER_CTX_cleanup(&ctx);
412 memset((char *)buf,0,sizeof(buf));
413 memset((char *)key,0,sizeof(key));
414 j+=i;
415 if (!o)
416 {
417 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
418 return(0);
419 }
420 *plen=j;
421 return(1);
422 }
423
424int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
425 {
426 int o;
427 const EVP_CIPHER *enc=NULL;
428 char *p,c;
429
430 cipher->cipher=NULL;
431 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
432 return(1);
433 if (strncmp(header,"Proc-Type: ",11) != 0)
434 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
435 header+=11;
436 if (*header != '4') return(0); header++;
437 if (*header != ',') return(0); header++;
438 if (strncmp(header,"ENCRYPTED",9) != 0)
439 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
440 for (; (*header != '\n') && (*header != '\0'); header++)
441 ;
442 if (*header == '\0')
443 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
444 header++;
445 if (strncmp(header,"DEK-Info: ",10) != 0)
446 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
447 header+=10;
448
449 p=header;
450 for (;;)
451 {
452 c= *header;
453#ifndef CHARSET_EBCDIC
454 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
455 ((c >= '0') && (c <= '9'))))
456 break;
457#else
458 if (!( isupper(c) || (c == '-') ||
459 isdigit(c)))
460 break;
461#endif
462 header++;
463 }
464 *header='\0';
465 o=OBJ_sn2nid(p);
466 cipher->cipher=enc=EVP_get_cipherbyname(p);
467 *header=c;
468 header++;
469
470 if (enc == NULL)
471 {
472 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
473 return(0);
474 }
475 if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),enc->iv_len)) return(0);
476
477 return(1);
478 }
479
480static int load_iv(unsigned char **fromp, unsigned char *to, int num)
481 {
482 int v,i;
483 unsigned char *from;
484
485 from= *fromp;
486 for (i=0; i<num; i++) to[i]=0;
487 num*=2;
488 for (i=0; i<num; i++)
489 {
490 if ((*from >= '0') && (*from <= '9'))
491 v= *from-'0';
492 else if ((*from >= 'A') && (*from <= 'F'))
493 v= *from-'A'+10;
494 else if ((*from >= 'a') && (*from <= 'f'))
495 v= *from-'a'+10;
496 else
497 {
498 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
499 return(0);
500 }
501 from++;
502 to[i/2]|=v<<(long)((!(i&1))*4);
503 }
504
505 *fromp=from;
506 return(1);
507 }
508
509#ifndef OPENSSL_NO_FP_API
510int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
511 long len)
512 {
513 BIO *b;
514 int ret;
515
516 if ((b=BIO_new(BIO_s_file())) == NULL)
517 {
518 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
519 return(0);
520 }
521 BIO_set_fp(b,fp,BIO_NOCLOSE);
522 ret=PEM_write_bio(b, name, header, data,len);
523 BIO_free(b);
524 return(ret);
525 }
526#endif
527
528int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
529 long len)
530 {
531 int nlen,n,i,j,outl;
532 unsigned char *buf;
533 EVP_ENCODE_CTX ctx;
534 int reason=ERR_R_BUF_LIB;
535
536 EVP_EncodeInit(&ctx);
537 nlen=strlen(name);
538
539 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
540 (BIO_write(bp,name,nlen) != nlen) ||
541 (BIO_write(bp,"-----\n",6) != 6))
542 goto err;
543
544 i=strlen(header);
545 if (i > 0)
546 {
547 if ( (BIO_write(bp,header,i) != i) ||
548 (BIO_write(bp,"\n",1) != 1))
549 goto err;
550 }
551
552 buf=(unsigned char *)OPENSSL_malloc(PEM_BUFSIZE*8);
553 if (buf == NULL)
554 {
555 reason=ERR_R_MALLOC_FAILURE;
556 goto err;
557 }
558
559 i=j=0;
560 while (len > 0)
561 {
562 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
563 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
564 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
565 goto err;
566 i+=outl;
567 len-=n;
568 j+=n;
569 }
570 EVP_EncodeFinal(&ctx,buf,&outl);
571 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
572 OPENSSL_free(buf);
573 if ( (BIO_write(bp,"-----END ",9) != 9) ||
574 (BIO_write(bp,name,nlen) != nlen) ||
575 (BIO_write(bp,"-----\n",6) != 6))
576 goto err;
577 return(i+outl);
578err:
579 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
580 return(0);
581 }
582
583#ifndef OPENSSL_NO_FP_API
584int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
585 long *len)
586 {
587 BIO *b;
588 int ret;
589
590 if ((b=BIO_new(BIO_s_file())) == NULL)
591 {
592 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
593 return(0);
594 }
595 BIO_set_fp(b,fp,BIO_NOCLOSE);
596 ret=PEM_read_bio(b, name, header, data,len);
597 BIO_free(b);
598 return(ret);
599 }
600#endif
601
602int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
603 long *len)
604 {
605 EVP_ENCODE_CTX ctx;
606 int end=0,i,k,bl=0,hl=0,nohead=0;
607 char buf[256];
608 BUF_MEM *nameB;
609 BUF_MEM *headerB;
610 BUF_MEM *dataB,*tmpB;
611
612 nameB=BUF_MEM_new();
613 headerB=BUF_MEM_new();
614 dataB=BUF_MEM_new();
615 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
616 {
617 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
618 return(0);
619 }
620
621 buf[254]='\0';
622 for (;;)
623 {
624 i=BIO_gets(bp,buf,254);
625
626 if (i <= 0)
627 {
628 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
629 goto err;
630 }
631
632 while ((i >= 0) && (buf[i] <= ' ')) i--;
633 buf[++i]='\n'; buf[++i]='\0';
634
635 if (strncmp(buf,"-----BEGIN ",11) == 0)
636 {
637 i=strlen(&(buf[11]));
638
639 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
640 continue;
641 if (!BUF_MEM_grow(nameB,i+9))
642 {
643 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
644 goto err;
645 }
646 memcpy(nameB->data,&(buf[11]),i-6);
647 nameB->data[i-6]='\0';
648 break;
649 }
650 }
651 hl=0;
652 if (!BUF_MEM_grow(headerB,256))
653 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
654 headerB->data[0]='\0';
655 for (;;)
656 {
657 i=BIO_gets(bp,buf,254);
658 if (i <= 0) break;
659
660 while ((i >= 0) && (buf[i] <= ' ')) i--;
661 buf[++i]='\n'; buf[++i]='\0';
662
663 if (buf[0] == '\n') break;
664 if (!BUF_MEM_grow(headerB,hl+i+9))
665 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
666 if (strncmp(buf,"-----END ",9) == 0)
667 {
668 nohead=1;
669 break;
670 }
671 memcpy(&(headerB->data[hl]),buf,i);
672 headerB->data[hl+i]='\0';
673 hl+=i;
674 }
675
676 bl=0;
677 if (!BUF_MEM_grow(dataB,1024))
678 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
679 dataB->data[0]='\0';
680 if (!nohead)
681 {
682 for (;;)
683 {
684 i=BIO_gets(bp,buf,254);
685 if (i <= 0) break;
686
687 while ((i >= 0) && (buf[i] <= ' ')) i--;
688 buf[++i]='\n'; buf[++i]='\0';
689
690 if (i != 65) end=1;
691 if (strncmp(buf,"-----END ",9) == 0)
692 break;
693 if (i > 65) break;
694 if (!BUF_MEM_grow(dataB,i+bl+9))
695 {
696 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
697 goto err;
698 }
699 memcpy(&(dataB->data[bl]),buf,i);
700 dataB->data[bl+i]='\0';
701 bl+=i;
702 if (end)
703 {
704 buf[0]='\0';
705 i=BIO_gets(bp,buf,254);
706 if (i <= 0) break;
707
708 while ((i >= 0) && (buf[i] <= ' ')) i--;
709 buf[++i]='\n'; buf[++i]='\0';
710
711 break;
712 }
713 }
714 }
715 else
716 {
717 tmpB=headerB;
718 headerB=dataB;
719 dataB=tmpB;
720 bl=hl;
721 }
722 i=strlen(nameB->data);
723 if ( (strncmp(buf,"-----END ",9) != 0) ||
724 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
725 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
726 {
727 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
728 goto err;
729 }
730
731 EVP_DecodeInit(&ctx);
732 i=EVP_DecodeUpdate(&ctx,
733 (unsigned char *)dataB->data,&bl,
734 (unsigned char *)dataB->data,bl);
735 if (i < 0)
736 {
737 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
738 goto err;
739 }
740 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
741 if (i < 0)
742 {
743 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
744 goto err;
745 }
746 bl+=k;
747
748 if (bl == 0) goto err;
749 *name=nameB->data;
750 *header=headerB->data;
751 *data=(unsigned char *)dataB->data;
752 *len=bl;
753 OPENSSL_free(nameB);
754 OPENSSL_free(headerB);
755 OPENSSL_free(dataB);
756 return(1);
757err:
758 BUF_MEM_free(nameB);
759 BUF_MEM_free(headerB);
760 BUF_MEM_free(dataB);
761 return(0);
762 }
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c
deleted file mode 100644
index 8d9064ea7c..0000000000
--- a/src/lib/libcrypto/pem/pem_oth.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/* crypto/pem/pem_oth.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68/* Handle 'other' PEMs: not private keys */
69
70char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
71 pem_password_cb *cb, void *u)
72 {
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 char *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
78 return NULL;
79 p = data;
80 ret=d2i(x,&p,len);
81 if (ret == NULL)
82 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
83 OPENSSL_free(data);
84 return(ret);
85 }
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
deleted file mode 100644
index f44182ffb5..0000000000
--- a/src/lib/libcrypto/pem/pem_pk8.c
+++ /dev/null
@@ -1,243 +0,0 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
70 int nid, const EVP_CIPHER *enc,
71 char *kstr, int klen,
72 pem_password_cb *cb, void *u);
73static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
74 int nid, const EVP_CIPHER *enc,
75 char *kstr, int klen,
76 pem_password_cb *cb, void *u);
77
78/* These functions write a private key in PKCS#8 format: it is a "drop in"
79 * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
80 * is NULL then it uses the unencrypted private key form. The 'nid' versions
81 * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
82 */
83
84int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
85 char *kstr, int klen,
86 pem_password_cb *cb, void *u)
87{
88 return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
89}
90
91int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
92 char *kstr, int klen,
93 pem_password_cb *cb, void *u)
94{
95 return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
96}
97
98int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
99 char *kstr, int klen,
100 pem_password_cb *cb, void *u)
101{
102 return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
103}
104
105int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
106 char *kstr, int klen,
107 pem_password_cb *cb, void *u)
108{
109 return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
110}
111
112static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
113 char *kstr, int klen,
114 pem_password_cb *cb, void *u)
115{
116 X509_SIG *p8;
117 PKCS8_PRIV_KEY_INFO *p8inf;
118 char buf[PEM_BUFSIZE];
119 int ret;
120 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
121 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
122 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
123 return 0;
124 }
125 if(enc || (nid != -1)) {
126 if(!kstr) {
127 if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
128 else klen = cb(buf, PEM_BUFSIZE, 1, u);
129 if(klen <= 0) {
130 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
131 PEM_R_READ_KEY);
132 PKCS8_PRIV_KEY_INFO_free(p8inf);
133 return 0;
134 }
135
136 kstr = buf;
137 }
138 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
139 if(kstr == buf) memset(buf, 0, klen);
140 PKCS8_PRIV_KEY_INFO_free(p8inf);
141 if(isder) ret = i2d_PKCS8_bio(bp, p8);
142 else ret = PEM_write_bio_PKCS8(bp, p8);
143 X509_SIG_free(p8);
144 return ret;
145 } else {
146 if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
147 else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
148 PKCS8_PRIV_KEY_INFO_free(p8inf);
149 return ret;
150 }
151}
152
153EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
154{
155 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
156 X509_SIG *p8 = NULL;
157 int klen;
158 EVP_PKEY *ret;
159 char psbuf[PEM_BUFSIZE];
160 p8 = d2i_PKCS8_bio(bp, NULL);
161 if(!p8) return NULL;
162 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
163 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
164 if (klen <= 0) {
165 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
166 X509_SIG_free(p8);
167 return NULL;
168 }
169 p8inf = PKCS8_decrypt(p8, psbuf, klen);
170 X509_SIG_free(p8);
171 if(!p8inf) return NULL;
172 ret = EVP_PKCS82PKEY(p8inf);
173 PKCS8_PRIV_KEY_INFO_free(p8inf);
174 if(!ret) return NULL;
175 if(x) {
176 if(*x) EVP_PKEY_free(*x);
177 *x = ret;
178 }
179 return ret;
180}
181
182#ifndef OPENSSL_NO_FP_API
183
184int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
185 char *kstr, int klen,
186 pem_password_cb *cb, void *u)
187{
188 return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
189}
190
191int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
192 char *kstr, int klen,
193 pem_password_cb *cb, void *u)
194{
195 return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
196}
197
198int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
199 char *kstr, int klen,
200 pem_password_cb *cb, void *u)
201{
202 return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
203}
204
205int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
206 char *kstr, int klen, pem_password_cb *cb, void *u)
207{
208 return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
209}
210
211static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
212 char *kstr, int klen,
213 pem_password_cb *cb, void *u)
214{
215 BIO *bp;
216 int ret;
217 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
218 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
219 return(0);
220 }
221 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
222 BIO_free(bp);
223 return ret;
224}
225
226EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
227{
228 BIO *bp;
229 EVP_PKEY *ret;
230 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
231 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
232 return NULL;
233 }
234 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
235 BIO_free(bp);
236 return ret;
237}
238
239#endif
240
241IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
242IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
243 PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
deleted file mode 100644
index d96ecf6940..0000000000
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69
70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
71 {
72 char *nm=NULL;
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 EVP_PKEY *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
78 return NULL;
79 p = data;
80
81 if (strcmp(nm,PEM_STRING_RSA) == 0)
82 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
83 else if (strcmp(nm,PEM_STRING_DSA) == 0)
84 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
85 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
86 PKCS8_PRIV_KEY_INFO *p8inf;
87 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
88 if(!p8inf) goto p8err;
89 ret = EVP_PKCS82PKEY(p8inf);
90 PKCS8_PRIV_KEY_INFO_free(p8inf);
91 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
92 PKCS8_PRIV_KEY_INFO *p8inf;
93 X509_SIG *p8;
94 int klen;
95 char psbuf[PEM_BUFSIZE];
96 p8 = d2i_X509_SIG(NULL, &p, len);
97 if(!p8) goto p8err;
98 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
99 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
100 if (klen <= 0) {
101 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
102 PEM_R_BAD_PASSWORD_READ);
103 goto err;
104 }
105 p8inf = PKCS8_decrypt(p8, psbuf, klen);
106 X509_SIG_free(p8);
107 if(!p8inf) goto p8err;
108 ret = EVP_PKCS82PKEY(p8inf);
109 if(x) {
110 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
111 *x = ret;
112 }
113 PKCS8_PRIV_KEY_INFO_free(p8inf);
114 }
115p8err:
116 if (ret == NULL)
117 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
118err:
119 OPENSSL_free(nm);
120 OPENSSL_free(data);
121 return(ret);
122 }
123
124#ifndef OPENSSL_NO_FP_API
125EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
126 {
127 BIO *b;
128 EVP_PKEY *ret;
129
130 if ((b=BIO_new(BIO_s_file())) == NULL)
131 {
132 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
133 return(0);
134 }
135 BIO_set_fp(b,fp,BIO_NOCLOSE);
136 ret=PEM_read_bio_PrivateKey(b,x,cb,u);
137 BIO_free(b);
138 return(ret);
139 }
140#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
deleted file mode 100644
index ae463a301d..0000000000
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/* crypto/pem/pem_seal.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/rand.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
69 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
70 int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int ret= -1;
74 int i,j,max=0;
75 char *s=NULL;
76
77 for (i=0; i<npubk; i++)
78 {
79 if (pubk[i]->type != EVP_PKEY_RSA)
80 {
81 PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA);
82 goto err;
83 }
84 j=RSA_size(pubk[i]->pkey.rsa);
85 if (j > max) max=j;
86 }
87 s=(char *)OPENSSL_malloc(max*2);
88 if (s == NULL)
89 {
90 PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93
94 EVP_EncodeInit(&ctx->encode);
95
96 EVP_MD_CTX_init(&ctx->md);
97 EVP_SignInit(&ctx->md,md_type);
98
99 EVP_CIPHER_CTX_init(&ctx->cipher);
100 ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk);
101 if (!ret) goto err;
102
103 /* base64 encode the keys */
104 for (i=0; i<npubk; i++)
105 {
106 j=EVP_EncodeBlock((unsigned char *)s,ek[i],
107 RSA_size(pubk[i]->pkey.rsa));
108 ekl[i]=j;
109 memcpy(ek[i],s,j+1);
110 }
111
112 ret=npubk;
113err:
114 if (s != NULL) OPENSSL_free(s);
115 memset(key,0,EVP_MAX_KEY_LENGTH);
116 return(ret);
117 }
118
119void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
120 unsigned char *in, int inl)
121 {
122 unsigned char buffer[1600];
123 int i,j;
124
125 *outl=0;
126 EVP_SignUpdate(&ctx->md,in,inl);
127 for (;;)
128 {
129 if (inl <= 0) break;
130 if (inl > 1200)
131 i=1200;
132 else
133 i=inl;
134 EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i);
135 EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j);
136 *outl+=j;
137 out+=j;
138 in+=i;
139 inl-=i;
140 }
141 }
142
143int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
144 unsigned char *out, int *outl, EVP_PKEY *priv)
145 {
146 unsigned char *s=NULL;
147 int ret=0,j;
148 unsigned int i;
149
150 if (priv->type != EVP_PKEY_RSA)
151 {
152 PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA);
153 goto err;
154 }
155 i=RSA_size(priv->pkey.rsa);
156 if (i < 100) i=100;
157 s=(unsigned char *)OPENSSL_malloc(i*2);
158 if (s == NULL)
159 {
160 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
161 goto err;
162 }
163
164 EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i);
165 EVP_EncodeUpdate(&ctx->encode,out,&j,s,i);
166 *outl=j;
167 out+=j;
168 EVP_EncodeFinal(&ctx->encode,out,&j);
169 *outl+=j;
170
171 if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err;
172 *sigl=EVP_EncodeBlock(sig,s,i);
173
174 ret=1;
175err:
176 EVP_MD_CTX_cleanup(&ctx->md);
177 EVP_CIPHER_CTX_cleanup(&ctx->cipher);
178 if (s != NULL) OPENSSL_free(s);
179 return(ret);
180 }
181#else /* !OPENSSL_NO_RSA */
182
183# if PEDANTIC
184static void *dummy=&dummy;
185# endif
186
187#endif
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
deleted file mode 100644
index c3b9808cb2..0000000000
--- a/src/lib/libcrypto/pem/pem_sign.c
+++ /dev/null
@@ -1,102 +0,0 @@
1/* crypto/pem/pem_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
67void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
68 {
69 EVP_DigestInit_ex(ctx, type, NULL);
70 }
71
72void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
73 unsigned int count)
74 {
75 EVP_DigestUpdate(ctx,data,count);
76 }
77
78int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char *m;
82 int i,ret=0;
83 unsigned int m_len;
84
85 m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2);
86 if (m == NULL)
87 {
88 PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
89 goto err;
90 }
91
92 if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err;
93
94 i=EVP_EncodeBlock(sigret,m,m_len);
95 *siglen=i;
96 ret=1;
97err:
98 /* ctx has been zeroed by EVP_SignFinal() */
99 if (m != NULL) OPENSSL_free(m);
100 return(ret);
101 }
102
diff --git a/src/lib/libcrypto/pem/pem_x509.c b/src/lib/libcrypto/pem/pem_x509.c
deleted file mode 100644
index 19f88d8d3a..0000000000
--- a/src/lib/libcrypto/pem/pem_x509.c
+++ /dev/null
@@ -1,69 +0,0 @@
1/* pem_x509.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69
diff --git a/src/lib/libcrypto/pem/pem_xaux.c b/src/lib/libcrypto/pem/pem_xaux.c
deleted file mode 100644
index 2f579b5421..0000000000
--- a/src/lib/libcrypto/pem/pem_xaux.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/* pem_xaux.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
diff --git a/src/lib/libcrypto/pem/pkcs7.lis b/src/lib/libcrypto/pem/pkcs7.lis
deleted file mode 100644
index be90c5d87f..0000000000
--- a/src/lib/libcrypto/pem/pkcs7.lis
+++ /dev/null
@@ -1,22 +0,0 @@
121 0:d=0 hl=2 l= 0 cons: univ: SEQUENCE
2 00 2:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-signedData
3 21 13:d=0 hl=2 l= 0 cons: cont: 00 # explicit tag
4 21 15:d=0 hl=2 l= 0 cons: univ: SEQUENCE
5 00 17:d=0 hl=2 l= 1 prim: univ: INTEGER # version
6 20 20:d=0 hl=2 l= 0 cons: univ: SET
7 21 22:d=0 hl=2 l= 0 cons: univ: SEQUENCE
8 00 24:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-data
9 00 35:d=0 hl=2 l= 0 prim: univ: EOC
10 21 37:d=0 hl=2 l= 0 cons: cont: 00 # cert tag
11 20 39:d=0 hl=4 l=545 cons: univ: SEQUENCE
12 20 588:d=0 hl=4 l=524 cons: univ: SEQUENCE
13 00 1116:d=0 hl=2 l= 0 prim: univ: EOC
14 21 1118:d=0 hl=2 l= 0 cons: cont: 01 # crl tag
15 20 1120:d=0 hl=4 l=653 cons: univ: SEQUENCE
16 20 1777:d=0 hl=4 l=285 cons: univ: SEQUENCE
17 00 2066:d=0 hl=2 l= 0 prim: univ: EOC
18 21 2068:d=0 hl=2 l= 0 cons: univ: SET # signers
19 00 2070:d=0 hl=2 l= 0 prim: univ: EOC
20 00 2072:d=0 hl=2 l= 0 prim: univ: EOC
21 00 2074:d=0 hl=2 l= 0 prim: univ: EOC
2200 2076:d=0 hl=2 l= 0 prim: univ: EOC