Skip to content

fix: never certify a document that is already signed - #9552

Open
no84by wants to merge 2 commits into
LibreSign:mainfrom
no84by:fix/no-certification-on-signed-document
Open

no84by wants to merge 2 commits into
LibreSign:mainfrom
no84by:fix/no-certification-on-signed-document

Conversation

@no84by

@no84by no84by commented Nov 18, 2026 •

Copy link
Copy Markdown

Part of #8946 (correct PAdES/DocMDP handling).

Summary

A certification (DocMDP) signature must be the first signature of a document. Two cases certified a document that was already signed:

  • Native engine: with DocMDP enabled, every invisible signature was a certification signature, even on a document that was already signed or already certified. It now certifies only when the document has no signature yet, for visible and invisible signatures alike.
  • JSignPdf: the JSignPdf parameters stay on the handler between signatures and new parameters are merged into them. After a certifying signature, the next signature from the same handler still had -cl and certified again. When DocMDP is enabled, a signature that does not certify now sends -cl NOT_CERTIFIED, which replaces any earlier level.

Two commits, one per engine, each with a regression test.

How to test

  1. Enable DocMDP and select the native engine. Sign a document that already has a signature without a visible element: the result has one certification at most, and all signatures validate.
  2. With JSignPdf, sign an unsigned document invisibly (it certifies), then sign an already-signed document with the same PHP process/handler: the second call no longer passes the certification level.

Validation evidence

  • Focused regression/acceptance test: PhpNativeSigningRegressionTest::testInvisibleSignatureDoesNotCertifyASignedDocument, ::testLaterSignatureKeepsTheCertificationOfTheFirstSignature (real signatures, checked with the validation service and OpenSSL) and JSignPdfHandlerTest::testCertificationLevelIsNotReusedByTheNextSignature. All three fail on main and pass with the fix.
  • Relevant lint/type/static-analysis checks: php-cs-fixer.
  • Broader suite required by the changed surface: unit tests for the sign engines and SignFileService; integration tests PhpNativeSigningRegressionTest, JSignPdfHandlerTest, Pkcs12HandlerTest.
  • CI reviewed

API / Back-end changes

  • Native engine: certify only when the document has no signature yet.
  • JSignPdf: clear a stale certification level when the signature does not certify.
  • 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 with 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

A certification (DocMDP) signature has to be the first signature of
a document. With DocMDP enabled, the native engine certified every
invisible signature, also on a document that was already signed or
already certified, which invalidates the earlier signatures' DocMDP
semantics. Certify only when the document has no signature yet, for
invisible and visible signatures alike.

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

The JSignPdf parameters are kept on the handler between signatures and
new parameters are merged into them. After a certifying signature, the
next signature made by the same handler (for example on a document that
is already signed) still carried "-cl" and certified again. When DocMDP
is enabled, a signature that does not certify now sends
"-cl NOT_CERTIFIED", which replaces any earlier level.

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.

1 participant