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