mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-25 18:47:22 -06:00
PKCS #12 HMAC errors now propagate as `SignError`. Key-bag lookup uses `find_map` and chain building uses `let … else`. `der::oid` (only ever given this crate's OID literals) keeps the standard's narrow, documented `expect` exception. The crate now denies the panic lints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
printcraft-sign
Layer L4: digital signatures (execution plan M9; ISO 32000-2 §12.8; PAdES, ETSI EN 319 142).
let id = pkcs12::open(&std::fs::read("me.p12")?, "password")?; // a digital ID
let signed = sign(&doc, &id, &SignOptions { page: 0, rect: Some(r), date, ..Default::default() })?;
for s in signatures(&doc, &bytes, &trust) { // list + validate
println!("{}: {} — {:?}", s.field, s.summary(), s.details);
}
- Formats, on RustCrypto primitives: a small DER reader and writer (
der), X.509 certificates (x509), CMS SignedData (cms), and PKCS #12 digital ID files (pkcs12): PBES2 (PBKDF2 + AES/3DES), the legacy SHA-1 3DES/RC2 schemes, and MAC checks. Writing uses OpenSSL 3's defaults (AES-256-CBC, HMAC-SHA-256). - Keys: RSA, ECDSA P-256 and P-384. Verification uses RustCrypto everywhere. RSA
private-key operations (signing, key generation) use
aws-lc-rson native targets and are refused in the browser (ADR-0009: thersacrate's Marvin advisory, RUSTSEC-2023-0071, has no fix, sorsais only used to verify). ECDSA signs with deterministic nonces (RFC 6979). - Signing: PAdES B-B (
ETSI.CAdES.detached, signing-certificate-v2, SHA-256/384, no SHA-1). An existing unsigned field or a new one (visible with Acrobat's name-and-details appearance, or invisible); certification with DocMDP P=1/2/3. The document is written incrementally with a zero-filled/Contentsand fixed-width/ByteRange, which are then patched in place. Encrypted documents are refused for now. - Validation:
/ByteRangeand the CMS are read from the file's own bytes; the digest, the signature value and the signer's chain (against aTrustStore) are checked. Later revisions are diffed against the signed one, and the changes are classified (signing, form fill, comments, metadata, page content, document structure) under the DocMDP permissions. The verdict follows Acrobat: valid, unknown (intact but the identity isn't trusted) or invalid.
Not yet: RFC 3161 timestamps, LTV (DSS/VRI, OCSP, CRL), FieldMDP locks, certificate security, OS key stores and PKCS #11 tokens.
Oracles: poppler's pdfsig reports our signatures valid; OpenSSL reads our .p12 files and
verifies our CMS; tests/data/openssl-signed.pdf is a signature OpenSSL made, which we validate.