]>
Commit | Line | Data |
---|---|---|
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 |