# Detached JAdES signatures — Signing Server

Prepare static-certificate-bound detached JAdES and complete B-B, B-T, B-LT and B-LTA with retained originals, configured time stamps, offline validation and archival renewal.

Installed archives include the JAdES baseline and source manifest. These reference documents describe the selected standards and encoding; they do not configure network retrieval or establish certificate trust.

## Registration and profile selection

The existing `/sign/{connection}` route, requester-signed whole DSS
envelope, configured connection allowlist, SAML identification, separate exact-input
consent, transaction expiry and durable replay protection remain required. No
new endpoint/listener is added. A trusted administrator must explicitly enable
this default-off local root profile for the registered requester:

```json
{
  "additional_signing_profiles": ["urn:se:idombud:signing:dss:jades:v1"]
}
```

This is the additional field inside an existing `requesters[]` entry, not a complete
service configuration or a caller request. Omitted/empty array preserves existing
standard-profile clients. Unknown/duplicate values reject configuration. The field
does not choose a signing credential or grant signer/requester/connection authority.
The [local SAML operations guide](https://github.com/fortifiedid/signing-server/blob/main/docs/60-operations/LOCAL-ACCESS-SAML-SIGNING.md)
explains the surrounding trusted configuration.

Set root `SignRequest/@Profile` to `urn:se:idombud:signing:dss:jades:v1`.
Use namespace `urn:se:idombud:signing:jades:dss:v1` for the local task collection.
This is explicitly a local DSS root profile, **not an official Sweden Connect
SigType**. Existing standard-profile XML/PDF/CMS/XAdES clients and schemas retain
their semantics. Never send local JAdES tasks under the standard root profile,
standard SignTasks under the local root profile, or a mixed collection.

Use the unchanged DSS request extension for requester/service/IdP/return URI,
intended signer, request validity and SignMessage. Sign the final full request
with the registered requester key. Base64 it and URL-form-encode it through the
signer browser as documented in the main guide. RelayState still exactly matches
RequestID; neither is signer authentication or signing consent.

## Keep the original and freeze protected input

retain JSON and non-JSON/binary originals with the consumer. JSON means
exact raw bytes: no parse/reserialize, whitespace/newline conversion, Unicode or
JSON normalization. SHA-256 is over those original octets. Original bytes never
enter Signing Server requests/logs and the server never uploads, fetches or
dereferences a reference. The opaque reference associates local retained data;
it is not network permission. The server cannot compare a protected digest with
an unseen original or prove the MIME/display meaning.

Obtain the actual preknown static signing-leaf certificate DER through trusted
installation configuration before preparing the header. A certificate supplied
inside the header never selects a private key. Use exactly these protected members:

| Member | Selected local requirement |
| --- | --- |
| `alg` | String `RS256`, RSA PKCS#1 v1.5 with SHA-256. |
| `typ` | String `JOSE+JSON`; this is a document signature, not JWT authentication issuance. |
| `b64` | JSON boolean `false`. |
| `crit` | Exactly the ordered array `["b64","sigD"]`. |
| `iat` | Nonnegative integer NumericDate seconds, lexical `0` or `[1-9][0-9]{0,18}`, no sign/fraction/exponent. Untrusted caller claim, no future time. |
| `x5c` | Exactly one standard canonical padded Base64 value: complete actual signing-leaf DER. |
| `x5t#S256` | Canonical unpadded base64url SHA-256 of that same complete actual leaf DER. |
| `sigD` | Exactly the five-member object described below. |

No unknown/duplicate names, escaped duplicate names, unprotected security fields,
key URLs, alternate algorithms, unsigned augmentation in signing requests or attached payload are
accepted. Strict UTF-8 without a BOM and strict bounded JSON parsing apply; duplicate names at
any nesting level reject. Header member order/whitespace may vary, but the exact
original serialization is frozen. Decoding and re-encoding semantically equivalent
JSON changes the signing input and requires fresh preparation/consent.

`sigD` has exactly:

```json
{
  "mId": "http://uri.etsi.org/19182/ObjectIdByURIHash",
  "pars": ["https://consumer.example/originals/document-1"],
  "hashM": "S256",
  "hashV": ["{{base64url(SHA-256(exact original octets)), no padding}}"],
  "ctys": ["application/json"]
}
```

The sample URI is an identifier, never fetched. Use one ASCII HTTPS URI at most
255 characters, with a host and absolute path, no userinfo/query/fragment; ports
must be omitted or 1–65535. Exactly one raw-original SHA-256 digest is required
because b64=false; do not hash Base64 text. `ctys` is one parameter-free MIME type,
at most 127 characters, matching
`[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+`. MIME accuracy remains a consumer assertion.
`x5t#S256` and `hashV` decode to exactly 32 bytes. Base64url uses only
`A–Z a–z 0–9 _ -`, no padding, whitespace or alternate encodings; x5c uses standard
Base64 instead. Actual RSA key strength must be 2048–4096 bits (returned signature at most 512 bytes).

The actual certificate must be valid at preparation/completion and at claimed iat
(`notBefore <= time < notAfter`); iat is not a trusted timestamp. Binding is checked
before transaction creation, again before private signing and against the returned
actual certificate. Fresh dynamic certificate hosts reject before identification/
issuance/signing; unknown future DER cannot be substituted after consent. Existing
dynamic generic XML/PDF/CMS behavior is unchanged.

## Exact signing message and local XML transport

let H be the exact strict UTF-8 protected-header JSON bytes. Let U be
canonical unpadded base64url(H). The exact complete signing message is:

```text
M = ASCII(U + ".")
D = SHA-256(M)
signature = RSASSA-PKCS1-v1_5-SHA256 prehash-sign(D)
```

The selected ObjectIdByURIHash mechanism gives the JWS payload an **empty stream**
contribution; sigD indirectly binds the original through its protected hash.
Ordinary detached JWS serialization alone still needs the original payload in
signature computation. This mechanism is what permits M to omit original bytes;
it is not an arbitrary payload-hash substitution. The crypto boundary receives
SHA-256(M) once for prehash signing, without double hashing. Do not send SHA-256(M)
as ToBeSignedBytes, sign SHA-256(original), append the original to M or hash D again.

M is 2–16384 bytes, ending in exactly one ASCII period after a nonempty base64url
header segment. The 16384-byte limit includes the period; header certificate
size counts. Shared 1–8 task, 65536 decoded XML, 131072 encoded form, XML depth32/
4096-node and original request/consent expiry bounds still apply. Strict protected
JSON additionally uses depth16/node1024 bounds. A per-input maximum does not grant
permission to exceed the entire encoded envelope bound.

Put the local collection under `InputDocuments/Other`:

```xml
<jad:JadesSignTasks xmlns:jad="urn:se:idombud:signing:jades:dss:v1">
  <jad:JadesSignTask TaskId="task-1"
    ProcessingRules="urn:se:idombud:signing:jades:detached-uri-hash-sha256-rsa:v1">
    <jad:ToBeSignedBytes>{{standard Base64 of exact M}}</jad:ToBeSignedBytes>
  </jad:JadesSignTask>
</jad:JadesSignTasks>
```

This illustrative unsigned fragment needs actual synthetic header/certificate/hash
values and a freshly signed outer envelope. XML transport uses standard Base64
of M, distinct from protected JSON's base64url. TaskId is required, unique in the
batch and matches `[A-Za-z0-9][A-Za-z0-9._:-]{0,95}`. ProcessingRules is required
and exact. Requests contain no Base64Signature or original/payload element. The
local XSD is explicitly loaded with pinned DSS schemas and is bundled as an API
artifact; never retrieve schemas from caller/network locations.

Success uses `SignatureObject/Other/jad:JadesSignTasks`, preserving exact ordered
TaskId, ProcessingRules and ToBeSignedBytes, and appends one `jad:Base64Signature`
with `Type="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"` and standard Base64
raw RSA signature bytes. The existing official csig response extension carries
actual public SignatureCertificateChain and selected signer evidence. Error
responses carry signed DSS result status without successful task signatures.

## Assemble and verify the complete signature

validate the registered service envelope key, pinned schemas, root
profile, RequestID/RelayState/private session, signed status, signer/assurance and
expiry before accepting any result. Match the exact ordered task IDs, rule and M,
expected actual leaf/credential and signature algorithm. Validate the certificate
under configured trust/purpose/revocation policy; an embedded x5c/returned chain
is public evidence, never automatic trust configuration. Verify RS256 over exact M.

Assemble the B-B flattened detached JWS JSON with exactly these two members:

```json
{"protected":"{{original exact U}}","signature":"{{base64url(raw RSA signature), no padding}}"}
```

B-B has no `payload`, `header`, unprotected member or extra signature. Higher
levels add only the `header.etsiU` container specified below. Retain
the original U without reserializing H. Independently verify protected properties,
critical extension support, actual certificate DER/thumbprint, original reference
association and SHA-256(original) against sigD.hashV, then verify the full selected
JAdES profile. Altered originals, header bytes, certificate binding, signature and
prehash/message confusion must fail. A valid raw signature or signed DSS envelope
alone cannot prove that the assembled JAdES matches the consumer's original.

The consumer owns **SignMessage association** with the document/business operation,
MIME claims and displayed meaning. Authentication is distinct from explicit
exact-input signing consent; it cannot establish those document assertions.
Avoid putting original content, tokens, private keys or full protected inputs in
application/audit logs. Consume the private consumer session once, only after full
verification. Lost response grants no signing retry or browser-resume authority.

## Levels and unsigned evidence

B-B remains exactly `{protected,signature}`. Higher levels add exactly
`header:{"etsiU":[...]}`; neither `payload` nor a `signatures` array is supported.
Each nonempty array entry is canonical unpadded base64url of strict UTF-8 JSON
with exactly one supported property. All entries use encoded mode; clear/mixed
objects and `canonAlg` are rejected. Preserve the original `protected` and
`signature` strings and every preceding encoded entry **verbatim**. New entries
are appended; historical JSON is never normalized or regenerated.

| Level | Consumer evidence |
| --- | --- |
| B-B | The unchanged protected header and signature, verified against the retained original. |
| B-T | One `sigTst`, containing exactly one RFC3161/RFC5816 token. |
| B-LT | B-T plus complete signer and TSA certificate/revocation material in the selected containers. |
| B-LTA | B-LT plus archival protection; append renewal material and a new `arcTst` without original signing. |

The bounded subset admits only `sigTst`, `anyValData` and `arcTst` components.
B-T is exactly `sigTst`; B-LT is `sigTst, anyValData`; B-LTA retains that prefix
and appends useful `anyValData` entries as needed, then one `arcTst`, per
generation. Multiple consecutive material entries preserve existing encoded blocks
while adding independently useful fresh or missing evidence; none may be empty
or redundant.
The final component is `arcTst`; at most eight archives are supported.
Standalone `xVals`, `rVals` and `tstVD` are rejected. A completed LTA may not
end in `anyValData`; its material must be followed by `arcTst`.
These are local subset rules, not the universal ETSI grammar. No countersignature, policy/content/reference timestamp, evidence URL,
OCSP, delta/indirect CRL or arbitrary unsigned property is accepted. Complete
direct-issuer CRLs satisfy this implementation's revocation-material path; this
is not an OCSP-support claim. Each present container must be nonempty and useful.
`xVals` entries are `{ "x509Cert": { "val": "<standard Base64 DER>" } }`;
`rVals` is `{ "crlVals": [{ "val": "<standard Base64 DER>" }] }`.
`anyValData` contains `xVals` and/or `rVals`. Timestamp containers
contain `tstTokens:[{"val":"<standard Base64 DER>"}]`, with exactly one token;
`type`, `encoding` and `specRef` are omitted. Inner PKI values use standard
canonical padded Base64; outer component strings use unpadded base64url.

## B-T: timestamp the encoded signature member

let `signatureU` be the exact canonical unpadded base64url string in
`signature`. Request the existing timestamp API with `imprint_kind=signature_value`
and `imprint=SHA-256(ASCII(signatureU))`. **Do not hash raw RSA bytes**, the quoted
JSON string, the full JWS, or the protected-header signing message. Correlate the
configured profile, expected TSA certificate/chain, policy, nonce and exact imprint;
validate token signature, certificate binding and generation time before appending
`sigTst`. Obtain it while the original signer certificate/status remains usable.
An invalid/unavailable token fails the requested level; never silently return B-B.

## B-LT: preserve validation material

validate the retained original and full B-T first. Incorporate missing
signer/TSA-path certificates and complete direct-issuer CRLs in `anyValData`,
using nested `xVals` and `rVals`. ETSI clause 5.3.5.6 permits this general
validation-data container; no `tstVD` component is used in this selected subset.
Evidence already present must not be copied redundantly.
Explicit certificate/CRL containers are deduplicated by DER identity across the
history; immutable token-embedded certificates are preserved. A root certificate
may be retained as material, but only separately configured roots establish trust.

Run full offline level validation with AIA, OCSP and CRL network retrieval disabled.
Check chain, issuer, certificate purpose, signatures, time, serial/status and
cross-evidence consistency. Reject missing, stale, revoked, forged, wrong-issuer
or inconsistent evidence. Fetch preparation material only under fixed bounded
administrator policy; the protected original URI is a local association and never
fetched. Claimed `iat` alone establishes no proof of existence.

## B-LTA and renewal

archive coverage uses ETSI TS119182-1 clause 5.3.6.2.3. For one original,
`b64=false` and ObjectIdByURIHash, the SHA-256 input is exactly:

```text
original exact octets
|| ASCII("." + protectedU + "." + signatureU + ".")
|| ASCII(encoded etsiU entry 0)
|| ... || ASCII(encoded etsiU entry immediately before this arcTst)
```

There are no separators, JSON quotes or decoded-component bytes between entries.
Exclude the new `arcTst` itself and all later entries. Unlike the original signing
message, archive hashing includes the original's actual octets. Prepare the exact bounded input; do not substitute its URI/hash, normalize JSON
or recompute old encodings.
Use `imprint_kind=original` on the existing timestamp API; the label conveys no
format validation to Signing Server.

Validate the complete existing artifact before renewal. Gather missing/fresh
material for the signer and every earlier timestamp, bind the configured next
TSA's material and trust, then append useful missing/fresh `anyValData` before
its new `arcTst`. This preloads the next TSA's chain/status evidence; the returned
token must match it exactly. There is no following `tstVD`. Preserve the whole previous prefix, original, protected header and signature;
renewal invokes no original document-signing key. Require strictly increasing
archive generation times and validate the exact requested full level before output.
The concrete accepted sequence is specified in the [machine contract](https://github.com/fortifiedid/signing-server/blob/main/api/support-service.xml-contract.json)
and executable consumer; ETSI's wider grammar is not a promise of local support.

Historical certificate/status evidence is evaluated at validated timestamp/proof-
of-existence instants with archive coverage. An old CRL is not rejected merely
because its `nextUpdate` is now past; stale unprotected evidence cannot fabricate
historical validity. Obtain valid new TSA evidence and renew before current
protection expires. Later timestamps cannot repair missing evidence, prior tampering
or an already lost protection chain.

## Bounds, recovery and retention

unchanged server limits above apply to original signing. Consumer
augmentation has separate aggregate bounds; it does not enlarge DSS/form inputs.
The consumer accepts originals 1..16,777,216 bytes, completed JWS at most
16,777,216 bytes and at most eight archive timestamps. B-B alone retains its
65,536-byte envelope ceiling. Explicit embedded certificates and CRLs are each
bounded to 32 across the complete history, independently of per-container limits. All simultaneous JSON, DER,
entry and hash-input bounds are listed in the machine contract; meeting one bound
does not authorize exceeding another. Strict decoding rejects duplicate decoded
names, malformed UTF-8/BOM/trailing bytes, ambiguous base64url/standard Base64,
unknown members and malformed/noncanonical/oversized inner DER before library parsing.

Freeze the original and prior artifact while preparing a timestamp. Bind their
hashes, exact prefix, prior level, timestamp imprint and configured trust/TSA
material to the expiring archive state. Retain the submitted timestamp request ID,
requester, profile, provider and policy in the surrounding consumer correlation
record; these are supplied and checked at completion, rather than stored by the
archive-preparation command. Complete only with fresh matching full-validation
evidence and the exact correlated fresh token. Use create-new
output paths; on timeout, mismatch, process loss or unknown outcome retain the prior
artifact and the original unchanged. A consumed timestamp ID remains consumed;
no automatic retry, reissue, fresh-ID substitution, poll/reset or browser resume
is authorized. Draft expiry never authorizes deleting transaction, receipt, audit
or key history. Follow the [timestamp recovery contract](https://github.com/fortifiedid/signing-server/blob/main/docs/70-integration/TIMESTAMP.md).

The preservation owner retains originals, every signature revision, encoded history,
public chains/CRLs, tokens, explicit trust/policy history, correlation and validation
receipts. Monitor algorithm suitability, TSA/issuer changes and latest usable
protection; schedule renewal with time for outages. Keep authoritative old revisions
until replacement validation and retention policy permit disposal. No fixed renewal
interval or hosted retention/preservation guarantee is implied.
