Lines Matching refs:si

70     CMS_SignerInfo *si;  in cms_sd_set_version()  local
99 si = sk_CMS_SignerInfo_value(sd->signerInfos, i); in cms_sd_set_version()
100 if (si->sid->type == CMS_SIGNERINFO_KEYIDENTIFIER) { in cms_sd_set_version()
101 if (si->version < 3) in cms_sd_set_version()
102 si->version = 3; in cms_sd_set_version()
105 } else if (si->version < 1) { in cms_sd_set_version()
106 si->version = 1; in cms_sd_set_version()
127 static int cms_set_si_contentType_attr(CMS_ContentInfo *cms, CMS_SignerInfo *si) in cms_set_si_contentType_attr() argument
132 return CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType, in cms_set_si_contentType_attr()
137 static int cms_copy_messageDigest(CMS_ContentInfo *cms, CMS_SignerInfo *si) in cms_copy_messageDigest() argument
148 if (sitmp == si) in cms_copy_messageDigest()
152 if (OBJ_cmp(si->digestAlgorithm->algorithm, in cms_copy_messageDigest()
164 if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest, in cms_copy_messageDigest()
230 static int cms_generic_sign(CMS_SignerInfo *si, int verify) in cms_generic_sign() argument
236 EVP_PKEY *pkey = si->pkey; in cms_generic_sign()
240 CMS_SignerInfo_get0_algs(si, NULL, NULL, &alg1, &alg2); in cms_generic_sign()
259 static int cms_sd_asn1_ctrl(CMS_SignerInfo *si, int cmd) in cms_sd_asn1_ctrl() argument
261 EVP_PKEY *pkey = si->pkey; in cms_sd_asn1_ctrl()
265 return cms_generic_sign(si, cmd) > 0; in cms_sd_asn1_ctrl()
267 return ossl_cms_rsa_sign(si, cmd) > 0; in cms_sd_asn1_ctrl()
271 return cms_generic_sign(si, cmd) > 0; in cms_sd_asn1_ctrl()
272 i = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_CMS_SIGN, cmd, si); in cms_sd_asn1_ctrl()
285 static int ossl_cms_add1_signing_cert(CMS_SignerInfo *si, in ossl_cms_add1_signing_cert() argument
303 ret = CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_signingCertificate, in ossl_cms_add1_signing_cert()
310 static int ossl_cms_add1_signing_cert_v2(CMS_SignerInfo *si, in ossl_cms_add1_signing_cert_v2() argument
328 ret = CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_signingCertificateV2, in ossl_cms_add1_signing_cert_v2()
339 CMS_SignerInfo *si = NULL; in CMS_add1_signer() local
351 si = M_ASN1_new_of(CMS_SignerInfo); in CMS_add1_signer()
352 if (!si) { in CMS_add1_signer()
362 si->cms_ctx = ctx; in CMS_add1_signer()
363 si->pkey = pk; in CMS_add1_signer()
364 si->signer = signer; in CMS_add1_signer()
365 si->mctx = EVP_MD_CTX_new(); in CMS_add1_signer()
366 si->pctx = NULL; in CMS_add1_signer()
368 if (si->mctx == NULL) { in CMS_add1_signer()
374 si->version = 3; in CMS_add1_signer()
380 si->version = 1; in CMS_add1_signer()
383 if (!ossl_cms_set1_SignerIdentifier(si->sid, signer, type, ctx)) in CMS_add1_signer()
402 X509_ALGOR_set_md(si->digestAlgorithm, md); in CMS_add1_signer()
429 if (!(flags & CMS_KEY_PARAM) && !cms_sd_asn1_ctrl(si, 0)) { in CMS_add1_signer()
439 if (!si->signedAttrs) { in CMS_add1_signer()
440 si->signedAttrs = sk_X509_ATTRIBUTE_new_null(); in CMS_add1_signer()
441 if (!si->signedAttrs) { in CMS_add1_signer()
452 i = CMS_add_smimecap(si, smcap); in CMS_add1_signer()
468 add_sc = ossl_cms_add1_signing_cert(si, sc); in CMS_add1_signer()
474 add_sc = ossl_cms_add1_signing_cert_v2(si, sc2); in CMS_add1_signer()
481 if (!cms_copy_messageDigest(cms, si)) in CMS_add1_signer()
483 if (!cms_set_si_contentType_attr(cms, si)) in CMS_add1_signer()
486 !CMS_SignerInfo_sign(si)) in CMS_add1_signer()
501 si->pctx = EVP_PKEY_CTX_new_from_pkey(ossl_cms_ctx_get0_libctx(ctx), in CMS_add1_signer()
502 si->pkey, in CMS_add1_signer()
504 if (si->pctx == NULL) in CMS_add1_signer()
506 if (EVP_PKEY_sign_init(si->pctx) <= 0) in CMS_add1_signer()
508 if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0) in CMS_add1_signer()
510 } else if (EVP_DigestSignInit_ex(si->mctx, &si->pctx, in CMS_add1_signer()
515 si->pctx = NULL; in CMS_add1_signer()
519 EVP_MD_CTX_set_flags(si->mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); in CMS_add1_signer()
525 if (sd->signerInfos == NULL || !sk_CMS_SignerInfo_push(sd->signerInfos, si)) { in CMS_add1_signer()
530 return si; in CMS_add1_signer()
533 M_ASN1_free_of(si, CMS_SignerInfo); in CMS_add1_signer()
541 CMS_SignerInfo *si; in ossl_cms_SignerInfos_set_cmsctx() local
550 si = sk_CMS_SignerInfo_value(sinfos, i); in ossl_cms_SignerInfos_set_cmsctx()
551 if (si != NULL) in ossl_cms_SignerInfos_set_cmsctx()
552 si->cms_ctx = ctx; in ossl_cms_SignerInfos_set_cmsctx()
556 static int cms_add1_signingTime(CMS_SignerInfo *si, ASN1_TIME *t) in cms_add1_signingTime() argument
571 if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime, in cms_add1_signingTime()
586 EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si) in CMS_SignerInfo_get0_pkey_ctx() argument
588 return si->pctx; in CMS_SignerInfo_get0_pkey_ctx()
591 EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si) in CMS_SignerInfo_get0_md_ctx() argument
593 return si->mctx; in CMS_SignerInfo_get0_md_ctx()
607 CMS_SignerInfo *si; in STACK_OF() local
612 si = sk_CMS_SignerInfo_value(sinfos, i); in STACK_OF()
613 if (si->signer != NULL) { in STACK_OF()
614 if (!ossl_x509_add_cert_new(&signers, si->signer, in STACK_OF()
624 void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer) in CMS_SignerInfo_set1_signer_cert() argument
628 EVP_PKEY_free(si->pkey); in CMS_SignerInfo_set1_signer_cert()
629 si->pkey = X509_get_pubkey(signer); in CMS_SignerInfo_set1_signer_cert()
631 X509_free(si->signer); in CMS_SignerInfo_set1_signer_cert()
632 si->signer = signer; in CMS_SignerInfo_set1_signer_cert()
635 int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, in CMS_SignerInfo_get0_signer_id() argument
639 return ossl_cms_SignerIdentifier_get0_signer_id(si->sid, keyid, issuer, sno); in CMS_SignerInfo_get0_signer_id()
642 int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert) in CMS_SignerInfo_cert_cmp() argument
644 return ossl_cms_SignerIdentifier_cert_cmp(si->sid, cert); in CMS_SignerInfo_cert_cmp()
651 CMS_SignerInfo *si; in CMS_set1_signers_certs() local
663 si = sk_CMS_SignerInfo_value(sd->signerInfos, i); in CMS_set1_signers_certs()
664 if (si->signer != NULL) in CMS_set1_signers_certs()
669 if (CMS_SignerInfo_cert_cmp(si, x) == 0) { in CMS_set1_signers_certs()
670 CMS_SignerInfo_set1_signer_cert(si, x); in CMS_set1_signers_certs()
676 if (si->signer != NULL || (flags & CMS_NOINTERN)) in CMS_set1_signers_certs()
684 if (CMS_SignerInfo_cert_cmp(si, x) == 0) { in CMS_set1_signers_certs()
685 CMS_SignerInfo_set1_signer_cert(si, x); in CMS_set1_signers_certs()
694 void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, in CMS_SignerInfo_get0_algs() argument
699 *pk = si->pkey; in CMS_SignerInfo_get0_algs()
701 *signer = si->signer; in CMS_SignerInfo_get0_algs()
703 *pdig = si->digestAlgorithm; in CMS_SignerInfo_get0_algs()
705 *psig = si->signatureAlgorithm; in CMS_SignerInfo_get0_algs()
708 ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si) in CMS_SignerInfo_get0_signature() argument
710 return si->signature; in CMS_SignerInfo_get0_signature()
714 CMS_SignerInfo *si, BIO *chain, in cms_SignerInfo_content_sign() argument
728 if (si->pkey == NULL) { in cms_SignerInfo_content_sign()
733 if (!ossl_cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm)) in cms_SignerInfo_content_sign()
736 if (si->pctx && !cms_sd_asn1_ctrl(si, 0)) in cms_SignerInfo_content_sign()
742 if (CMS_signed_get_attr_count(si) >= 0) { in cms_SignerInfo_content_sign()
750 if (!CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest, in cms_SignerInfo_content_sign()
754 if (!cms_set_si_contentType_attr(cms, si)) in cms_SignerInfo_content_sign()
757 if (!CMS_SignerInfo_sign(si)) in cms_SignerInfo_content_sign()
759 } else if (si->pctx) { in cms_SignerInfo_content_sign()
764 pctx = si->pctx; in cms_SignerInfo_content_sign()
765 si->pctx = NULL; in cms_SignerInfo_content_sign()
771 siglen = EVP_PKEY_get_size(si->pkey); in cms_SignerInfo_content_sign()
778 ASN1_STRING_set0(si->signature, sig, siglen); in cms_SignerInfo_content_sign()
787 siglen = EVP_PKEY_get_size(si->pkey); in cms_SignerInfo_content_sign()
790 if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey, in cms_SignerInfo_content_sign()
797 ASN1_STRING_set0(si->signature, sig, siglen); in cms_SignerInfo_content_sign()
814 CMS_SignerInfo *si; in ossl_cms_SignedData_final() local
819 si = sk_CMS_SignerInfo_value(sinfos, i); in ossl_cms_SignedData_final()
820 if (!cms_SignerInfo_content_sign(cms, si, chain, in ossl_cms_SignedData_final()
828 int CMS_SignerInfo_sign(CMS_SignerInfo *si) in CMS_SignerInfo_sign() argument
830 EVP_MD_CTX *mctx = si->mctx; in CMS_SignerInfo_sign()
835 const CMS_CTX *ctx = si->cms_ctx; in CMS_SignerInfo_sign()
839 si->digestAlgorithm->algorithm, 0) <= 0) in CMS_SignerInfo_sign()
842 if (CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1) < 0) { in CMS_SignerInfo_sign()
843 if (!cms_add1_signingTime(si, NULL)) in CMS_SignerInfo_sign()
847 if (!ossl_cms_si_check_attributes(si)) in CMS_SignerInfo_sign()
850 if (si->pctx) { in CMS_SignerInfo_sign()
851 pctx = si->pctx; in CMS_SignerInfo_sign()
856 ossl_cms_ctx_get0_propq(ctx), si->pkey, in CMS_SignerInfo_sign()
860 si->pctx = pctx; in CMS_SignerInfo_sign()
863 alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf, in CMS_SignerInfo_sign()
880 ASN1_STRING_set0(si->signature, abuf, siglen); in CMS_SignerInfo_sign()
890 int CMS_SignerInfo_verify(CMS_SignerInfo *si) in CMS_SignerInfo_verify() argument
898 const CMS_CTX *ctx = si->cms_ctx; in CMS_SignerInfo_verify()
902 if (si->pkey == NULL) { in CMS_SignerInfo_verify()
907 if (!ossl_cms_si_check_attributes(si)) in CMS_SignerInfo_verify()
910 OBJ_obj2txt(name, sizeof(name), si->digestAlgorithm->algorithm, 0); in CMS_SignerInfo_verify()
918 md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm); in CMS_SignerInfo_verify()
926 if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) { in CMS_SignerInfo_verify()
930 mctx = si->mctx; in CMS_SignerInfo_verify()
931 if (si->pctx != NULL) { in CMS_SignerInfo_verify()
932 EVP_PKEY_CTX_free(si->pctx); in CMS_SignerInfo_verify()
933 si->pctx = NULL; in CMS_SignerInfo_verify()
935 if (EVP_DigestVerifyInit_ex(mctx, &si->pctx, EVP_MD_get0_name(md), libctx, in CMS_SignerInfo_verify()
936 propq, si->pkey, NULL) <= 0) { in CMS_SignerInfo_verify()
937 si->pctx = NULL; in CMS_SignerInfo_verify()
942 if (!cms_sd_asn1_ctrl(si, 1)) in CMS_SignerInfo_verify()
945 alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf, in CMS_SignerInfo_verify()
956 si->signature->data, si->signature->length); in CMS_SignerInfo_verify()
997 int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain) in CMS_SignerInfo_verify_content() argument
1011 if (CMS_signed_get_attr_count(si) >= 0) { in CMS_SignerInfo_verify_content()
1012 os = CMS_signed_get0_data_by_OBJ(si, in CMS_SignerInfo_verify_content()
1021 if (!ossl_cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm)) in CMS_SignerInfo_verify_content()
1044 const CMS_CTX *ctx = si->cms_ctx; in CMS_SignerInfo_verify_content()
1047 si->pkey, in CMS_SignerInfo_verify_content()
1055 si->pctx = pkctx; in CMS_SignerInfo_verify_content()
1056 if (!cms_sd_asn1_ctrl(si, 1)) { in CMS_SignerInfo_verify_content()
1057 si->pctx = NULL; in CMS_SignerInfo_verify_content()
1060 si->pctx = NULL; in CMS_SignerInfo_verify_content()
1061 r = EVP_PKEY_verify(pkctx, si->signature->data, in CMS_SignerInfo_verify_content()
1062 si->signature->length, mval, mlen); in CMS_SignerInfo_verify_content()
1117 int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs) in CMS_add_smimecap() argument
1125 r = CMS_signed_add1_attr_by_NID(si, NID_SMIMECapabilities, in CMS_add_smimecap()