Skip to content

Commit a182fb0

Browse files
committed
Add context to CrlExpired errors
1 parent 3f08209 commit a182fb0

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/crl/types.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl CertRevocationList<'_> {
150150
};
151151

152152
if time >= next_update {
153-
return Err(Error::CrlExpired);
153+
return Err(Error::CrlExpired { time, next_update });
154154
}
155155

156156
Ok(())
@@ -1254,8 +1254,10 @@ mod tests {
12541254
let crl = CertRevocationList::from(BorrowedCertRevocationList::from_der(&crl[..]).unwrap());
12551255
// Friday, February 2, 2024 8:26:19 PM GMT
12561256
let time = UnixTime::since_unix_epoch(Duration::from_secs(1_706_905_579));
1257-
1258-
assert!(matches!(crl.check_expiration(time), Err(Error::CrlExpired)));
1257+
assert!(matches!(
1258+
crl.check_expiration(time),
1259+
Err(Error::CrlExpired { .. })
1260+
));
12591261
}
12601262

12611263
#[test]

src/error.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ pub enum Error {
6262

6363
/// The CRL is expired; i.e. the verification time is not before the time
6464
/// in the CRL nextUpdate field.
65-
CrlExpired,
65+
CrlExpired {
66+
/// The validation time.
67+
time: UnixTime,
68+
/// The nextUpdate time of the CRL.
69+
next_update: UnixTime,
70+
},
6671

6772
/// An end-entity certificate is being used as a CA certificate.
6873
EndEntityUsedAsCa,
@@ -235,7 +240,7 @@ impl Error {
235240
// Errors related to certificate validity
236241
Self::CertNotValidYet { .. } | Self::CertExpired { .. } => 290,
237242
Self::CertNotValidForName(_) => 280,
238-
Self::CertRevoked | Self::UnknownRevocationStatus | Self::CrlExpired => 270,
243+
Self::CertRevoked | Self::UnknownRevocationStatus | Self::CrlExpired { .. } => 270,
239244
Self::InvalidCrlSignatureForPublicKey | Self::InvalidSignatureForPublicKey => 260,
240245
Self::SignatureAlgorithmMismatch => 250,
241246
Self::RequiredEkuNotFound => 240,

tests/client_auth_revocation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,10 @@ fn expired_crl_enforce_expiration() {
16621662
let revocation = Some(builder.build());
16631663
assert_eq!(
16641664
check_cert(ee, intermediates, ca, revocation),
1665-
Err(webpki::Error::CrlExpired)
1665+
Err(webpki::Error::CrlExpired {
1666+
time: UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d)),
1667+
next_update: UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d - 10)),
1668+
})
16661669
);
16671670
}
16681671

@@ -1691,6 +1694,9 @@ fn expired_crl_enforce_expiration_owned() {
16911694
let revocation = Some(builder.build());
16921695
assert_eq!(
16931696
check_cert(ee, intermediates, ca, revocation),
1694-
Err(webpki::Error::CrlExpired)
1697+
Err(webpki::Error::CrlExpired {
1698+
time: UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d)),
1699+
next_update: UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d - 10)),
1700+
})
16951701
);
16961702
}

tests/generate.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,14 +2246,20 @@ def _expired_crl_enforce_expiration() -> None:
22462246
)
22472247

22482248
# Providing a CRL that's expired should error if the expiration policy is set to enforce.
2249+
expected_error = """
2250+
CrlExpired {
2251+
time: UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d)),
2252+
next_update: UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d - 10)),
2253+
}
2254+
"""
22492255
_revocation_test(
22502256
test_name=test_name,
22512257
chain=no_ku_chain,
22522258
crl_paths=[ee_not_revoked_crl_path],
22532259
depth=ChainDepth.CHAIN,
22542260
policy=StatusRequirement.ALLOW_UNKNOWN,
22552261
expiration=ExpirationPolicy.ENFORCE,
2256-
expected_error="CrlExpired",
2262+
expected_error=expected_error,
22572263
)
22582264

22592265
with trim_top("client_auth_revocation.rs") as output:

0 commit comments

Comments
 (0)