Skip to content

fix(docmdp): accept DSS and document timestamp updates after certification - #9556

Open
no84by wants to merge 1 commit into
LibreSign:mainfrom
no84by:fix/docmdp-allow-dss
Open

no84by wants to merge 1 commit into
LibreSign:mainfrom
no84by:fix/docmdp-allow-dss

Conversation

@no84by

@no84by no84by commented Nov 18, 2026

Copy link
Copy Markdown

Resolves: #9534

Part of #8946

Summary

ISO 32000-2 12.8.2.2.1 and ETSI EN 319 142-1 5.4 exempt incremental updates that only add a DSS dictionary (VRI, Certs, CRLs, OCSPs) or a document timestamp from DocMDP restrictions. DocMdpHandler classified such an update as an unknown modification, so a certified document was reported as a DocMDP violation as soon as long-term validation data was added, at every level (P=1, 2 and 3).

Before the existing classification, DocMdpHandler now checks whether the bytes after the certified revision are validation data only. The check is strict, so a lenient reading cannot be used to slip content changes through:

  • The bytes are parsed as a sequence of incremental updates: indirect objects, a classic xref table listing exactly those objects at their offsets, a trailer and startxref. Each trailer must keep the certified /Root and /Info, chain /Prev to the previous section and carry no /Encrypt. Xref streams, object streams, objects outside the xref and anything unparsable mean the update is not validation data only.
  • The certified revision is read through its classic xref tables, so rewritten objects are compared with their certified version.
  • New objects must use numbers from the certified /Size on.
  • Of the existing objects, an update may only rewrite:
    • the catalog: /DSS, /Extensions, /Version;
    • the AcroForm: /SigFlags, and timestamp fields appended to /Fields;
    • a page: timestamp fields appended to /Annots;
    • the information dictionary: /ModDate, /Producer.
  • A new field must be an invisible document timestamp field: zero-area /Rect, no /Kids, /Parent, /A or /AA, and /V pointing to a new /DocTimeStamp with /SubFilter /ETSI.RFC3161. Any other new signature, field or annotation keeps the update a violation.
  • Rewritten objects are compared in a canonical form: sorted keys, names with #xx escapes decoded, strings by their bytes, duplicate keys rejected, bounded nesting. LTV tools rewrite the catalog and the information dictionary with their own formatting.

Out of scope: a certified revision written with xref streams is not exempted (behaviour unchanged for such files).

How to test

  1. Certify a PDF with DocMDP P=1 (or 2).
  2. Add a DSS with an external tool, for example pyHanko (DocumentSecurityStore.supply_dss_in_writer), or add a document timestamp (PdfTimeStamper).
  3. Validate the file: the certification is valid and the modification message says that only validation data or document timestamps were added.
  4. Change page content in an incremental update instead, or swap the trailer /Root: still reported as a DocMDP violation.

Validation evidence

  • Focused regression/acceptance test
    • DocMdpHandlerTest (68 tests). Accepted: DSS at P=1/2/3, document timestamp, DSS and timestamp in one update, timestamp then DSS. Rejected at P=1:
      • page content added; catalog /OpenAction; duplicate catalog key; information dictionary /Title changed; page tree rewritten;
      • text annotation; non-signature field; existing field removed; approval signature; field value that is not a document timestamp; visible timestamp widget; timestamp field with /AA or /Kids;
      • object stream, also behind a #xx name escape;
      • forged trailer (/Root, /Info, /Encrypt, /Prev); object outside the update xref; xref stream update.
    • DocMdpHandlerValidationDataTest (integration, 8 tests). A PDF certified with P=1 by the native engine with a throwaway certificate, then a DSS incremental update (catalog /DSS and /Version, information dictionary rewritten), is accepted, and the certification signature stays cryptographically valid. Still violations:
      • a rewritten page content stream next to the DSS;
      • a trailer /Root swap to a new page tree;
      • a redefinition hidden behind a comment between generation number and obj, or swallowed by an unterminated stream;
      • a visible signature field holding an approval signature;
      • a duplicate /Pages key;
      • an object stream behind a name escape.
    • Manual check: a P=1 document from the native engine with a DSS, and with a document timestamp followed by a DSS, both added by pyHanko 0.38.1, is accepted.
  • Relevant lint/type/static-analysis checks (php-cs-fixer, psalm on DocMdpHandler, lint:translator-hints)
  • Broader suite required by the changed surface (PHPUnit unit suite, tests/php/Integration/Handler, PdfSignatureDetectionServiceTest)
  • CI reviewed

API / Back-end changes

  • DocMdpHandler: DSS-only and document-timestamp-only incremental updates after certification are reported as MODIFICATION_ALLOWED with a new translatable message
  • Unit and/or integration tests added or updated
  • Authorization and negative paths checked when applicable
  • Capabilities updated when applicable
  • Documentation updated when applicable
  • API documentation regenerated using composer openapi when necessary

Checklist

  • I have read and followed the contribution guide.
  • The diff does not contain unrelated refactors or generated changes.
  • Commits follow Conventional Commits where applicable.
  • All commits include the required DCO sign-off.

AI (if applicable)

  • The content of this PR was partially or fully generated using AI

…ation

ISO 32000-2 12.8.2.2.1 and ETSI EN 319 142-1 5.4 exempt incremental
updates that only add a DSS dictionary (VRI, Certs, CRLs, OCSPs) or a
document timestamp from DocMDP restrictions. The validation classified
such an update as an unknown modification, so a certified document
became invalid as soon as long-term validation data was added, at every
DocMDP level.

Before classifying the modification, parse the bytes after the certified
revision strictly as incremental updates: indirect objects, a classic
xref table listing exactly those objects at their offsets, a trailer
whose /Root, /Info and /Prev match the certified revision and has no
/Encrypt, and startxref. Xref streams, unlisted or unparsable bytes and
object streams mean the update is not validation data only. The
certified revision is read through its classic xref tables.

New objects must use numbers from the certified /Size on. Of the
existing objects, an update may only rewrite the catalog (/DSS,
/Extensions, /Version), the AcroForm (/SigFlags, timestamp fields
appended to /Fields), a page (timestamp fields appended to /Annots) and
the information dictionary (/ModDate, /Producer). A new field must be an
invisible document timestamp field (zero-area /Rect, no /Kids, /Parent,
/A or /AA) whose value is a new /DocTimeStamp with /SubFilter
/ETSI.RFC3161; any other new signature, field or annotation keeps the
update a violation.

Rewritten objects are compared in a canonical form (sorted keys, names
with #xx escapes decoded, strings by their bytes, duplicate keys
rejected, bounded nesting), since LTV tools rewrite the catalog and the
information dictionary with their own formatting.

Signed-off-by: no84by <50858621+no84by@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post-signing DSS addition breaks DocMDP validation

1 participant