diff options
Diffstat (limited to 'src/lib/libcrypto/pem')
-rw-r--r-- | src/lib/libcrypto/pem/message | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem.h | 562 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem_all.c | 488 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem_err.c | 122 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem_info.c | 365 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem_lib.c | 762 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem_seal.c | 191 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pem_sign.c | 109 | ||||
-rw-r--r-- | src/lib/libcrypto/pem/pkcs7.lis | 22 |
9 files changed, 2637 insertions, 0 deletions
diff --git a/src/lib/libcrypto/pem/message b/src/lib/libcrypto/pem/message new file mode 100644 index 0000000000..e8bf9d7592 --- /dev/null +++ b/src/lib/libcrypto/pem/message | |||
@@ -0,0 +1,16 @@ | |||
1 | -----BEGIN PRIVACY-ENHANCED MESSAGE----- | ||
2 | Proc-Type: 4,ENCRYPTED | ||
3 | Proc-Type: 4,MIC-ONLY | ||
4 | Proc-Type: 4,MIC-CLEAR | ||
5 | Content-Domain: RFC822 | ||
6 | DEK-Info: DES-CBC,0123456789abcdef | ||
7 | Originator-Certificate | ||
8 | xxxx | ||
9 | Issuer-Certificate | ||
10 | xxxx | ||
11 | MIC-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 new file mode 100644 index 0000000000..55fbaeffe2 --- /dev/null +++ b/src/lib/libcrypto/pem/pem.h | |||
@@ -0,0 +1,562 @@ | |||
1 | /* crypto/pem/pem.org */ | ||
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 | /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | ||
60 | * | ||
61 | * Always modify pem.org since pem.h is automatically generated from | ||
62 | * it during SSLeay configuration. | ||
63 | * | ||
64 | * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | ||
65 | */ | ||
66 | |||
67 | #ifndef HEADER_PEM_H | ||
68 | #define HEADER_PEM_H | ||
69 | |||
70 | #ifdef __cplusplus | ||
71 | extern "C" { | ||
72 | #endif | ||
73 | |||
74 | #include "evp.h" | ||
75 | #include "x509.h" | ||
76 | |||
77 | #define PEM_OBJ_UNDEF 0 | ||
78 | #define PEM_OBJ_X509 1 | ||
79 | #define PEM_OBJ_X509_REQ 2 | ||
80 | #define PEM_OBJ_CRL 3 | ||
81 | #define PEM_OBJ_SSL_SESSION 4 | ||
82 | #define PEM_OBJ_PRIV_KEY 10 | ||
83 | #define PEM_OBJ_PRIV_RSA 11 | ||
84 | #define PEM_OBJ_PRIV_DSA 12 | ||
85 | #define PEM_OBJ_PRIV_DH 13 | ||
86 | #define PEM_OBJ_PUB_RSA 14 | ||
87 | #define PEM_OBJ_PUB_DSA 15 | ||
88 | #define PEM_OBJ_PUB_DH 16 | ||
89 | #define PEM_OBJ_DHPARAMS 17 | ||
90 | #define PEM_OBJ_DSAPARAMS 18 | ||
91 | #define PEM_OBJ_PRIV_RSA_PUBLIC 19 | ||
92 | |||
93 | #define PEM_ERROR 30 | ||
94 | #define PEM_DEK_DES_CBC 40 | ||
95 | #define PEM_DEK_IDEA_CBC 45 | ||
96 | #define PEM_DEK_DES_EDE 50 | ||
97 | #define PEM_DEK_DES_ECB 60 | ||
98 | #define PEM_DEK_RSA 70 | ||
99 | #define PEM_DEK_RSA_MD2 80 | ||
100 | #define PEM_DEK_RSA_MD5 90 | ||
101 | |||
102 | #define PEM_MD_MD2 NID_md2 | ||
103 | #define PEM_MD_MD5 NID_md5 | ||
104 | #define PEM_MD_SHA NID_sha | ||
105 | #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption | ||
106 | #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption | ||
107 | #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption | ||
108 | |||
109 | #define PEM_STRING_X509_OLD "X509 CERTIFICATE" | ||
110 | #define PEM_STRING_X509 "CERTIFICATE" | ||
111 | #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" | ||
112 | #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" | ||
113 | #define PEM_STRING_X509_CRL "X509 CRL" | ||
114 | #define PEM_STRING_EVP_PKEY "PRIVATE KEY" | ||
115 | #define PEM_STRING_RSA "RSA PRIVATE KEY" | ||
116 | #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" | ||
117 | #define PEM_STRING_DSA "DSA PRIVATE KEY" | ||
118 | #define PEM_STRING_PKCS7 "PKCS7" | ||
119 | #define PEM_STRING_DHPARAMS "DH PARAMETERS" | ||
120 | #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" | ||
121 | #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" | ||
122 | |||
123 | #ifndef HEADER_ENVELOPE_H | ||
124 | |||
125 | #define EVP_ENCODE_CTX_SIZE 96 | ||
126 | #define EVP_MD_SIZE 60 | ||
127 | #define EVP_MD_CTX_SIZE 152 | ||
128 | #define EVP_CIPHER_SIZE 40 | ||
129 | #define EVP_CIPHER_CTX_SIZE 4212 | ||
130 | #define EVP_MAX_MD_SIZE 20 | ||
131 | |||
132 | typedef struct evp_encode_ctx_st | ||
133 | { | ||
134 | char data[EVP_ENCODE_CTX_SIZE]; | ||
135 | } EVP_ENCODE_CTX; | ||
136 | |||
137 | typedef struct env_md_ctx_st | ||
138 | { | ||
139 | char data[EVP_MD_CTX_SIZE]; | ||
140 | } EVP_MD_CTX; | ||
141 | |||
142 | typedef struct evp_cipher_st | ||
143 | { | ||
144 | char data[EVP_CIPHER_SIZE]; | ||
145 | } EVP_CIPHER; | ||
146 | |||
147 | typedef struct evp_cipher_ctx_st | ||
148 | { | ||
149 | char data[EVP_CIPHER_CTX_SIZE]; | ||
150 | } EVP_CIPHER_CTX; | ||
151 | #endif | ||
152 | |||
153 | |||
154 | typedef struct PEM_Encode_Seal_st | ||
155 | { | ||
156 | EVP_ENCODE_CTX encode; | ||
157 | EVP_MD_CTX md; | ||
158 | EVP_CIPHER_CTX cipher; | ||
159 | } PEM_ENCODE_SEAL_CTX; | ||
160 | |||
161 | /* enc_type is one off */ | ||
162 | #define PEM_TYPE_ENCRYPTED 10 | ||
163 | #define PEM_TYPE_MIC_ONLY 20 | ||
164 | #define PEM_TYPE_MIC_CLEAR 30 | ||
165 | #define PEM_TYPE_CLEAR 40 | ||
166 | |||
167 | typedef struct pem_recip_st | ||
168 | { | ||
169 | char *name; | ||
170 | X509_NAME *dn; | ||
171 | |||
172 | int cipher; | ||
173 | int key_enc; | ||
174 | char iv[8]; | ||
175 | } PEM_USER; | ||
176 | |||
177 | typedef struct pem_ctx_st | ||
178 | { | ||
179 | int type; /* what type of object */ | ||
180 | |||
181 | struct { | ||
182 | int version; | ||
183 | int mode; | ||
184 | } proc_type; | ||
185 | |||
186 | char *domain; | ||
187 | |||
188 | struct { | ||
189 | int cipher; | ||
190 | unsigned char iv[8]; | ||
191 | } DEK_info; | ||
192 | |||
193 | PEM_USER *originator; | ||
194 | |||
195 | int num_recipient; | ||
196 | PEM_USER **recipient; | ||
197 | |||
198 | #ifdef HEADER_STACK_H | ||
199 | STACK *x509_chain; /* certificate chain */ | ||
200 | #else | ||
201 | char *x509_chain; /* certificate chain */ | ||
202 | #endif | ||
203 | EVP_MD *md; /* signature type */ | ||
204 | |||
205 | int md_enc; /* is the md encrypted or not? */ | ||
206 | int md_len; /* length of md_data */ | ||
207 | char *md_data; /* message digest, could be pkey encrypted */ | ||
208 | |||
209 | EVP_CIPHER *dec; /* date encryption cipher */ | ||
210 | int key_len; /* key length */ | ||
211 | unsigned char *key; /* key */ | ||
212 | unsigned char iv[8]; /* the iv */ | ||
213 | |||
214 | |||
215 | int data_enc; /* is the data encrypted */ | ||
216 | int data_len; | ||
217 | unsigned char *data; | ||
218 | } PEM_CTX; | ||
219 | |||
220 | #ifdef SSLEAY_MACROS | ||
221 | |||
222 | #define PEM_write_SSL_SESSION(fp,x) \ | ||
223 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | ||
224 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) | ||
225 | #define PEM_write_X509(fp,x) \ | ||
226 | PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ | ||
227 | (char *)x, NULL,NULL,0,NULL) | ||
228 | #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ | ||
229 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ | ||
230 | NULL,NULL,0,NULL) | ||
231 | #define PEM_write_X509_CRL(fp,x) \ | ||
232 | PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ | ||
233 | fp,(char *)x, NULL,NULL,0,NULL) | ||
234 | #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ | ||
235 | PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ | ||
236 | (char *)x,enc,kstr,klen,cb) | ||
237 | #define PEM_write_RSAPublicKey(fp,x) \ | ||
238 | PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ | ||
239 | PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) | ||
240 | #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ | ||
241 | PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ | ||
242 | (char *)x,enc,kstr,klen,cb) | ||
243 | #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
244 | PEM_ASN1_write((int (*)())i2d_PrivateKey,\ | ||
245 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | ||
246 | bp,(char *)x,enc,kstr,klen,cb) | ||
247 | #define PEM_write_PKCS7(fp,x) \ | ||
248 | PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ | ||
249 | (char *)x, NULL,NULL,0,NULL) | ||
250 | #define PEM_write_DHparams(fp,x) \ | ||
251 | PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ | ||
252 | (char *)x,NULL,NULL,0,NULL) | ||
253 | |||
254 | #define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ | ||
255 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) | ||
256 | #define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ | ||
257 | (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) | ||
258 | #define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ | ||
259 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) | ||
260 | #define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ | ||
261 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) | ||
262 | #define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ | ||
263 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) | ||
264 | #define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ | ||
265 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) | ||
266 | #define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ | ||
267 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) | ||
268 | #define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ | ||
269 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) | ||
270 | #define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ | ||
271 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) | ||
272 | #define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ | ||
273 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) | ||
274 | |||
275 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | ||
276 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | ||
277 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) | ||
278 | #define PEM_write_bio_X509(bp,x) \ | ||
279 | PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ | ||
280 | (char *)x, NULL,NULL,0,NULL) | ||
281 | #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ | ||
282 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ | ||
283 | NULL,NULL,0,NULL) | ||
284 | #define PEM_write_bio_X509_CRL(bp,x) \ | ||
285 | PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ | ||
286 | bp,(char *)x, NULL,NULL,0,NULL) | ||
287 | #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
288 | PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ | ||
289 | bp,(char *)x,enc,kstr,klen,cb) | ||
290 | #define PEM_write_bio_RSAPublicKey(bp,x) \ | ||
291 | PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ | ||
292 | PEM_STRING_RSA_PUBLIC,\ | ||
293 | bp,(char *)x,NULL,NULL,0,NULL) | ||
294 | #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
295 | PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ | ||
296 | bp,(char *)x,enc,kstr,klen,cb) | ||
297 | #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
298 | PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ | ||
299 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | ||
300 | bp,(char *)x,enc,kstr,klen,cb) | ||
301 | #define PEM_write_bio_PKCS7(bp,x) \ | ||
302 | PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ | ||
303 | (char *)x, NULL,NULL,0,NULL) | ||
304 | #define PEM_write_bio_DHparams(bp,x) \ | ||
305 | PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ | ||
306 | bp,(char *)x,NULL,NULL,0,NULL) | ||
307 | #define PEM_write_bio_DSAparams(bp,x) \ | ||
308 | PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ | ||
309 | PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) | ||
310 | |||
311 | #define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ | ||
312 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) | ||
313 | #define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ | ||
314 | (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) | ||
315 | #define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ | ||
316 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) | ||
317 | #define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ | ||
318 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) | ||
319 | #define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ | ||
320 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) | ||
321 | #define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ | ||
322 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) | ||
323 | #define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ | ||
324 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) | ||
325 | #define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ | ||
326 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) | ||
327 | |||
328 | #define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ | ||
329 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) | ||
330 | #define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ | ||
331 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) | ||
332 | #define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ | ||
333 | (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) | ||
334 | |||
335 | #endif | ||
336 | |||
337 | #ifndef NOPROTO | ||
338 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); | ||
339 | int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, | ||
340 | int (*callback)()); | ||
341 | |||
342 | #ifdef HEADER_BIO_H | ||
343 | int PEM_read_bio(BIO *bp, char **name, char **header, | ||
344 | unsigned char **data,long *len); | ||
345 | int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, | ||
346 | long len); | ||
347 | char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, | ||
348 | int (*cb)()); | ||
349 | int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, | ||
350 | EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); | ||
351 | STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); | ||
352 | int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, | ||
353 | unsigned char *kstr, int klen, int (*cb)()); | ||
354 | #endif | ||
355 | |||
356 | #ifndef WIN16 | ||
357 | int PEM_read(FILE *fp, char **name, char **header, | ||
358 | unsigned char **data,long *len); | ||
359 | int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); | ||
360 | char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, | ||
361 | int (*cb)()); | ||
362 | int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, | ||
363 | EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); | ||
364 | STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); | ||
365 | #endif | ||
366 | |||
367 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, | ||
368 | EVP_MD *md_type, unsigned char **ek, int *ekl, | ||
369 | unsigned char *iv, EVP_PKEY **pubk, int npubk); | ||
370 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, | ||
371 | unsigned char *in, int inl); | ||
372 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, | ||
373 | unsigned char *out, int *outl, EVP_PKEY *priv); | ||
374 | |||
375 | void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); | ||
376 | void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); | ||
377 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, | ||
378 | unsigned int *siglen, EVP_PKEY *pkey); | ||
379 | |||
380 | void ERR_load_PEM_strings(void); | ||
381 | |||
382 | void PEM_proc_type(char *buf, int type); | ||
383 | void PEM_dek_info(char *buf, char *type, int len, char *str); | ||
384 | |||
385 | #ifndef SSLEAY_MACROS | ||
386 | |||
387 | #ifndef WIN16 | ||
388 | X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); | ||
389 | X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)()); | ||
390 | X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)()); | ||
391 | RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)()); | ||
392 | RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)()); | ||
393 | DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)()); | ||
394 | EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)()); | ||
395 | PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)()); | ||
396 | DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)()); | ||
397 | DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)()); | ||
398 | int PEM_write_X509(FILE *fp,X509 *x); | ||
399 | int PEM_write_X509_REQ(FILE *fp,X509_REQ *x); | ||
400 | int PEM_write_X509_CRL(FILE *fp,X509_CRL *x); | ||
401 | int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr, | ||
402 | int klen,int (*cb)()); | ||
403 | int PEM_write_RSAPublicKey(FILE *fp,RSA *x); | ||
404 | int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr, | ||
405 | int klen,int (*cb)()); | ||
406 | int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc, | ||
407 | unsigned char *kstr,int klen,int (*cb)()); | ||
408 | int PEM_write_PKCS7(FILE *fp,PKCS7 *x); | ||
409 | int PEM_write_DHparams(FILE *fp,DH *x); | ||
410 | int PEM_write_DSAparams(FILE *fp,DSA *x); | ||
411 | #endif | ||
412 | |||
413 | #ifdef HEADER_BIO_H | ||
414 | X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); | ||
415 | X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); | ||
416 | X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); | ||
417 | RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); | ||
418 | RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); | ||
419 | DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); | ||
420 | EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); | ||
421 | PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); | ||
422 | DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); | ||
423 | DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); | ||
424 | int PEM_write_bio_X509(BIO *bp,X509 *x); | ||
425 | int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); | ||
426 | int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); | ||
427 | int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, | ||
428 | unsigned char *kstr,int klen,int (*cb)()); | ||
429 | int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); | ||
430 | int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, | ||
431 | unsigned char *kstr,int klen,int (*cb)()); | ||
432 | int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, | ||
433 | unsigned char *kstr,int klen,int (*cb)()); | ||
434 | int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x); | ||
435 | int PEM_write_bio_DHparams(BIO *bp,DH *x); | ||
436 | int PEM_write_bio_DSAparams(BIO *bp,DSA *x); | ||
437 | #endif | ||
438 | |||
439 | #endif /* SSLEAY_MACROS */ | ||
440 | |||
441 | |||
442 | #else | ||
443 | |||
444 | int PEM_get_EVP_CIPHER_INFO(); | ||
445 | int PEM_do_header(); | ||
446 | int PEM_read_bio(); | ||
447 | int PEM_write_bio(); | ||
448 | #ifndef WIN16 | ||
449 | int PEM_read(); | ||
450 | int PEM_write(); | ||
451 | STACK * PEM_X509_INFO_read(); | ||
452 | char * PEM_ASN1_read(); | ||
453 | int PEM_ASN1_write(); | ||
454 | #endif | ||
455 | STACK * PEM_X509_INFO_read_bio(); | ||
456 | int PEM_X509_INFO_write_bio(); | ||
457 | char * PEM_ASN1_read_bio(); | ||
458 | int PEM_ASN1_write_bio(); | ||
459 | int PEM_SealInit(); | ||
460 | void PEM_SealUpdate(); | ||
461 | int PEM_SealFinal(); | ||
462 | int PEM_SignFinal(); | ||
463 | |||
464 | void ERR_load_PEM_strings(); | ||
465 | |||
466 | void PEM_proc_type(); | ||
467 | void PEM_dek_info(); | ||
468 | |||
469 | #ifndef SSLEAY_MACROS | ||
470 | #ifndef WIN16 | ||
471 | X509 *PEM_read_X509(); | ||
472 | X509_REQ *PEM_read_X509_REQ(); | ||
473 | X509_CRL *PEM_read_X509_CRL(); | ||
474 | RSA *PEM_read_RSAPrivateKey(); | ||
475 | RSA *PEM_read_RSAPublicKey(); | ||
476 | DSA *PEM_read_DSAPrivateKey(); | ||
477 | EVP_PKEY *PEM_read_PrivateKey(); | ||
478 | PKCS7 *PEM_read_PKCS7(); | ||
479 | DH *PEM_read_DHparams(); | ||
480 | DSA *PEM_read_DSAparams(); | ||
481 | int PEM_write_X509(); | ||
482 | int PEM_write_X509_REQ(); | ||
483 | int PEM_write_X509_CRL(); | ||
484 | int PEM_write_RSAPrivateKey(); | ||
485 | int PEM_write_RSAPublicKey(); | ||
486 | int PEM_write_DSAPrivateKey(); | ||
487 | int PEM_write_PrivateKey(); | ||
488 | int PEM_write_PKCS7(); | ||
489 | int PEM_write_DHparams(); | ||
490 | int PEM_write_DSAparams(); | ||
491 | #endif | ||
492 | |||
493 | X509 *PEM_read_bio_X509(); | ||
494 | X509_REQ *PEM_read_bio_X509_REQ(); | ||
495 | X509_CRL *PEM_read_bio_X509_CRL(); | ||
496 | RSA *PEM_read_bio_RSAPrivateKey(); | ||
497 | RSA *PEM_read_bio_RSAPublicKey(); | ||
498 | DSA *PEM_read_bio_DSAPrivateKey(); | ||
499 | EVP_PKEY *PEM_read_bio_PrivateKey(); | ||
500 | PKCS7 *PEM_read_bio_PKCS7(); | ||
501 | DH *PEM_read_bio_DHparams(); | ||
502 | DSA *PEM_read_bio_DSAparams(); | ||
503 | int PEM_write_bio_X509(); | ||
504 | int PEM_write_bio_X509_REQ(); | ||
505 | int PEM_write_bio_X509_CRL(); | ||
506 | int PEM_write_bio_RSAPrivateKey(); | ||
507 | int PEM_write_bio_RSAPublicKey(); | ||
508 | int PEM_write_bio_DSAPrivateKey(); | ||
509 | int PEM_write_bio_PrivateKey(); | ||
510 | int PEM_write_bio_PKCS7(); | ||
511 | int PEM_write_bio_DHparams(); | ||
512 | int PEM_write_bio_DSAparams(); | ||
513 | |||
514 | #endif /* SSLEAY_MACROS */ | ||
515 | |||
516 | #endif | ||
517 | |||
518 | /* BEGIN ERROR CODES */ | ||
519 | /* Error codes for the PEM functions. */ | ||
520 | |||
521 | /* Function codes. */ | ||
522 | #define PEM_F_DEF_CALLBACK 100 | ||
523 | #define PEM_F_LOAD_IV 101 | ||
524 | #define PEM_F_PEM_ASN1_READ 102 | ||
525 | #define PEM_F_PEM_ASN1_READ_BIO 103 | ||
526 | #define PEM_F_PEM_ASN1_WRITE 104 | ||
527 | #define PEM_F_PEM_ASN1_WRITE_BIO 105 | ||
528 | #define PEM_F_PEM_DO_HEADER 106 | ||
529 | #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 | ||
530 | #define PEM_F_PEM_READ 108 | ||
531 | #define PEM_F_PEM_READ_BIO 109 | ||
532 | #define PEM_F_PEM_SEALFINAL 110 | ||
533 | #define PEM_F_PEM_SEALINIT 111 | ||
534 | #define PEM_F_PEM_SIGNFINAL 112 | ||
535 | #define PEM_F_PEM_WRITE 113 | ||
536 | #define PEM_F_PEM_WRITE_BIO 114 | ||
537 | #define PEM_F_PEM_X509_INFO_READ 115 | ||
538 | #define PEM_F_PEM_X509_INFO_READ_BIO 116 | ||
539 | #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 | ||
540 | |||
541 | /* Reason codes. */ | ||
542 | #define PEM_R_BAD_BASE64_DECODE 100 | ||
543 | #define PEM_R_BAD_DECRYPT 101 | ||
544 | #define PEM_R_BAD_END_LINE 102 | ||
545 | #define PEM_R_BAD_IV_CHARS 103 | ||
546 | #define PEM_R_BAD_PASSWORD_READ 104 | ||
547 | #define PEM_R_NOT_DEK_INFO 105 | ||
548 | #define PEM_R_NOT_ENCRYPTED 106 | ||
549 | #define PEM_R_NOT_PROC_TYPE 107 | ||
550 | #define PEM_R_NO_START_LINE 108 | ||
551 | #define PEM_R_PROBLEMS_GETTING_PASSWORD 109 | ||
552 | #define PEM_R_PUBLIC_KEY_NO_RSA 110 | ||
553 | #define PEM_R_READ_KEY 111 | ||
554 | #define PEM_R_SHORT_HEADER 112 | ||
555 | #define PEM_R_UNSUPPORTED_CIPHER 113 | ||
556 | #define PEM_R_UNSUPPORTED_ENCRYPTION 114 | ||
557 | |||
558 | #ifdef __cplusplus | ||
559 | } | ||
560 | #endif | ||
561 | #endif | ||
562 | |||
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c new file mode 100644 index 0000000000..d1cda7aabe --- /dev/null +++ b/src/lib/libcrypto/pem/pem_all.c | |||
@@ -0,0 +1,488 @@ | |||
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 "bio.h" | ||
63 | #include "evp.h" | ||
64 | #include "x509.h" | ||
65 | #include "pkcs7.h" | ||
66 | #include "pem.h" | ||
67 | |||
68 | #ifndef NO_FP_API | ||
69 | /* The X509 functions */ | ||
70 | X509 *PEM_read_X509(fp,x,cb) | ||
71 | FILE *fp; | ||
72 | X509 **x; | ||
73 | int (*cb)(); | ||
74 | { | ||
75 | return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509, | ||
76 | PEM_STRING_X509,fp,(char **)x,cb)); | ||
77 | } | ||
78 | #endif | ||
79 | |||
80 | X509 *PEM_read_bio_X509(bp,x,cb) | ||
81 | BIO *bp; | ||
82 | X509 **x; | ||
83 | int (*cb)(); | ||
84 | { | ||
85 | return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509, | ||
86 | PEM_STRING_X509,bp,(char **)x,cb)); | ||
87 | } | ||
88 | |||
89 | #ifndef NO_FP_API | ||
90 | int PEM_write_X509(fp,x) | ||
91 | FILE *fp; | ||
92 | X509 *x; | ||
93 | { | ||
94 | return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, | ||
95 | (char *)x, NULL,NULL,0,NULL)); | ||
96 | } | ||
97 | #endif | ||
98 | |||
99 | int PEM_write_bio_X509(bp,x) | ||
100 | BIO *bp; | ||
101 | X509 *x; | ||
102 | { | ||
103 | return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, | ||
104 | (char *)x, NULL,NULL,0,NULL)); | ||
105 | } | ||
106 | |||
107 | #ifndef NO_FP_API | ||
108 | /* The X509_REQ functions */ | ||
109 | X509_REQ *PEM_read_X509_REQ(fp,x,cb) | ||
110 | FILE *fp; | ||
111 | X509_REQ **x; | ||
112 | int (*cb)(); | ||
113 | { | ||
114 | return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ, | ||
115 | PEM_STRING_X509_REQ,fp,(char **)x,cb)); | ||
116 | } | ||
117 | #endif | ||
118 | |||
119 | X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) | ||
120 | BIO *bp; | ||
121 | X509_REQ **x; | ||
122 | int (*cb)(); | ||
123 | { | ||
124 | return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ, | ||
125 | PEM_STRING_X509_REQ,bp,(char **)x,cb)); | ||
126 | } | ||
127 | |||
128 | #ifndef NO_FP_API | ||
129 | int PEM_write_X509_REQ(fp,x) | ||
130 | FILE *fp; | ||
131 | X509_REQ *x; | ||
132 | { | ||
133 | return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp, | ||
134 | (char *)x, NULL,NULL,0,NULL)); | ||
135 | } | ||
136 | #endif | ||
137 | |||
138 | int PEM_write_bio_X509_REQ(bp,x) | ||
139 | BIO *bp; | ||
140 | X509_REQ *x; | ||
141 | { | ||
142 | return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ, | ||
143 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
144 | } | ||
145 | |||
146 | #ifndef NO_FP_API | ||
147 | /* The X509_CRL functions */ | ||
148 | X509_CRL *PEM_read_X509_CRL(fp,x,cb) | ||
149 | FILE *fp; | ||
150 | X509_CRL **x; | ||
151 | int (*cb)(); | ||
152 | { | ||
153 | return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL, | ||
154 | PEM_STRING_X509_CRL,fp,(char **)x,cb)); | ||
155 | } | ||
156 | #endif | ||
157 | |||
158 | X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb) | ||
159 | BIO *bp; | ||
160 | X509_CRL **x; | ||
161 | int (*cb)(); | ||
162 | { | ||
163 | return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL, | ||
164 | PEM_STRING_X509_CRL,bp,(char **)x,cb)); | ||
165 | } | ||
166 | |||
167 | #ifndef NO_FP_API | ||
168 | int PEM_write_X509_CRL(fp,x) | ||
169 | FILE *fp; | ||
170 | X509_CRL *x; | ||
171 | { | ||
172 | return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp, | ||
173 | (char *)x, NULL,NULL,0,NULL)); | ||
174 | } | ||
175 | #endif | ||
176 | |||
177 | int PEM_write_bio_X509_CRL(bp,x) | ||
178 | BIO *bp; | ||
179 | X509_CRL *x; | ||
180 | { | ||
181 | return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, | ||
182 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
183 | } | ||
184 | |||
185 | #ifndef NO_RSA | ||
186 | #ifndef NO_FP_API | ||
187 | /* The RSAPrivateKey functions */ | ||
188 | RSA *PEM_read_RSAPrivateKey(fp,x,cb) | ||
189 | FILE *fp; | ||
190 | RSA **x; | ||
191 | int (*cb)(); | ||
192 | { | ||
193 | return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey, | ||
194 | PEM_STRING_RSA,fp,(char **)x,cb)); | ||
195 | } | ||
196 | |||
197 | RSA *PEM_read_RSAPublicKey(fp,x,cb) | ||
198 | FILE *fp; | ||
199 | RSA **x; | ||
200 | int (*cb)(); | ||
201 | { | ||
202 | return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey, | ||
203 | PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)); | ||
204 | } | ||
205 | #endif | ||
206 | |||
207 | RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) | ||
208 | BIO *bp; | ||
209 | RSA **x; | ||
210 | int (*cb)(); | ||
211 | { | ||
212 | return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey, | ||
213 | PEM_STRING_RSA,bp,(char **)x,cb)); | ||
214 | } | ||
215 | |||
216 | RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) | ||
217 | BIO *bp; | ||
218 | RSA **x; | ||
219 | int (*cb)(); | ||
220 | { | ||
221 | return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey, | ||
222 | PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)); | ||
223 | } | ||
224 | |||
225 | #ifndef NO_FP_API | ||
226 | int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) | ||
227 | FILE *fp; | ||
228 | RSA *x; | ||
229 | EVP_CIPHER *enc; | ||
230 | unsigned char *kstr; | ||
231 | int klen; | ||
232 | int (*cb)(); | ||
233 | { | ||
234 | return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp, | ||
235 | (char *)x,enc,kstr,klen,cb)); | ||
236 | } | ||
237 | |||
238 | int PEM_write_RSAPublicKey(fp,x) | ||
239 | FILE *fp; | ||
240 | RSA *x; | ||
241 | { | ||
242 | return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey, | ||
243 | PEM_STRING_RSA_PUBLIC,fp, | ||
244 | (char *)x,NULL,NULL,0,NULL)); | ||
245 | } | ||
246 | #endif | ||
247 | |||
248 | int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) | ||
249 | BIO *bp; | ||
250 | RSA *x; | ||
251 | EVP_CIPHER *enc; | ||
252 | unsigned char *kstr; | ||
253 | int klen; | ||
254 | int (*cb)(); | ||
255 | { | ||
256 | return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA, | ||
257 | bp,(char *)x,enc,kstr,klen,cb)); | ||
258 | } | ||
259 | |||
260 | int PEM_write_bio_RSAPublicKey(bp,x) | ||
261 | BIO *bp; | ||
262 | RSA *x; | ||
263 | { | ||
264 | return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, | ||
265 | PEM_STRING_RSA_PUBLIC, | ||
266 | bp,(char *)x,NULL,NULL,0,NULL)); | ||
267 | } | ||
268 | #endif /* !NO_RSA */ | ||
269 | |||
270 | #ifndef NO_DSA | ||
271 | #ifndef NO_FP_API | ||
272 | /* The DSAPrivateKey functions */ | ||
273 | DSA *PEM_read_DSAPrivateKey(fp,x,cb) | ||
274 | FILE *fp; | ||
275 | DSA **x; | ||
276 | int (*cb)(); | ||
277 | { | ||
278 | return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey, | ||
279 | PEM_STRING_DSA,fp,(char **)x,cb)); | ||
280 | } | ||
281 | #endif | ||
282 | |||
283 | DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb) | ||
284 | BIO *bp; | ||
285 | DSA **x; | ||
286 | int (*cb)(); | ||
287 | { | ||
288 | return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey, | ||
289 | PEM_STRING_DSA,bp,(char **)x,cb)); | ||
290 | } | ||
291 | |||
292 | #ifndef NO_FP_API | ||
293 | int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) | ||
294 | FILE *fp; | ||
295 | DSA *x; | ||
296 | EVP_CIPHER *enc; | ||
297 | unsigned char *kstr; | ||
298 | int klen; | ||
299 | int (*cb)(); | ||
300 | { | ||
301 | return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp, | ||
302 | (char *)x,enc,kstr,klen,cb)); | ||
303 | } | ||
304 | #endif | ||
305 | |||
306 | int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) | ||
307 | BIO *bp; | ||
308 | DSA *x; | ||
309 | EVP_CIPHER *enc; | ||
310 | unsigned char *kstr; | ||
311 | int klen; | ||
312 | int (*cb)(); | ||
313 | { | ||
314 | return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA, | ||
315 | bp,(char *)x,enc,kstr,klen,cb)); | ||
316 | } | ||
317 | #endif | ||
318 | |||
319 | #ifndef NO_FP_API | ||
320 | /* The PrivateKey functions */ | ||
321 | EVP_PKEY *PEM_read_PrivateKey(fp,x,cb) | ||
322 | FILE *fp; | ||
323 | EVP_PKEY **x; | ||
324 | int (*cb)(); | ||
325 | { | ||
326 | return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey, | ||
327 | PEM_STRING_EVP_PKEY,fp,(char **)x,cb)); | ||
328 | } | ||
329 | #endif | ||
330 | |||
331 | EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb) | ||
332 | BIO *bp; | ||
333 | EVP_PKEY **x; | ||
334 | int (*cb)(); | ||
335 | { | ||
336 | return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey, | ||
337 | PEM_STRING_EVP_PKEY,bp,(char **)x,cb)); | ||
338 | } | ||
339 | |||
340 | #ifndef NO_FP_API | ||
341 | int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb) | ||
342 | FILE *fp; | ||
343 | EVP_PKEY *x; | ||
344 | EVP_CIPHER *enc; | ||
345 | unsigned char *kstr; | ||
346 | int klen; | ||
347 | int (*cb)(); | ||
348 | { | ||
349 | return(PEM_ASN1_write((int (*)())i2d_PrivateKey, | ||
350 | ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
351 | fp,(char *)x,enc,kstr,klen,cb)); | ||
352 | } | ||
353 | #endif | ||
354 | |||
355 | int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) | ||
356 | BIO *bp; | ||
357 | EVP_PKEY *x; | ||
358 | EVP_CIPHER *enc; | ||
359 | unsigned char *kstr; | ||
360 | int klen; | ||
361 | int (*cb)(); | ||
362 | { | ||
363 | return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey, | ||
364 | ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
365 | bp,(char *)x,enc,kstr,klen,cb)); | ||
366 | } | ||
367 | |||
368 | #ifndef NO_FP_API | ||
369 | /* The PKCS7 functions */ | ||
370 | PKCS7 *PEM_read_PKCS7(fp,x,cb) | ||
371 | FILE *fp; | ||
372 | PKCS7 **x; | ||
373 | int (*cb)(); | ||
374 | { | ||
375 | return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7, | ||
376 | PEM_STRING_PKCS7,fp,(char **)x,cb)); | ||
377 | } | ||
378 | #endif | ||
379 | |||
380 | PKCS7 *PEM_read_bio_PKCS7(bp,x,cb) | ||
381 | BIO *bp; | ||
382 | PKCS7 **x; | ||
383 | int (*cb)(); | ||
384 | { | ||
385 | return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7, | ||
386 | PEM_STRING_PKCS7,bp,(char **)x,cb)); | ||
387 | } | ||
388 | |||
389 | #ifndef NO_FP_API | ||
390 | int PEM_write_PKCS7(fp,x) | ||
391 | FILE *fp; | ||
392 | PKCS7 *x; | ||
393 | { | ||
394 | return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, | ||
395 | (char *)x, NULL,NULL,0,NULL)); | ||
396 | } | ||
397 | #endif | ||
398 | |||
399 | int PEM_write_bio_PKCS7(bp,x) | ||
400 | BIO *bp; | ||
401 | PKCS7 *x; | ||
402 | { | ||
403 | return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, | ||
404 | (char *)x, NULL,NULL,0,NULL)); | ||
405 | } | ||
406 | |||
407 | #ifndef NO_DH | ||
408 | #ifndef NO_FP_API | ||
409 | /* The DHparams functions */ | ||
410 | DH *PEM_read_DHparams(fp,x,cb) | ||
411 | FILE *fp; | ||
412 | DH **x; | ||
413 | int (*cb)(); | ||
414 | { | ||
415 | return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams, | ||
416 | PEM_STRING_DHPARAMS,fp,(char **)x,cb)); | ||
417 | } | ||
418 | #endif | ||
419 | |||
420 | DH *PEM_read_bio_DHparams(bp,x,cb) | ||
421 | BIO *bp; | ||
422 | DH **x; | ||
423 | int (*cb)(); | ||
424 | { | ||
425 | return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams, | ||
426 | PEM_STRING_DHPARAMS,bp,(char **)x,cb)); | ||
427 | } | ||
428 | |||
429 | #ifndef NO_FP_API | ||
430 | int PEM_write_DHparams(fp,x) | ||
431 | FILE *fp; | ||
432 | DH *x; | ||
433 | { | ||
434 | return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp, | ||
435 | (char *)x, NULL,NULL,0,NULL)); | ||
436 | } | ||
437 | #endif | ||
438 | |||
439 | int PEM_write_bio_DHparams(bp,x) | ||
440 | BIO *bp; | ||
441 | DH *x; | ||
442 | { | ||
443 | return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS, | ||
444 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
445 | } | ||
446 | #endif | ||
447 | |||
448 | #ifndef NO_DSA | ||
449 | #ifndef NO_FP_API | ||
450 | /* The DSAparams functions */ | ||
451 | DSA *PEM_read_DSAparams(fp,x,cb) | ||
452 | FILE *fp; | ||
453 | DSA **x; | ||
454 | int (*cb)(); | ||
455 | { | ||
456 | return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams, | ||
457 | PEM_STRING_DSAPARAMS,fp,(char **)x,cb)); | ||
458 | } | ||
459 | #endif | ||
460 | |||
461 | DSA *PEM_read_bio_DSAparams(bp,x,cb) | ||
462 | BIO *bp; | ||
463 | DSA **x; | ||
464 | int (*cb)(); | ||
465 | { | ||
466 | return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams, | ||
467 | PEM_STRING_DSAPARAMS,bp,(char **)x,cb)); | ||
468 | } | ||
469 | |||
470 | #ifndef NO_FP_API | ||
471 | int PEM_write_DSAparams(fp,x) | ||
472 | FILE *fp; | ||
473 | DSA *x; | ||
474 | { | ||
475 | return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp, | ||
476 | (char *)x, NULL,NULL,0,NULL)); | ||
477 | } | ||
478 | #endif | ||
479 | |||
480 | int PEM_write_bio_DSAparams(bp,x) | ||
481 | BIO *bp; | ||
482 | DSA *x; | ||
483 | { | ||
484 | return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS, | ||
485 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
486 | } | ||
487 | #endif | ||
488 | |||
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c new file mode 100644 index 0000000000..e17fcdb540 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_err.c | |||
@@ -0,0 +1,122 @@ | |||
1 | /* lib/pem/pem_err.c */ | ||
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 | #include <stdio.h> | ||
59 | #include "err.h" | ||
60 | #include "pem.h" | ||
61 | |||
62 | /* BEGIN ERROR CODES */ | ||
63 | #ifndef NO_ERR | ||
64 | static ERR_STRING_DATA PEM_str_functs[]= | ||
65 | { | ||
66 | {ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"}, | ||
67 | {ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"}, | ||
68 | {ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"}, | ||
69 | {ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"}, | ||
70 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, | ||
71 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, | ||
72 | {ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, | ||
73 | {ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, | ||
74 | {ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, | ||
75 | {ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, | ||
76 | {ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"}, | ||
77 | {ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"}, | ||
78 | {ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, | ||
79 | {ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, | ||
80 | {ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, | ||
81 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, | ||
82 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, | ||
83 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, | ||
84 | {0,NULL}, | ||
85 | }; | ||
86 | |||
87 | static ERR_STRING_DATA PEM_str_reasons[]= | ||
88 | { | ||
89 | {PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"}, | ||
90 | {PEM_R_BAD_DECRYPT ,"bad decrypt"}, | ||
91 | {PEM_R_BAD_END_LINE ,"bad end line"}, | ||
92 | {PEM_R_BAD_IV_CHARS ,"bad iv chars"}, | ||
93 | {PEM_R_BAD_PASSWORD_READ ,"bad password read"}, | ||
94 | {PEM_R_NOT_DEK_INFO ,"not dek info"}, | ||
95 | {PEM_R_NOT_ENCRYPTED ,"not encrypted"}, | ||
96 | {PEM_R_NOT_PROC_TYPE ,"not proc type"}, | ||
97 | {PEM_R_NO_START_LINE ,"no start line"}, | ||
98 | {PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"}, | ||
99 | {PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"}, | ||
100 | {PEM_R_READ_KEY ,"read key"}, | ||
101 | {PEM_R_SHORT_HEADER ,"short header"}, | ||
102 | {PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
103 | {PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, | ||
104 | {0,NULL}, | ||
105 | }; | ||
106 | |||
107 | #endif | ||
108 | |||
109 | void ERR_load_PEM_strings() | ||
110 | { | ||
111 | static int init=1; | ||
112 | |||
113 | if (init); | ||
114 | {; | ||
115 | init=0; | ||
116 | #ifndef NO_ERR | ||
117 | ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); | ||
118 | ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons); | ||
119 | #endif | ||
120 | |||
121 | } | ||
122 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c new file mode 100644 index 0000000000..4b69833b62 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_info.c | |||
@@ -0,0 +1,365 @@ | |||
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 "buffer.h" | ||
62 | #include "objects.h" | ||
63 | #include "evp.h" | ||
64 | #include "x509.h" | ||
65 | #include "pem.h" | ||
66 | |||
67 | #ifndef NO_FP_API | ||
68 | STACK *PEM_X509_INFO_read(fp,sk,cb) | ||
69 | FILE *fp; | ||
70 | STACK *sk; | ||
71 | int (*cb)(); | ||
72 | { | ||
73 | BIO *b; | ||
74 | STACK *ret; | ||
75 | |||
76 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
77 | { | ||
78 | PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB); | ||
79 | return(0); | ||
80 | } | ||
81 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
82 | ret=PEM_X509_INFO_read_bio(b,sk,cb); | ||
83 | BIO_free(b); | ||
84 | return(ret); | ||
85 | } | ||
86 | #endif | ||
87 | |||
88 | STACK *PEM_X509_INFO_read_bio(bp,sk,cb) | ||
89 | BIO *bp; | ||
90 | STACK *sk; | ||
91 | int (*cb)(); | ||
92 | { | ||
93 | X509_INFO *xi=NULL; | ||
94 | char *name=NULL,*header=NULL,**pp; | ||
95 | unsigned char *data=NULL,*p; | ||
96 | long len,error=0; | ||
97 | int ok=0; | ||
98 | STACK *ret=NULL; | ||
99 | unsigned int i,raw; | ||
100 | char *(*d2i)(); | ||
101 | |||
102 | if (sk == NULL) | ||
103 | { | ||
104 | if ((ret=sk_new_null()) == NULL) | ||
105 | { | ||
106 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
107 | goto err; | ||
108 | } | ||
109 | } | ||
110 | else | ||
111 | ret=sk; | ||
112 | |||
113 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
114 | for (;;) | ||
115 | { | ||
116 | raw=0; | ||
117 | i=PEM_read_bio(bp,&name,&header,&data,&len); | ||
118 | if (i == 0) | ||
119 | { | ||
120 | error=ERR_GET_REASON(ERR_peek_error()); | ||
121 | if (error == PEM_R_NO_START_LINE) | ||
122 | { | ||
123 | ERR_clear_error(); | ||
124 | break; | ||
125 | } | ||
126 | goto err; | ||
127 | } | ||
128 | start: | ||
129 | if ( (strcmp(name,PEM_STRING_X509) == 0) || | ||
130 | (strcmp(name,PEM_STRING_X509_OLD) == 0)) | ||
131 | { | ||
132 | d2i=(char *(*)())d2i_X509; | ||
133 | if (xi->x509 != NULL) | ||
134 | { | ||
135 | if (!sk_push(ret,(char *)xi)) goto err; | ||
136 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
137 | goto start; | ||
138 | } | ||
139 | pp=(char **)&(xi->x509); | ||
140 | } | ||
141 | else if (strcmp(name,PEM_STRING_X509_CRL) == 0) | ||
142 | { | ||
143 | d2i=(char *(*)())d2i_X509_CRL; | ||
144 | if (xi->crl != NULL) | ||
145 | { | ||
146 | if (!sk_push(ret,(char *)xi)) goto err; | ||
147 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
148 | goto start; | ||
149 | } | ||
150 | pp=(char **)&(xi->crl); | ||
151 | } | ||
152 | else | ||
153 | #ifndef NO_RSA | ||
154 | if (strcmp(name,PEM_STRING_RSA) == 0) | ||
155 | { | ||
156 | d2i=(char *(*)())d2i_RSAPrivateKey; | ||
157 | if (xi->x_pkey != NULL) | ||
158 | { | ||
159 | if (!sk_push(ret,(char *)xi)) goto err; | ||
160 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
161 | goto start; | ||
162 | } | ||
163 | |||
164 | xi->enc_data=NULL; | ||
165 | xi->enc_len=0; | ||
166 | |||
167 | xi->x_pkey=X509_PKEY_new(); | ||
168 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | ||
169 | goto err; | ||
170 | xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA; | ||
171 | pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa); | ||
172 | if ((int)strlen(header) > 10) /* assume encrypted */ | ||
173 | raw=1; | ||
174 | } | ||
175 | else | ||
176 | #endif | ||
177 | #ifndef NO_DSA | ||
178 | if (strcmp(name,PEM_STRING_DSA) == 0) | ||
179 | { | ||
180 | d2i=(char *(*)())d2i_DSAPrivateKey; | ||
181 | if (xi->x_pkey != NULL) | ||
182 | { | ||
183 | if (!sk_push(ret,(char *)xi)) goto err; | ||
184 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
185 | goto start; | ||
186 | } | ||
187 | |||
188 | xi->enc_data=NULL; | ||
189 | xi->enc_len=0; | ||
190 | |||
191 | xi->x_pkey=X509_PKEY_new(); | ||
192 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | ||
193 | goto err; | ||
194 | xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA; | ||
195 | pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa); | ||
196 | if ((int)strlen(header) > 10) /* assume encrypted */ | ||
197 | raw=1; | ||
198 | } | ||
199 | else | ||
200 | #endif | ||
201 | { | ||
202 | d2i=NULL; | ||
203 | pp=NULL; | ||
204 | } | ||
205 | |||
206 | if (d2i != NULL) | ||
207 | { | ||
208 | if (!raw) | ||
209 | { | ||
210 | EVP_CIPHER_INFO cipher; | ||
211 | |||
212 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) | ||
213 | goto err; | ||
214 | if (!PEM_do_header(&cipher,data,&len,cb)) | ||
215 | goto err; | ||
216 | p=data; | ||
217 | if (d2i(pp,&p,len) == NULL) | ||
218 | { | ||
219 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); | ||
220 | goto err; | ||
221 | } | ||
222 | } | ||
223 | else | ||
224 | { /* encrypted RSA data */ | ||
225 | if (!PEM_get_EVP_CIPHER_INFO(header, | ||
226 | &xi->enc_cipher)) goto err; | ||
227 | xi->enc_data=(char *)data; | ||
228 | xi->enc_len=(int)len; | ||
229 | data=NULL; | ||
230 | } | ||
231 | } | ||
232 | else { | ||
233 | /* unknown */ | ||
234 | } | ||
235 | if (name != NULL) Free(name); | ||
236 | if (header != NULL) Free(header); | ||
237 | if (data != NULL) Free(data); | ||
238 | name=NULL; | ||
239 | header=NULL; | ||
240 | data=NULL; | ||
241 | } | ||
242 | |||
243 | /* if the last one hasn't been pushed yet and there is anything | ||
244 | * in it then add it to the stack ... | ||
245 | */ | ||
246 | if ((xi->x509 != NULL) || (xi->crl != NULL) || | ||
247 | (xi->x_pkey != NULL) || (xi->enc_data != NULL)) | ||
248 | { | ||
249 | if (!sk_push(ret,(char *)xi)) goto err; | ||
250 | xi=NULL; | ||
251 | } | ||
252 | ok=1; | ||
253 | err: | ||
254 | if (xi != NULL) X509_INFO_free(xi); | ||
255 | if (!ok) | ||
256 | { | ||
257 | for (i=0; ((int)i)<sk_num(ret); i++) | ||
258 | { | ||
259 | xi=(X509_INFO *)sk_value(ret,i); | ||
260 | X509_INFO_free(xi); | ||
261 | } | ||
262 | if (ret != sk) sk_free(ret); | ||
263 | ret=NULL; | ||
264 | } | ||
265 | |||
266 | if (name != NULL) Free(name); | ||
267 | if (header != NULL) Free(header); | ||
268 | if (data != NULL) Free(data); | ||
269 | return(ret); | ||
270 | } | ||
271 | |||
272 | |||
273 | /* A TJH addition */ | ||
274 | int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb) | ||
275 | BIO *bp; | ||
276 | X509_INFO *xi; | ||
277 | EVP_CIPHER *enc; | ||
278 | unsigned char *kstr; | ||
279 | int klen; | ||
280 | int (*cb)(); | ||
281 | { | ||
282 | EVP_CIPHER_CTX ctx; | ||
283 | int i,ret=0; | ||
284 | unsigned char *data=NULL; | ||
285 | char *objstr=NULL; | ||
286 | #define PEM_BUFSIZE 1024 | ||
287 | char buf[PEM_BUFSIZE]; | ||
288 | unsigned char *iv=NULL; | ||
289 | |||
290 | if (enc != NULL) | ||
291 | { | ||
292 | objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc)); | ||
293 | if (objstr == NULL) | ||
294 | { | ||
295 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
296 | goto err; | ||
297 | } | ||
298 | } | ||
299 | |||
300 | /* now for the fun part ... if we have a private key then | ||
301 | * we have to be able to handle a not-yet-decrypted key | ||
302 | * being written out correctly ... if it is decrypted or | ||
303 | * it is non-encrypted then we use the base code | ||
304 | */ | ||
305 | if (xi->x_pkey!=NULL) | ||
306 | { | ||
307 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) | ||
308 | { | ||
309 | /* copy from wierdo names into more normal things */ | ||
310 | iv=xi->enc_cipher.iv; | ||
311 | data=(unsigned char *)xi->enc_data; | ||
312 | i=xi->enc_len; | ||
313 | |||
314 | /* we take the encryption data from the | ||
315 | * internal stuff rather than what the | ||
316 | * user has passed us ... as we have to | ||
317 | * match exactly for some strange reason | ||
318 | */ | ||
319 | objstr=OBJ_nid2sn( | ||
320 | EVP_CIPHER_nid(xi->enc_cipher.cipher)); | ||
321 | if (objstr == NULL) | ||
322 | { | ||
323 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
324 | goto err; | ||
325 | } | ||
326 | |||
327 | /* create the right magic header stuff */ | ||
328 | buf[0]='\0'; | ||
329 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | ||
330 | PEM_dek_info(buf,objstr,8,(char *)iv); | ||
331 | |||
332 | /* use the normal code to write things out */ | ||
333 | i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i); | ||
334 | if (i <= 0) goto err; | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | /* Add DSA/DH */ | ||
339 | #ifndef NO_RSA | ||
340 | /* normal optionally encrypted stuff */ | ||
341 | if (PEM_write_bio_RSAPrivateKey(bp, | ||
342 | xi->x_pkey->dec_pkey->pkey.rsa, | ||
343 | enc,kstr,klen,cb)<=0) | ||
344 | goto err; | ||
345 | #endif | ||
346 | } | ||
347 | } | ||
348 | |||
349 | /* if we have a certificate then write it out now */ | ||
350 | if ((xi->x509 != NULL) || (PEM_write_bio_X509(bp,xi->x509) <= 0)) | ||
351 | goto err; | ||
352 | |||
353 | /* we are ignoring anything else that is loaded into the X509_INFO | ||
354 | * structure for the moment ... as I don't need it so I'm not | ||
355 | * coding it here and Eric can do it when this makes it into the | ||
356 | * base library --tjh | ||
357 | */ | ||
358 | |||
359 | ret=1; | ||
360 | |||
361 | err: | ||
362 | memset((char *)&ctx,0,sizeof(ctx)); | ||
363 | memset(buf,0,PEM_BUFSIZE); | ||
364 | return(ret); | ||
365 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c new file mode 100644 index 0000000000..7a2c0ad83b --- /dev/null +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
@@ -0,0 +1,762 @@ | |||
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 "buffer.h" | ||
62 | #include "objects.h" | ||
63 | #include "evp.h" | ||
64 | #include "rand.h" | ||
65 | #include "x509.h" | ||
66 | #include "pem.h" | ||
67 | #ifndef NO_DES | ||
68 | #include "des.h" | ||
69 | #endif | ||
70 | |||
71 | char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998"; | ||
72 | |||
73 | #define MIN_LENGTH 4 | ||
74 | |||
75 | /* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
76 | * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
77 | */ | ||
78 | |||
79 | #ifndef NOPROTO | ||
80 | static int def_callback(char *buf, int num, int w); | ||
81 | static int load_iv(unsigned char **fromp,unsigned char *to, int num); | ||
82 | #else | ||
83 | static int def_callback(); | ||
84 | static int load_iv(); | ||
85 | #endif | ||
86 | |||
87 | static int def_callback(buf, num, w) | ||
88 | char *buf; | ||
89 | int num; | ||
90 | int w; | ||
91 | { | ||
92 | #ifdef NO_FP_API | ||
93 | /* We should not ever call the default callback routine from | ||
94 | * windows. */ | ||
95 | PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
96 | return(-1); | ||
97 | #else | ||
98 | int i,j; | ||
99 | char *prompt; | ||
100 | |||
101 | prompt=EVP_get_pw_prompt(); | ||
102 | if (prompt == NULL) | ||
103 | prompt="Enter PEM pass phrase:"; | ||
104 | |||
105 | for (;;) | ||
106 | { | ||
107 | i=EVP_read_pw_string(buf,num,prompt,w); | ||
108 | if (i != 0) | ||
109 | { | ||
110 | PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD); | ||
111 | memset(buf,0,(unsigned int)num); | ||
112 | return(-1); | ||
113 | } | ||
114 | j=strlen(buf); | ||
115 | if (j < MIN_LENGTH) | ||
116 | { | ||
117 | fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH); | ||
118 | } | ||
119 | else | ||
120 | break; | ||
121 | } | ||
122 | return(j); | ||
123 | #endif | ||
124 | } | ||
125 | |||
126 | void PEM_proc_type(buf, type) | ||
127 | char *buf; | ||
128 | int type; | ||
129 | { | ||
130 | char *str; | ||
131 | |||
132 | if (type == PEM_TYPE_ENCRYPTED) | ||
133 | str="ENCRYPTED"; | ||
134 | else if (type == PEM_TYPE_MIC_CLEAR) | ||
135 | str="MIC-CLEAR"; | ||
136 | else if (type == PEM_TYPE_MIC_ONLY) | ||
137 | str="MIC-ONLY"; | ||
138 | else | ||
139 | str="BAD-TYPE"; | ||
140 | |||
141 | strcat(buf,"Proc-Type: 4,"); | ||
142 | strcat(buf,str); | ||
143 | strcat(buf,"\n"); | ||
144 | } | ||
145 | |||
146 | void PEM_dek_info(buf, type, len, str) | ||
147 | char *buf; | ||
148 | char *type; | ||
149 | int len; | ||
150 | char *str; | ||
151 | { | ||
152 | static unsigned char map[17]="0123456789ABCDEF"; | ||
153 | long i; | ||
154 | int j; | ||
155 | |||
156 | strcat(buf,"DEK-Info: "); | ||
157 | strcat(buf,type); | ||
158 | strcat(buf,","); | ||
159 | j=strlen(buf); | ||
160 | for (i=0; i<len; i++) | ||
161 | { | ||
162 | buf[j+i*2] =map[(str[i]>>4)&0x0f]; | ||
163 | buf[j+i*2+1]=map[(str[i] )&0x0f]; | ||
164 | } | ||
165 | buf[j+i*2]='\n'; | ||
166 | buf[j+i*2+1]='\0'; | ||
167 | } | ||
168 | |||
169 | #ifndef NO_FP_API | ||
170 | char *PEM_ASN1_read(d2i,name,fp, x, cb) | ||
171 | char *(*d2i)(); | ||
172 | char *name; | ||
173 | FILE *fp; | ||
174 | char **x; | ||
175 | int (*cb)(); | ||
176 | { | ||
177 | BIO *b; | ||
178 | char *ret; | ||
179 | |||
180 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
181 | { | ||
182 | PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB); | ||
183 | return(0); | ||
184 | } | ||
185 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
186 | ret=PEM_ASN1_read_bio(d2i,name,b,x,cb); | ||
187 | BIO_free(b); | ||
188 | return(ret); | ||
189 | } | ||
190 | #endif | ||
191 | |||
192 | char *PEM_ASN1_read_bio(d2i,name,bp, x, cb) | ||
193 | char *(*d2i)(); | ||
194 | char *name; | ||
195 | BIO *bp; | ||
196 | char **x; | ||
197 | int (*cb)(); | ||
198 | { | ||
199 | EVP_CIPHER_INFO cipher; | ||
200 | char *nm=NULL,*header=NULL; | ||
201 | unsigned char *p=NULL,*data=NULL; | ||
202 | long len; | ||
203 | char *ret=NULL; | ||
204 | |||
205 | for (;;) | ||
206 | { | ||
207 | if (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL); | ||
208 | if ( (strcmp(nm,name) == 0) || | ||
209 | ((strcmp(nm,PEM_STRING_RSA) == 0) && | ||
210 | (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || | ||
211 | ((strcmp(nm,PEM_STRING_DSA) == 0) && | ||
212 | (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || | ||
213 | ((strcmp(nm,PEM_STRING_X509_OLD) == 0) && | ||
214 | (strcmp(name,PEM_STRING_X509) == 0)) || | ||
215 | ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) && | ||
216 | (strcmp(name,PEM_STRING_X509_REQ) == 0)) | ||
217 | ) | ||
218 | break; | ||
219 | Free(nm); | ||
220 | Free(header); | ||
221 | Free(data); | ||
222 | } | ||
223 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; | ||
224 | if (!PEM_do_header(&cipher,data,&len,cb)) goto err; | ||
225 | p=data; | ||
226 | if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) | ||
227 | { | ||
228 | if (strcmp(nm,PEM_STRING_RSA) == 0) | ||
229 | ret=d2i(EVP_PKEY_RSA,x,&p,len); | ||
230 | else if (strcmp(nm,PEM_STRING_DSA) == 0) | ||
231 | ret=d2i(EVP_PKEY_DSA,x,&p,len); | ||
232 | } | ||
233 | else | ||
234 | ret=d2i(x,&p,len); | ||
235 | if (ret == NULL) | ||
236 | PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); | ||
237 | err: | ||
238 | Free(nm); | ||
239 | Free(header); | ||
240 | Free(data); | ||
241 | return(ret); | ||
242 | } | ||
243 | |||
244 | #ifndef NO_FP_API | ||
245 | int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback) | ||
246 | int (*i2d)(); | ||
247 | char *name; | ||
248 | FILE *fp; | ||
249 | char *x; | ||
250 | EVP_CIPHER *enc; | ||
251 | unsigned char *kstr; | ||
252 | int klen; | ||
253 | int (*callback)(); | ||
254 | { | ||
255 | BIO *b; | ||
256 | int ret; | ||
257 | |||
258 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
259 | { | ||
260 | PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB); | ||
261 | return(0); | ||
262 | } | ||
263 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
264 | ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback); | ||
265 | BIO_free(b); | ||
266 | return(ret); | ||
267 | } | ||
268 | #endif | ||
269 | |||
270 | int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback) | ||
271 | int (*i2d)(); | ||
272 | char *name; | ||
273 | BIO *bp; | ||
274 | char *x; | ||
275 | EVP_CIPHER *enc; | ||
276 | unsigned char *kstr; | ||
277 | int klen; | ||
278 | int (*callback)(); | ||
279 | { | ||
280 | EVP_CIPHER_CTX ctx; | ||
281 | int dsize=0,i,j,ret=0; | ||
282 | unsigned char *p,*data=NULL; | ||
283 | char *objstr=NULL; | ||
284 | #define PEM_BUFSIZE 1024 | ||
285 | char buf[PEM_BUFSIZE]; | ||
286 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
287 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
288 | |||
289 | if (enc != NULL) | ||
290 | { | ||
291 | objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc)); | ||
292 | if (objstr == NULL) | ||
293 | { | ||
294 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
295 | goto err; | ||
296 | } | ||
297 | } | ||
298 | |||
299 | if ((dsize=i2d(x,NULL)) < 0) | ||
300 | { | ||
301 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
302 | dsize=0; | ||
303 | goto err; | ||
304 | } | ||
305 | /* dzise + 8 bytes are needed */ | ||
306 | data=(unsigned char *)Malloc((unsigned int)dsize+20); | ||
307 | if (data == NULL) | ||
308 | { | ||
309 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
310 | goto err; | ||
311 | } | ||
312 | p=data; | ||
313 | i=i2d(x,&p); | ||
314 | |||
315 | if (enc != NULL) | ||
316 | { | ||
317 | if (kstr == NULL) | ||
318 | { | ||
319 | if (callback == NULL) | ||
320 | klen=def_callback(buf,PEM_BUFSIZE,1); | ||
321 | else | ||
322 | klen=(*callback)(buf,PEM_BUFSIZE,1); | ||
323 | if (klen <= 0) | ||
324 | { | ||
325 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); | ||
326 | goto err; | ||
327 | } | ||
328 | kstr=(unsigned char *)buf; | ||
329 | } | ||
330 | RAND_seed(data,i);/* put in the RSA key. */ | ||
331 | RAND_bytes(iv,8); /* Generate a salt */ | ||
332 | /* The 'iv' is used as the iv and as a salt. It is | ||
333 | * NOT taken from the BytesToKey function */ | ||
334 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); | ||
335 | |||
336 | if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE); | ||
337 | |||
338 | buf[0]='\0'; | ||
339 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | ||
340 | PEM_dek_info(buf,objstr,8,(char *)iv); | ||
341 | /* k=strlen(buf); */ | ||
342 | |||
343 | EVP_EncryptInit(&ctx,enc,key,iv); | ||
344 | EVP_EncryptUpdate(&ctx,data,&j,data,i); | ||
345 | EVP_EncryptFinal(&ctx,&(data[j]),&i); | ||
346 | i+=j; | ||
347 | ret=1; | ||
348 | } | ||
349 | else | ||
350 | { | ||
351 | ret=1; | ||
352 | buf[0]='\0'; | ||
353 | } | ||
354 | i=PEM_write_bio(bp,name,buf,data,i); | ||
355 | if (i <= 0) ret=0; | ||
356 | err: | ||
357 | memset(key,0,sizeof(key)); | ||
358 | memset(iv,0,sizeof(iv)); | ||
359 | memset((char *)&ctx,0,sizeof(ctx)); | ||
360 | memset(buf,0,PEM_BUFSIZE); | ||
361 | memset(data,0,(unsigned int)dsize); | ||
362 | Free(data); | ||
363 | return(ret); | ||
364 | } | ||
365 | |||
366 | int PEM_do_header(cipher, data, plen, callback) | ||
367 | EVP_CIPHER_INFO *cipher; | ||
368 | unsigned char *data; | ||
369 | long *plen; | ||
370 | int (*callback)(); | ||
371 | { | ||
372 | int i,j,o,klen; | ||
373 | long len; | ||
374 | EVP_CIPHER_CTX ctx; | ||
375 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
376 | char buf[PEM_BUFSIZE]; | ||
377 | |||
378 | len= *plen; | ||
379 | |||
380 | if (cipher->cipher == NULL) return(1); | ||
381 | if (callback == NULL) | ||
382 | klen=def_callback(buf,PEM_BUFSIZE,0); | ||
383 | else | ||
384 | klen=callback(buf,PEM_BUFSIZE,0); | ||
385 | if (klen <= 0) | ||
386 | { | ||
387 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); | ||
388 | return(0); | ||
389 | } | ||
390 | EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), | ||
391 | (unsigned char *)buf,klen,1,key,NULL); | ||
392 | |||
393 | j=(int)len; | ||
394 | EVP_DecryptInit(&ctx,cipher->cipher,key,&(cipher->iv[0])); | ||
395 | EVP_DecryptUpdate(&ctx,data,&i,data,j); | ||
396 | o=EVP_DecryptFinal(&ctx,&(data[i]),&j); | ||
397 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
398 | memset((char *)buf,0,sizeof(buf)); | ||
399 | memset((char *)key,0,sizeof(key)); | ||
400 | j+=i; | ||
401 | if (!o) | ||
402 | { | ||
403 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT); | ||
404 | return(0); | ||
405 | } | ||
406 | *plen=j; | ||
407 | return(1); | ||
408 | } | ||
409 | |||
410 | int PEM_get_EVP_CIPHER_INFO(header,cipher) | ||
411 | char *header; | ||
412 | EVP_CIPHER_INFO *cipher; | ||
413 | { | ||
414 | int o; | ||
415 | EVP_CIPHER *enc=NULL; | ||
416 | char *p,c; | ||
417 | |||
418 | cipher->cipher=NULL; | ||
419 | if ((header == NULL) || (*header == '\0') || (*header == '\n')) | ||
420 | return(1); | ||
421 | if (strncmp(header,"Proc-Type: ",11) != 0) | ||
422 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); } | ||
423 | header+=11; | ||
424 | if (*header != '4') return(0); header++; | ||
425 | if (*header != ',') return(0); header++; | ||
426 | if (strncmp(header,"ENCRYPTED",9) != 0) | ||
427 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); } | ||
428 | for (; (*header != '\n') && (*header != '\0'); header++) | ||
429 | ; | ||
430 | if (*header == '\0') | ||
431 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); } | ||
432 | header++; | ||
433 | if (strncmp(header,"DEK-Info: ",10) != 0) | ||
434 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); } | ||
435 | header+=10; | ||
436 | |||
437 | p=header; | ||
438 | for (;;) | ||
439 | { | ||
440 | c= *header; | ||
441 | if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || | ||
442 | ((c >= '0') && (c <= '9')))) | ||
443 | break; | ||
444 | header++; | ||
445 | } | ||
446 | *header='\0'; | ||
447 | o=OBJ_sn2nid(p); | ||
448 | cipher->cipher=enc=EVP_get_cipherbyname(p); | ||
449 | *header=c; | ||
450 | header++; | ||
451 | |||
452 | if (enc == NULL) | ||
453 | { | ||
454 | PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION); | ||
455 | return(0); | ||
456 | } | ||
457 | if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),8)) return(0); | ||
458 | |||
459 | return(1); | ||
460 | } | ||
461 | |||
462 | static int load_iv(fromp,to,num) | ||
463 | unsigned char **fromp,*to; | ||
464 | int num; | ||
465 | { | ||
466 | int v,i; | ||
467 | unsigned char *from; | ||
468 | |||
469 | from= *fromp; | ||
470 | for (i=0; i<num; i++) to[i]=0; | ||
471 | num*=2; | ||
472 | for (i=0; i<num; i++) | ||
473 | { | ||
474 | if ((*from >= '0') && (*from <= '9')) | ||
475 | v= *from-'0'; | ||
476 | else if ((*from >= 'A') && (*from <= 'F')) | ||
477 | v= *from-'A'+10; | ||
478 | else if ((*from >= 'a') && (*from <= 'f')) | ||
479 | v= *from-'a'+10; | ||
480 | else | ||
481 | { | ||
482 | PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS); | ||
483 | return(0); | ||
484 | } | ||
485 | from++; | ||
486 | to[i/2]|=v<<(long)((!(i&1))*4); | ||
487 | } | ||
488 | |||
489 | *fromp=from; | ||
490 | return(1); | ||
491 | } | ||
492 | |||
493 | #ifndef NO_FP_API | ||
494 | int PEM_write(fp, name, header, data,len) | ||
495 | FILE *fp; | ||
496 | char *name; | ||
497 | char *header; | ||
498 | unsigned char *data; | ||
499 | long len; | ||
500 | { | ||
501 | BIO *b; | ||
502 | int ret; | ||
503 | |||
504 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
505 | { | ||
506 | PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB); | ||
507 | return(0); | ||
508 | } | ||
509 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
510 | ret=PEM_write_bio(b, name, header, data,len); | ||
511 | BIO_free(b); | ||
512 | return(ret); | ||
513 | } | ||
514 | #endif | ||
515 | |||
516 | int PEM_write_bio(bp, name, header, data,len) | ||
517 | BIO *bp; | ||
518 | char *name; | ||
519 | char *header; | ||
520 | unsigned char *data; | ||
521 | long len; | ||
522 | { | ||
523 | int nlen,n,i,j,outl; | ||
524 | unsigned char *buf; | ||
525 | EVP_ENCODE_CTX ctx; | ||
526 | int reason=ERR_R_BUF_LIB; | ||
527 | |||
528 | EVP_EncodeInit(&ctx); | ||
529 | nlen=strlen(name); | ||
530 | |||
531 | if ( (BIO_write(bp,"-----BEGIN ",11) != 11) || | ||
532 | (BIO_write(bp,name,nlen) != nlen) || | ||
533 | (BIO_write(bp,"-----\n",6) != 6)) | ||
534 | goto err; | ||
535 | |||
536 | i=strlen(header); | ||
537 | if (i > 0) | ||
538 | { | ||
539 | if ( (BIO_write(bp,header,i) != i) || | ||
540 | (BIO_write(bp,"\n",1) != 1)) | ||
541 | goto err; | ||
542 | } | ||
543 | |||
544 | buf=(unsigned char *)Malloc(PEM_BUFSIZE*8); | ||
545 | if (buf == NULL) | ||
546 | { | ||
547 | reason=ERR_R_MALLOC_FAILURE; | ||
548 | goto err; | ||
549 | } | ||
550 | |||
551 | i=j=0; | ||
552 | while (len > 0) | ||
553 | { | ||
554 | n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len); | ||
555 | EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n); | ||
556 | if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl)) | ||
557 | goto err; | ||
558 | i+=outl; | ||
559 | len-=n; | ||
560 | j+=n; | ||
561 | } | ||
562 | EVP_EncodeFinal(&ctx,buf,&outl); | ||
563 | if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; | ||
564 | Free(buf); | ||
565 | if ( (BIO_write(bp,"-----END ",9) != 9) || | ||
566 | (BIO_write(bp,name,nlen) != nlen) || | ||
567 | (BIO_write(bp,"-----\n",6) != 6)) | ||
568 | goto err; | ||
569 | return(i+outl); | ||
570 | err: | ||
571 | PEMerr(PEM_F_PEM_WRITE_BIO,reason); | ||
572 | return(0); | ||
573 | } | ||
574 | |||
575 | #ifndef NO_FP_API | ||
576 | int PEM_read(fp, name, header, data,len) | ||
577 | FILE *fp; | ||
578 | char **name; | ||
579 | char **header; | ||
580 | unsigned char **data; | ||
581 | long *len; | ||
582 | { | ||
583 | BIO *b; | ||
584 | int ret; | ||
585 | |||
586 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
587 | { | ||
588 | PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB); | ||
589 | return(0); | ||
590 | } | ||
591 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
592 | ret=PEM_read_bio(b, name, header, data,len); | ||
593 | BIO_free(b); | ||
594 | return(ret); | ||
595 | } | ||
596 | #endif | ||
597 | |||
598 | int PEM_read_bio(bp, name, header, data, len) | ||
599 | BIO *bp; | ||
600 | char **name; | ||
601 | char **header; | ||
602 | unsigned char **data; | ||
603 | long *len; | ||
604 | { | ||
605 | EVP_ENCODE_CTX ctx; | ||
606 | int end=0,i,k,bl=0,hl=0,nohead=0; | ||
607 | char buf[256]; | ||
608 | BUF_MEM *nameB; | ||
609 | BUF_MEM *headerB; | ||
610 | BUF_MEM *dataB,*tmpB; | ||
611 | |||
612 | nameB=BUF_MEM_new(); | ||
613 | headerB=BUF_MEM_new(); | ||
614 | dataB=BUF_MEM_new(); | ||
615 | if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL)) | ||
616 | { | ||
617 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
618 | return(0); | ||
619 | } | ||
620 | |||
621 | buf[254]='\0'; | ||
622 | for (;;) | ||
623 | { | ||
624 | i=BIO_gets(bp,buf,254); | ||
625 | |||
626 | if (i <= 0) | ||
627 | { | ||
628 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE); | ||
629 | goto err; | ||
630 | } | ||
631 | |||
632 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
633 | buf[++i]='\n'; buf[++i]='\0'; | ||
634 | |||
635 | if (strncmp(buf,"-----BEGIN ",11) == 0) | ||
636 | { | ||
637 | i=strlen(&(buf[11])); | ||
638 | |||
639 | if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0) | ||
640 | continue; | ||
641 | if (!BUF_MEM_grow(nameB,i+9)) | ||
642 | { | ||
643 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
644 | goto err; | ||
645 | } | ||
646 | strncpy(nameB->data,&(buf[11]),(unsigned int)i-6); | ||
647 | nameB->data[i-6]='\0'; | ||
648 | break; | ||
649 | } | ||
650 | } | ||
651 | hl=0; | ||
652 | if (!BUF_MEM_grow(headerB,256)) | ||
653 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
654 | headerB->data[0]='\0'; | ||
655 | for (;;) | ||
656 | { | ||
657 | i=BIO_gets(bp,buf,254); | ||
658 | if (i <= 0) break; | ||
659 | |||
660 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
661 | buf[++i]='\n'; buf[++i]='\0'; | ||
662 | |||
663 | if (buf[0] == '\n') break; | ||
664 | if (!BUF_MEM_grow(headerB,hl+i+9)) | ||
665 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
666 | if (strncmp(buf,"-----END ",9) == 0) | ||
667 | { | ||
668 | nohead=1; | ||
669 | break; | ||
670 | } | ||
671 | strncpy(&(headerB->data[hl]),buf,(unsigned int)i); | ||
672 | headerB->data[hl+i]='\0'; | ||
673 | hl+=i; | ||
674 | } | ||
675 | |||
676 | bl=0; | ||
677 | if (!BUF_MEM_grow(dataB,1024)) | ||
678 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
679 | dataB->data[0]='\0'; | ||
680 | if (!nohead) | ||
681 | { | ||
682 | for (;;) | ||
683 | { | ||
684 | i=BIO_gets(bp,buf,254); | ||
685 | if (i <= 0) break; | ||
686 | |||
687 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
688 | buf[++i]='\n'; buf[++i]='\0'; | ||
689 | |||
690 | if (i != 65) end=1; | ||
691 | if (strncmp(buf,"-----END ",9) == 0) | ||
692 | break; | ||
693 | if (i > 65) break; | ||
694 | if (!BUF_MEM_grow(dataB,i+bl+9)) | ||
695 | { | ||
696 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
697 | goto err; | ||
698 | } | ||
699 | strncpy(&(dataB->data[bl]),buf,(unsigned int)i); | ||
700 | dataB->data[bl+i]='\0'; | ||
701 | bl+=i; | ||
702 | if (end) | ||
703 | { | ||
704 | buf[0]='\0'; | ||
705 | i=BIO_gets(bp,buf,254); | ||
706 | if (i <= 0) break; | ||
707 | |||
708 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
709 | buf[++i]='\n'; buf[++i]='\0'; | ||
710 | |||
711 | break; | ||
712 | } | ||
713 | } | ||
714 | } | ||
715 | else | ||
716 | { | ||
717 | tmpB=headerB; | ||
718 | headerB=dataB; | ||
719 | dataB=tmpB; | ||
720 | bl=hl; | ||
721 | } | ||
722 | i=strlen(nameB->data); | ||
723 | if ( (strncmp(buf,"-----END ",9) != 0) || | ||
724 | (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) || | ||
725 | (strncmp(&(buf[9+i]),"-----\n",6) != 0)) | ||
726 | { | ||
727 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); | ||
728 | goto err; | ||
729 | } | ||
730 | |||
731 | EVP_DecodeInit(&ctx); | ||
732 | i=EVP_DecodeUpdate(&ctx, | ||
733 | (unsigned char *)dataB->data,&bl, | ||
734 | (unsigned char *)dataB->data,bl); | ||
735 | if (i < 0) | ||
736 | { | ||
737 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE); | ||
738 | goto err; | ||
739 | } | ||
740 | i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k); | ||
741 | if (i < 0) | ||
742 | { | ||
743 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE); | ||
744 | goto err; | ||
745 | } | ||
746 | bl+=k; | ||
747 | |||
748 | if (bl == 0) goto err; | ||
749 | *name=nameB->data; | ||
750 | *header=headerB->data; | ||
751 | *data=(unsigned char *)dataB->data; | ||
752 | *len=bl; | ||
753 | Free(nameB); | ||
754 | Free(headerB); | ||
755 | Free(dataB); | ||
756 | return(1); | ||
757 | err: | ||
758 | BUF_MEM_free(nameB); | ||
759 | BUF_MEM_free(headerB); | ||
760 | BUF_MEM_free(dataB); | ||
761 | return(0); | ||
762 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c new file mode 100644 index 0000000000..b4b36df453 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_seal.c | |||
@@ -0,0 +1,191 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "rand.h" | ||
63 | #include "objects.h" | ||
64 | #include "x509.h" | ||
65 | #include "pem.h" | ||
66 | |||
67 | int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) | ||
68 | PEM_ENCODE_SEAL_CTX *ctx; | ||
69 | EVP_CIPHER *type; | ||
70 | EVP_MD *md_type; | ||
71 | unsigned char **ek; | ||
72 | int *ekl; | ||
73 | unsigned char *iv; | ||
74 | EVP_PKEY **pubk; | ||
75 | int npubk; | ||
76 | { | ||
77 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
78 | int ret= -1; | ||
79 | int i,j,max=0; | ||
80 | char *s=NULL; | ||
81 | |||
82 | for (i=0; i<npubk; i++) | ||
83 | { | ||
84 | if (pubk[i]->type != EVP_PKEY_RSA) | ||
85 | { | ||
86 | PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA); | ||
87 | goto err; | ||
88 | } | ||
89 | j=RSA_size(pubk[i]->pkey.rsa); | ||
90 | if (j > max) max=j; | ||
91 | } | ||
92 | s=(char *)Malloc(max*2); | ||
93 | if (s == NULL) | ||
94 | { | ||
95 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); | ||
96 | goto err; | ||
97 | } | ||
98 | |||
99 | EVP_EncodeInit(&(ctx->encode)); | ||
100 | EVP_SignInit(&(ctx->md),md_type); | ||
101 | |||
102 | ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk); | ||
103 | if (!ret) goto err; | ||
104 | |||
105 | /* base64 encode the keys */ | ||
106 | for (i=0; i<npubk; i++) | ||
107 | { | ||
108 | j=EVP_EncodeBlock((unsigned char *)s,ek[i], | ||
109 | RSA_size(pubk[i]->pkey.rsa)); | ||
110 | ekl[i]=j; | ||
111 | memcpy(ek[i],s,j+1); | ||
112 | } | ||
113 | |||
114 | ret=npubk; | ||
115 | err: | ||
116 | if (s != NULL) Free(s); | ||
117 | memset(key,0,EVP_MAX_KEY_LENGTH); | ||
118 | return(ret); | ||
119 | } | ||
120 | |||
121 | void PEM_SealUpdate(ctx,out,outl,in,inl) | ||
122 | PEM_ENCODE_SEAL_CTX *ctx; | ||
123 | unsigned char *out; | ||
124 | int *outl; | ||
125 | unsigned char *in; | ||
126 | int inl; | ||
127 | { | ||
128 | unsigned char buffer[1600]; | ||
129 | int i,j; | ||
130 | |||
131 | *outl=0; | ||
132 | EVP_SignUpdate(&(ctx->md),in,inl); | ||
133 | for (;;) | ||
134 | { | ||
135 | if (inl <= 0) break; | ||
136 | if (inl > 1200) | ||
137 | i=1200; | ||
138 | else | ||
139 | i=inl; | ||
140 | EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i); | ||
141 | EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j); | ||
142 | *outl+=j; | ||
143 | out+=j; | ||
144 | in+=i; | ||
145 | inl-=i; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) | ||
150 | PEM_ENCODE_SEAL_CTX *ctx; | ||
151 | unsigned char *sig; | ||
152 | int *sigl; | ||
153 | unsigned char *out; | ||
154 | int *outl; | ||
155 | EVP_PKEY *priv; | ||
156 | { | ||
157 | unsigned char *s=NULL; | ||
158 | int ret=0,j; | ||
159 | unsigned int i; | ||
160 | |||
161 | if (priv->type != EVP_PKEY_RSA) | ||
162 | { | ||
163 | PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA); | ||
164 | goto err; | ||
165 | } | ||
166 | i=RSA_size(priv->pkey.rsa); | ||
167 | if (i < 100) i=100; | ||
168 | s=(unsigned char *)Malloc(i*2); | ||
169 | if (s == NULL) | ||
170 | { | ||
171 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); | ||
172 | goto err; | ||
173 | } | ||
174 | |||
175 | EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i); | ||
176 | EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i); | ||
177 | *outl=j; | ||
178 | out+=j; | ||
179 | EVP_EncodeFinal(&(ctx->encode),out,&j); | ||
180 | *outl+=j; | ||
181 | |||
182 | if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err; | ||
183 | *sigl=EVP_EncodeBlock(sig,s,i); | ||
184 | |||
185 | ret=1; | ||
186 | err: | ||
187 | memset((char *)&(ctx->md),0,sizeof(ctx->md)); | ||
188 | memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher)); | ||
189 | if (s != NULL) Free(s); | ||
190 | return(ret); | ||
191 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c new file mode 100644 index 0000000000..d56f9f9e14 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_sign.c | |||
@@ -0,0 +1,109 @@ | |||
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 "rand.h" | ||
62 | #include "evp.h" | ||
63 | #include "objects.h" | ||
64 | #include "x509.h" | ||
65 | #include "pem.h" | ||
66 | |||
67 | void PEM_SignInit(ctx,type) | ||
68 | EVP_MD_CTX *ctx; | ||
69 | EVP_MD *type; | ||
70 | { | ||
71 | EVP_DigestInit(ctx,type); | ||
72 | } | ||
73 | |||
74 | void PEM_SignUpdate(ctx,data,count) | ||
75 | EVP_MD_CTX *ctx; | ||
76 | unsigned char *data; | ||
77 | unsigned int count; | ||
78 | { | ||
79 | EVP_DigestUpdate(ctx,data,count); | ||
80 | } | ||
81 | |||
82 | int PEM_SignFinal(ctx,sigret,siglen,pkey) | ||
83 | EVP_MD_CTX *ctx; | ||
84 | unsigned char *sigret; | ||
85 | unsigned int *siglen; | ||
86 | EVP_PKEY *pkey; | ||
87 | { | ||
88 | unsigned char *m; | ||
89 | int i,ret=0; | ||
90 | unsigned int m_len; | ||
91 | |||
92 | m=(unsigned char *)Malloc(EVP_PKEY_size(pkey)+2); | ||
93 | if (m == NULL) | ||
94 | { | ||
95 | PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE); | ||
96 | goto err; | ||
97 | } | ||
98 | |||
99 | if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err; | ||
100 | |||
101 | i=EVP_EncodeBlock(sigret,m,m_len); | ||
102 | *siglen=i; | ||
103 | ret=1; | ||
104 | err: | ||
105 | /* ctx has been zeroed by EVP_SignFinal() */ | ||
106 | if (m != NULL) Free(m); | ||
107 | return(ret); | ||
108 | } | ||
109 | |||
diff --git a/src/lib/libcrypto/pem/pkcs7.lis b/src/lib/libcrypto/pem/pkcs7.lis new file mode 100644 index 0000000000..be90c5d87f --- /dev/null +++ b/src/lib/libcrypto/pem/pkcs7.lis | |||
@@ -0,0 +1,22 @@ | |||
1 | 21 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 | ||
22 | 00 2076:d=0 hl=2 l= 0 prim: univ: EOC | ||