# Exact UTF-8 text with detached CMS

Signing Server 1.0.0 text signing: use the existing [generic CMS binding](GENERIC-CMS.md)
and its exact ProcessingRules URI `urn:se:idombud:signing:cms:detached-sha256-rsa:v1`.
This is a consumer specialization, not another server task type or endpoint.
The server receives DER SignedAttrs, never original text. CMS id-data does not
declare a text MIME type. The consumer labels its retained original separately
as `text/plain; charset=UTF-8`.

## Freeze the original before preparing consent

- Accept strict UTF-8 only: reject malformed, overlong, truncated, surrogate and
  out-of-range encodings without replacement characters. Reject unpaired UTF-16
  surrogates when creating bytes from a Java string.
- Accept 0 through 1048576 bytes, inclusive. Empty text is supported. This bound
  belongs to the example consumer; the server cannot measure an absent original.
  Existing server task/envelope limits remain unchanged.
- Preserve any UTF-8 BOM (`EF BB BF`) as signed bytes; never silently add/remove it.
- Preserve LF, CRLF, CR, trailing whitespace and final newline exactly.
- Perform no Unicode normalization. Composed `é` and decomposed `e` plus U+0301
  are distinct originals. An application may explicitly normalize before freezing,
  but must disclose its choice and retain/sign/verify the same resulting bytes.
- Freeze `meddelande.txt` before hashing and consent preparation. No editor save,
  newline conversion, BOM stripping, decoding/re-encoding or normalization after
  freezing is permitted. The filename is a packaging convention, not validation.

## Runnable separate consumer

The source-code links, source receipt and Maven commands in this guide target a
repository checkout. The consumer example and reference-source corpus are not
bundled server components. The packaged server contains this guide and the generic
CMS guide; use the repository for building and running the separate consumer.

[Utf8TextConsumer](https://github.com/fortifiedid/signing-server/blob/main/testkit/architecture-tests/src/test/java/se/idombud/signing/architecture/Utf8TextConsumer.java)
is a Java25 example outside the server. It reuses consumer-only GenericCmsConsumer
for RFC5652 assembly and independent Bouncy Castle verification. It neither creates
private keys nor invokes a private signing operation. Build its test classes and
classpath from the repository root (Maven dependency resolution may require network):

```sh
mvn -pl testkit/architecture-tests -am test-compile dependency:build-classpath -DskipTests -Dmdep.outputFile=target/text-consumer.classpath
TEXT_CONSUMER_CP="testkit/architecture-tests/target/test-classes:$(cat testkit/architecture-tests/target/text-consumer.classpath)"
java -cp "$TEXT_CONSUMER_CP" se.idombud.signing.architecture.Utf8TextConsumer freeze source.txt meddelande.txt
java -cp "$TEXT_CONSUMER_CP" se.idombud.signing.architecture.Utf8TextConsumer prepare meddelande.txt attrs.der
```

The example uses exactly contentType id-data and messageDigest SHA-256(original),
without signingTime or cmsAlgorithmProtect. This does not remove either optional
attribute from generic CMS. Base64-encode the complete DER SET (`0x31`) attrs.der
into ToBeSignedBytes in the normal requester-signed CMS SignTaskData. Do not send
meddelande.txt. Run the existing signed DSS/SAML flow, fresh user identification
and separate exact-input consent as described in [the main guide](/products/signing-server/next/integration/document-signing/).

Before extracting `signature.bin` and the accepted public certificate, verify the
service-signed response, RequestID/RelayState, signer and credential constraints,
ordered task IDs, CMS type, exact ProcessingRules, unchanged attrs.der and RSA
signature algorithm. Apply your configured certificate-trust policy; a certificate
returned by the server or embedded in CMS cannot establish its own trust.

```sh
java -cp "$TEXT_CONSUMER_CP" se.idombud.signing.architecture.Utf8TextConsumer assemble meddelande.txt attrs.der signature.bin accepted.pem meddelande.p7s accepted-certificate
java -cp "$TEXT_CONSUMER_CP" se.idombud.signing.architecture.Utf8TextConsumer verify meddelande.p7s meddelande.txt accepted.pem
```

Output creation refuses overwrite. Assembly checks retained attributes against the
exact original and rejects altered returned signatures. Verification checks current
certificate validity and the explicitly supplied accepted certificate; certificate
path, purpose, identity, revocation and trust acceptance remain the caller's policy.
The command is a cryptographic exact-byte check, not a PKIX trust-policy engine.

Deliver meddelande.txt and meddelande.p7s separately. The CMS has absent eContent.
ASCII, Swedish/non-Latin/supplementary characters, mixed newlines and empty text
verify against their frozen originals. Changing characters, whitespace, newline,
BOM or Unicode form must fail. A valid cryptographic signature alone does not
prove that the signer saw the original text or that the certificate is trusted.

## SignMessage and verification scope

SignMessage is the separate existing consent display. The consumer owns the
association between that message, the frozen original and its prepared digest.
Signing Server cannot inspect or attest to unseen text, or detect a false original
digest without the original. No additional display mode is introduced.

