# Detached XAdES signatures — Signing Server

Prepare static-certificate-bound detached XAdES and complete B-B, B-T, B-LT and B-LTA with consumer-owned originals, trusted timestamps, complete validation material and archival renewal. The consumer selects and verifies the completed level; the signing request has no separate Baseline-level field.

Read the [document-signing instructions](/products/signing-server/next/integration/document-signing/), [OpenAPI](/assets/products/signing-server/support-service/support-service.openapi.json) and [XML contract map](/assets/products/signing-server/support-service/support-service.xml-contract.json) alongside this guide. The selected profile follows ETSI EN 319 132-1 V1.3.1, the applicable namespace schemas, XMLDSig 1.1 and exclusive canonicalization.

## Prepare and freeze the input

Keep the original with the consumer. The original may be binary, text
or XML; hash its exact octets with SHA-256, without decoding, normalization or
XML transforms. Enveloped XML is outside this subset. Signing Server never
uploads, fetches or dereferences the original. It validates prepared inputs,
not the unseen original reference digest or the truth of its MIME/display claims.

Obtain the actual preknown static signing-leaf certificate DER through trusted
installation configuration before preparation. The requester cannot choose a key
by sending a certificate. SigningCertificateV2 binds SHA-256 of the **complete
actual signing-leaf DER**, not its public key, issuer certificate or requester key.
The actual credential is checked before transaction creation, before private
signing and against the returned certificate. Dynamic fresh certificate hosts
reject this profile before identification/issuance/signing: an unknown future leaf
cannot be inserted into immutable exact-input consent. Existing dynamic generic
XML/PDF/CMS behavior remains unchanged.

Build one ds:Signature skeleton with a unique SignatureId and exactly:

- SignedInfo using exclusive C14N without comments/parameters and RSA-SHA256.
- One original Reference, with a unique Id, SHA-256 and **no transforms**. Its URI
  is an opaque bounded `urn:NID:NSS`, never a network/relative URI. The local ASCII
  grammar is `urn:[A-Za-z0-9][A-Za-z0-9-]{0,30}[A-Za-z0-9]:[A-Za-z0-9._:-]+`.
- One SignedProperties Reference, URI `#` plus its Id, exact Type
  `http://uri.etsi.org/01903#SignedProperties`, SHA-256 and exactly one exclusive
  C14N transform.
- One complete ds:Object containing QualifyingProperties Target `#SignatureId`
  and SignedProperties. SignedSignatureProperties contains SigningTime followed
  by SigningCertificateV2/Cert/CertDigest. SignedDataObjectProperties contains one
  DataObjectFormat targeting the original Reference Id and one MimeType.

SigningTime is an **untrusted caller claim**, not a trusted timestamp. Use UTC
`YYYY-MM-DDTHH:mm:ss[.fraction]Z`, with at most nine fractional digits, no future
time and certificate validity covering the claim and current preparation/signing
operation (`notBefore <= time < notAfter`). The RSA leaf must have at least 2048
bits. IDs match `[A-Za-z_][A-Za-z0-9_.-]{0,95}` and must be globally unique across
the supplied skeleton inputs. Original URI is at most 255 characters. MimeType is
parameter-free, at most 127 characters, with local grammar
`[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+`; MIME accuracy belongs to the consumer.
All digest values are canonical padded Base64 of exactly 32 bytes.

Canonicalize SignedProperties in its actual ds:Object context and put its SHA-256
in the typed Reference. Freeze exact canonical SignedInfo and complete ds:Object
bytes. Each is nonempty and at most 8192 decoded bytes. The shared 8-task, 65536
XML-byte and 131072 encoded-form-byte bounds also apply; two individually bounded
inputs can still exceed the total envelope limit. Unexpected attributes/elements,
duplicate IDs, xml:base/xml:id, comments, processing instructions, entities,
external property references, unsigned properties and unsupported transforms reject
**in server signing inputs**. Consumer-only unsigned augmentation below never
returns through this prepared-input boundary.

## Submit and receive the selected binding

Select all three values together: `SigType="XML"`, `AdESType="BES"`,
and `ProcessingRules="urn:se:idombud:signing:xades:detached-b-b-sha256-rsa:v1"`.
The existing schema's BES marker selects certificate-binding data; the exact rule
defines this B-B subset. Generic XML/PDF continue to reject ProcessingRules and
use omitted/None AdESType. Generic CMS retains its separate exact rule.

Illustrative unsigned task fragment, with placeholders requiring fresh preparation:

```xml
<csig:SignTaskData xmlns:csig="http://id.elegnamnden.se/csig/1.1/dss-ext/ns"
  SignTaskId="task-1" SigType="XML" AdESType="BES"
  ProcessingRules="urn:se:idombud:signing:xades:detached-b-b-sha256-rsa:v1">
  <csig:ToBeSignedBytes>{{Base64 exact canonical SignedInfo}}</csig:ToBeSignedBytes>
  <csig:AdESObject>
    <csig:SignatureId>signature</csig:SignatureId>
    <csig:AdESObjectBytes>{{Base64 complete ds:Object}}</csig:AdESObjectBytes>
  </csig:AdESObject>
</csig:SignTaskData>
```

The downloadable [synthetic XML task fragment](/assets/products/signing-server/support-service/examples/xades-b-b-task.fragment.xml)
and [JSON preparation shape](/assets/products/signing-server/support-service/examples/xades-b-b-task.fragment.json)
contain placeholders, not a complete signed request or captured runtime proof.
Do not include OtherAdESData, OtherSignTaskData or a request signature value.
Sign the complete DSS envelope using the registered requester key after freezing
all inputs. Base64 the original serialized DSS request XML bytes, then URL-form-encode once and follow the browser
consent and fresh authentication sequence in the main guide. A valid authentication
is distinct from authorization over these exact bytes and the transaction.

Validate the signed result envelope/session/signer/assurance and configured service
key first. Match ordered task IDs, XML/BES, exact ProcessingRules, SignatureId,
ToBeSignedBytes and complete AdESObject to retained input. Verify returned raw
Base64Signature with RSA-SHA256 over exact SignedInfo and the expected actual leaf
in public SignatureCertificateChain. No raw-signature success alone proves XAdES.

## Assemble and independently verify

Insert SignatureValue and actual accepted certificate into the retained
skeleton, preserving the canonical SignedInfo and SignedProperties bytes/context.
Namespace placement, ancestor context, serialization or later XML embedding can
change canonical bytes. Compare canonical input before and after assembly; do not
assume copying XML preserves its signature. Reject altered originals, properties,
certificate binding, signature or canonicalization context.

The consumer verifies every original Reference against the retained exact octets,
SignedProperties digest/type/target, certificate binding, algorithms and final
signature/profile. It owns configured certificate trust, purpose/revocation policy,
MIME assertions and **SignMessage association** with the original/business action.
Signing Server cannot infer those facts from prepared input. A returned chain is
public evidence, not automatic trust-anchor registration.

The runnable Java fixture exposes preparation, assembly and XMLDSig verification:
[XadesConsumer.java](https://github.com/fortifiedid/signing-server/blob/main/testkit/architecture-tests/src/test/java/se/idombud/signing/architecture/XadesConsumer.java).
The adapter enforcement is [XadesSigningInput.java](https://github.com/fortifiedid/signing-server/blob/main/modules/protocol-dss/src/main/java/se/idombud/signing/dss/XadesSigningInput.java)
and [DssAdapter.java](https://github.com/fortifiedid/signing-server/blob/main/modules/protocol-dss/src/main/java/se/idombud/signing/dss/DssAdapter.java).
The independent [EU DSS helper](https://github.com/fortifiedid/signing-server/blob/main/testkit/xades-verifier/README.md), pinned to
EU DSS 6.5.1 with a [dependency receipt](https://github.com/fortifiedid/signing-server/blob/main/testkit/xades-verifier/dependency-receipt.json),
is mandatory for this profile's test acceptance; Java XMLDSig alone is insufficient.
Root Maven and `-pl testkit/architecture-tests -am` builds prepare this test-only
helper automatically. The test-only helper edge excludes all transitives, keeping
EU DSS implementation classes isolated; existing independently declared shared
libraries remain on their original test/production classpaths. An optional standalone build/invocation from the
repository root uses synthetic public fixture files:

```sh
mvn -o -q -Daether.syncContext.named.factory=noop -f testkit/xades-verifier/pom.xml package dependency:build-classpath -Dmdep.outputFile=target/classpath.txt
java -cp "testkit/xades-verifier/target/classes:$(cat testkit/xades-verifier/target/classpath.txt)" se.idombud.signing.testkit.xades.VerifyXades signature.xml original.bin accepted-leaf.cer reports
```

The helper receives the actual retained original locally, rejects network retrieval,
and retains simple/detailed/diagnostic reports. It requires TOTAL_PASSED,
the exact requested XAdES_BASELINE_B/T/LT/LTA level, schema/structural and complete
level checks and exact accepted certificate identification. INDETERMINATE fails.
The four-argument B-B invocation above preserves the historical synthetic-leaf
policy. LT/LTA validation uses independently configured CA roots only, embedded
evidence and no AIA/OCSP/CRL network retrieval. Public embedded certificates cannot
promote themselves to trust anchors. No failed validation is suppressed.

The six-argument synthetic B-T invocation adds explicitly configured TSA leaf
trust while retaining the historical synthetic signer-leaf policy:

```sh
java -cp "testkit/xades-verifier/target/classes:$(cat testkit/xades-verifier/target/classpath.txt)" se.idombud.signing.testkit.xades.VerifyXades signature.xml original.bin accepted-leaf.cer reports XAdES_BASELINE_T explicit-tsa-leaftrust.pem
```

This form validates the explicitly trusted dedicated current TSA leaves. The
seven-argument CA-roots-only form (optionally eight with a validation instant)
is mandatory for LT/LTA and validates the complete chain and status evidence. Extended complete-level invocation:

```sh
java -cp "testkit/xades-verifier/target/classes:$(cat testkit/xades-verifier/target/classpath.txt)" se.idombud.signing.testkit.xades.VerifyXades signature.xml original.bin accepted-leaf.cer reports XAdES_BASELINE_LTA roots.pem roots-only
```

An optional final UTC validation instant supports controlled historical-validation
checks. Keep raw simple, detailed and diagnostic reports and exact source/helper/
dependency/artifact identities. Basic XMLDSig validation alone is insufficient.

The source references and helper commands target an integration source checkout.
Run the reference consumer and standalone verifier separately from the installed
Signing Server process. This example accepts a nonempty original up to16777216bytes; that is
a consumer-only bound, since Signing Server never receives the original.

## Choose the completed level

The same signed XML/BES task yields the original document signature.
The consumer chooses a completed level and performs public-only augmentation;
no later step creates new human consent or calls the original signing key.

| Level | Use and additional dependencies |
| --- | --- |
| B-B | Immediate signature validation. Retain the exact original, signed XML and independently accepted trust/status evidence. SigningTime is an untrusted caller claim. |
| B-T | Trusted evidence that the signature existed by the TSA time. Use an administrator-configured RFC3161/RFC5816 TSA profile, pinned policy/chain and permitted machine requester. |
| B-LT | Later offline validation. Obtain and validate signer/TSA chains and complete CRLs under independently configured roots; embed the required support evidence while available. |
| B-LTA | Maintained archival evidence. Add archival protection, assign a preservation owner, monitor evidence/algorithm validity and renew using a currently trusted TSA before protection becomes insufficient. |

Higher levels retain the preknown actual static leaf restriction. There is no
hosted archive, implicit issuance, dynamic fresh-certificate support, legal status
or external conformance declaration. No universal retention period or renewal
interval is supplied: the consumer's receiving process and retention policy set it.

## B-T: timestamp the canonical SignatureValue element

After B-B verification, add exactly one v1.3.2 `SignatureTimeStamp` within the
single `QualifyingProperties/UnsignedProperties/UnsignedSignatureProperties`.
Use explicit exclusive `ds:CanonicalizationMethod` without comments/parameters
and one canonical Base64 `EncapsulatedTimeStamp`. Hash the canonical **complete
ds:SignatureValue element**, including markup and namespace context. Raw RSA bytes
or bare Base64 text have different coverage and must not be timestamped here.

Use the existing [timestamp API](/products/signing-server/next/integration/time-stamping/) with SHA-256 of those exact covered
bytes. The consumer validates the returned token's imprint, signature, configured
certificate/path, policy, nonce and generation time, and correlates the exact
request/derived transaction/requester/profile/provider/kind/imprint/chain/time.
The initial timestamp must precede original signer expiry/revocation. The initial
B-T consumer operation also conservatively requires the signer certificate to be
current at use; later preservation uses independently validated historical POE. A claimed
SigningTime, response time or successful machine authentication is no substitute.
Altered tokens, wrong coverage, outage or uncertain results fail the requested
level; do not silently label the prior B-B artifact as B-T or sign it again.

## B-LT: incorporate public validation material

Append v1.4.1 `AnyValidationData` with nested v1.3.2 `CertificateValues` and/or
`RevocationValues` (complete CRLs only). At least one collection must be nonempty;
`URI` is forbidden. Clauses 5.4.6 and 6.3 cc permit this direct container for all
signature-supporting evidence, including signer and TSA paths. Do not use top-level
signer-only CertificateValues for a TSA-only path. Skip known identical values
already incorporated; retain required earlier evidence.

Validate actual signer/TSA chains and status under explicit configured roots.
Reject missing, stale, revoked, forged, wrong-issuer, duplicate/conflicting or
unrelated evidence. No OCSP, delta/indirect CRL or document-driven retrieval is
supported by this bounded consumer. Retrieval uses bounded administrator-pinned
HTTPS locations and transport trust, with no caller URL, redirects, trust-anchor
promotion or fallback. Complete the requested LT level using the separate offline
validator with network retrieval disabled; embedded public certificates alone
prove no trust. Preserve exact signed canonical bytes and unsigned contexts.

## B-LTA and renewal

Validate the complete prior LT/LTA history under independent roots and trusted
proof-of-existence time. Incorporate missing support evidence before calculating
the next archive imprint, then append one v1.4.1 `ArchiveTimeStamp`, with explicit
exclusive C14N and one encapsulated token. The archive covers this concatenation,
without separators, in EN319132-1 clause 5.5.2.3 order:

1. Exact retained original octets and transformed SignedProperties octets, in
   SignedInfo reference order.
2. Canonical SignedInfo, SignatureValue and KeyInfo, in that order.
3. Each preceding unsigned property individually canonicalized in document order,
   including validation material and prior timestamps.

Exclude the new archive element itself. Verify an earlier archive against only
its preceding properties. Preserve original reference bytes, SignedInfo,
SignedProperties, SignatureValue and every prior unsigned canonical element and
namespace context. XML serialization changes cannot be assumed harmless.
No Manifest, RenewedDigestsV2, Include, distributed data, extra Object,
countersignature or other unsigned property is admitted.

Renewal verifies history before adding new current-TSA support evidence and an
archive timestamp. Expired old signer/TSA certificates or CRLs are evaluated with
protected historical evidence and appropriate proof-of-existence time, never a
blanket expiry bypass or a current-time-only check. Adjacent AnyValidationData blocks are allowed when fresh initial-archive or
renewal material is needed; they count toward the same overall unsigned-property
limit. A completed LTA artifact ends with ArchiveTimeStamp, never trailing
unprotected validation material. A new TSA cannot repair an
already invalid history. Preserve old roots, chains, CRLs, tokens, exact original,
signature artifacts and validation reports under the retention policy. Rotate
TSA trust explicitly and renew before the latest protection/evidence becomes
insufficient. Renewal does not need the original signer process or private key.

The runnable consumer flow uses `prepare`, `assemble`, `timestamp`, `lt`,
`archive-prepare` and `archive-complete`; a prepared archive freezes exact covered
bytes and correlation state before requesting the token. Treat these as consumer
operations, not additional HTTP signing endpoints. Use the [runnable consumer and exact JSON configurations](https://github.com/fortifiedid/signing-server/blob/main/testkit/xades-consumer/README.md)
with the matching frozen source/artifact. After its documented build, run:

```sh
testkit/xades-consumer/xades-consumer operation.json
```

The launcher is a source-checkout reference tool, not an installed server command.
`assemble` requires `returned_signed_info`, `returned_object` and `returned_leaf`
as well as the raw signature; compare all against the retained preparation.
Archive preparation writes `previous.xml`, `prepared.xml` and exact `covered.bin`
with independently retained state hash. Retain failed/unknown request correlation;
never overwrite the prior accepted artifact.

## Consumer bounds, rejection and recovery

These consumer limits are additional to the unchanged signing-request bounds:

| Item | Maximum |
| --- | --- |
| Nonempty retained original | 16777216 bytes (16 MiB) |
| Assembled signature XML | 8388608 bytes (8 MiB) |
| XML structure | Depth 32, 8192 nodes, checked by a bounded pre-DOM guard |
| Raw RSA signature | 32768 bytes; exact length equals the actual RSA modulus byte length |
| Unsigned properties overall | 18, including the one signature timestamp, all AnyValidationData blocks and archive timestamps |
| Signature/archive timestamps | One signature timestamp; eight archive timestamps |
| Each RFC3161 token | 65536 bytes |
| Encapsulated values overall | 32 certificates, each 32768 bytes; 32 CRLs, each 262144 bytes |
| Independently configured roots / each configured chain | Four roots / four certificates |
| Preparation/archive draft lifetime | Default and maximum 300 seconds, shortened by applicable certificate/status validity |
| Independent-validation receipt / process | 30 seconds / 45-second timeout with forced cleanup |

The combined XML bound also constrains individually permitted maxima. The
32768-byte raw-signature bound is not a 512-byte restriction or an RSA4096
maximum; the actual RSA modulus must still satisfy the existing minimum2048-bit
signing-certificate policy and exact signature-length check. Reject
DTD/entities/XInclude, comments/PIs, namespace/wrapping/context substitution,
duplicate/global ambiguous IDs, wrong Target/parents, unsupported attributes,
algorithms/transforms and external reference dereferencing. No runtime network
schema loader is installed. Fresh signing validity checks remain distinct from
historical preservation; expired original preparation cannot assemble a new
signature and later augmentation grants no signing authority.

Keep the prior valid artifact unchanged until completion and full independent
validation succeeds. Missing/expired state, wrong renewal order, mismatched
evidence/token/correlation and validation timeout fail closed. Timestamp errors
retain the [existing fixed API codes](/products/signing-server/next/integration/time-stamping/#errors),
including `invalid_timestamp`, `unavailable`, `outcome_unknown` and
`duplicate_request`. An unknown/interrupted consumed request stays consumed after
restart. Reconcile the business outcome; never automatically retry with a fresh
request ID or perform another private document-signing operation. Do not publish
partial output as a completed level.
