Skip to content

Commit

Permalink
enable tests with expired cert
Browse files Browse the repository at this point in the history
fix verify_chain test by ignoring CERT_EXPIRED error
  • Loading branch information
Taowyoo committed Dec 20, 2022
1 parent 9cdb8ea commit 98948fc
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions mbedtls/src/x509/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Certificate {
let mut cert = MbedtlsBox::<Certificate>::init()?;
unsafe { x509_crt_parse((&mut (*cert)).into(), pem.as_ptr(), pem.len()) }.into_result()?;


if !(*cert).inner.next.is_null() {
// Use from_pem_multiple for parsing multiple certificates in a pem.
return Err(Error::X509BadInputData);
Expand Down Expand Up @@ -571,7 +572,7 @@ impl MbedtlsList<Certificate> {
self.inner.is_none()
}

pub fn push(&mut self, certificate: MbedtlsBox<Certificate>) {
pub fn push(&mut self, certificate: MbedtlsBox<Certificate>) -> () {
self.append(MbedtlsList::<Certificate> { inner: Some(certificate) });
}

Expand Down Expand Up @@ -1023,15 +1024,12 @@ cYp0bH/RcPTC0Z+ZaqSWMtfxRrk63MJQF9EXpDCdvQRcTMD9D85DJrMKn8aumq0M
// try again after fixing the chain
chain.push(c_int2.clone());


let mut err_str = String::new();

// ignore cert expired error
let verify_callback = |_crt: &Certificate, _depth: i32, verify_flags: &mut VerifyError| {
verify_flags.remove(VerifyError::CERT_EXPIRED);
Ok(())
};

Certificate::verify(&chain, &mut c_root, None, None).unwrap();
let mut err_str = String::new();
let res = Certificate::verify_with_callback(&chain, &mut c_root, None, Some(&mut err_str), verify_callback);

match res {
Expand All @@ -1046,13 +1044,11 @@ cYp0bH/RcPTC0Z+ZaqSWMtfxRrk63MJQF9EXpDCdvQRcTMD9D85DJrMKn8aumq0M
chain.push(c_int1.clone());
chain.push(c_int2.clone());

Certificate::verify(&chain, &mut c_root, None, None).unwrap();

// ignore cert expired error
let verify_callback = |_crt: &Certificate, _depth: i32, verify_flags: &mut VerifyError| {
verify_flags.remove(VerifyError::CERT_EXPIRED);
Ok(())
};

let mut err_str = String::new();
let res = Certificate::verify_with_callback(&chain, &mut c_root, None, Some(&mut err_str), verify_callback);

Expand Down

0 comments on commit 98948fc

Please sign in to comment.