diff --git a/Cargo.lock b/Cargo.lock index 4266ba5aae..f594c38c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1384,7 +1384,7 @@ dependencies = [ [[package]] name = "craft-pkcs7" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=8479a1f3bbabb0e0b25194c508ab2eb14aa5490f#8479a1f3bbabb0e0b25194c508ab2eb14aa5490f" +source = "git+https://github.com/storytold/craft-libs?rev=a62ce81f2447b1791a8d8c0aa6317fb6388f189b#a62ce81f2447b1791a8d8c0aa6317fb6388f189b" dependencies = [ "aes", "aws-lc-rs", diff --git a/crates/sign/Cargo.toml b/crates/sign/Cargo.toml index 72698021f5..86e0215cbd 100644 --- a/crates/sign/Cargo.toml +++ b/crates/sign/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] # Existing shared ASN.1 codec; PDF signature policy remains local. -craft-pkcs7 = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8479a1f3bbabb0e0b25194c508ab2eb14aa5490f" } +craft-pkcs7 = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "a62ce81f2447b1791a8d8c0aa6317fb6388f189b" } pdfcraft-cos = { workspace = true } pdfcraft-annot = { workspace = true } pdfcraft-content = { workspace = true } diff --git a/crates/sign/src/revocation.rs b/crates/sign/src/revocation.rs index 93191b2528..5630bfcba5 100644 --- a/crates/sign/src/revocation.rs +++ b/crates/sign/src/revocation.rs @@ -65,6 +65,21 @@ pub struct CertificateList { impl CertificateList { pub fn parse(bytes: &[u8]) -> Result { + let parsed = craft_pkcs7::revocation::CertificateList::parse(bytes).map_err(crate::der::app_error)?.into_parts(); + Ok(Self { + tbs: parsed.tbs, + sig_alg: parsed.sig_alg, + signature: parsed.signature, + issuer_raw: parsed.issuer_raw, + this_update: parsed.this_update, + next_update: parsed.next_update, + revoked: parsed.revoked, + }) + } + + // Retained parity oracle: original CRL parser by Justin John (4d0078aeff). + #[cfg(test)] + fn parse_legacy(bytes: &[u8]) -> Result { if bytes.is_empty() || bytes.len() > MAX_EVIDENCE { return Err(bad("CRL is empty or exceeds the 2 MiB limit")); } @@ -307,3 +322,44 @@ impl OcspResponse { } } } + +#[cfg(test)] +mod shared_crl_tests { + use super::*; + use crate::der; + + #[test] + fn shared_crl_parser_matches_retained_app_reader() { + let date = Time { year: 2026, month: 6, day: 15, hour: 12, minute: 0, second: 0 }; + let algorithm = DigestAlg::Sha256.algorithm(); + let tbs = der::seq(&[ + &der::int(1), + &algorithm, + &der::seq(&[]), + &date.encode(), + &date.encode(), + &der::seq(&[&der::seq(&[&der::uint(&[0x80]), &date.encode()])]), + ]); + let valid = der::seq(&[&tbs, &algorithm, &der::bit_string(&[1, 2, 3])]); + let compare = |bytes: &[u8]| match (CertificateList::parse(bytes), CertificateList::parse_legacy(bytes)) { + (Ok(a), Ok(b)) => { + assert_eq!( + (a.tbs, a.sig_alg, a.signature, a.issuer_raw, a.this_update, a.next_update, a.revoked), + (b.tbs, b.sig_alg, b.signature, b.issuer_raw, b.this_update, b.next_update, b.revoked) + ); + } + (Err(a), Err(b)) => assert_eq!(format!("{a:?}"), format!("{b:?}")), + _ => panic!("shared and retained CRL parsers disagree"), + }; + for end in 0..=valid.len() { + compare(&valid[..end]); + } + for i in 0..valid.len() { + let mut mutated = valid.clone(); + mutated[i] ^= 0x80; + compare(&mutated); + } + compare(&vec![0; MAX_EVIDENCE]); + compare(&vec![0; MAX_EVIDENCE + 1]); + } +}