DEV Community
Follow
Why your PDF signature breaks the moment someone edits the file
A client's unsigned agreement, showing a green tick in their viewer but invalid in mine, highlights the core problem with PDF signatures: they cover bytes, not meaning. When a PDF is signed, the tool signs a specific byte range, not the visual content. Viewers vary in their validation; some only check for existence and certificate chain, while others verify the byte range against the current file. This disparity explains why the same file can appear valid or invalid in different viewers.PDFs allow incremental updates, where new objects are appended, leaving original bytes intact. In this case, the signature remains technically valid, but the file now contains unsigned content, potentially after the signature block. Alternatively, rewriting the file, common with "Save as" or online tools, shifts all offsets, rendering the signature permanently invalid.To discern the type of modification, the 'pdfsig' tool can report both integrity and coverage. It differentiates between a valid signature with subsequent modifications and an entirely invalid signature due to file rewriting. Additionally, 'openssl' can reveal the actual signer's certificate details, which may not always align with the presumed signatory.Common practical issues include fixing typos after signing, which invalidates the signature despite the visual image remaining, or redlining with comments, which adds unsigned content. Another problematic scenario is a pasted image as a "signature," lacking any cryptographic validation.To avoid these pitfalls, the recommended workflow is to sign last. If changes are necessary post-signing, re-sign and retain both versions, prioritizing the audit trail. Always verify the file with a tool like 'pdfsig' before sending, checking for integrity rather than just presence. A "modified" status indicates a mismatch between signed and visible content, prompting internal discussion.For legally binding documents, understanding the distinction between qualified and advanced signatures, as defined by regulations like eIDAS and ESIGN, is crucial, as it impacts tooling and legal claims. The silent failure of PDF signatures, where the visual document appears correct but the cryptographic link is broken, is a significant concern for those building PDF tooling. The only reliable check is to read the file, not just the page content.