OLD | NEW |
1 /* crypto/cms/cms_smime.c */ | 1 /* crypto/cms/cms_smime.c */ |
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 * project. | 3 * project. |
4 */ | 4 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return r; | 164 return r; |
165 } | 165 } |
166 | 166 |
167 CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags) | 167 CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags) |
168 { | 168 { |
169 CMS_ContentInfo *cms; | 169 CMS_ContentInfo *cms; |
170 cms = cms_Data_create(); | 170 cms = cms_Data_create(); |
171 if (!cms) | 171 if (!cms) |
172 return NULL; | 172 return NULL; |
173 | 173 |
174 » if (CMS_final(cms, in, NULL, flags)) | 174 » if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) |
175 return cms; | 175 return cms; |
176 | 176 |
177 CMS_ContentInfo_free(cms); | 177 CMS_ContentInfo_free(cms); |
178 | 178 |
179 return NULL; | 179 return NULL; |
180 } | 180 } |
181 | 181 |
182 int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, | 182 int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, |
183 unsigned int flags) | 183 unsigned int flags) |
184 { | 184 { |
(...skipping 22 matching lines...) Expand all Loading... |
207 unsigned int flags) | 207 unsigned int flags) |
208 { | 208 { |
209 CMS_ContentInfo *cms; | 209 CMS_ContentInfo *cms; |
210 if (!md) | 210 if (!md) |
211 md = EVP_sha1(); | 211 md = EVP_sha1(); |
212 cms = cms_DigestedData_create(md); | 212 cms = cms_DigestedData_create(md); |
213 if (!cms) | 213 if (!cms) |
214 return NULL; | 214 return NULL; |
215 | 215 |
216 if(!(flags & CMS_DETACHED)) | 216 if(!(flags & CMS_DETACHED)) |
217 { | |
218 flags &= ~CMS_STREAM; | |
219 CMS_set_detached(cms, 0); | 217 CMS_set_detached(cms, 0); |
220 } | |
221 | 218 |
222 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) | 219 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) |
223 return cms; | 220 return cms; |
224 | 221 |
225 CMS_ContentInfo_free(cms); | 222 CMS_ContentInfo_free(cms); |
226 return NULL; | 223 return NULL; |
227 } | 224 } |
228 | 225 |
229 int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, | 226 int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, |
230 const unsigned char *key, size_t keylen, | 227 const unsigned char *key, size_t keylen, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER); | 259 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER); |
263 return NULL; | 260 return NULL; |
264 } | 261 } |
265 cms = CMS_ContentInfo_new(); | 262 cms = CMS_ContentInfo_new(); |
266 if (!cms) | 263 if (!cms) |
267 return NULL; | 264 return NULL; |
268 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) | 265 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) |
269 return NULL; | 266 return NULL; |
270 | 267 |
271 if(!(flags & CMS_DETACHED)) | 268 if(!(flags & CMS_DETACHED)) |
272 { | |
273 flags &= ~CMS_STREAM; | |
274 CMS_set_detached(cms, 0); | 269 CMS_set_detached(cms, 0); |
275 } | |
276 | 270 |
277 if ((flags & (CMS_STREAM|CMS_PARTIAL)) | 271 if ((flags & (CMS_STREAM|CMS_PARTIAL)) |
278 || CMS_final(cms, in, NULL, flags)) | 272 || CMS_final(cms, in, NULL, flags)) |
279 return cms; | 273 return cms; |
280 | 274 |
281 CMS_ContentInfo_free(cms); | 275 CMS_ContentInfo_free(cms); |
282 return NULL; | 276 return NULL; |
283 } | 277 } |
284 | 278 |
285 static int cms_signerinfo_verify_cert(CMS_SignerInfo *si, | 279 static int cms_signerinfo_verify_cert(CMS_SignerInfo *si, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 sk_X509_CRL_pop_free(crls, X509_CRL_free); | 443 sk_X509_CRL_pop_free(crls, X509_CRL_free); |
450 | 444 |
451 return ret; | 445 return ret; |
452 } | 446 } |
453 | 447 |
454 int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, | 448 int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, |
455 STACK_OF(X509) *certs, | 449 STACK_OF(X509) *certs, |
456 X509_STORE *store, unsigned int flags) | 450 X509_STORE *store, unsigned int flags) |
457 { | 451 { |
458 int r; | 452 int r; |
| 453 flags &= ~(CMS_DETACHED|CMS_TEXT); |
459 r = CMS_verify(rcms, certs, store, NULL, NULL, flags); | 454 r = CMS_verify(rcms, certs, store, NULL, NULL, flags); |
460 if (r <= 0) | 455 if (r <= 0) |
461 return r; | 456 return r; |
462 return cms_Receipt_verify(rcms, ocms); | 457 return cms_Receipt_verify(rcms, ocms); |
463 } | 458 } |
464 | 459 |
465 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, | 460 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, |
466 BIO *data, unsigned int flags) | 461 BIO *data, unsigned int flags) |
467 { | 462 { |
468 CMS_ContentInfo *cms; | 463 CMS_ContentInfo *cms; |
(...skipping 10 matching lines...) Expand all Loading... |
479 } | 474 } |
480 | 475 |
481 for (i = 0; i < sk_X509_num(certs); i++) | 476 for (i = 0; i < sk_X509_num(certs); i++) |
482 { | 477 { |
483 X509 *x = sk_X509_value(certs, i); | 478 X509 *x = sk_X509_value(certs, i); |
484 if (!CMS_add1_cert(cms, x)) | 479 if (!CMS_add1_cert(cms, x)) |
485 goto merr; | 480 goto merr; |
486 } | 481 } |
487 | 482 |
488 if(!(flags & CMS_DETACHED)) | 483 if(!(flags & CMS_DETACHED)) |
489 { | |
490 flags &= ~CMS_STREAM; | |
491 CMS_set_detached(cms, 0); | 484 CMS_set_detached(cms, 0); |
492 } | |
493 | 485 |
494 if ((flags & (CMS_STREAM|CMS_PARTIAL)) | 486 if ((flags & (CMS_STREAM|CMS_PARTIAL)) |
495 || CMS_final(cms, data, NULL, flags)) | 487 || CMS_final(cms, data, NULL, flags)) |
496 return cms; | 488 return cms; |
497 else | 489 else |
498 goto err; | 490 goto err; |
499 | 491 |
500 merr: | 492 merr: |
501 CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE); | 493 CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE); |
502 | 494 |
503 err: | 495 err: |
504 if (cms) | 496 if (cms) |
505 CMS_ContentInfo_free(cms); | 497 CMS_ContentInfo_free(cms); |
506 return NULL; | 498 return NULL; |
507 } | 499 } |
508 | 500 |
509 CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, | 501 CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, |
510 X509 *signcert, EVP_PKEY *pkey, | 502 X509 *signcert, EVP_PKEY *pkey, |
511 STACK_OF(X509) *certs, | 503 STACK_OF(X509) *certs, |
512 unsigned int flags) | 504 unsigned int flags) |
513 { | 505 { |
514 CMS_SignerInfo *rct_si; | 506 CMS_SignerInfo *rct_si; |
515 CMS_ContentInfo *cms = NULL; | 507 CMS_ContentInfo *cms = NULL; |
516 ASN1_OCTET_STRING **pos, *os; | 508 ASN1_OCTET_STRING **pos, *os; |
517 BIO *rct_cont = NULL; | 509 BIO *rct_cont = NULL; |
518 int r = 0; | 510 int r = 0; |
519 | 511 |
520 » flags &= ~CMS_STREAM; | 512 » flags &= ~(CMS_STREAM|CMS_TEXT); |
521 /* Not really detached but avoids content being allocated */ | 513 /* Not really detached but avoids content being allocated */ |
522 flags |= CMS_PARTIAL|CMS_BINARY|CMS_DETACHED; | 514 flags |= CMS_PARTIAL|CMS_BINARY|CMS_DETACHED; |
523 if (!pkey || !signcert) | 515 if (!pkey || !signcert) |
524 { | 516 { |
525 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_NO_KEY_OR_CERT); | 517 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_NO_KEY_OR_CERT); |
526 return NULL; | 518 return NULL; |
527 } | 519 } |
528 | 520 |
529 /* Initialize signed data */ | 521 /* Initialize signed data */ |
530 | 522 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 { | 583 { |
592 recip = sk_X509_value(certs, i); | 584 recip = sk_X509_value(certs, i); |
593 if (!CMS_add1_recipient_cert(cms, recip, flags)) | 585 if (!CMS_add1_recipient_cert(cms, recip, flags)) |
594 { | 586 { |
595 CMSerr(CMS_F_CMS_ENCRYPT, CMS_R_RECIPIENT_ERROR); | 587 CMSerr(CMS_F_CMS_ENCRYPT, CMS_R_RECIPIENT_ERROR); |
596 goto err; | 588 goto err; |
597 } | 589 } |
598 } | 590 } |
599 | 591 |
600 if(!(flags & CMS_DETACHED)) | 592 if(!(flags & CMS_DETACHED)) |
601 { | |
602 flags &= ~CMS_STREAM; | |
603 CMS_set_detached(cms, 0); | 593 CMS_set_detached(cms, 0); |
604 } | |
605 | 594 |
606 if ((flags & (CMS_STREAM|CMS_PARTIAL)) | 595 if ((flags & (CMS_STREAM|CMS_PARTIAL)) |
607 || CMS_final(cms, data, NULL, flags)) | 596 || CMS_final(cms, data, NULL, flags)) |
608 return cms; | 597 return cms; |
609 else | 598 else |
610 goto err; | 599 goto err; |
611 | 600 |
612 merr: | 601 merr: |
613 CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE); | 602 CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE); |
614 err: | 603 err: |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) | 763 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) |
775 { | 764 { |
776 CMS_ContentInfo *cms; | 765 CMS_ContentInfo *cms; |
777 if (comp_nid <= 0) | 766 if (comp_nid <= 0) |
778 comp_nid = NID_zlib_compression; | 767 comp_nid = NID_zlib_compression; |
779 cms = cms_CompressedData_create(comp_nid); | 768 cms = cms_CompressedData_create(comp_nid); |
780 if (!cms) | 769 if (!cms) |
781 return NULL; | 770 return NULL; |
782 | 771 |
783 if(!(flags & CMS_DETACHED)) | 772 if(!(flags & CMS_DETACHED)) |
784 { | |
785 flags &= ~CMS_STREAM; | |
786 CMS_set_detached(cms, 0); | 773 CMS_set_detached(cms, 0); |
787 } | |
788 | 774 |
789 » if (CMS_final(cms, in, NULL, flags)) | 775 » if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) |
790 return cms; | 776 return cms; |
791 | 777 |
792 CMS_ContentInfo_free(cms); | 778 CMS_ContentInfo_free(cms); |
793 return NULL; | 779 return NULL; |
794 } | 780 } |
795 | 781 |
796 #else | 782 #else |
797 | 783 |
798 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, | 784 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, |
799 unsigned int flags) | 785 unsigned int flags) |
800 { | 786 { |
801 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | 787 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
802 return 0; | 788 return 0; |
803 } | 789 } |
804 | 790 |
805 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) | 791 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags) |
806 { | 792 { |
807 CMSerr(CMS_F_CMS_COMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | 793 CMSerr(CMS_F_CMS_COMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
808 return NULL; | 794 return NULL; |
809 } | 795 } |
810 | 796 |
811 #endif | 797 #endif |
OLD | NEW |