Skip to content

Commit b787686

Browse files
committed
Test for cert time validity
1 parent 67801e0 commit b787686

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/integration.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,56 @@ fn expect_cert_dns_names<'name>(
320320

321321
assert!(cert.valid_dns_names().eq(expected_names))
322322
}
323+
324+
#[cfg(feature = "alloc")]
325+
#[test]
326+
fn cert_time_validity() {
327+
let ee: &[u8] = include_bytes!("netflix/ee.der");
328+
let inter = CertificateDer::from(&include_bytes!("netflix/inter.der")[..]);
329+
let ca = CertificateDer::from(&include_bytes!("netflix/ca.der")[..]);
330+
331+
let anchors = [anchor_from_trusted_cert(&ca).unwrap()];
332+
333+
let not_before = UnixTime::since_unix_epoch(Duration::from_secs(1_478_563_200));
334+
let not_after = UnixTime::since_unix_epoch(Duration::from_secs(1_541_203_199));
335+
336+
let just_before = UnixTime::since_unix_epoch(Duration::from_secs(not_before.as_secs() - 1));
337+
let just_after = UnixTime::since_unix_epoch(Duration::from_secs(not_after.as_secs() + 1));
338+
339+
let ee = CertificateDer::from(ee);
340+
let cert = webpki::EndEntityCert::try_from(&ee).unwrap();
341+
342+
assert_eq!(
343+
cert.verify_for_usage(
344+
webpki::ALL_VERIFICATION_ALGS,
345+
&anchors,
346+
&[inter.clone()],
347+
just_before,
348+
KeyUsage::server_auth(),
349+
None,
350+
None,
351+
)
352+
.err(),
353+
Some(webpki::Error::CertNotValidYet {
354+
time: just_before,
355+
not_before
356+
})
357+
);
358+
359+
assert_eq!(
360+
cert.verify_for_usage(
361+
webpki::ALL_VERIFICATION_ALGS,
362+
&anchors,
363+
&[inter],
364+
just_after,
365+
KeyUsage::server_auth(),
366+
None,
367+
None,
368+
)
369+
.err(),
370+
Some(webpki::Error::CertExpired {
371+
time: just_after,
372+
not_after
373+
})
374+
);
375+
}

0 commit comments

Comments
 (0)