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

Correctly encode a CRL with empty revokedCertificates. #295

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
30 changes: 27 additions & 3 deletions src/repository/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ impl RevokedCertificates {

/// Returns a value encoder for a reference to the value.
pub fn encode_ref(&self) -> impl encode::Values + '_ {
encode::sequence(&self.0)
(!self.0.is_empty()).then(|| {
encode::sequence(&self.0)
})
}

/// Create a value from an iterator over CRL entries.
Expand Down Expand Up @@ -818,6 +820,7 @@ mod signer_test {

#[test]
fn build_ta_cert() {
// CRL with two CrlEntries.
let signer = OpenSslSigner::new();
let key = signer.create_key(PublicKeyFormat::Rsa).unwrap();
let pubkey = signer.get_key_info(&key).unwrap();
Expand All @@ -826,12 +829,33 @@ mod signer_test {
pubkey.to_subject_name(),
Time::now(),
Time::tomorrow(),
vec![CrlEntry::new(12u64.into(), Time::now())],
vec![
CrlEntry::new(12u64.into(), Time::now()),
CrlEntry::new(42u64.into(), Time::now())
],
pubkey.key_identifier(),
12u64.into()
);
let crl = crl.into_crl(&signer, &key).unwrap().to_captured();
let crl = Crl::decode(crl.as_slice()).unwrap();
assert_eq!(
crl.revoked_certs().iter().collect::<Vec<_>>().len(),
2
);

// CRL with no CrlEntries.
let crl = TbsCertList::new(
Default::default(),
pubkey.to_subject_name(),
Time::now(),
Time::tomorrow(),
vec![],
pubkey.key_identifier(),
12u64.into()
);
let crl = crl.into_crl(&signer, &key).unwrap().to_captured();
let _crl = Crl::decode(crl.as_slice()).unwrap();
let crl = Crl::decode(crl.as_slice()).unwrap();
assert!(crl.revoked_certs().iter().next().is_none());
}
}

Loading