summaryrefslogtreecommitdiff
path: root/lib/pkcs7/p7decode.c
diff options
context:
space:
mode:
authorBrian Smith <bsmith@mozilla.com>2013-04-04 21:59:57 +0200
committerBrian Smith <bsmith@mozilla.com>2013-04-04 21:59:57 +0200
commit1c41b335177935297ecd21b402f49ef4365b5c5d (patch)
tree31c2fa8e192bac87602fb5a4b572152b1e231061 /lib/pkcs7/p7decode.c
parent619f38f2435c11c12cd8c14ce4a44e110c8b6a67 (diff)
downloadnss-hg-1c41b335177935297ecd21b402f49ef4365b5c5d.tar.gz
Bug 842856 - Add SEC_PKCS7VerifyDetachedSignatureAtTime for verifying the certificate chain at the current time instead of the signing time, r=rrelyeaNSS_3_15_BETA1
Diffstat (limited to 'lib/pkcs7/p7decode.c')
-rw-r--r--lib/pkcs7/p7decode.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/lib/pkcs7/p7decode.c b/lib/pkcs7/p7decode.c
index 93e61f7aa..c45c2a769 100644
--- a/lib/pkcs7/p7decode.c
+++ b/lib/pkcs7/p7decode.c
@@ -1246,13 +1246,17 @@ SEC_PKCS7ContentIsSigned(SEC_PKCS7ContentInfo *cinfo)
/*
- * SEC_PKCS7ContentVerifySignature
+ * sec_pkcs7_verify_signature
+ *
* Look at a PKCS7 contentInfo and check if the signature is good.
* The digest was either calculated earlier (and is stored in the
* contentInfo itself) or is passed in via "detached_digest".
*
* The verification checks that the signing cert is valid and trusted
- * for the purpose specified by "certusage".
+ * for the purpose specified by "certusage" at
+ * - "*atTime" if "atTime" is not null, or
+ * - the signing time if the signing time is available in "cinfo", or
+ * - the current time (as returned by PR_Now).
*
* In addition, if "keepcerts" is true, add any new certificates found
* into our local database.
@@ -1281,7 +1285,8 @@ sec_pkcs7_verify_signature(SEC_PKCS7ContentInfo *cinfo,
SECCertUsage certusage,
const SECItem *detached_digest,
HASH_HashType digest_type,
- PRBool keepcerts)
+ PRBool keepcerts,
+ const PRTime *atTime)
{
SECAlgorithmID **digestalgs, *bulkid;
const SECItem *digest;
@@ -1299,7 +1304,8 @@ sec_pkcs7_verify_signature(SEC_PKCS7ContentInfo *cinfo,
SECItem *content_type;
PK11SymKey *sigkey;
SECItem *encoded_stime;
- int64 stime;
+ PRTime stime;
+ PRTime verificationTime;
SECStatus rv;
/*
@@ -1436,8 +1442,14 @@ sec_pkcs7_verify_signature(SEC_PKCS7ContentInfo *cinfo,
* in a time (and for non-S/MIME callers to pass in nothing, or
* maybe make them pass in the current time, always?).
*/
- if (CERT_VerifyCert (certdb, cert, PR_TRUE, certusage,
- encoded_stime != NULL ? stime : PR_Now(),
+ if (atTime) {
+ verificationTime = *atTime;
+ } else if (encoded_stime != NULL) {
+ verificationTime = stime;
+ } else {
+ verificationTime = PR_Now();
+ }
+ if (CERT_VerifyCert (certdb, cert, PR_TRUE, certusage, verificationTime,
cinfo->pwfn_arg, NULL) != SECSuccess)
{
/*
@@ -1748,7 +1760,7 @@ SEC_PKCS7VerifySignature(SEC_PKCS7ContentInfo *cinfo,
PRBool keepcerts)
{
return sec_pkcs7_verify_signature (cinfo, certusage,
- NULL, HASH_AlgNULL, keepcerts);
+ NULL, HASH_AlgNULL, keepcerts, 0);
}
/*
@@ -1770,9 +1782,31 @@ SEC_PKCS7VerifyDetachedSignature(SEC_PKCS7ContentInfo *cinfo,
{
return sec_pkcs7_verify_signature (cinfo, certusage,
detached_digest, digest_type,
- keepcerts);
+ keepcerts, NULL);
}
+/*
+ * SEC_PKCS7VerifyDetachedSignatureAtTime
+ * Look at a PKCS7 contentInfo and check if the signature matches
+ * a passed-in digest (calculated, supposedly, from detached contents).
+ * The verification checks that the signing cert is valid and trusted
+ * for the purpose specified by "certusage" at time "atTime".
+ *
+ * In addition, if "keepcerts" is true, add any new certificates found
+ * into our local database.
+ */
+PRBool
+SEC_PKCS7VerifyDetachedSignatureAtTime(SEC_PKCS7ContentInfo *cinfo,
+ SECCertUsage certusage,
+ const SECItem *detached_digest,
+ HASH_HashType digest_type,
+ PRBool keepcerts,
+ PRTime atTime)
+{
+ return sec_pkcs7_verify_signature (cinfo, certusage,
+ detached_digest, digest_type,
+ keepcerts, &atTime);
+}
/*
* Return the asked-for portion of the name of the signer of a PKCS7
@@ -1835,7 +1869,7 @@ sec_pkcs7_get_signer_cert_info(SEC_PKCS7ContentInfo *cinfo, int selector)
* some valid usage to pass in.
*/
(void) sec_pkcs7_verify_signature (cinfo, certUsageEmailSigner,
- NULL, HASH_AlgNULL, PR_FALSE);
+ NULL, HASH_AlgNULL, PR_FALSE, 0);
signercert = signerinfos[0]->cert;
if (signercert == NULL)
return NULL;