#![cfg(all(feature = "alloc", any(feature = "ring", feature = "aws_lc_rs")))]
use core::time::Duration;
use pki_types::{CertificateDer, UnixTime};
use webpki::{anchor_from_trusted_cert, KeyUsage};
fn check_cert(ee: &[u8], ca: &[u8]) -> Result<(), webpki::Error> {
let ca = CertificateDer::from(ca);
let anchors = &[anchor_from_trusted_cert(&ca).unwrap()];
let time = UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d));
let ee = CertificateDer::from(ee);
let cert = webpki::EndEntityCert::try_from(&ee).unwrap();
cert.verify_for_usage(
webpki::ALL_VERIFICATION_ALGS,
anchors,
&[],
time,
KeyUsage::client_auth(),
None,
None,
)
.map(|_| ())
}
#[test]
fn cert_with_no_eku_accepted_for_client_auth() {
let ee = include_bytes!("client_auth/cert_with_no_eku_accepted_for_client_auth.ee.der");
let ca = include_bytes!("client_auth/cert_with_no_eku_accepted_for_client_auth.ca.der");
assert_eq!(check_cert(ee, ca), Ok(()));
}
#[test]
fn cert_with_clientauth_eku_accepted_for_client_auth() {
let ee = include_bytes!("client_auth/cert_with_clientauth_eku_accepted_for_client_auth.ee.der");
let ca = include_bytes!("client_auth/cert_with_clientauth_eku_accepted_for_client_auth.ca.der");
assert_eq!(check_cert(ee, ca), Ok(()));
}
#[test]
fn cert_with_both_ekus_accepted_for_client_auth() {
let ee = include_bytes!("client_auth/cert_with_both_ekus_accepted_for_client_auth.ee.der");
let ca = include_bytes!("client_auth/cert_with_both_ekus_accepted_for_client_auth.ca.der");
assert_eq!(check_cert(ee, ca), Ok(()));
}
#[test]
fn cert_with_serverauth_eku_rejected_for_client_auth() {
let ee = include_bytes!("client_auth/cert_with_serverauth_eku_rejected_for_client_auth.ee.der");
let ca = include_bytes!("client_auth/cert_with_serverauth_eku_rejected_for_client_auth.ca.der");
assert_eq!(check_cert(ee, ca), Err(webpki::Error::RequiredEkuNotFound));
}