summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2005-03-12 00:02:08 +0000
committercvs2svn <admin@example.com>2005-03-12 00:02:08 +0000
commit259e36b1c57849c281afb8526bab11e7ba2592e2 (patch)
treed0e478b7669f593934b32e564b5611b40796a4b1 /src/lib/libcrypto/pem
parent9a03506f8308b6023a12f108a2072feb958607a6 (diff)
downloadopenbsd-OPENBSD_3_7_BASE.tar.gz
openbsd-OPENBSD_3_7_BASE.tar.bz2
openbsd-OPENBSD_3_7_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_3_7_BASE'.OPENBSD_3_7_BASE
Diffstat (limited to 'src/lib/libcrypto/pem')
-rw-r--r--src/lib/libcrypto/pem/message16
-rw-r--r--src/lib/libcrypto/pem/pem.h672
-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.c365
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c771
-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.c144
-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, 3141 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 d330cbf9a3..0000000000
--- a/src/lib/libcrypto/pem/pem.h
+++ /dev/null
@@ -1,672 +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]; unused and wrong size */
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 /* unused, and wrong size
169 unsigned char iv[8]; */
170 } DEK_info;
171
172 PEM_USER *originator;
173
174 int num_recipient;
175 PEM_USER **recipient;
176
177#ifndef OPENSSL_NO_STACK
178 STACK *x509_chain; /* certificate chain */
179#else
180 char *x509_chain; /* certificate chain */
181#endif
182 EVP_MD *md; /* signature type */
183
184 int md_enc; /* is the md encrypted or not? */
185 int md_len; /* length of md_data */
186 char *md_data; /* message digest, could be pkey encrypted */
187
188 EVP_CIPHER *dec; /* date encryption cipher */
189 int key_len; /* key length */
190 unsigned char *key; /* key */
191 /* unused, and wrong size
192 unsigned char iv[8]; */
193
194
195 int data_enc; /* is the data encrypted */
196 int data_len;
197 unsigned char *data;
198 } PEM_CTX;
199
200/* These macros make the PEM_read/PEM_write functions easier to maintain and
201 * write. Now they are all implemented with either:
202 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
203 */
204
205#ifdef OPENSSL_NO_FP_API
206
207#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
208#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
209#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
210
211#else
212
213#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
214type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
215{ \
216return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
217 cb,u)); \
218} \
219
220#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
221int PEM_write_##name(FILE *fp, type *x) \
222{ \
223return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
224 NULL,NULL,0,NULL,NULL)); \
225}
226
227#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
228int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
229 unsigned char *kstr, int klen, pem_password_cb *cb, \
230 void *u) \
231 { \
232 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
233 (char *)x,enc,kstr,klen,cb,u)); \
234 }
235
236#endif
237
238#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
239type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
240{ \
241return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
242 (char **)x,cb,u)); \
243}
244
245#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
246int PEM_write_bio_##name(BIO *bp, type *x) \
247{ \
248return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
249 NULL,NULL,0,NULL,NULL)); \
250}
251
252#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
253int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
254 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
255 { \
256 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
257 (char *)x,enc,kstr,klen,cb,u)); \
258 }
259
260#define IMPLEMENT_PEM_write(name, type, str, asn1) \
261 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
262 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
263
264#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
265 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
266 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
267
268#define IMPLEMENT_PEM_read(name, type, str, asn1) \
269 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
270 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
271
272#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
273 IMPLEMENT_PEM_read(name, type, str, asn1) \
274 IMPLEMENT_PEM_write(name, type, str, asn1)
275
276#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
277 IMPLEMENT_PEM_read(name, type, str, asn1) \
278 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
279
280/* These are the same except they are for the declarations */
281
282#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
283
284#define DECLARE_PEM_read_fp(name, type) /**/
285#define DECLARE_PEM_write_fp(name, type) /**/
286#define DECLARE_PEM_write_cb_fp(name, type) /**/
287
288#else
289
290#define DECLARE_PEM_read_fp(name, type) \
291 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
292
293#define DECLARE_PEM_write_fp(name, type) \
294 int PEM_write_##name(FILE *fp, type *x);
295
296#define DECLARE_PEM_write_cb_fp(name, type) \
297 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
299
300#endif
301
302#ifndef OPENSSL_NO_BIO
303#define DECLARE_PEM_read_bio(name, type) \
304 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
305
306#define DECLARE_PEM_write_bio(name, type) \
307 int PEM_write_bio_##name(BIO *bp, type *x);
308
309#define DECLARE_PEM_write_cb_bio(name, type) \
310 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
311 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
312
313#else
314
315#define DECLARE_PEM_read_bio(name, type) /**/
316#define DECLARE_PEM_write_bio(name, type) /**/
317#define DECLARE_PEM_write_cb_bio(name, type) /**/
318
319#endif
320
321#define DECLARE_PEM_write(name, type) \
322 DECLARE_PEM_write_bio(name, type) \
323 DECLARE_PEM_write_fp(name, type)
324
325#define DECLARE_PEM_write_cb(name, type) \
326 DECLARE_PEM_write_cb_bio(name, type) \
327 DECLARE_PEM_write_cb_fp(name, type)
328
329#define DECLARE_PEM_read(name, type) \
330 DECLARE_PEM_read_bio(name, type) \
331 DECLARE_PEM_read_fp(name, type)
332
333#define DECLARE_PEM_rw(name, type) \
334 DECLARE_PEM_read(name, type) \
335 DECLARE_PEM_write(name, type)
336
337#define DECLARE_PEM_rw_cb(name, type) \
338 DECLARE_PEM_read(name, type) \
339 DECLARE_PEM_write_cb(name, type)
340
341#ifdef SSLEAY_MACROS
342
343#define PEM_write_SSL_SESSION(fp,x) \
344 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
345 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
346#define PEM_write_X509(fp,x) \
347 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
348 (char *)x, NULL,NULL,0,NULL,NULL)
349#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
350 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
351 NULL,NULL,0,NULL,NULL)
352#define PEM_write_X509_CRL(fp,x) \
353 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
354 fp,(char *)x, NULL,NULL,0,NULL,NULL)
355#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
356 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
357 (char *)x,enc,kstr,klen,cb,u)
358#define PEM_write_RSAPublicKey(fp,x) \
359 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
360 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
361#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
362 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
363 (char *)x,enc,kstr,klen,cb,u)
364#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
365 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
366 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
367 bp,(char *)x,enc,kstr,klen,cb,u)
368#define PEM_write_PKCS7(fp,x) \
369 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
370 (char *)x, NULL,NULL,0,NULL,NULL)
371#define PEM_write_DHparams(fp,x) \
372 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
373 (char *)x,NULL,NULL,0,NULL,NULL)
374
375#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
376 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
377 PEM_STRING_X509,fp, \
378 (char *)x, NULL,NULL,0,NULL,NULL)
379
380#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
381 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
382#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
383 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
384#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
385 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
386#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
387 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
388#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
389 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
390#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
391 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
392#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
393 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
394#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
395 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
396#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
397 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
398#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
399 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
400
401#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
402 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
403 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
404 (char **)x,cb,u)
405
406#define PEM_write_bio_SSL_SESSION(bp,x) \
407 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
408 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
409#define PEM_write_bio_X509(bp,x) \
410 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
411 (char *)x, NULL,NULL,0,NULL,NULL)
412#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
413 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
414 NULL,NULL,0,NULL,NULL)
415#define PEM_write_bio_X509_CRL(bp,x) \
416 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
417 bp,(char *)x, NULL,NULL,0,NULL,NULL)
418#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
419 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
420 bp,(char *)x,enc,kstr,klen,cb,u)
421#define PEM_write_bio_RSAPublicKey(bp,x) \
422 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
423 PEM_STRING_RSA_PUBLIC,\
424 bp,(char *)x,NULL,NULL,0,NULL,NULL)
425#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
426 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
427 bp,(char *)x,enc,kstr,klen,cb,u)
428#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
429 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
430 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
431 bp,(char *)x,enc,kstr,klen,cb,u)
432#define PEM_write_bio_PKCS7(bp,x) \
433 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
434 (char *)x, NULL,NULL,0,NULL,NULL)
435#define PEM_write_bio_DHparams(bp,x) \
436 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
437 bp,(char *)x,NULL,NULL,0,NULL,NULL)
438#define PEM_write_bio_DSAparams(bp,x) \
439 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
440 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
441
442#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
443 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
444 PEM_STRING_X509,bp, \
445 (char *)x, NULL,NULL,0,NULL,NULL)
446
447#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
448 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
449#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
450 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
451#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
453#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
455#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
457#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
458 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
459#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
461#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
462 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
463
464#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
465 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
466#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
467 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
468#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
469 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
470
471#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
472 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
473 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
474 (char **)x,cb,u)
475
476#endif
477
478#if 1
479/* "userdata": new with OpenSSL 0.9.4 */
480typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
481#else
482/* OpenSSL 0.9.3, 0.9.3a */
483typedef int pem_password_cb(char *buf, int size, int rwflag);
484#endif
485
486int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
487int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
488 pem_password_cb *callback,void *u);
489
490#ifndef OPENSSL_NO_BIO
491int PEM_read_bio(BIO *bp, char **name, char **header,
492 unsigned char **data,long *len);
493int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
494 long len);
495int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
496 pem_password_cb *cb, void *u);
497char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
498 pem_password_cb *cb, void *u);
499int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
500 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
501 pem_password_cb *cb, void *u);
502STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
503int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
504 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
505#endif
506
507#ifndef OPENSSL_SYS_WIN16
508int PEM_read(FILE *fp, char **name, char **header,
509 unsigned char **data,long *len);
510int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
511char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
512 pem_password_cb *cb, void *u);
513int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
514 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
515 pem_password_cb *callback, void *u);
516STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
517 pem_password_cb *cb, void *u);
518#endif
519
520int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
521 EVP_MD *md_type, unsigned char **ek, int *ekl,
522 unsigned char *iv, EVP_PKEY **pubk, int npubk);
523void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
524 unsigned char *in, int inl);
525int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
526 unsigned char *out, int *outl, EVP_PKEY *priv);
527
528void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
529void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
530int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
531 unsigned int *siglen, EVP_PKEY *pkey);
532
533int PEM_def_callback(char *buf, int num, int w, void *key);
534void PEM_proc_type(char *buf, int type);
535void PEM_dek_info(char *buf, const char *type, int len, char *str);
536
537#ifndef SSLEAY_MACROS
538
539#include <openssl/symhacks.h>
540
541DECLARE_PEM_rw(X509, X509)
542
543DECLARE_PEM_rw(X509_AUX, X509)
544
545DECLARE_PEM_rw(X509_REQ, X509_REQ)
546DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
547
548DECLARE_PEM_rw(X509_CRL, X509_CRL)
549
550DECLARE_PEM_rw(PKCS7, PKCS7)
551
552DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
553
554DECLARE_PEM_rw(PKCS8, X509_SIG)
555
556DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
557
558#ifndef OPENSSL_NO_RSA
559
560DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
561
562DECLARE_PEM_rw(RSAPublicKey, RSA)
563DECLARE_PEM_rw(RSA_PUBKEY, RSA)
564
565#endif
566
567#ifndef OPENSSL_NO_DSA
568
569DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
570
571DECLARE_PEM_rw(DSA_PUBKEY, DSA)
572
573DECLARE_PEM_rw(DSAparams, DSA)
574
575#endif
576
577#ifndef OPENSSL_NO_DH
578
579DECLARE_PEM_rw(DHparams, DH)
580
581#endif
582
583DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
584
585DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
586
587int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
588 char *kstr, int klen,
589 pem_password_cb *cb, void *u);
590int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
591 char *, int, pem_password_cb *, void *);
592int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
593 char *kstr, int klen,
594 pem_password_cb *cb, void *u);
595int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
596 char *kstr, int klen,
597 pem_password_cb *cb, void *u);
598EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
599
600int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
601 char *kstr, int klen,
602 pem_password_cb *cb, void *u);
603int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
604 char *kstr, int klen,
605 pem_password_cb *cb, void *u);
606int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
607 char *kstr, int klen,
608 pem_password_cb *cb, void *u);
609
610EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
611
612int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
613 char *kstr,int klen, pem_password_cb *cd, void *u);
614
615#endif /* SSLEAY_MACROS */
616
617
618/* BEGIN ERROR CODES */
619/* The following lines are auto generated by the script mkerr.pl. Any changes
620 * made after this point may be overwritten when the script is next run.
621 */
622void ERR_load_PEM_strings(void);
623
624/* Error codes for the PEM functions. */
625
626/* Function codes. */
627#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
628#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
629#define PEM_F_DEF_CALLBACK 100
630#define PEM_F_LOAD_IV 101
631#define PEM_F_PEM_ASN1_READ 102
632#define PEM_F_PEM_ASN1_READ_BIO 103
633#define PEM_F_PEM_ASN1_WRITE 104
634#define PEM_F_PEM_ASN1_WRITE_BIO 105
635#define PEM_F_PEM_DO_HEADER 106
636#define PEM_F_PEM_F_DO_PK8KEY_FP 122
637#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
638#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
639#define PEM_F_PEM_READ 108
640#define PEM_F_PEM_READ_BIO 109
641#define PEM_F_PEM_SEALFINAL 110
642#define PEM_F_PEM_SEALINIT 111
643#define PEM_F_PEM_SIGNFINAL 112
644#define PEM_F_PEM_WRITE 113
645#define PEM_F_PEM_WRITE_BIO 114
646#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
647#define PEM_F_PEM_X509_INFO_READ 115
648#define PEM_F_PEM_X509_INFO_READ_BIO 116
649#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
650
651/* Reason codes. */
652#define PEM_R_BAD_BASE64_DECODE 100
653#define PEM_R_BAD_DECRYPT 101
654#define PEM_R_BAD_END_LINE 102
655#define PEM_R_BAD_IV_CHARS 103
656#define PEM_R_BAD_PASSWORD_READ 104
657#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
658#define PEM_R_NOT_DEK_INFO 105
659#define PEM_R_NOT_ENCRYPTED 106
660#define PEM_R_NOT_PROC_TYPE 107
661#define PEM_R_NO_START_LINE 108
662#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
663#define PEM_R_PUBLIC_KEY_NO_RSA 110
664#define PEM_R_READ_KEY 111
665#define PEM_R_SHORT_HEADER 112
666#define PEM_R_UNSUPPORTED_CIPHER 113
667#define PEM_R_UNSUPPORTED_ENCRYPTION 114
668
669#ifdef __cplusplus
670}
671#endif
672#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 9e4af29c95..0000000000
--- a/src/lib/libcrypto/pem/pem_info.c
+++ /dev/null
@@ -1,365 +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 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
328 buf[0]='\0';
329 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
330 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
331
332 /* use the normal code to write things out */
333 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
334 if (i <= 0) goto err;
335 }
336 else
337 {
338 /* Add DSA/DH */
339#ifndef OPENSSL_NO_RSA
340 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb,u)<=0)
344 goto err;
345#endif
346 }
347 }
348
349 /* if we have a certificate then write it out now */
350 if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0))
351 goto err;
352
353 /* we are ignoring anything else that is loaded into the X509_INFO
354 * structure for the moment ... as I don't need it so I'm not
355 * coding it here and Eric can do it when this makes it into the
356 * base library --tjh
357 */
358
359 ret=1;
360
361err:
362 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
363 OPENSSL_cleanse(buf,PEM_BUFSIZE);
364 return(ret);
365 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
deleted file mode 100644
index 7785039b99..0000000000
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ /dev/null
@@ -1,771 +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 BUF_strlcat(buf,"Proc-Type: 4,",PEM_BUFSIZE);
135 BUF_strlcat(buf,str,PEM_BUFSIZE);
136 BUF_strlcat(buf,"\n",PEM_BUFSIZE);
137 }
138
139void PEM_dek_info(char *buf, const char *type, int len, char *str)
140 {
141 static const unsigned char map[17]="0123456789ABCDEF";
142 long i;
143 int j;
144
145 BUF_strlcat(buf,"DEK-Info: ",PEM_BUFSIZE);
146 BUF_strlcat(buf,type,PEM_BUFSIZE);
147 BUF_strlcat(buf,",",PEM_BUFSIZE);
148 j=strlen(buf);
149 if (j + (len * 2) + 1 > PEM_BUFSIZE)
150 return;
151 for (i=0; i<len; i++)
152 {
153 buf[j+i*2] =map[(str[i]>>4)&0x0f];
154 buf[j+i*2+1]=map[(str[i] )&0x0f];
155 }
156 buf[j+i*2]='\n';
157 buf[j+i*2+1]='\0';
158 }
159
160#ifndef OPENSSL_NO_FP_API
161char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
162 pem_password_cb *cb, void *u)
163 {
164 BIO *b;
165 char *ret;
166
167 if ((b=BIO_new(BIO_s_file())) == NULL)
168 {
169 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
170 return(0);
171 }
172 BIO_set_fp(b,fp,BIO_NOCLOSE);
173 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
174 BIO_free(b);
175 return(ret);
176 }
177#endif
178
179static int check_pem(const char *nm, const char *name)
180{
181 /* Normal matching nm and name */
182 if (!strcmp(nm,name)) return 1;
183
184 /* Make PEM_STRING_EVP_PKEY match any private key */
185
186 if(!strcmp(nm,PEM_STRING_PKCS8) &&
187 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
188
189 if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
190 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
191
192 if(!strcmp(nm,PEM_STRING_RSA) &&
193 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
194
195 if(!strcmp(nm,PEM_STRING_DSA) &&
196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
197
198 /* Permit older strings */
199
200 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
201 !strcmp(name,PEM_STRING_X509)) return 1;
202
203 if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) &&
204 !strcmp(name,PEM_STRING_X509_REQ)) return 1;
205
206 /* Allow normal certs to be read as trusted certs */
207 if(!strcmp(nm,PEM_STRING_X509) &&
208 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
209
210 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
211 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
212
213 /* Some CAs use PKCS#7 with CERTIFICATE headers */
214 if(!strcmp(nm, PEM_STRING_X509) &&
215 !strcmp(name, PEM_STRING_PKCS7)) return 1;
216
217 return 0;
218}
219
220int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
221 pem_password_cb *cb, void *u)
222 {
223 EVP_CIPHER_INFO cipher;
224 char *nm=NULL,*header=NULL;
225 unsigned char *data=NULL;
226 long len;
227 int ret = 0;
228
229 for (;;)
230 {
231 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) {
232 if(ERR_GET_REASON(ERR_peek_error()) ==
233 PEM_R_NO_START_LINE)
234 ERR_add_error_data(2, "Expecting: ", name);
235 return 0;
236 }
237 if(check_pem(nm, name)) break;
238 OPENSSL_free(nm);
239 OPENSSL_free(header);
240 OPENSSL_free(data);
241 }
242 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
243 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
244
245 *pdata = data;
246 *plen = len;
247
248 if (pnm)
249 *pnm = nm;
250
251 ret = 1;
252
253err:
254 if (!ret || !pnm) OPENSSL_free(nm);
255 OPENSSL_free(header);
256 if (!ret) OPENSSL_free(data);
257 return ret;
258 }
259
260#ifndef OPENSSL_NO_FP_API
261int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
262 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
263 pem_password_cb *callback, void *u)
264 {
265 BIO *b;
266 int ret;
267
268 if ((b=BIO_new(BIO_s_file())) == NULL)
269 {
270 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
271 return(0);
272 }
273 BIO_set_fp(b,fp,BIO_NOCLOSE);
274 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
275 BIO_free(b);
276 return(ret);
277 }
278#endif
279
280int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
281 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
282 pem_password_cb *callback, void *u)
283 {
284 EVP_CIPHER_CTX ctx;
285 int dsize=0,i,j,ret=0;
286 unsigned char *p,*data=NULL;
287 const char *objstr=NULL;
288 char buf[PEM_BUFSIZE];
289 unsigned char key[EVP_MAX_KEY_LENGTH];
290 unsigned char iv[EVP_MAX_IV_LENGTH];
291
292 if (enc != NULL)
293 {
294 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
295 if (objstr == NULL)
296 {
297 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
298 goto err;
299 }
300 }
301
302 if ((dsize=i2d(x,NULL)) < 0)
303 {
304 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
305 dsize=0;
306 goto err;
307 }
308 /* dzise + 8 bytes are needed */
309 /* actually it needs the cipher block size extra... */
310 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20);
311 if (data == NULL)
312 {
313 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
314 goto err;
315 }
316 p=data;
317 i=i2d(x,&p);
318
319 if (enc != NULL)
320 {
321 if (kstr == NULL)
322 {
323 if (callback == NULL)
324 klen=PEM_def_callback(buf,PEM_BUFSIZE,1,u);
325 else
326 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
327 if (klen <= 0)
328 {
329 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
330 goto err;
331 }
332#ifdef CHARSET_EBCDIC
333 /* Convert the pass phrase from EBCDIC */
334 ebcdic2ascii(buf, buf, klen);
335#endif
336 kstr=(unsigned char *)buf;
337 }
338 RAND_add(data,i,0);/* put in the RSA key. */
339 OPENSSL_assert(enc->iv_len <= sizeof iv);
340 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
341 goto err;
342 /* The 'iv' is used as the iv and as a salt. It is
343 * NOT taken from the BytesToKey function */
344 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
345
346 if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE);
347
348 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
349
350 buf[0]='\0';
351 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
352 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
353 /* k=strlen(buf); */
354
355 EVP_CIPHER_CTX_init(&ctx);
356 EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv);
357 EVP_EncryptUpdate(&ctx,data,&j,data,i);
358 EVP_EncryptFinal_ex(&ctx,&(data[j]),&i);
359 EVP_CIPHER_CTX_cleanup(&ctx);
360 i+=j;
361 ret=1;
362 }
363 else
364 {
365 ret=1;
366 buf[0]='\0';
367 }
368 i=PEM_write_bio(bp,name,buf,data,i);
369 if (i <= 0) ret=0;
370err:
371 OPENSSL_cleanse(key,sizeof(key));
372 OPENSSL_cleanse(iv,sizeof(iv));
373 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
374 OPENSSL_cleanse(buf,PEM_BUFSIZE);
375 if (data != NULL)
376 {
377 OPENSSL_cleanse(data,(unsigned int)dsize);
378 OPENSSL_free(data);
379 }
380 return(ret);
381 }
382
383int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
384 pem_password_cb *callback,void *u)
385 {
386 int i,j,o,klen;
387 long len;
388 EVP_CIPHER_CTX ctx;
389 unsigned char key[EVP_MAX_KEY_LENGTH];
390 char buf[PEM_BUFSIZE];
391
392 len= *plen;
393
394 if (cipher->cipher == NULL) return(1);
395 if (callback == NULL)
396 klen=PEM_def_callback(buf,PEM_BUFSIZE,0,u);
397 else
398 klen=callback(buf,PEM_BUFSIZE,0,u);
399 if (klen <= 0)
400 {
401 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
402 return(0);
403 }
404#ifdef CHARSET_EBCDIC
405 /* Convert the pass phrase from EBCDIC */
406 ebcdic2ascii(buf, buf, klen);
407#endif
408
409 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
410 (unsigned char *)buf,klen,1,key,NULL);
411
412 j=(int)len;
413 EVP_CIPHER_CTX_init(&ctx);
414 EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0]));
415 EVP_DecryptUpdate(&ctx,data,&i,data,j);
416 o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j);
417 EVP_CIPHER_CTX_cleanup(&ctx);
418 OPENSSL_cleanse((char *)buf,sizeof(buf));
419 OPENSSL_cleanse((char *)key,sizeof(key));
420 j+=i;
421 if (!o)
422 {
423 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
424 return(0);
425 }
426 *plen=j;
427 return(1);
428 }
429
430int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
431 {
432 int o;
433 const EVP_CIPHER *enc=NULL;
434 char *p,c;
435
436 cipher->cipher=NULL;
437 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
438 return(1);
439 if (strncmp(header,"Proc-Type: ",11) != 0)
440 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
441 header+=11;
442 if (*header != '4') return(0); header++;
443 if (*header != ',') return(0); header++;
444 if (strncmp(header,"ENCRYPTED",9) != 0)
445 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
446 for (; (*header != '\n') && (*header != '\0'); header++)
447 ;
448 if (*header == '\0')
449 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
450 header++;
451 if (strncmp(header,"DEK-Info: ",10) != 0)
452 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
453 header+=10;
454
455 p=header;
456 for (;;)
457 {
458 c= *header;
459#ifndef CHARSET_EBCDIC
460 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
461 ((c >= '0') && (c <= '9'))))
462 break;
463#else
464 if (!( isupper(c) || (c == '-') ||
465 isdigit(c)))
466 break;
467#endif
468 header++;
469 }
470 *header='\0';
471 o=OBJ_sn2nid(p);
472 cipher->cipher=enc=EVP_get_cipherbyname(p);
473 *header=c;
474 header++;
475
476 if (enc == NULL)
477 {
478 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
479 return(0);
480 }
481 if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),enc->iv_len)) return(0);
482
483 return(1);
484 }
485
486static int load_iv(unsigned char **fromp, unsigned char *to, int num)
487 {
488 int v,i;
489 unsigned char *from;
490
491 from= *fromp;
492 for (i=0; i<num; i++) to[i]=0;
493 num*=2;
494 for (i=0; i<num; i++)
495 {
496 if ((*from >= '0') && (*from <= '9'))
497 v= *from-'0';
498 else if ((*from >= 'A') && (*from <= 'F'))
499 v= *from-'A'+10;
500 else if ((*from >= 'a') && (*from <= 'f'))
501 v= *from-'a'+10;
502 else
503 {
504 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
505 return(0);
506 }
507 from++;
508 to[i/2]|=v<<(long)((!(i&1))*4);
509 }
510
511 *fromp=from;
512 return(1);
513 }
514
515#ifndef OPENSSL_NO_FP_API
516int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
517 long len)
518 {
519 BIO *b;
520 int ret;
521
522 if ((b=BIO_new(BIO_s_file())) == NULL)
523 {
524 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
525 return(0);
526 }
527 BIO_set_fp(b,fp,BIO_NOCLOSE);
528 ret=PEM_write_bio(b, name, header, data,len);
529 BIO_free(b);
530 return(ret);
531 }
532#endif
533
534int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
535 long len)
536 {
537 int nlen,n,i,j,outl;
538 unsigned char *buf = NULL;
539 EVP_ENCODE_CTX ctx;
540 int reason=ERR_R_BUF_LIB;
541
542 EVP_EncodeInit(&ctx);
543 nlen=strlen(name);
544
545 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
546 (BIO_write(bp,name,nlen) != nlen) ||
547 (BIO_write(bp,"-----\n",6) != 6))
548 goto err;
549
550 i=strlen(header);
551 if (i > 0)
552 {
553 if ( (BIO_write(bp,header,i) != i) ||
554 (BIO_write(bp,"\n",1) != 1))
555 goto err;
556 }
557
558 buf = OPENSSL_malloc(PEM_BUFSIZE*8);
559 if (buf == NULL)
560 {
561 reason=ERR_R_MALLOC_FAILURE;
562 goto err;
563 }
564
565 i=j=0;
566 while (len > 0)
567 {
568 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
569 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
570 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
571 goto err;
572 i+=outl;
573 len-=n;
574 j+=n;
575 }
576 EVP_EncodeFinal(&ctx,buf,&outl);
577 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
578 OPENSSL_free(buf);
579 buf = NULL;
580 if ( (BIO_write(bp,"-----END ",9) != 9) ||
581 (BIO_write(bp,name,nlen) != nlen) ||
582 (BIO_write(bp,"-----\n",6) != 6))
583 goto err;
584 return(i+outl);
585err:
586 if (buf)
587 OPENSSL_free(buf);
588 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
589 return(0);
590 }
591
592#ifndef OPENSSL_NO_FP_API
593int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
594 long *len)
595 {
596 BIO *b;
597 int ret;
598
599 if ((b=BIO_new(BIO_s_file())) == NULL)
600 {
601 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
602 return(0);
603 }
604 BIO_set_fp(b,fp,BIO_NOCLOSE);
605 ret=PEM_read_bio(b, name, header, data,len);
606 BIO_free(b);
607 return(ret);
608 }
609#endif
610
611int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
612 long *len)
613 {
614 EVP_ENCODE_CTX ctx;
615 int end=0,i,k,bl=0,hl=0,nohead=0;
616 char buf[256];
617 BUF_MEM *nameB;
618 BUF_MEM *headerB;
619 BUF_MEM *dataB,*tmpB;
620
621 nameB=BUF_MEM_new();
622 headerB=BUF_MEM_new();
623 dataB=BUF_MEM_new();
624 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
625 {
626 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
627 return(0);
628 }
629
630 buf[254]='\0';
631 for (;;)
632 {
633 i=BIO_gets(bp,buf,254);
634
635 if (i <= 0)
636 {
637 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
638 goto err;
639 }
640
641 while ((i >= 0) && (buf[i] <= ' ')) i--;
642 buf[++i]='\n'; buf[++i]='\0';
643
644 if (strncmp(buf,"-----BEGIN ",11) == 0)
645 {
646 i=strlen(&(buf[11]));
647
648 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
649 continue;
650 if (!BUF_MEM_grow(nameB,i+9))
651 {
652 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
653 goto err;
654 }
655 memcpy(nameB->data,&(buf[11]),i-6);
656 nameB->data[i-6]='\0';
657 break;
658 }
659 }
660 hl=0;
661 if (!BUF_MEM_grow(headerB,256))
662 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
663 headerB->data[0]='\0';
664 for (;;)
665 {
666 i=BIO_gets(bp,buf,254);
667 if (i <= 0) break;
668
669 while ((i >= 0) && (buf[i] <= ' ')) i--;
670 buf[++i]='\n'; buf[++i]='\0';
671
672 if (buf[0] == '\n') break;
673 if (!BUF_MEM_grow(headerB,hl+i+9))
674 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
675 if (strncmp(buf,"-----END ",9) == 0)
676 {
677 nohead=1;
678 break;
679 }
680 memcpy(&(headerB->data[hl]),buf,i);
681 headerB->data[hl+i]='\0';
682 hl+=i;
683 }
684
685 bl=0;
686 if (!BUF_MEM_grow(dataB,1024))
687 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
688 dataB->data[0]='\0';
689 if (!nohead)
690 {
691 for (;;)
692 {
693 i=BIO_gets(bp,buf,254);
694 if (i <= 0) break;
695
696 while ((i >= 0) && (buf[i] <= ' ')) i--;
697 buf[++i]='\n'; buf[++i]='\0';
698
699 if (i != 65) end=1;
700 if (strncmp(buf,"-----END ",9) == 0)
701 break;
702 if (i > 65) break;
703 if (!BUF_MEM_grow_clean(dataB,i+bl+9))
704 {
705 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
706 goto err;
707 }
708 memcpy(&(dataB->data[bl]),buf,i);
709 dataB->data[bl+i]='\0';
710 bl+=i;
711 if (end)
712 {
713 buf[0]='\0';
714 i=BIO_gets(bp,buf,254);
715 if (i <= 0) break;
716
717 while ((i >= 0) && (buf[i] <= ' ')) i--;
718 buf[++i]='\n'; buf[++i]='\0';
719
720 break;
721 }
722 }
723 }
724 else
725 {
726 tmpB=headerB;
727 headerB=dataB;
728 dataB=tmpB;
729 bl=hl;
730 }
731 i=strlen(nameB->data);
732 if ( (strncmp(buf,"-----END ",9) != 0) ||
733 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
734 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
735 {
736 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
737 goto err;
738 }
739
740 EVP_DecodeInit(&ctx);
741 i=EVP_DecodeUpdate(&ctx,
742 (unsigned char *)dataB->data,&bl,
743 (unsigned char *)dataB->data,bl);
744 if (i < 0)
745 {
746 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
747 goto err;
748 }
749 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
750 if (i < 0)
751 {
752 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
753 goto err;
754 }
755 bl+=k;
756
757 if (bl == 0) goto err;
758 *name=nameB->data;
759 *header=headerB->data;
760 *data=(unsigned char *)dataB->data;
761 *len=bl;
762 OPENSSL_free(nameB);
763 OPENSSL_free(headerB);
764 OPENSSL_free(dataB);
765 return(1);
766err:
767 BUF_MEM_free(nameB);
768 BUF_MEM_free(headerB);
769 BUF_MEM_free(dataB);
770 return(0);
771 }
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 db38a2a79d..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) OPENSSL_cleanse(buf, 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 f77c949e87..0000000000
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ /dev/null
@@ -1,144 +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 if(x) {
91 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
92 *x = ret;
93 }
94 PKCS8_PRIV_KEY_INFO_free(p8inf);
95 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
96 PKCS8_PRIV_KEY_INFO *p8inf;
97 X509_SIG *p8;
98 int klen;
99 char psbuf[PEM_BUFSIZE];
100 p8 = d2i_X509_SIG(NULL, &p, len);
101 if(!p8) goto p8err;
102 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
103 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
104 if (klen <= 0) {
105 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
106 PEM_R_BAD_PASSWORD_READ);
107 goto err;
108 }
109 p8inf = PKCS8_decrypt(p8, psbuf, klen);
110 X509_SIG_free(p8);
111 if(!p8inf) goto p8err;
112 ret = EVP_PKCS82PKEY(p8inf);
113 if(x) {
114 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
115 *x = ret;
116 }
117 PKCS8_PRIV_KEY_INFO_free(p8inf);
118 }
119p8err:
120 if (ret == NULL)
121 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
122err:
123 OPENSSL_free(nm);
124 OPENSSL_free(data);
125 return(ret);
126 }
127
128#ifndef OPENSSL_NO_FP_API
129EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
130 {
131 BIO *b;
132 EVP_PKEY *ret;
133
134 if ((b=BIO_new(BIO_s_file())) == NULL)
135 {
136 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
137 return(0);
138 }
139 BIO_set_fp(b,fp,BIO_NOCLOSE);
140 ret=PEM_read_bio_PrivateKey(b,x,cb,u);
141 BIO_free(b);
142 return(ret);
143 }
144#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
deleted file mode 100644
index 56e08abd70..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 OPENSSL_cleanse(key,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