Skip to content

Commit 441d571

Browse files
DrToberaoulstrackxkoentange
authored andcommitted
Merge #214
214: Add support for certificate revocation lists r=raoulstrackx a=monokles Originally introduced by PR #112 but never made it into master. I cherry-picked the original commits onto a fresh branch and fixed the resulting code. Since it changes the API, the version number is bumped. Co-authored-by: Raoul Strackx <[email protected]> Co-authored-by: koentange <[email protected]>
1 parent 3a8f53c commit 441d571

File tree

1 file changed

+21
-44
lines changed

1 file changed

+21
-44
lines changed

mbedtls/src/x509/certificate.rs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,58 +1009,35 @@ cYp0bH/RcPTC0Z+ZaqSWMtfxRrk63MJQF9EXpDCdvQRcTMD9D85DJrMKn8aumq0M
10091009
let c_int2 = Certificate::from_pem(C_INT2.as_bytes()).unwrap();
10101010
let mut c_root = Certificate::from_pem_multiple(C_ROOT.as_bytes()).unwrap();
10111011

1012-
{
1013-
let mut chain = MbedtlsList::<Certificate>::new();
1014-
chain.push(c_leaf.clone());
1015-
chain.push(c_int1.clone());
1016-
1017-
let err = Certificate::verify(&chain, &mut c_root, None).unwrap_err();
1018-
assert_eq!(err, Error::X509CertVerifyFailed);
1019-
1020-
// try again after fixing the chain
1021-
chain.push(c_int2.clone());
1022-
1023-
1024-
let mut err_str = String::new();
1025-
1026-
let verify_callback = |_crt: &Certificate, _depth: i32, verify_flags: &mut VerifyError| {
1027-
verify_flags.remove(VerifyError::CERT_EXPIRED);
1028-
Ok(())
1029-
};
1012+
// Certificate C_INT2 is missing at the beginning so the verification should fail at first
1013+
let mut chain = MbedtlsList::<Certificate>::new();
1014+
chain.push(c_leaf.clone());
1015+
chain.push(c_int1.clone());
10301016

1031-
Certificate::verify(&chain, &mut c_root, None).unwrap();
1032-
let res = Certificate::verify_with_callback(&chain, &mut c_root, Some(&mut err_str), verify_callback);
1017+
// The certificates used for this test are expired so we remove the CERT_EXPIRED flag with the callback
1018+
let verify_callback = |_crt: &Certificate, _depth: i32, verify_flags: &mut VerifyError| {
1019+
verify_flags.remove(VerifyError::CERT_EXPIRED);
1020+
Ok(())
1021+
};
10331022

1034-
match res {
1035-
Ok(()) => (),
1036-
Err(e) => assert!(false, "Failed to verify, error: {}, err_str: {}", e, err_str),
1037-
};
1023+
let res = Certificate::verify_with_callback(&chain, &mut c_root, None, verify_callback);
1024+
match res {
1025+
Ok(_) => panic!("Certificate chain verification should have failed, but it succeeded"),
1026+
Err(err) => assert_eq!(err, Error::X509CertVerifyFailed),
10381027
}
10391028

1040-
{
1041-
let mut chain = MbedtlsList::<Certificate>::new();
1042-
chain.push(c_leaf.clone());
1043-
chain.push(c_int1.clone());
1044-
chain.push(c_int2.clone());
1045-
1046-
Certificate::verify(&chain, &mut c_root, None).unwrap();
1029+
// try again after fixing the chain
1030+
chain.push(c_int2.clone());
10471031

1048-
let verify_callback = |_crt: &Certificate, _depth: i32, verify_flags: &mut VerifyError| {
1049-
verify_flags.remove(VerifyError::CERT_EXPIRED);
1050-
Ok(())
1051-
};
1032+
let mut err_str = String::new();
10521033

1053-
let mut err_str = String::new();
1054-
let res = Certificate::verify_with_callback(&chain, &mut c_root, Some(&mut err_str), verify_callback);
1034+
let res = Certificate::verify_with_callback(&chain, &mut c_root, Some(&mut err_str), verify_callback);
10551035

1056-
match res {
1057-
Ok(()) => (),
1058-
Err(e) => assert!(false, "Failed to verify, error: {}, err_str: {}", e, err_str),
1059-
};
1060-
}
1036+
match res {
1037+
Ok(()) => (),
1038+
Err(e) => panic!("Failed to verify, error: {}, err_str: {}", e, err_str),
1039+
};
10611040
}
1062-
1063-
10641041

10651042
#[test]
10661043
fn clone_test() {

0 commit comments

Comments
 (0)