Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix webpki CRL test, deprecations. #142

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn test_crl() -> (CertificateRevocationList, Certificate) {
let now = OffsetDateTime::now_utc();
let next_week = now + Duration::weeks(1);
let revoked_cert = RevokedCertParams{
serial_number: SerialNumber::from_slice(&[0xC0, 0xFF, 0xEE]),
serial_number: SerialNumber::from_slice(&[0x00, 0xC0, 0xFF, 0xEE]),
revocation_time: now,
reason_code: Some(RevocationReason::KeyCompromise),
invalidity_date: None,
Expand Down
22 changes: 11 additions & 11 deletions tests/webpki.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// TODO: we import deprecated webpki items here, get rid of them and allow this
#![allow(deprecated)]
#[cfg(feature = "x509-parser")]
use rcgen::{CertificateSigningRequest, DnValue};
use rcgen::{BasicConstraints, Certificate, CertificateParams, DnType, IsCa, KeyPair, RemoteKeyPair};
use rcgen::{KeyUsagePurpose, ExtendedKeyUsagePurpose, SerialNumber};
use rcgen::{CertificateRevocationList, CertificateRevocationListParams, RevocationReason, RevokedCertParams};
use webpki::{EndEntityCert, TlsServerTrustAnchors, TrustAnchor, BorrowedCertRevocationList, CertRevocationList, TlsClientTrustAnchors};
use webpki::{EndEntityCert, TrustAnchor, BorrowedCertRevocationList, CertRevocationList, KeyUsage};
use webpki::SignatureAlgorithm;
use webpki::{Time, DnsNameRef};

Expand Down Expand Up @@ -54,18 +52,19 @@ fn check_cert_ca<'a, 'b>(cert_der :&[u8], cert :&'a Certificate, ca_der :&[u8],
sign_fn :impl FnOnce(&'a Certificate, &'b [u8]) -> Vec<u8>) {
let trust_anchor = TrustAnchor::try_from_cert_der(&ca_der).unwrap();
let trust_anchor_list = &[trust_anchor];
let trust_anchors = TlsServerTrustAnchors(trust_anchor_list);
let end_entity_cert = EndEntityCert::try_from(cert_der).unwrap();

// Set time to Jan 10, 2004
let time = Time::from_seconds_since_unix_epoch(0x40_00_00_00);

// (1/3) Check whether the cert is valid
end_entity_cert.verify_is_valid_tls_server_cert(
end_entity_cert.verify_for_usage(
&[&cert_alg, &ca_alg],
&trust_anchors,
&trust_anchor_list[..],
&[],
time,
KeyUsage::server_auth(),
&[],
).expect("valid TLS server cert");

// (2/3) Check that the cert is valid for the given DNS name
Expand Down Expand Up @@ -485,17 +484,17 @@ fn test_webpki_crl_revoke() {
// Set up webpki's verification requirements.
let trust_anchor = TrustAnchor::try_from_cert_der(issuer_der.as_ref()).unwrap();
let trust_anchor_list = &[trust_anchor];
let trust_anchors = TlsClientTrustAnchors(trust_anchor_list);
let end_entity_cert = EndEntityCert::try_from(ee_der.as_ref()).unwrap();
let unix_time = 0x40_00_00_00;
let time = Time::from_seconds_since_unix_epoch(unix_time);

// The end entity cert should validate with the issuer without error.
end_entity_cert.verify_is_valid_tls_client_cert(
end_entity_cert.verify_for_usage(
&[&webpki::ECDSA_P256_SHA256],
&trust_anchors,
&trust_anchor_list[..],
&[],
time,
KeyUsage::client_auth(),
&[],
).expect("failed to validate ee cert with issuer");

Expand All @@ -520,11 +519,12 @@ fn test_webpki_crl_revoke() {
let crl = BorrowedCertRevocationList::from_der(&crl_der).unwrap();

// The end entity cert should **not** validate when we provide a CRL that revokes the EE cert.
let result = end_entity_cert.verify_is_valid_tls_client_cert(
let result = end_entity_cert.verify_for_usage(
&[&webpki::ECDSA_P256_SHA256],
&trust_anchors,
&trust_anchor_list[..],
&[],
time,
KeyUsage::client_auth(),
&[&crl],
);
assert!(matches!(result, Err(webpki::Error::CertRevoked)));
Expand Down
Loading