mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-19 02:26:48 +00:00
Merge pull request #7654 from storytold/refactor/shared-crl
Sign: parse crl through shared PKCS7 components
This commit is contained in:
3 files changed
+58
-2
No files matched your search
Generated
+1
-1
@@ -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",
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -65,6 +65,21 @@ pub struct CertificateList {
|
||||
|
||||
impl CertificateList {
|
||||
pub fn parse(bytes: &[u8]) -> Result<CertificateList, SignError> {
|
||||
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<CertificateList, SignError> {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user