提交 ff80280b 编写于 作者: D Dr. Stephen Henson

Set contentType attribute just before signing to allow encapsulated content

type to be set at any time in applications.
上级 e45641bd
...@@ -404,16 +404,17 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, ...@@ -404,16 +404,17 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
if (!(flags & CMS_NOATTR)) if (!(flags & CMS_NOATTR))
{ {
/* Copy content type across */ /* Initialialize signed attributes strutucture so other
ASN1_OBJECT *ctype = * attributes such as signing time etc are added later
OBJ_dup(sd->encapContentInfo->eContentType); * even if we add none here.
if (!ctype) */
goto merr; if (!si->signedAttrs)
i = CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType, {
V_ASN1_OBJECT, ctype, -1); si->signedAttrs = sk_X509_ATTRIBUTE_new_null();
ASN1_OBJECT_free(ctype); if (!si->signedAttrs)
if (i <= 0) goto merr;
goto merr; }
if (!(flags & CMS_NOSMIMECAP)) if (!(flags & CMS_NOSMIMECAP))
{ {
STACK_OF(X509_ALGOR) *smcap = NULL; STACK_OF(X509_ALGOR) *smcap = NULL;
...@@ -615,7 +616,8 @@ void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, X509 **signer, ...@@ -615,7 +616,8 @@ void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, X509 **signer,
*psig = si->signatureAlgorithm; *psig = si->signatureAlgorithm;
} }
static int cms_SignerInfo_content_sign(CMS_SignerInfo *si, BIO *chain) static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
CMS_SignerInfo *si, BIO *chain)
{ {
EVP_MD_CTX mctx; EVP_MD_CTX mctx;
int r = 0; int r = 0;
...@@ -635,6 +637,8 @@ static int cms_SignerInfo_content_sign(CMS_SignerInfo *si, BIO *chain) ...@@ -635,6 +637,8 @@ static int cms_SignerInfo_content_sign(CMS_SignerInfo *si, BIO *chain)
if (CMS_signed_get_attr_count(si) >= 0) if (CMS_signed_get_attr_count(si) >= 0)
{ {
ASN1_OBJECT *ctype =
cms->d.signedData->encapContentInfo->eContentType;
unsigned char md[EVP_MAX_MD_SIZE]; unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen; unsigned int mdlen;
EVP_DigestFinal_ex(&mctx, md, &mdlen); EVP_DigestFinal_ex(&mctx, md, &mdlen);
...@@ -642,6 +646,10 @@ static int cms_SignerInfo_content_sign(CMS_SignerInfo *si, BIO *chain) ...@@ -642,6 +646,10 @@ static int cms_SignerInfo_content_sign(CMS_SignerInfo *si, BIO *chain)
V_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING,
md, mdlen)) md, mdlen))
goto err; goto err;
/* Copy content type across */
if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType,
V_ASN1_OBJECT, ctype, -1) <= 0)
goto err;
if (!CMS_SignerInfo_sign(si)) if (!CMS_SignerInfo_sign(si))
goto err; goto err;
} }
...@@ -683,7 +691,7 @@ int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain) ...@@ -683,7 +691,7 @@ int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain)
for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
{ {
si = sk_CMS_SignerInfo_value(sinfos, i); si = sk_CMS_SignerInfo_value(sinfos, i);
if (!cms_SignerInfo_content_sign(si, chain)) if (!cms_SignerInfo_content_sign(cms, si, chain))
return 0; return 0;
} }
cms->d.signedData->encapContentInfo->partial = 0; cms->d.signedData->encapContentInfo->partial = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册