…lines 1–92 unchanged (92 lines)
93
94static int pkcs7_bio_add_digest(BIO **pbio, X509_ALGOR *alg,
95 const PKCS7_CTX *ctx)
96{
97 BIO *btmp;
98 char name[OSSL_MAX_NAME_SIZE];
99 EVP_MD *fetched = NULL;
100 const EVP_MD *md;
101
102 if ((btmp = BIO_new(BIO_f_md())) == NULL) {
103 ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
104 goto err;
105 }
106
107 OBJ_obj2txt(name, sizeof(name), alg->algorithm, 0);
108
109 (void)ERR_set_mark();
110 fetched = EVP_MD_fetch(ossl_pkcs7_ctx_get0_libctx(ctx), name,
111 ossl_pkcs7_ctx_get0_propq(ctx));
112 if (fetched != NULL)
113 md = fetched;
114 else
115 md = EVP_get_digestbyname(name);
116
117 if (md == NULL) {
118 (void)ERR_clear_last_mark();
119 ERR_raise(ERR_LIB_PKCS7, PKCS7_R_UNKNOWN_DIGEST_TYPE);
120 goto err;
121 }
122 (void)ERR_pop_to_mark();
123
124 if (BIO_set_md(btmp, md) <= 0) {
125 ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
126 EVP_MD_free(fetched);
127 goto err;
128 }
129 EVP_MD_free(fetched);
130 if (*pbio == NULL)
131 *pbio = btmp;
132 else if (!BIO_push(*pbio, btmp)) {
133 ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
134 goto err;
135 }
…lines 136–436 unchanged (301 lines)
437BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
438{
439 int i, len;
440 BIO *out = NULL, *btmp = NULL, *etmp = NULL, *bio = NULL;
441 X509_ALGOR *xa;
442 ASN1_OCTET_STRING *data_body = NULL;
443 EVP_MD *evp_md = NULL;
444 const EVP_MD *md;
445 EVP_CIPHER *evp_cipher = NULL;
446 const EVP_CIPHER *cipher = NULL;
447 EVP_CIPHER_CTX *evp_ctx = NULL;
448 X509_ALGOR *enc_alg = NULL;
449 STACK_OF(X509_ALGOR) *md_sk = NULL;
450 STACK_OF(PKCS7_RECIP_INFO) *rsk = NULL;
451 PKCS7_RECIP_INFO *ri = NULL;
452 unsigned char *ek = NULL, *tkey = NULL;
…lines 453–493 unchanged (41 lines)
494 /* data_body is NULL if the optional EncryptedContent is missing. */
495 data_body = p7->d.signed_and_enveloped->enc_data->enc_data;
496 enc_alg = p7->d.signed_and_enveloped->enc_data->algorithm;
497
498 OBJ_obj2txt(name, sizeof(name), enc_alg->algorithm, 0);
499
500 (void)ERR_set_mark();
501 evp_cipher = EVP_CIPHER_fetch(libctx, name, propq);
502 if (evp_cipher != NULL)
503 cipher = evp_cipher;
504 else
505 cipher = EVP_get_cipherbyname(name);
506
507 if (cipher == NULL) {
508 (void)ERR_clear_last_mark();
509 ERR_raise(ERR_LIB_PKCS7, PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
510 goto err;
511 }
512 (void)ERR_pop_to_mark();
513 break;
514 case NID_pkcs7_enveloped:
515 rsk = p7->d.enveloped->recipientinfo;
516 enc_alg = p7->d.enveloped->enc_data->algorithm;
517 /* data_body is NULL if the optional EncryptedContent is missing. */
518 data_body = p7->d.enveloped->enc_data->enc_data;
519 OBJ_obj2txt(name, sizeof(name), enc_alg->algorithm, 0);
520
521 (void)ERR_set_mark();
522 evp_cipher = EVP_CIPHER_fetch(libctx, name, propq);
523 if (evp_cipher != NULL)
524 cipher = evp_cipher;
525 else
526 cipher = EVP_get_cipherbyname(name);
527
528 if (cipher == NULL) {
529 (void)ERR_clear_last_mark();
530 ERR_raise(ERR_LIB_PKCS7, PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
531 goto err;
532 }
533 (void)ERR_pop_to_mark();
534 break;
535 default:
536 ERR_raise(ERR_LIB_PKCS7, PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
537 goto err;
538 }
539
…lines 540–550 unchanged (11 lines)
551 ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
552 goto err;
553 }
554
555 OBJ_obj2txt(name, sizeof(name), xa->algorithm, 0);
556
557 (void)ERR_set_mark();
558 evp_md = EVP_MD_fetch(libctx, name, propq);
559 if (evp_md != NULL)
560 md = evp_md;
561 else
562 md = EVP_get_digestbyname(name);
563
564 if (md == NULL) {
565 (void)ERR_clear_last_mark();
566 ERR_raise(ERR_LIB_PKCS7, PKCS7_R_UNKNOWN_DIGEST_TYPE);
567 goto err;
568 }
569 (void)ERR_pop_to_mark();
570
571 if (BIO_set_md(btmp, md) <= 0) {
572 EVP_MD_free(evp_md);
573 ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
574 goto err;
575 }
576 EVP_MD_free(evp_md);
577 if (out == NULL)
578 out = btmp;
579 else
580 BIO_push(out, btmp);
581 btmp = NULL;
582 }
…lines 583–699 unchanged (117 lines)
700 }
701 if (bio == NULL)
702 goto err;
703 }
704 BIO_push(out, bio);
705 bio = NULL;
706 EVP_CIPHER_free(evp_cipher);
707 return out;
708
709err:
710 EVP_CIPHER_free(evp_cipher);
711 OPENSSL_clear_free(ek, eklen);
712 OPENSSL_clear_free(tkey, tkeylen);
713 BIO_free_all(out);
714 BIO_free_all(btmp);
715 BIO_free_all(etmp);
716 BIO_free_all(bio);
…lines 717–1061 unchanged (345 lines)
1062
1063int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
1064 X509 *signer)
1065{
1066 ASN1_OCTET_STRING *os;
1067 EVP_MD_CTX *mdc_tmp, *mdc;
1068 const EVP_MD *md;
1069 EVP_MD *fetched_md = NULL;
1070 int ret = 0, i;
1071 int md_type;
1072 STACK_OF(X509_ATTRIBUTE) *sk;
1073 BIO *btmp;
1074 EVP_PKEY *pkey;
1075 unsigned char *abuf = NULL;
…lines 1076–1135 unchanged (60 lines)
1136 if ((message_digest->length != (int)md_len) || (memcmp(message_digest->data, md_dat, md_len))) {
1137 ERR_raise(ERR_LIB_PKCS7, PKCS7_R_DIGEST_FAILURE);
1138 ret = -1;
1139 goto err;
1140 }
1141
1142 (void)ERR_set_mark();
1143 fetched_md = EVP_MD_fetch(libctx, OBJ_nid2sn(md_type), propq);
1144
1145 if (fetched_md != NULL)
1146 md = fetched_md;
1147 else
1148 md = EVP_get_digestbynid(md_type);
1149
1150 if (md == NULL || !EVP_VerifyInit_ex(mdc_tmp, md, NULL)) {
1151 (void)ERR_clear_last_mark();
1152 goto err;
1153 }
1154 (void)ERR_pop_to_mark();
1155
1156 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
1157 ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
1158 if (alen <= 0 || abuf == NULL) {
1159 ERR_raise(ERR_LIB_PKCS7, ERR_R_ASN1_LIB);
1160 ret = -1;
…lines 1161–1177 unchanged (17 lines)
1178 goto err;
1179 }
1180 ret = 1;
1181err:
1182 OPENSSL_free(abuf);
1183 EVP_MD_CTX_free(mdc_tmp);
1184 EVP_MD_free(fetched_md);
1185 return ret;
1186}
1187
1188PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
1189{
1190 STACK_OF(PKCS7_RECIP_INFO) *rsk;
…lines 1191–1299 unchanged (109 lines)