Size DSS /Contents dynamically with a retry fallback (#430)#431
Merged
Conversation
The DSS engine reserved DSS's fixed default of 9472 bytes for the CMS /Contents, which is too small for large certificate chains (eID / qualified certs) combined with an embedded signature timestamp. Signing then failed with "The signature size [9472] is too small ...". Estimate the reservation from the actual certificate chain plus a fixed timestamp allowance so the common eID+TSA case signs in a single pass, and grow-and-resign when DSS still reports it too small. Both behaviours are configurable: - engine.dss.contentSize: explicit reserved size (0 = auto-estimate) - engine.dss.retryOnUndersize: grow and re-sign on undersize (default on) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When an undersized /Contents cannot be recovered (retry disabled, or exhausted) the only feedback was DSS's raw exception naming setContentSize(...), a DSS API call rather than a JSignPdf setting. Log an actionable message that names the two knobs and a concrete value: enable engine.dss.retryOnUndersize, or raise engine.dss.contentSize. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The new EU DSS (PAdES) engine reserved DSS's fixed default of 9472 bytes for the CMS signature
/Contents. That is too small for large certificate chains (eID / qualified certs) combined with an embedded signature timestamp, so signing consistently failed with:Fixes #430.
Approach
The reservation must be fixed before the byte ranges are digested, so it cannot be derived from the produced signature. Instead:
Σ cert.getEncoded().length) + overhead for the signer info / signed attributes / signature value / ASN.1 framing, plus a fixed TSA allowance when a timestamp is embedded. This covers the eID+TSA case in a single pass.Both behaviours are configurable via
EngineConfig:engine.dss.contentSize0/Contentssize in bytes;0= auto-estimateengine.dss.retryOnUndersizetrueTradeoffs
Tests
Added 3 tests (14 total, all green):
🤖 Generated with Claude Code