diff options
Diffstat (limited to 'src/lib/libcrypto/pem/pem_all.c')
-rw-r--r-- | src/lib/libcrypto/pem/pem_all.c | 429 |
1 files changed, 27 insertions, 402 deletions
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c index d1cda7aabe..bc473f3cff 100644 --- a/src/lib/libcrypto/pem/pem_all.c +++ b/src/lib/libcrypto/pem/pem_all.c | |||
@@ -59,430 +59,55 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #undef SSLEAY_MACROS | 60 | #undef SSLEAY_MACROS |
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include "bio.h" | 62 | #include <openssl/bio.h> |
63 | #include "evp.h" | 63 | #include <openssl/evp.h> |
64 | #include "x509.h" | 64 | #include <openssl/x509.h> |
65 | #include "pkcs7.h" | 65 | #include <openssl/pkcs7.h> |
66 | #include "pem.h" | 66 | #include <openssl/pem.h> |
67 | 67 | ||
68 | #ifndef NO_FP_API | 68 | IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509) |
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 | 69 | ||
99 | int PEM_write_bio_X509(bp,x) | 70 | IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) |
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 | 71 | ||
107 | #ifndef NO_FP_API | 72 | IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) |
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 | 73 | ||
119 | X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) | 74 | IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) |
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 | 75 | ||
128 | #ifndef NO_FP_API | 76 | IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, |
129 | int PEM_write_X509_REQ(fp,x) | 77 | PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) |
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 | 78 | ||
138 | int PEM_write_bio_X509_REQ(bp,x) | 79 | IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG) |
139 | BIO *bp; | 80 | IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, |
140 | X509_REQ *x; | 81 | PKCS8_PRIV_KEY_INFO) |
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 | 82 | ||
185 | #ifndef NO_RSA | 83 | #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 | 84 | ||
207 | RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) | 85 | IMPLEMENT_PEM_rw_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) |
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 | 86 | ||
216 | RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) | 87 | IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) |
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 | 88 | ||
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 | 89 | #endif |
247 | 90 | ||
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 | 91 | #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 | 92 | ||
306 | int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) | 93 | IMPLEMENT_PEM_rw_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) |
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 | 94 | ||
355 | int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) | 95 | IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) |
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 | 96 | ||
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 | 97 | #endif |
379 | 98 | ||
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 | 99 | #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 | 100 | ||
420 | DH *PEM_read_bio_DHparams(bp,x,cb) | 101 | IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) |
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 | 102 | ||
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 | 103 | #endif |
438 | 104 | ||
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 | 105 | ||
106 | /* The PrivateKey case is not that straightforward. | ||
107 | * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) | ||
108 | * does not work, RSA and DSA keys have specific strings. | ||
109 | * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything | ||
110 | * appropriate.) | ||
111 | */ | ||
112 | IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) | ||
113 | IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey) | ||