2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
35 * CMS signerInfo methods.
38 #include <Security/SecCmsSignerInfo.h>
39 #include "SecSMIMEPriv.h"
48 #include <security_asn1/secasn1.h>
49 #include <security_asn1/secerr.h>
50 #include <Security/SecKeychain.h>
51 #include <Security/SecIdentity.h>
52 #include <Security/SecCertificatePriv.h>
53 #include <Security/SecKeyPriv.h>
54 #include <CoreFoundation/CFTimeZone.h>
55 #include <utilities/SecCFWrappers.h>
56 #include <AssertMacros.h>
57 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
58 #include <Security/SecPolicyPriv.h>
60 #include "tsaSupport.h"
61 #include "tsaSupportPriv.h"
63 #define HIDIGIT(v) (((v) / 10) + '0')
64 #define LODIGIT(v) (((v) % 10) + '0')
66 #define ISDIGIT(dig) (((dig) >= '0') && ((dig) <= '9'))
67 #define CAPTURE(var,p,label) \
69 if (!ISDIGIT((p)[0]) || !ISDIGIT((p)[1])) goto label; \
70 (var) = ((p)[0] - '0') * 10 + ((p)[1] - '0'); \
74 #define SIGINFO_DEBUG 1
78 #define dprintf(args...) printf(args)
80 #define dprintf(args...)
84 #define dprintfRC(args...) dprintf(args)
86 #define dprintfRC(args...)
90 DER_UTCTimeToCFDate(const CSSM_DATA_PTR utcTime
, CFAbsoluteTime
*date
)
92 CFGregorianDate gdate
;
93 char *string
= (char *)utcTime
->Data
;
94 long year
, month
, mday
, hour
, minute
, second
, hourOff
, minOff
;
95 CFTimeZoneRef timeZone
;
97 /* Verify time is formatted properly and capture information */
101 CAPTURE(year
,string
+0,loser
);
103 /* ASSUME that year # is in the 2000's, not the 1900's */
106 CAPTURE(month
,string
+2,loser
);
107 if ((month
== 0) || (month
> 12)) goto loser
;
108 CAPTURE(mday
,string
+4,loser
);
109 if ((mday
== 0) || (mday
> 31)) goto loser
;
110 CAPTURE(hour
,string
+6,loser
);
111 if (hour
> 23) goto loser
;
112 CAPTURE(minute
,string
+8,loser
);
113 if (minute
> 59) goto loser
;
114 if (ISDIGIT(string
[10])) {
115 CAPTURE(second
,string
+10,loser
);
116 if (second
> 59) goto loser
;
119 if (string
[10] == '+') {
120 CAPTURE(hourOff
,string
+11,loser
);
121 if (hourOff
> 23) goto loser
;
122 CAPTURE(minOff
,string
+13,loser
);
123 if (minOff
> 59) goto loser
;
124 } else if (string
[10] == '-') {
125 CAPTURE(hourOff
,string
+11,loser
);
126 if (hourOff
> 23) goto loser
;
128 CAPTURE(minOff
,string
+13,loser
);
129 if (minOff
> 59) goto loser
;
131 } else if (string
[10] != 'Z') {
135 gdate
.year
= (SInt32
)(year
+ 1900);
139 gdate
.minute
= minute
;
140 gdate
.second
= second
;
142 if (hourOff
== 0 && minOff
== 0)
143 timeZone
= NULL
; /* GMT */
146 timeZone
= CFTimeZoneCreateWithTimeIntervalFromGMT(NULL
, (hourOff
* 60 + minOff
) * 60);
149 *date
= CFGregorianDateGetAbsoluteTime(gdate
, timeZone
);
160 DER_CFDateToUTCTime(CFAbsoluteTime date
, CSSM_DATA_PTR utcTime
)
162 CFGregorianDate gdate
= CFAbsoluteTimeGetGregorianDate(date
, NULL
/* GMT */);
166 utcTime
->Length
= 13;
167 utcTime
->Data
= d
= PORT_Alloc(13);
171 /* UTC time does not handle the years before 1950 */
172 if (gdate
.year
< 1950)
175 /* remove the century since it's added to the year by the
176 CFAbsoluteTimeGetGregorianDate routine, but is not needed for UTC time */
178 second
= gdate
.second
+ 0.5;
180 d
[0] = HIDIGIT(gdate
.year
);
181 d
[1] = LODIGIT(gdate
.year
);
182 d
[2] = HIDIGIT(gdate
.month
);
183 d
[3] = LODIGIT(gdate
.month
);
184 d
[4] = HIDIGIT(gdate
.day
);
185 d
[5] = LODIGIT(gdate
.day
);
186 d
[6] = HIDIGIT(gdate
.hour
);
187 d
[7] = LODIGIT(gdate
.hour
);
188 d
[8] = HIDIGIT(gdate
.minute
);
189 d
[9] = LODIGIT(gdate
.minute
);
190 d
[10] = HIDIGIT(second
);
191 d
[11] = LODIGIT(second
);
196 /* =============================================================================
200 nss_cmssignerinfo_create(SecCmsMessageRef cmsg
, SecCmsSignerIDSelector type
, SecCertificateRef cert
, CSSM_DATA_PTR subjKeyID
, SecPublicKeyRef pubKey
, SecPrivateKeyRef signingKey
, SECOidTag digestalgtag
);
203 SecCmsSignerInfoCreateWithSubjKeyID(SecCmsMessageRef cmsg
, CSSM_DATA_PTR subjKeyID
, SecPublicKeyRef pubKey
, SecPrivateKeyRef signingKey
, SECOidTag digestalgtag
)
205 return nss_cmssignerinfo_create(cmsg
, SecCmsSignerIDSubjectKeyID
, NULL
, subjKeyID
, pubKey
, signingKey
, digestalgtag
);
209 SecCmsSignerInfoCreate(SecCmsMessageRef cmsg
, SecIdentityRef identity
, SECOidTag digestalgtag
)
211 SecCmsSignerInfoRef signerInfo
= NULL
;
212 SecCertificateRef cert
= NULL
;
213 SecPrivateKeyRef signingKey
= NULL
;
215 if (SecIdentityCopyCertificate(identity
, &cert
))
217 if (SecIdentityCopyPrivateKey(identity
, &signingKey
))
220 signerInfo
= nss_cmssignerinfo_create(cmsg
, SecCmsSignerIDIssuerSN
, cert
, NULL
, NULL
, signingKey
, digestalgtag
);
226 CFRelease(signingKey
);
232 nss_cmssignerinfo_create(SecCmsMessageRef cmsg
, SecCmsSignerIDSelector type
, SecCertificateRef cert
, CSSM_DATA_PTR subjKeyID
, SecPublicKeyRef pubKey
, SecPrivateKeyRef signingKey
, SECOidTag digestalgtag
)
235 SecCmsSignerInfoRef signerinfo
;
241 mark
= PORT_ArenaMark(poolp
);
243 signerinfo
= (SecCmsSignerInfoRef
)PORT_ArenaZAlloc(poolp
, sizeof(SecCmsSignerInfo
));
244 if (signerinfo
== NULL
) {
245 PORT_ArenaRelease(poolp
, mark
);
250 signerinfo
->cmsg
= cmsg
;
253 case SecCmsSignerIDIssuerSN
:
254 signerinfo
->signerIdentifier
.identifierType
= SecCmsSignerIDIssuerSN
;
255 if ((signerinfo
->cert
= CERT_DupCertificate(cert
)) == NULL
)
257 if ((signerinfo
->signerIdentifier
.id
.issuerAndSN
= CERT_GetCertIssuerAndSN(poolp
, cert
)) == NULL
)
259 dprintfRC("nss_cmssignerinfo_create: SecCmsSignerIDIssuerSN: cert.rc %d\n",
260 (int)CFGetRetainCount(signerinfo
->cert
));
262 case SecCmsSignerIDSubjectKeyID
:
263 signerinfo
->signerIdentifier
.identifierType
= SecCmsSignerIDSubjectKeyID
;
264 PORT_Assert(subjKeyID
);
267 signerinfo
->signerIdentifier
.id
.subjectKeyID
= PORT_ArenaNew(poolp
, CSSM_DATA
);
268 SECITEM_CopyItem(poolp
, signerinfo
->signerIdentifier
.id
.subjectKeyID
,
270 signerinfo
->pubKey
= SECKEY_CopyPublicKey(pubKey
);
271 if (!signerinfo
->pubKey
)
281 signerinfo
->signingKey
= SECKEY_CopyPrivateKey(signingKey
);
282 if (!signerinfo
->signingKey
)
285 /* set version right now */
286 version
= SEC_CMS_SIGNER_INFO_VERSION_ISSUERSN
;
287 /* RFC2630 5.3 "version is the syntax version number. If the .... " */
288 if (signerinfo
->signerIdentifier
.identifierType
== SecCmsSignerIDSubjectKeyID
)
289 version
= SEC_CMS_SIGNER_INFO_VERSION_SUBJKEY
;
290 (void)SEC_ASN1EncodeInteger(poolp
, &(signerinfo
->version
), (long)version
);
292 if (SECOID_SetAlgorithmID(poolp
, &signerinfo
->digestAlg
, digestalgtag
, NULL
) != SECSuccess
)
295 PORT_ArenaUnmark(poolp
, mark
);
299 PORT_ArenaRelease(poolp
, mark
);
304 * SecCmsSignerInfoDestroy - destroy a SignerInfo data structure
307 SecCmsSignerInfoDestroy(SecCmsSignerInfoRef si
)
309 if (si
->cert
!= NULL
) {
310 dprintfRC("SecCmsSignerInfoDestroy top: certp %p cert.rc %d\n",
311 si
->cert
, (int)CFGetRetainCount(si
->cert
));
312 CERT_DestroyCertificate(si
->cert
);
314 if (si
->certList
!= NULL
) {
315 dprintfRC("SecCmsSignerInfoDestroy top: certList.rc %d\n",
316 (int)CFGetRetainCount(si
->certList
));
317 CFRelease(si
->certList
);
319 if (si
->timestampCertList
!= NULL
) {
320 dprintfRC("SecCmsSignerInfoDestroy top: timestampCertList.rc %d\n",
321 (int)CFGetRetainCount(si
->timestampCertList
));
322 CFRelease(si
->timestampCertList
);
324 /* XXX storage ??? */
328 * SecCmsSignerInfoSign - sign something
332 SecCmsSignerInfoSign(SecCmsSignerInfoRef signerinfo
, CSSM_DATA_PTR digest
, CSSM_DATA_PTR contentType
)
334 SecCertificateRef cert
;
335 SecPrivateKeyRef privkey
= NULL
;
336 SECOidTag digestalgtag
;
337 SECOidTag pubkAlgTag
;
338 CSSM_DATA signature
= { 0 };
340 PLArenaPool
*poolp
, *tmppoolp
= NULL
;
341 const SECAlgorithmID
*algID
;
342 SECAlgorithmID freeAlgID
;
343 //CERTSubjectPublicKeyInfo *spki;
345 PORT_Assert (digest
!= NULL
);
347 poolp
= signerinfo
->cmsg
->poolp
;
349 switch (signerinfo
->signerIdentifier
.identifierType
) {
350 case SecCmsSignerIDIssuerSN
:
351 privkey
= signerinfo
->signingKey
;
352 signerinfo
->signingKey
= NULL
;
353 cert
= signerinfo
->cert
;
354 if (SecCertificateGetAlgorithmID(cert
,&algID
)) {
355 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM
);
359 case SecCmsSignerIDSubjectKeyID
:
360 privkey
= signerinfo
->signingKey
;
361 signerinfo
->signingKey
= NULL
;
363 spki
= SECKEY_CreateSubjectPublicKeyInfo(signerinfo
->pubKey
);
364 SECKEY_DestroyPublicKey(signerinfo
->pubKey
);
365 signerinfo
->pubKey
= NULL
;
366 SECOID_CopyAlgorithmID(NULL
, &freeAlgID
, &spki
->algorithm
);
367 SECKEY_DestroySubjectPublicKeyInfo(spki
);
370 if (SecKeyGetAlgorithmID(signerinfo
->pubKey
,&algID
)) {
371 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM
);
374 CFRelease(signerinfo
->pubKey
);
375 signerinfo
->pubKey
= NULL
;
379 PORT_SetError(SEC_ERROR_UNSUPPORTED_MESSAGE_TYPE
);
382 digestalgtag
= SecCmsSignerInfoGetDigestAlgTag(signerinfo
);
384 * XXX I think there should be a cert-level interface for this,
385 * so that I do not have to know about subjectPublicKeyInfo...
387 pubkAlgTag
= SECOID_GetAlgorithmTag(algID
);
388 if (signerinfo
->signerIdentifier
.identifierType
== SecCmsSignerIDSubjectKeyID
) {
389 SECOID_DestroyAlgorithmID(&freeAlgID
, PR_FALSE
);
394 /* Fortezza MISSI have weird signature formats.
395 * Map them to standard DSA formats
397 pubkAlgTag
= PK11_FortezzaMapSig(pubkAlgTag
);
400 if (signerinfo
->authAttr
!= NULL
) {
401 CSSM_DATA encoded_attrs
;
403 /* find and fill in the message digest attribute. */
404 rv
= SecCmsAttributeArraySetAttr(poolp
, &(signerinfo
->authAttr
),
405 SEC_OID_PKCS9_MESSAGE_DIGEST
, digest
, PR_FALSE
);
406 if (rv
!= SECSuccess
)
409 if (contentType
!= NULL
) {
410 /* if the caller wants us to, find and fill in the content type attribute. */
411 rv
= SecCmsAttributeArraySetAttr(poolp
, &(signerinfo
->authAttr
),
412 SEC_OID_PKCS9_CONTENT_TYPE
, contentType
, PR_FALSE
);
413 if (rv
!= SECSuccess
)
417 if ((tmppoolp
= PORT_NewArena (1024)) == NULL
) {
418 PORT_SetError(SEC_ERROR_NO_MEMORY
);
423 * Before encoding, reorder the attributes so that when they
424 * are encoded, they will be conforming DER, which is required
425 * to have a specific order and that is what must be used for
426 * the hash/signature. We do this here, rather than building
427 * it into EncodeAttributes, because we do not want to do
428 * such reordering on incoming messages (which also uses
429 * EncodeAttributes) or our old signatures (and other "broken"
430 * implementations) will not verify. So, we want to guarantee
431 * that we send out good DER encodings of attributes, but not
432 * to expect to receive them.
434 if (SecCmsAttributeArrayReorder(signerinfo
->authAttr
) != SECSuccess
)
437 encoded_attrs
.Data
= NULL
;
438 encoded_attrs
.Length
= 0;
439 if (SecCmsAttributeArrayEncode(tmppoolp
, &(signerinfo
->authAttr
),
440 &encoded_attrs
) == NULL
)
443 rv
= SEC_SignData(&signature
, encoded_attrs
.Data
, (int)encoded_attrs
.Length
,
444 privkey
, digestalgtag
, pubkAlgTag
);
445 PORT_FreeArena(tmppoolp
, PR_FALSE
); /* awkward memory management :-( */
448 rv
= SGN_Digest(privkey
, digestalgtag
, pubkAlgTag
, &signature
, digest
);
450 SECKEY_DestroyPrivateKey(privkey
);
453 if (rv
!= SECSuccess
)
456 if (SECITEM_CopyItem(poolp
, &(signerinfo
->encDigest
), &signature
)
460 SECITEM_FreeItem(&signature
, PR_FALSE
);
462 if(pubkAlgTag
== SEC_OID_EC_PUBLIC_KEY
) {
464 * RFC 3278 section section 2.1.1 states that the signatureAlgorithm
465 * field contains the full ecdsa-with-SHA1 OID, not plain old ecPublicKey
466 * as would appear in other forms of signed datas. However Microsoft doesn't
467 * do this, it puts ecPublicKey there, and if we put ecdsa-with-SHA1 there,
468 * MS can't verify - presumably because it takes the digest of the digest
469 * before feeding it to ECDSA.
470 * We handle this with a preference; default if it's not there is
471 * "Microsoft compatibility mode".
473 if(!SecCmsMsEcdsaCompatMode()) {
474 pubkAlgTag
= SEC_OID_ECDSA_WithSHA1
;
476 /* else violating the spec for compatibility */
479 if (SECOID_SetAlgorithmID(poolp
, &(signerinfo
->digestEncAlg
), pubkAlgTag
,
486 if (signature
.Length
!= 0)
487 SECITEM_FreeItem (&signature
, PR_FALSE
);
489 SECKEY_DestroyPrivateKey(privkey
);
490 if((algID
!= NULL
) & (algID
!= &freeAlgID
)) {
491 /* this is dicey - this was actually mallocd by either SecCertificate or
492 * by SecKey...it all boils down to a free() in the end though. */
493 SECOID_DestroyAlgorithmID((SECAlgorithmID
*)algID
, PR_FALSE
);
496 PORT_FreeArena(tmppoolp
, PR_FALSE
);
501 SecCmsSignerInfoVerifyCertificate(SecCmsSignerInfoRef signerinfo
, SecKeychainRef keychainOrArray
,
502 CFTypeRef policies
, SecTrustRef
*trustRef
)
504 SecCertificateRef cert
;
505 CFAbsoluteTime stime
;
507 CSSM_DATA_PTR
*otherCerts
;
509 if ((cert
= SecCmsSignerInfoGetSigningCertificate(signerinfo
, keychainOrArray
)) == NULL
) {
510 dprintf("SecCmsSignerInfoVerifyCertificate: no signing cert\n");
511 signerinfo
->verificationStatus
= SecCmsVSSigningCertNotFound
;
516 * Get and convert the signing time; if available, it will be used
517 * both on the cert verification and for importing the sender
520 CFTypeRef timeStampPolicies
=SecPolicyCreateAppleTimeStampingAndRevocationPolicies(policies
);
521 if (SecCmsSignerInfoGetTimestampTimeWithPolicy(signerinfo
, timeStampPolicies
, &stime
) != SECSuccess
)
522 if (SecCmsSignerInfoGetSigningTime(signerinfo
, &stime
) != SECSuccess
)
523 stime
= CFAbsoluteTimeGetCurrent();
524 CFReleaseSafe(timeStampPolicies
);
526 rv
= SecCmsSignedDataRawCerts(signerinfo
->sigd
, &otherCerts
);
530 rv
= CERT_VerifyCert(keychainOrArray
, cert
, otherCerts
, policies
, stime
, trustRef
);
531 dprintfRC("SecCmsSignerInfoVerifyCertificate after vfy: certp %p cert.rc %d\n",
532 cert
, (int)CFGetRetainCount(cert
));
535 if (PORT_GetError() == SEC_ERROR_UNTRUSTED_CERT
)
537 /* Signature or digest level verificationStatus errors should supercede certificate level errors, so only change the verificationStatus if the status was GoodSignature. */
538 if (signerinfo
->verificationStatus
== SecCmsVSGoodSignature
)
539 signerinfo
->verificationStatus
= SecCmsVSSigningCertNotTrusted
;
542 /* FIXME isn't this leaking the cert? */
543 dprintf("SecCmsSignerInfoVerifyCertificate: CertVerify rtn %d\n", (int)rv
);
547 static void debugShowSigningCertificate(SecCmsSignerInfoRef signerinfo
)
550 CFStringRef cn
= SecCmsSignerInfoGetSignerCommonName(signerinfo
);
553 char *ccn
= cfStringToChar(cn
);
556 dprintf("SecCmsSignerInfoVerify: cn: %s\n", ccn
);
565 * SecCmsSignerInfoVerify - verify the signature of a single SignerInfo
567 * Just verifies the signature. The assumption is that verification of the certificate
571 SecCmsSignerInfoVerify(SecCmsSignerInfoRef signerinfo
, CSSM_DATA_PTR digest
, CSSM_DATA_PTR contentType
)
573 return SecCmsSignerInfoVerifyWithPolicy(signerinfo
,NULL
, digest
,contentType
);
577 SecCmsSignerInfoVerifyWithPolicy(SecCmsSignerInfoRef signerinfo
,CFTypeRef timeStampPolicy
, CSSM_DATA_PTR digest
, CSSM_DATA_PTR contentType
)
579 SecPublicKeyRef publickey
= NULL
;
580 SecCmsAttribute
*attr
;
581 CSSM_DATA encoded_attrs
;
582 SecCertificateRef cert
;
583 SecCmsVerificationStatus vs
= SecCmsVSUnverified
;
585 SECOidTag digestAlgTag
, digestEncAlgTag
;
587 if (signerinfo
== NULL
)
590 /* SecCmsSignerInfoGetSigningCertificate will fail if 2nd parm is NULL and */
591 /* cert has not been verified */
592 if ((cert
= SecCmsSignerInfoGetSigningCertificate(signerinfo
, NULL
)) == NULL
) {
593 dprintf("SecCmsSignerInfoVerify: no signing cert\n");
594 vs
= SecCmsVSSigningCertNotFound
;
598 dprintfRC("SecCmsSignerInfoVerify top: cert %p cert.rc %d\n", cert
, (int)CFGetRetainCount(cert
));
600 debugShowSigningCertificate(signerinfo
);
602 if (SecCertificateCopyPublicKey(cert
, &publickey
)) {
603 vs
= SecCmsVSProcessingError
;
607 digestAlgTag
= SECOID_GetAlgorithmTag(&(signerinfo
->digestAlg
));
608 digestEncAlgTag
= SECOID_GetAlgorithmTag(&(signerinfo
->digestEncAlg
));
611 * Gross hack necessitated by RFC 3278 section 2.1.1, which states
612 * that the signature algorithm (here, digestEncAlg) contains ecdsa_with-SHA1,
613 * *not* (as in all other algorithms) the raw signature algorithm, e.g.
614 * pkcs1RSAEncryption.
616 if(digestEncAlgTag
== SEC_OID_ECDSA_WithSHA1
) {
617 digestEncAlgTag
= SEC_OID_EC_PUBLIC_KEY
;
620 if (!SecCmsArrayIsEmpty((void **)signerinfo
->authAttr
)) {
625 * RFC2630 sez that if there are any authenticated attributes,
626 * then there must be one for content type which matches the
627 * content type of the content being signed, and there must
628 * be one for message digest which matches our message digest.
629 * So check these things first.
631 if ((attr
= SecCmsAttributeArrayFindAttrByOidTag(signerinfo
->authAttr
,
632 SEC_OID_PKCS9_CONTENT_TYPE
, PR_TRUE
)) == NULL
)
634 vs
= SecCmsVSMalformedSignature
;
638 if (SecCmsAttributeCompareValue(attr
, contentType
) == PR_FALSE
) {
639 vs
= SecCmsVSMalformedSignature
;
647 if ((attr
= SecCmsAttributeArrayFindAttrByOidTag(signerinfo
->authAttr
, SEC_OID_PKCS9_MESSAGE_DIGEST
, PR_TRUE
)) == NULL
)
649 vs
= SecCmsVSMalformedSignature
;
652 if (SecCmsAttributeCompareValue(attr
, digest
) == PR_FALSE
) {
653 vs
= SecCmsVSDigestMismatch
;
657 if ((poolp
= PORT_NewArena (1024)) == NULL
) {
658 vs
= SecCmsVSProcessingError
;
665 * The signature is based on a digest of the DER-encoded authenticated
666 * attributes. So, first we encode and then we digest/verify.
667 * we trust the decoder to have the attributes in the right (sorted) order
669 encoded_attrs
.Data
= NULL
;
670 encoded_attrs
.Length
= 0;
672 if (SecCmsAttributeArrayEncode(poolp
, &(signerinfo
->authAttr
), &encoded_attrs
) == NULL
||
673 encoded_attrs
.Data
== NULL
|| encoded_attrs
.Length
== 0)
675 vs
= SecCmsVSProcessingError
;
679 vs
= (VFY_VerifyData (encoded_attrs
.Data
, (int)encoded_attrs
.Length
,
680 publickey
, &(signerinfo
->encDigest
),
681 digestAlgTag
, digestEncAlgTag
,
682 signerinfo
->cmsg
->pwfn_arg
) != SECSuccess
) ? SecCmsVSBadSignature
: SecCmsVSGoodSignature
;
684 dprintf("VFY_VerifyData (authenticated attributes): %s\n",
685 (vs
== SecCmsVSGoodSignature
)?"SecCmsVSGoodSignature":"SecCmsVSBadSignature");
687 PORT_FreeArena(poolp
, PR_FALSE
); /* awkward memory management :-( */
692 /* No authenticated attributes. The signature is based on the plain message digest. */
693 sig
= &(signerinfo
->encDigest
);
694 if (sig
->Length
== 0)
697 vs
= (VFY_VerifyDigest(digest
, publickey
, sig
,
698 digestAlgTag
, digestEncAlgTag
,
699 signerinfo
->cmsg
->pwfn_arg
) != SECSuccess
) ? SecCmsVSBadSignature
: SecCmsVSGoodSignature
;
701 dprintf("VFY_VerifyData (plain message digest): %s\n",
702 (vs
== SecCmsVSGoodSignature
)?"SecCmsVSGoodSignature":"SecCmsVSBadSignature");
705 if (!SecCmsArrayIsEmpty((void **)signerinfo
->unAuthAttr
))
707 dprintf("found an unAuthAttr\n");
708 OSStatus rux
= SecCmsSignerInfoVerifyUnAuthAttrsWithPolicy(signerinfo
,timeStampPolicy
);
709 dprintf("SecCmsSignerInfoVerifyUnAuthAttrs Status: %ld\n", (long)rux
);
714 if (vs
== SecCmsVSBadSignature
) {
716 * XXX Change the generic error into our specific one, because
717 * in that case we get a better explanation out of the Security
718 * Advisor. This is really a bug in our error strings (the
719 * "generic" error has a lousy/wrong message associated with it
720 * which assumes the signature verification was done for the
721 * purposes of checking the issuer signature on a certificate)
722 * but this is at least an easy workaround and/or in the
723 * Security Advisor, which specifically checks for the error
724 * SEC_ERROR_PKCS7_BAD_SIGNATURE and gives more explanation
725 * in that case but does not similarly check for
726 * SEC_ERROR_BAD_SIGNATURE. It probably should, but then would
727 * probably say the wrong thing in the case that it *was* the
728 * certificate signature check that failed during the cert
729 * verification done above. Our error handling is really a mess.
731 if (PORT_GetError() == SEC_ERROR_BAD_SIGNATURE
)
732 PORT_SetError(SEC_ERROR_PKCS7_BAD_SIGNATURE
);
735 if (publickey
!= NULL
)
736 CFRelease(publickey
);
738 signerinfo
->verificationStatus
= vs
;
739 dprintfRC("SecCmsSignerInfoVerify end: cerp %p cert.rc %d\n",
740 cert
, (int)CFGetRetainCount(cert
));
742 dprintf("verificationStatus: %d\n", vs
);
744 return (vs
== SecCmsVSGoodSignature
) ? SECSuccess
: SECFailure
;
747 if (publickey
!= NULL
)
748 SECKEY_DestroyPublicKey (publickey
);
750 dprintf("verificationStatus2: %d\n", vs
);
751 signerinfo
->verificationStatus
= vs
;
753 PORT_SetError (SEC_ERROR_PKCS7_BAD_SIGNATURE
);
758 SecCmsSignerInfoVerifyUnAuthAttrs(SecCmsSignerInfoRef signerinfo
) {
759 return SecCmsSignerInfoVerifyUnAuthAttrsWithPolicy(signerinfo
, NULL
);
763 SecCmsSignerInfoVerifyUnAuthAttrsWithPolicy(SecCmsSignerInfoRef signerinfo
,CFTypeRef timeStampPolicy
)
766 unAuthAttr is an array of attributes; we expect to
767 see just one: the timestamp blob. If we have an unAuthAttr,
768 but don't see a timestamp, return an error since we have
769 no other cases where this would be present.
772 SecCmsAttribute
*attr
= NULL
;
773 OSStatus status
= SECFailure
;
775 require(signerinfo
, xit
);
776 attr
= SecCmsAttributeArrayFindAttrByOidTag(signerinfo
->unAuthAttr
,
777 SEC_OID_PKCS9_TIMESTAMP_TOKEN
, PR_TRUE
);
780 status
= errSecTimestampMissing
;
784 dprintf("found an id-ct-TSTInfo\n");
785 // Don't check the nonce in this case
786 status
= decodeTimeStampTokenWithPolicy(signerinfo
, timeStampPolicy
, (attr
->values
)[0], &signerinfo
->encDigest
, 0);
792 SecCmsSignerInfoGetEncDigest(SecCmsSignerInfoRef signerinfo
)
794 return &signerinfo
->encDigest
;
797 SecCmsVerificationStatus
798 SecCmsSignerInfoGetVerificationStatus(SecCmsSignerInfoRef signerinfo
)
800 return signerinfo
->verificationStatus
;
804 SecCmsSignerInfoGetDigestAlg(SecCmsSignerInfoRef signerinfo
)
806 return SECOID_FindOID (&(signerinfo
->digestAlg
.algorithm
));
810 SecCmsSignerInfoGetDigestAlgTag(SecCmsSignerInfoRef signerinfo
)
814 algdata
= SECOID_FindOID (&(signerinfo
->digestAlg
.algorithm
));
816 return algdata
->offset
;
818 return SEC_OID_UNKNOWN
;
822 SecCmsSignerInfoGetCertList(SecCmsSignerInfoRef signerinfo
)
824 dprintfRC("SecCmsSignerInfoGetCertList: certList.rc %d\n",
825 (int)CFGetRetainCount(signerinfo
->certList
));
826 return signerinfo
->certList
;
830 SecCmsSignerInfoGetTimestampCertList(SecCmsSignerInfoRef signerinfo
)
832 dprintfRC("SecCmsSignerInfoGetCertList: timestampCertList.rc %d\n",
833 (int)CFGetRetainCount(signerinfo
->timestampCertList
));
834 return signerinfo
->timestampCertList
;
840 SecCmsSignerInfoGetVersion(SecCmsSignerInfoRef signerinfo
)
842 unsigned long version
;
844 /* always take apart the CSSM_DATA */
845 if (SEC_ASN1DecodeInteger(&(signerinfo
->version
), &version
) != SECSuccess
)
852 * SecCmsSignerInfoGetSigningTime - return the signing time,
853 * in UTCTime format, of a CMS signerInfo.
855 * sinfo - signerInfo data for this signer
857 * Returns a pointer to XXXX (what?)
858 * A return value of NULL is an error.
861 SecCmsSignerInfoGetSigningTime(SecCmsSignerInfoRef sinfo
, CFAbsoluteTime
*stime
)
863 SecCmsAttribute
*attr
;
869 if (sinfo
->signingTime
!= 0) {
870 *stime
= sinfo
->signingTime
; /* cached copy */
874 attr
= SecCmsAttributeArrayFindAttrByOidTag(sinfo
->authAttr
, SEC_OID_PKCS9_SIGNING_TIME
, PR_TRUE
);
875 /* XXXX multi-valued attributes NIH */
876 if (attr
== NULL
|| (value
= SecCmsAttributeGetValue(attr
)) == NULL
)
877 return errSecSigningTimeMissing
;
878 if (DER_UTCTimeToCFDate(value
, stime
) != SECSuccess
)
879 return errSecSigningTimeMissing
;
880 sinfo
->signingTime
= *stime
; /* make cached copy */
885 SecCmsSignerInfoGetTimestampTime(SecCmsSignerInfoRef sinfo
, CFAbsoluteTime
*stime
)
887 return SecCmsSignerInfoGetTimestampTimeWithPolicy(sinfo
, NULL
, stime
);
891 SecCmsSignerInfoGetTimestampTimeWithPolicy(SecCmsSignerInfoRef sinfo
, CFTypeRef timeStampPolicy
, CFAbsoluteTime
*stime
)
893 OSStatus status
= paramErr
;
895 require(sinfo
&& stime
, xit
);
897 if (sinfo
->timestampTime
!= 0)
899 *stime
= sinfo
->timestampTime
; /* cached copy */
903 // A bit heavyweight if haven't already called verify
904 status
= SecCmsSignerInfoVerifyUnAuthAttrsWithPolicy(sinfo
,timeStampPolicy
);
905 *stime
= sinfo
->timestampTime
;
911 * Return the signing cert of a CMS signerInfo.
913 * the certs in the enclosing SignedData must have been imported already
916 SecCmsSignerInfoGetSigningCertificate(SecCmsSignerInfoRef signerinfo
, SecKeychainRef keychainOrArray
)
918 SecCertificateRef cert
;
919 SecCmsSignerIdentifier
*sid
;
921 CSSM_DATA_PTR
*rawCerts
;
923 if (signerinfo
->cert
!= NULL
) {
924 dprintfRC("SecCmsSignerInfoGetSigningCertificate top: cert %p cert.rc %d\n",
925 signerinfo
->cert
, (int)CFGetRetainCount(signerinfo
->cert
));
926 return signerinfo
->cert
;
928 ortn
= SecCmsSignedDataRawCerts(signerinfo
->sigd
, &rawCerts
);
932 dprintf("SecCmsSignerInfoGetSigningCertificate: numRawCerts %d\n",
933 SecCmsArrayCount((void **)rawCerts
));
936 * This cert will also need to be freed, but since we save it
937 * in signerinfo for later, we do not want to destroy it when
938 * we leave this function -- we let the clean-up of the entire
939 * cinfo structure later do the destroy of this cert.
941 sid
= &signerinfo
->signerIdentifier
;
942 switch (sid
->identifierType
) {
943 case SecCmsSignerIDIssuerSN
:
944 cert
= CERT_FindCertByIssuerAndSN(keychainOrArray
, rawCerts
, signerinfo
->cmsg
->poolp
,
945 sid
->id
.issuerAndSN
);
947 case SecCmsSignerIDSubjectKeyID
:
948 cert
= CERT_FindCertBySubjectKeyID(keychainOrArray
, rawCerts
, sid
->id
.subjectKeyID
);
955 /* cert can be NULL at that point */
956 signerinfo
->cert
= cert
; /* earmark it */
957 dprintfRC("SecCmsSignerInfoGetSigningCertificate end: certp %p cert.rc %d\n",
958 signerinfo
->cert
, (int)CFGetRetainCount(signerinfo
->cert
));
964 * SecCmsSignerInfoGetSignerCommonName - return the common name of the signer
966 * sinfo - signerInfo data for this signer
968 * Returns a CFStringRef containing the common name of the signer.
969 * A return value of NULL is an error.
972 SecCmsSignerInfoGetSignerCommonName(SecCmsSignerInfoRef sinfo
)
974 SecCertificateRef signercert
;
975 CFStringRef commonName
= NULL
;
977 /* will fail if cert is not verified */
978 if ((signercert
= SecCmsSignerInfoGetSigningCertificate(sinfo
, NULL
)) == NULL
)
981 SecCertificateCopyCommonName(signercert
, &commonName
);
987 * SecCmsSignerInfoGetSignerEmailAddress - return the email address of the signer
989 * sinfo - signerInfo data for this signer
991 * Returns a CFStringRef containing the name of the signer.
992 * A return value of NULL is an error.
995 SecCmsSignerInfoGetSignerEmailAddress(SecCmsSignerInfoRef sinfo
)
997 SecCertificateRef signercert
;
998 CFStringRef emailAddress
= NULL
;
1000 if ((signercert
= SecCmsSignerInfoGetSigningCertificate(sinfo
, NULL
)) == NULL
)
1003 SecCertificateGetEmailAddress(signercert
, &emailAddress
);
1005 return emailAddress
;
1010 * SecCmsSignerInfoAddAuthAttr - add an attribute to the
1011 * authenticated (i.e. signed) attributes of "signerinfo".
1014 SecCmsSignerInfoAddAuthAttr(SecCmsSignerInfoRef signerinfo
, SecCmsAttribute
*attr
)
1016 return SecCmsAttributeArrayAddAttr(signerinfo
->cmsg
->poolp
, &(signerinfo
->authAttr
), attr
);
1020 * SecCmsSignerInfoAddUnauthAttr - add an attribute to the
1021 * unauthenticated attributes of "signerinfo".
1024 SecCmsSignerInfoAddUnauthAttr(SecCmsSignerInfoRef signerinfo
, SecCmsAttribute
*attr
)
1026 return SecCmsAttributeArrayAddAttr(signerinfo
->cmsg
->poolp
, &(signerinfo
->unAuthAttr
), attr
);
1030 * SecCmsSignerInfoAddSigningTime - add the signing time to the
1031 * authenticated (i.e. signed) attributes of "signerinfo".
1033 * This is expected to be included in outgoing signed
1034 * messages for email (S/MIME) but is likely useful in other situations.
1036 * This should only be added once; a second call will do nothing.
1038 * XXX This will probably just shove the current time into "signerinfo"
1039 * but it will not actually get signed until the entire item is
1040 * processed for encoding. Is this (expected to be small) delay okay?
1043 SecCmsSignerInfoAddSigningTime(SecCmsSignerInfoRef signerinfo
, CFAbsoluteTime t
)
1045 SecCmsAttribute
*attr
;
1050 poolp
= signerinfo
->cmsg
->poolp
;
1052 mark
= PORT_ArenaMark(poolp
);
1054 /* create new signing time attribute */
1055 if (DER_CFDateToUTCTime(t
, &stime
) != SECSuccess
)
1058 if ((attr
= SecCmsAttributeCreate(poolp
, SEC_OID_PKCS9_SIGNING_TIME
, &stime
, PR_FALSE
)) == NULL
) {
1059 SECITEM_FreeItem (&stime
, PR_FALSE
);
1063 SECITEM_FreeItem (&stime
, PR_FALSE
);
1065 if (SecCmsSignerInfoAddAuthAttr(signerinfo
, attr
) != SECSuccess
)
1068 PORT_ArenaUnmark (poolp
, mark
);
1073 PORT_ArenaRelease (poolp
, mark
);
1078 * SecCmsSignerInfoAddSMIMECaps - add a SMIMECapabilities attribute to the
1079 * authenticated (i.e. signed) attributes of "signerinfo".
1081 * This is expected to be included in outgoing signed
1082 * messages for email (S/MIME).
1085 SecCmsSignerInfoAddSMIMECaps(SecCmsSignerInfoRef signerinfo
)
1087 SecCmsAttribute
*attr
;
1088 CSSM_DATA_PTR smimecaps
= NULL
;
1092 poolp
= signerinfo
->cmsg
->poolp
;
1094 mark
= PORT_ArenaMark(poolp
);
1096 smimecaps
= SECITEM_AllocItem(poolp
, NULL
, 0);
1097 if (smimecaps
== NULL
)
1100 /* create new signing time attribute */
1102 // @@@ We don't do Fortezza yet.
1103 if (SecSMIMECreateSMIMECapabilities((SecArenaPoolRef
)poolp
, smimecaps
, PR_FALSE
) != SECSuccess
)
1105 if (SecSMIMECreateSMIMECapabilities(poolp
, smimecaps
,
1106 PK11_FortezzaHasKEA(signerinfo
->cert
)) != SECSuccess
)
1110 if ((attr
= SecCmsAttributeCreate(poolp
, SEC_OID_PKCS9_SMIME_CAPABILITIES
, smimecaps
, PR_TRUE
)) == NULL
)
1113 if (SecCmsSignerInfoAddAuthAttr(signerinfo
, attr
) != SECSuccess
)
1116 PORT_ArenaUnmark (poolp
, mark
);
1120 PORT_ArenaRelease (poolp
, mark
);
1125 * SecCmsSignerInfoAddSMIMEEncKeyPrefs - add a SMIMEEncryptionKeyPreferences attribute to the
1126 * authenticated (i.e. signed) attributes of "signerinfo".
1128 * This is expected to be included in outgoing signed messages for email (S/MIME).
1131 SecCmsSignerInfoAddSMIMEEncKeyPrefs(SecCmsSignerInfoRef signerinfo
, SecCertificateRef cert
, SecKeychainRef keychainOrArray
)
1133 SecCmsAttribute
*attr
;
1134 CSSM_DATA_PTR smimeekp
= NULL
;
1141 /* verify this cert for encryption */
1142 policy
= CERT_PolicyForCertUsage(certUsageEmailRecipient
);
1143 if (CERT_VerifyCert(keychainOrArray
, cert
, policy
, CFAbsoluteTimeGetCurrent(), NULL
) != SECSuccess
) {
1150 poolp
= signerinfo
->cmsg
->poolp
;
1151 mark
= PORT_ArenaMark(poolp
);
1153 smimeekp
= SECITEM_AllocItem(poolp
, NULL
, 0);
1154 if (smimeekp
== NULL
)
1157 /* create new signing time attribute */
1158 if (SecSMIMECreateSMIMEEncKeyPrefs((SecArenaPoolRef
)poolp
, smimeekp
, cert
) != SECSuccess
)
1161 if ((attr
= SecCmsAttributeCreate(poolp
, SEC_OID_SMIME_ENCRYPTION_KEY_PREFERENCE
, smimeekp
, PR_TRUE
)) == NULL
)
1164 if (SecCmsSignerInfoAddAuthAttr(signerinfo
, attr
) != SECSuccess
)
1167 PORT_ArenaUnmark (poolp
, mark
);
1171 PORT_ArenaRelease (poolp
, mark
);
1176 * SecCmsSignerInfoAddMSSMIMEEncKeyPrefs - add a SMIMEEncryptionKeyPreferences attribute to the
1177 * authenticated (i.e. signed) attributes of "signerinfo", using the OID prefered by Microsoft.
1179 * This is expected to be included in outgoing signed messages for email (S/MIME),
1180 * if compatibility with Microsoft mail clients is wanted.
1183 SecCmsSignerInfoAddMSSMIMEEncKeyPrefs(SecCmsSignerInfoRef signerinfo
, SecCertificateRef cert
, SecKeychainRef keychainOrArray
)
1185 SecCmsAttribute
*attr
;
1186 CSSM_DATA_PTR smimeekp
= NULL
;
1193 /* verify this cert for encryption */
1194 policy
= CERT_PolicyForCertUsage(certUsageEmailRecipient
);
1195 if (CERT_VerifyCert(keychainOrArray
, cert
, policy
, CFAbsoluteTimeGetCurrent(), NULL
) != SECSuccess
) {
1202 poolp
= signerinfo
->cmsg
->poolp
;
1203 mark
= PORT_ArenaMark(poolp
);
1205 smimeekp
= SECITEM_AllocItem(poolp
, NULL
, 0);
1206 if (smimeekp
== NULL
)
1209 /* create new signing time attribute */
1210 if (SecSMIMECreateMSSMIMEEncKeyPrefs((SecArenaPoolRef
)poolp
, smimeekp
, cert
) != SECSuccess
)
1213 if ((attr
= SecCmsAttributeCreate(poolp
, SEC_OID_MS_SMIME_ENCRYPTION_KEY_PREFERENCE
, smimeekp
, PR_TRUE
)) == NULL
)
1216 if (SecCmsSignerInfoAddAuthAttr(signerinfo
, attr
) != SECSuccess
)
1219 PORT_ArenaUnmark (poolp
, mark
);
1223 PORT_ArenaRelease (poolp
, mark
);
1228 * SecCmsSignerInfoAddTimeStamp - add time stamp to the
1229 * unauthenticated (i.e. unsigned) attributes of "signerinfo".
1231 * This will initially be used for time stamping signed applications
1232 * by using a Time Stamping Authority. It may also be included in outgoing signed
1233 * messages for email (S/MIME), and may be useful in other situations.
1235 * This should only be added once; a second call will do nothing.
1240 Countersignature attribute values have ASN.1 type Countersignature:
1241 Countersignature ::= SignerInfo
1242 Countersignature values have the same meaning as SignerInfo values
1243 for ordinary signatures, except that:
1244 1. The signedAttributes field MUST NOT contain a content-type
1245 attribute; there is no content type for countersignatures.
1246 2. The signedAttributes field MUST contain a message-digest
1247 attribute if it contains any other attributes.
1248 3. The input to the message-digesting process is the contents octets
1249 of the DER encoding of the signatureValue field of the SignerInfo
1250 value with which the attribute is associated.
1255 @abstract Create a timestamp unsigned attribute with a TimeStampToken.
1259 SecCmsSignerInfoAddTimeStamp(SecCmsSignerInfoRef signerinfo
, CSSM_DATA
*tstoken
)
1261 SecCmsAttribute
*attr
;
1262 PLArenaPool
*poolp
= signerinfo
->cmsg
->poolp
;
1263 void *mark
= PORT_ArenaMark(poolp
);
1265 // We have already encoded this ourselves, so last param is PR_TRUE
1266 if ((attr
= SecCmsAttributeCreate(poolp
, SEC_OID_PKCS9_TIMESTAMP_TOKEN
, tstoken
, PR_TRUE
)) == NULL
)
1269 if (SecCmsSignerInfoAddUnauthAttr(signerinfo
, attr
) != SECSuccess
)
1272 PORT_ArenaUnmark (poolp
, mark
);
1277 PORT_ArenaRelease (poolp
, mark
);
1282 * SecCmsSignerInfoAddCounterSignature - countersign a signerinfo
1284 * 1. digest the DER-encoded signature value of the original signerinfo
1285 * 2. create new signerinfo with correct version, sid, digestAlg
1286 * 3. add message-digest authAttr, but NO content-type
1287 * 4. sign the authAttrs
1288 * 5. DER-encode the new signerInfo
1289 * 6. add the whole thing to original signerInfo's unAuthAttrs
1290 * as a SEC_OID_PKCS9_COUNTER_SIGNATURE attribute
1292 * XXXX give back the new signerinfo?
1295 SecCmsSignerInfoAddCounterSignature(SecCmsSignerInfoRef signerinfo
,
1296 SECOidTag digestalg
, SecIdentityRef identity
)
1303 * XXXX the following needs to be done in the S/MIME layer code
1304 * after signature of a signerinfo is verified
1307 SecCmsSignerInfoSaveSMIMEProfile(SecCmsSignerInfoRef signerinfo
)
1309 SecCertificateRef cert
= NULL
;
1310 CSSM_DATA_PTR profile
= NULL
;
1311 SecCmsAttribute
*attr
;
1312 CSSM_DATA_PTR utc_stime
= NULL
;
1316 Boolean must_free_cert
= PR_FALSE
;
1318 SecKeychainRef keychainOrArray
;
1320 status
= SecKeychainCopyDefault(&keychainOrArray
);
1322 /* sanity check - see if verification status is ok (unverified does not count...) */
1323 if (signerinfo
->verificationStatus
!= SecCmsVSGoodSignature
)
1326 /* find preferred encryption cert */
1327 if (!SecCmsArrayIsEmpty((void **)signerinfo
->authAttr
) &&
1328 (attr
= SecCmsAttributeArrayFindAttrByOidTag(signerinfo
->authAttr
,
1329 SEC_OID_SMIME_ENCRYPTION_KEY_PREFERENCE
, PR_TRUE
)) != NULL
)
1330 { /* we have a SMIME_ENCRYPTION_KEY_PREFERENCE attribute! */
1331 ekp
= SecCmsAttributeGetValue(attr
);
1335 /* we assume that all certs coming with the message have been imported to the */
1336 /* temporary database */
1337 cert
= SecSMIMEGetCertFromEncryptionKeyPreference(keychainOrArray
, ekp
);
1340 must_free_cert
= PR_TRUE
;
1344 /* no preferred cert found?
1345 * find the cert the signerinfo is signed with instead */
1346 CFStringRef emailAddress
=NULL
;
1348 cert
= SecCmsSignerInfoGetSigningCertificate(signerinfo
, keychainOrArray
);
1351 if (SecCertificateGetEmailAddress(cert
,&emailAddress
))
1355 /* verify this cert for encryption (has been verified for signing so far) */ /* don't verify this cert for encryption. It may just be a signing cert.
1356 * that's OK, we can still save the S/MIME profile. The encryption cert
1357 * should have already been saved */
1359 if (CERT_VerifyCert(keychainOrArray
, cert
, certUsageEmailRecipient
, CFAbsoluteTimeGetCurrent(), NULL
) != SECSuccess
) {
1361 CERT_DestroyCertificate(cert
);
1366 /* XXX store encryption cert permanently? */
1369 * Remember the current error set because we do not care about
1370 * anything set by the functions we are about to call.
1372 save_error
= PORT_GetError();
1374 if (!SecCmsArrayIsEmpty((void **)signerinfo
->authAttr
)) {
1375 attr
= SecCmsAttributeArrayFindAttrByOidTag(signerinfo
->authAttr
,
1376 SEC_OID_PKCS9_SMIME_CAPABILITIES
,
1378 profile
= SecCmsAttributeGetValue(attr
);
1379 attr
= SecCmsAttributeArrayFindAttrByOidTag(signerinfo
->authAttr
,
1380 SEC_OID_PKCS9_SIGNING_TIME
,
1382 utc_stime
= SecCmsAttributeGetValue(attr
);
1385 rv
= CERT_SaveSMimeProfile (cert
, profile
, utc_stime
);
1387 CERT_DestroyCertificate(cert
);
1390 * Restore the saved error in case the calls above set a new
1391 * one that we do not actually care about.
1393 PORT_SetError (save_error
);
1399 * SecCmsSignerInfoIncludeCerts - set cert chain inclusion mode for this signer
1402 SecCmsSignerInfoIncludeCerts(SecCmsSignerInfoRef signerinfo
, SecCmsCertChainMode cm
, SECCertUsage usage
)
1404 if (signerinfo
->cert
== NULL
)
1407 /* don't leak if we get called twice */
1408 if (signerinfo
->certList
!= NULL
) {
1409 CFRelease(signerinfo
->certList
);
1410 signerinfo
->certList
= NULL
;
1415 signerinfo
->certList
= NULL
;
1417 case SecCmsCMCertOnly
:
1418 signerinfo
->certList
= CERT_CertListFromCert(signerinfo
->cert
);
1420 case SecCmsCMCertChain
:
1421 signerinfo
->certList
= CERT_CertChainFromCert(signerinfo
->cert
, usage
, PR_FALSE
);
1423 case SecCmsCMCertChainWithRoot
:
1424 signerinfo
->certList
= CERT_CertChainFromCert(signerinfo
->cert
, usage
, PR_TRUE
);
1428 if (cm
!= SecCmsCMNone
&& signerinfo
->certList
== NULL
)