summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs7/pk7_doit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pkcs7/pk7_doit.c')
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c134
1 files changed, 53 insertions, 81 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index e84eee6d8f..484620a686 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.40 2016/12/30 15:38:13 jsing Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.41 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -110,14 +110,13 @@ PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
110 BIO *btmp; 110 BIO *btmp;
111 const EVP_MD *md; 111 const EVP_MD *md;
112 if ((btmp = BIO_new(BIO_f_md())) == NULL) { 112 if ((btmp = BIO_new(BIO_f_md())) == NULL) {
113 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, ERR_R_BIO_LIB); 113 PKCS7error(ERR_R_BIO_LIB);
114 goto err; 114 goto err;
115 } 115 }
116 116
117 md = EVP_get_digestbyobj(alg->algorithm); 117 md = EVP_get_digestbyobj(alg->algorithm);
118 if (md == NULL) { 118 if (md == NULL) {
119 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, 119 PKCS7error(PKCS7_R_UNKNOWN_DIGEST_TYPE);
120 PKCS7_R_UNKNOWN_DIGEST_TYPE);
121 goto err; 120 goto err;
122 } 121 }
123 122
@@ -125,7 +124,7 @@ PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
125 if (*pbio == NULL) 124 if (*pbio == NULL)
126 *pbio = btmp; 125 *pbio = btmp;
127 else if (!BIO_push(*pbio, btmp)) { 126 else if (!BIO_push(*pbio, btmp)) {
128 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, ERR_R_BIO_LIB); 127 PKCS7error(ERR_R_BIO_LIB);
129 goto err; 128 goto err;
130 } 129 }
131 btmp = NULL; 130 btmp = NULL;
@@ -160,7 +159,7 @@ pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri, unsigned char *key, int keylen)
160 159
161 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT, 160 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT,
162 EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0) { 161 EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0) {
163 PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, PKCS7_R_CTRL_ERROR); 162 PKCS7error(PKCS7_R_CTRL_ERROR);
164 goto err; 163 goto err;
165 } 164 }
166 165
@@ -170,7 +169,7 @@ pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri, unsigned char *key, int keylen)
170 ek = malloc(eklen); 169 ek = malloc(eklen);
171 170
172 if (ek == NULL) { 171 if (ek == NULL) {
173 PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, ERR_R_MALLOC_FAILURE); 172 PKCS7error(ERR_R_MALLOC_FAILURE);
174 goto err; 173 goto err;
175 } 174 }
176 175
@@ -209,7 +208,7 @@ pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, PKCS7_RECIP_INFO *ri,
209 208
210 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT, 209 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT,
211 EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0) { 210 EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0) {
212 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, PKCS7_R_CTRL_ERROR); 211 PKCS7error(PKCS7_R_CTRL_ERROR);
213 goto err; 212 goto err;
214 } 213 }
215 214
@@ -219,14 +218,14 @@ pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, PKCS7_RECIP_INFO *ri,
219 218
220 ek = malloc(eklen); 219 ek = malloc(eklen);
221 if (ek == NULL) { 220 if (ek == NULL) {
222 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_MALLOC_FAILURE); 221 PKCS7error(ERR_R_MALLOC_FAILURE);
223 goto err; 222 goto err;
224 } 223 }
225 224
226 if (EVP_PKEY_decrypt(pctx, ek, &eklen, 225 if (EVP_PKEY_decrypt(pctx, ek, &eklen,
227 ri->enc_key->data, ri->enc_key->length) <= 0) { 226 ri->enc_key->data, ri->enc_key->length) <= 0) {
228 ret = 0; 227 ret = 0;
229 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_EVP_LIB); 228 PKCS7error(ERR_R_EVP_LIB);
230 goto err; 229 goto err;
231 } 230 }
232 231
@@ -262,7 +261,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
262 ASN1_OCTET_STRING *os = NULL; 261 ASN1_OCTET_STRING *os = NULL;
263 262
264 if (p7 == NULL) { 263 if (p7 == NULL) {
265 PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_INVALID_NULL_POINTER); 264 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
266 return NULL; 265 return NULL;
267 } 266 }
268 267
@@ -279,7 +278,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
279 * an error. 278 * an error.
280 */ 279 */
281 if (p7->d.ptr == NULL) { 280 if (p7->d.ptr == NULL) {
282 PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_NO_CONTENT); 281 PKCS7error(PKCS7_R_NO_CONTENT);
283 return NULL; 282 return NULL;
284 } 283 }
285 284
@@ -297,8 +296,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
297 xalg = p7->d.signed_and_enveloped->enc_data->algorithm; 296 xalg = p7->d.signed_and_enveloped->enc_data->algorithm;
298 evp_cipher = p7->d.signed_and_enveloped->enc_data->cipher; 297 evp_cipher = p7->d.signed_and_enveloped->enc_data->cipher;
299 if (evp_cipher == NULL) { 298 if (evp_cipher == NULL) {
300 PKCS7err(PKCS7_F_PKCS7_DATAINIT, 299 PKCS7error(PKCS7_R_CIPHER_NOT_INITIALIZED);
301 PKCS7_R_CIPHER_NOT_INITIALIZED);
302 goto err; 300 goto err;
303 } 301 }
304 break; 302 break;
@@ -307,8 +305,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
307 xalg = p7->d.enveloped->enc_data->algorithm; 305 xalg = p7->d.enveloped->enc_data->algorithm;
308 evp_cipher = p7->d.enveloped->enc_data->cipher; 306 evp_cipher = p7->d.enveloped->enc_data->cipher;
309 if (evp_cipher == NULL) { 307 if (evp_cipher == NULL) {
310 PKCS7err(PKCS7_F_PKCS7_DATAINIT, 308 PKCS7error(PKCS7_R_CIPHER_NOT_INITIALIZED);
311 PKCS7_R_CIPHER_NOT_INITIALIZED);
312 goto err; 309 goto err;
313 } 310 }
314 break; 311 break;
@@ -319,8 +316,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
319 case NID_pkcs7_data: 316 case NID_pkcs7_data:
320 break; 317 break;
321 default: 318 default:
322 PKCS7err(PKCS7_F_PKCS7_DATAINIT, 319 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
323 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
324 goto err; 320 goto err;
325 } 321 }
326 322
@@ -338,7 +334,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
338 EVP_CIPHER_CTX *ctx; 334 EVP_CIPHER_CTX *ctx;
339 335
340 if ((btmp = BIO_new(BIO_f_cipher())) == NULL) { 336 if ((btmp = BIO_new(BIO_f_cipher())) == NULL) {
341 PKCS7err(PKCS7_F_PKCS7_DATAINIT, ERR_R_BIO_LIB); 337 PKCS7error(ERR_R_BIO_LIB);
342 goto err; 338 goto err;
343 } 339 }
344 BIO_get_cipher_ctx(btmp, &ctx); 340 BIO_get_cipher_ctx(btmp, &ctx);
@@ -440,13 +436,12 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
440 int eklen = 0, tkeylen = 0; 436 int eklen = 0, tkeylen = 0;
441 437
442 if (p7 == NULL) { 438 if (p7 == NULL) {
443 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 439 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
444 PKCS7_R_INVALID_NULL_POINTER);
445 return NULL; 440 return NULL;
446 } 441 }
447 442
448 if (p7->d.ptr == NULL) { 443 if (p7->d.ptr == NULL) {
449 PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_CONTENT); 444 PKCS7error(PKCS7_R_NO_CONTENT);
450 return NULL; 445 return NULL;
451 } 446 }
452 447
@@ -465,8 +460,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
465 enc_alg = p7->d.signed_and_enveloped->enc_data->algorithm; 460 enc_alg = p7->d.signed_and_enveloped->enc_data->algorithm;
466 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm); 461 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm);
467 if (evp_cipher == NULL) { 462 if (evp_cipher == NULL) {
468 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 463 PKCS7error(PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
469 PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
470 goto err; 464 goto err;
471 } 465 }
472 break; 466 break;
@@ -476,14 +470,12 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
476 data_body = p7->d.enveloped->enc_data->enc_data; 470 data_body = p7->d.enveloped->enc_data->enc_data;
477 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm); 471 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm);
478 if (evp_cipher == NULL) { 472 if (evp_cipher == NULL) {
479 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 473 PKCS7error(PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
480 PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
481 goto err; 474 goto err;
482 } 475 }
483 break; 476 break;
484 default: 477 default:
485 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 478 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
486 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
487 goto err; 479 goto err;
488 } 480 }
489 481
@@ -492,16 +484,14 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
492 for (i = 0; i < sk_X509_ALGOR_num(md_sk); i++) { 484 for (i = 0; i < sk_X509_ALGOR_num(md_sk); i++) {
493 xa = sk_X509_ALGOR_value(md_sk, i); 485 xa = sk_X509_ALGOR_value(md_sk, i);
494 if ((btmp = BIO_new(BIO_f_md())) == NULL) { 486 if ((btmp = BIO_new(BIO_f_md())) == NULL) {
495 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 487 PKCS7error(ERR_R_BIO_LIB);
496 ERR_R_BIO_LIB);
497 goto err; 488 goto err;
498 } 489 }
499 490
500 j = OBJ_obj2nid(xa->algorithm); 491 j = OBJ_obj2nid(xa->algorithm);
501 evp_md = EVP_get_digestbynid(j); 492 evp_md = EVP_get_digestbynid(j);
502 if (evp_md == NULL) { 493 if (evp_md == NULL) {
503 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 494 PKCS7error(PKCS7_R_UNKNOWN_DIGEST_TYPE);
504 PKCS7_R_UNKNOWN_DIGEST_TYPE);
505 goto err; 495 goto err;
506 } 496 }
507 497
@@ -516,7 +506,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
516 506
517 if (evp_cipher != NULL) { 507 if (evp_cipher != NULL) {
518 if ((etmp = BIO_new(BIO_f_cipher())) == NULL) { 508 if ((etmp = BIO_new(BIO_f_cipher())) == NULL) {
519 PKCS7err(PKCS7_F_PKCS7_DATADECODE, ERR_R_BIO_LIB); 509 PKCS7error(ERR_R_BIO_LIB);
520 goto err; 510 goto err;
521 } 511 }
522 512
@@ -534,8 +524,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
534 ri = NULL; 524 ri = NULL;
535 } 525 }
536 if (ri == NULL) { 526 if (ri == NULL) {
537 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 527 PKCS7error(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
538 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
539 goto err; 528 goto err;
540 } 529 }
541 } 530 }
@@ -659,14 +648,12 @@ PKCS7_find_digest(EVP_MD_CTX **pmd, BIO *bio, int nid)
659 for (;;) { 648 for (;;) {
660 bio = BIO_find_type(bio, BIO_TYPE_MD); 649 bio = BIO_find_type(bio, BIO_TYPE_MD);
661 if (bio == NULL) { 650 if (bio == NULL) {
662 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST, 651 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
663 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
664 return NULL; 652 return NULL;
665 } 653 }
666 BIO_get_md_ctx(bio, pmd); 654 BIO_get_md_ctx(bio, pmd);
667 if (*pmd == NULL) { 655 if (*pmd == NULL) {
668 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST, 656 PKCS7error(ERR_R_INTERNAL_ERROR);
669 ERR_R_INTERNAL_ERROR);
670 return NULL; 657 return NULL;
671 } 658 }
672 if (EVP_MD_CTX_type(*pmd) == nid) 659 if (EVP_MD_CTX_type(*pmd) == nid)
@@ -685,19 +672,18 @@ do_pkcs7_signed_attrib(PKCS7_SIGNER_INFO *si, EVP_MD_CTX *mctx)
685 /* Add signing time if not already present */ 672 /* Add signing time if not already present */
686 if (!PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime)) { 673 if (!PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime)) {
687 if (!PKCS7_add0_attrib_signing_time(si, NULL)) { 674 if (!PKCS7_add0_attrib_signing_time(si, NULL)) {
688 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, 675 PKCS7error(ERR_R_MALLOC_FAILURE);
689 ERR_R_MALLOC_FAILURE);
690 return 0; 676 return 0;
691 } 677 }
692 } 678 }
693 679
694 /* Add digest */ 680 /* Add digest */
695 if (!EVP_DigestFinal_ex(mctx, md_data, &md_len)) { 681 if (!EVP_DigestFinal_ex(mctx, md_data, &md_len)) {
696 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_EVP_LIB); 682 PKCS7error(ERR_R_EVP_LIB);
697 return 0; 683 return 0;
698 } 684 }
699 if (!PKCS7_add1_attrib_digest(si, md_data, md_len)) { 685 if (!PKCS7_add1_attrib_digest(si, md_data, md_len)) {
700 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_MALLOC_FAILURE); 686 PKCS7error(ERR_R_MALLOC_FAILURE);
701 return 0; 687 return 0;
702 } 688 }
703 689
@@ -722,13 +708,12 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
722 ASN1_OCTET_STRING *os = NULL; 708 ASN1_OCTET_STRING *os = NULL;
723 709
724 if (p7 == NULL) { 710 if (p7 == NULL) {
725 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 711 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
726 PKCS7_R_INVALID_NULL_POINTER);
727 return 0; 712 return 0;
728 } 713 }
729 714
730 if (p7->d.ptr == NULL) { 715 if (p7->d.ptr == NULL) {
731 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_NO_CONTENT); 716 PKCS7error(PKCS7_R_NO_CONTENT);
732 return 0; 717 return 0;
733 } 718 }
734 719
@@ -747,8 +732,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
747 if (!os) { 732 if (!os) {
748 os = ASN1_OCTET_STRING_new(); 733 os = ASN1_OCTET_STRING_new();
749 if (!os) { 734 if (!os) {
750 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 735 PKCS7error(ERR_R_MALLOC_FAILURE);
751 ERR_R_MALLOC_FAILURE);
752 goto err; 736 goto err;
753 } 737 }
754 p7->d.signed_and_enveloped->enc_data->enc_data = os; 738 p7->d.signed_and_enveloped->enc_data->enc_data = os;
@@ -760,8 +744,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
760 if (!os) { 744 if (!os) {
761 os = ASN1_OCTET_STRING_new(); 745 os = ASN1_OCTET_STRING_new();
762 if (!os) { 746 if (!os) {
763 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 747 PKCS7error(ERR_R_MALLOC_FAILURE);
764 ERR_R_MALLOC_FAILURE);
765 goto err; 748 goto err;
766 } 749 }
767 p7->d.enveloped->enc_data->enc_data = os; 750 p7->d.enveloped->enc_data->enc_data = os;
@@ -771,7 +754,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
771 si_sk = p7->d.sign->signer_info; 754 si_sk = p7->d.sign->signer_info;
772 os = PKCS7_get_octet_string(p7->d.sign->contents); 755 os = PKCS7_get_octet_string(p7->d.sign->contents);
773 if (!PKCS7_is_detached(p7) && os == NULL) { 756 if (!PKCS7_is_detached(p7) && os == NULL) {
774 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR); 757 PKCS7error(PKCS7_R_DECODE_ERROR);
775 goto err; 758 goto err;
776 } 759 }
777 /* If detached data then the content is excluded */ 760 /* If detached data then the content is excluded */
@@ -785,7 +768,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
785 case NID_pkcs7_digest: 768 case NID_pkcs7_digest:
786 os = PKCS7_get_octet_string(p7->d.digest->contents); 769 os = PKCS7_get_octet_string(p7->d.digest->contents);
787 if (os == NULL) { 770 if (os == NULL) {
788 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR); 771 PKCS7error(PKCS7_R_DECODE_ERROR);
789 goto err; 772 goto err;
790 } 773 }
791 /* If detached data then the content is excluded */ 774 /* If detached data then the content is excluded */
@@ -798,8 +781,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
798 break; 781 break;
799 782
800 default: 783 default:
801 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 784 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
802 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
803 goto err; 785 goto err;
804 } 786 }
805 787
@@ -836,8 +818,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
836 818
837 if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen, 819 if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen,
838 si->pkey)) { 820 si->pkey)) {
839 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 821 PKCS7error(ERR_R_EVP_LIB);
840 ERR_R_EVP_LIB);
841 goto err; 822 goto err;
842 } 823 }
843 ASN1_STRING_set0(si->enc_digest, abuf, abuflen); 824 ASN1_STRING_set0(si->enc_digest, abuf, abuflen);
@@ -870,8 +851,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
870 851
871 btmp = BIO_find_type(bio, BIO_TYPE_MEM); 852 btmp = BIO_find_type(bio, BIO_TYPE_MEM);
872 if (btmp == NULL) { 853 if (btmp == NULL) {
873 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 854 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
874 PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
875 goto err; 855 goto err;
876 } 856 }
877 contlen = BIO_get_mem_data(btmp, &cont); 857 contlen = BIO_get_mem_data(btmp, &cont);
@@ -910,7 +890,7 @@ PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
910 890
911 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, 891 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
912 EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0) { 892 EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0) {
913 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR); 893 PKCS7error(PKCS7_R_CTRL_ERROR);
914 goto err; 894 goto err;
915 } 895 }
916 896
@@ -932,7 +912,7 @@ PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
932 912
933 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, 913 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
934 EVP_PKEY_CTRL_PKCS7_SIGN, 1, si) <= 0) { 914 EVP_PKEY_CTRL_PKCS7_SIGN, 1, si) <= 0) {
935 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR); 915 PKCS7error(PKCS7_R_CTRL_ERROR);
936 goto err; 916 goto err;
937 } 917 }
938 918
@@ -958,13 +938,12 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
958 X509 *x509; 938 X509 *x509;
959 939
960 if (p7 == NULL) { 940 if (p7 == NULL) {
961 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, 941 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
962 PKCS7_R_INVALID_NULL_POINTER);
963 return 0; 942 return 0;
964 } 943 }
965 944
966 if (p7->d.ptr == NULL) { 945 if (p7->d.ptr == NULL) {
967 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_NO_CONTENT); 946 PKCS7error(PKCS7_R_NO_CONTENT);
968 return 0; 947 return 0;
969 } 948 }
970 949
@@ -973,7 +952,7 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
973 } else if (PKCS7_type_is_signedAndEnveloped(p7)) { 952 } else if (PKCS7_type_is_signedAndEnveloped(p7)) {
974 cert = p7->d.signed_and_enveloped->cert; 953 cert = p7->d.signed_and_enveloped->cert;
975 } else { 954 } else {
976 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_WRONG_PKCS7_TYPE); 955 PKCS7error(PKCS7_R_WRONG_PKCS7_TYPE);
977 goto err; 956 goto err;
978 } 957 }
979 /* XXXX */ 958 /* XXXX */
@@ -983,14 +962,13 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
983 962
984 /* were we able to find the cert in passed to us */ 963 /* were we able to find the cert in passed to us */
985 if (x509 == NULL) { 964 if (x509 == NULL) {
986 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, 965 PKCS7error(PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
987 PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
988 goto err; 966 goto err;
989 } 967 }
990 968
991 /* Lets verify */ 969 /* Lets verify */
992 if (!X509_STORE_CTX_init(ctx, cert_store, x509, cert)) { 970 if (!X509_STORE_CTX_init(ctx, cert_store, x509, cert)) {
993 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, ERR_R_X509_LIB); 971 PKCS7error(ERR_R_X509_LIB);
994 goto err; 972 goto err;
995 } 973 }
996 if (X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN) == 0) { 974 if (X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN) == 0) {
@@ -999,7 +977,7 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
999 } 977 }
1000 i = X509_verify_cert(ctx); 978 i = X509_verify_cert(ctx);
1001 if (i <= 0) { 979 if (i <= 0) {
1002 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, ERR_R_X509_LIB); 980 PKCS7error(ERR_R_X509_LIB);
1003 X509_STORE_CTX_cleanup(ctx); 981 X509_STORE_CTX_cleanup(ctx);
1004 goto err; 982 goto err;
1005 } 983 }
@@ -1026,8 +1004,7 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1026 1004
1027 if (!PKCS7_type_is_signed(p7) && 1005 if (!PKCS7_type_is_signed(p7) &&
1028 !PKCS7_type_is_signedAndEnveloped(p7)) { 1006 !PKCS7_type_is_signedAndEnveloped(p7)) {
1029 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1007 PKCS7error(PKCS7_R_WRONG_PKCS7_TYPE);
1030 PKCS7_R_WRONG_PKCS7_TYPE);
1031 goto err; 1008 goto err;
1032 } 1009 }
1033 1010
@@ -1037,14 +1014,12 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1037 for (;;) { 1014 for (;;) {
1038 if ((btmp == NULL) || 1015 if ((btmp == NULL) ||
1039 ((btmp = BIO_find_type(btmp, BIO_TYPE_MD)) == NULL)) { 1016 ((btmp = BIO_find_type(btmp, BIO_TYPE_MD)) == NULL)) {
1040 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1017 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1041 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1042 goto err; 1018 goto err;
1043 } 1019 }
1044 BIO_get_md_ctx(btmp, &mdc); 1020 BIO_get_md_ctx(btmp, &mdc);
1045 if (mdc == NULL) { 1021 if (mdc == NULL) {
1046 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1022 PKCS7error(ERR_R_INTERNAL_ERROR);
1047 ERR_R_INTERNAL_ERROR);
1048 goto err; 1023 goto err;
1049 } 1024 }
1050 if (EVP_MD_CTX_type(mdc) == md_type) 1025 if (EVP_MD_CTX_type(mdc) == md_type)
@@ -1073,14 +1048,12 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1073 goto err; 1048 goto err;
1074 message_digest = PKCS7_digest_from_attributes(sk); 1049 message_digest = PKCS7_digest_from_attributes(sk);
1075 if (!message_digest) { 1050 if (!message_digest) {
1076 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1051 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1077 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1078 goto err; 1052 goto err;
1079 } 1053 }
1080 if ((message_digest->length != (int)md_len) || 1054 if ((message_digest->length != (int)md_len) ||
1081 (memcmp(message_digest->data, md_dat, md_len))) { 1055 (memcmp(message_digest->data, md_dat, md_len))) {
1082 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1056 PKCS7error(PKCS7_R_DIGEST_FAILURE);
1083 PKCS7_R_DIGEST_FAILURE);
1084 ret = -1; 1057 ret = -1;
1085 goto err; 1058 goto err;
1086 } 1059 }
@@ -1092,7 +1065,7 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1092 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf, 1065 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
1093 &PKCS7_ATTR_VERIFY_it); 1066 &PKCS7_ATTR_VERIFY_it);
1094 if (alen <= 0) { 1067 if (alen <= 0) {
1095 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, ERR_R_ASN1_LIB); 1068 PKCS7error(ERR_R_ASN1_LIB);
1096 ret = -1; 1069 ret = -1;
1097 goto err; 1070 goto err;
1098 } 1071 }
@@ -1112,8 +1085,7 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1112 i = EVP_VerifyFinal(&mdc_tmp, os->data, os->length, pkey); 1085 i = EVP_VerifyFinal(&mdc_tmp, os->data, os->length, pkey);
1113 EVP_PKEY_free(pkey); 1086 EVP_PKEY_free(pkey);
1114 if (i <= 0) { 1087 if (i <= 0) {
1115 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1088 PKCS7error(PKCS7_R_SIGNATURE_FAILURE);
1116 PKCS7_R_SIGNATURE_FAILURE);
1117 ret = -1; 1089 ret = -1;
1118 goto err; 1090 goto err;
1119 } else 1091 } else