# Security considerations

A valid stamp establishes a limited set of facts. This page describes those facts, the threats the protocol is designed to resist, and the risks that remain with issuers, verifiers and readers.

## What a valid stamp establishes

A valid stamp is a statement by the holder of a domain about a set of facts. It establishes the
following.

| A valid stamp establishes | A valid stamp does not establish |
|---|---|
| That the stamp was signed with a key published by the holder of the domain. | That the facts are true. A stamp identifies who stated them, not whether they are correct. |
| That the facts in the stamp have not been altered since signing. | That the printed document matches the stamp. This comparison is made by the reader. |
| The time at which the stamp was signed, as stated by the signer. | That the domain belongs to the organisation the reader has in mind. |
| | Confidentiality. Anyone who scans a stamp can read its contents. |

The time of issue is part of the signed data, but it is chosen by whoever holds the key. It is
reliable to the extent that the key has not been stolen.

## Trust model

DKDS has no certificate authority and no registry. Verification relies on the following:

- **The holder of the domain**, to publish only keys it controls. The identity shown to the reader is
  a domain name, not a legal entity.
- **The DNS**, to deliver the key record unaltered. With DNSSEC, this trust rests on the signed chain
  from the DNS root to the issuer's zone. Without DNSSEC, it rests on the resolvers and the network
  path to them.
- **The verifier software and the device** on which it runs.
- **The reader**, a person or a system acting for the recipient, to check that the domain is the one
  known for the issuer and to compare the fields with the document
  ([Receiving documents](https://dkds.org/docs/receiving)).

Several of the measures below make the reader's two tasks easier and harder to subvert.

## Threats and mitigations

| Threat | Mitigation | Remaining risk | Section |
|---|---|---|---|
| Altered document | The reader compares the signed fields with the document | Fields that the stamp does not contain | [9.1](https://dkds.org/docs/specification#9-1-presentation) |
| Forged stamp | Ed25519 signature over all data | None known, while the key is secret | [6](https://dkds.org/docs/specification#6-signature) |
| Lookalike domain | Prominent display of the domain; warnings | A reader who does not know the issuer's domain | [9.3](https://dkds.org/docs/specification#9-3-warnings) |
| Stolen private key | Revocation of the key; keys replaced at a fixed interval and earlier keys destroyed | Stamps accepted before the revocation | [7.4](https://dkds.org/docs/specification#7-4-revocation) |
| Forged DNS answer | DNSSEC; two resolvers | Unsigned zones on a compromised path | [9.2](https://dkds.org/docs/specification#9-2-dns) |
| Changed DNS records | Restricted access to the DNS; published records checked on a schedule | Keys added under new key IDs | [7.1](https://dkds.org/docs/specification#7-1-location) |
| Lapsed or transferred domain | None within the protocol; issuers keep their domains | The new holder can sign stamps | [12](https://dkds.org/docs/specification#12-security-considerations) |
| Copied stamp | Fields that identify subject and document | Stamps without such fields | [10](https://dkds.org/docs/specification#10-issuer-requirements) |
| Hostile input | Bounded lengths; fixed order of checks | Defects in an implementation | [8.2](https://dkds.org/docs/specification#8-2-procedure) |
| Display spoofing | Forbidden code points; separated display | Visually similar characters in field values | [Appendix B](https://dkds.org/docs/specification#appendix-b-forbidden-code-points) |

### Altered documents

A stamp reveals alterations made after issue. A verifier reports the fields as signed; the reader
compares them with the document. A difference between the two shows that the
document, or the stamp, has been changed. An alteration to a part of the document that the stamp does
not cover is not detected, which is why issuers include every fact on which the recipient relies.

### Lookalike domains

The protocol proves which domain signed a stamp, not that the reader recognises it. A forger can
register a domain such as `northwind-invoices.example` or one that uses characters from another
script, publish a key under it, and sign stamps that verify as `valid`. Verifiers therefore display
the domain prominently to a person, present internationalised domains in their Unicode form, and warn about mixed
scripts, confusable characters and domains similar to those the reader has verified before
([Building a verifier](https://dkds.org/docs/verifying#warnings)). Readers compare the domain with the one on record
for the issuer ([Receiving documents](https://dkds.org/docs/receiving#domain)). Issuers reduce the risk by using
the domain under which they are already known to their recipients.

### Stolen private keys

A holder of a stolen key can sign stamps with any time of issue. Revocation therefore invalidates all
stamps of the key, including those signed before the theft, because the two cannot be distinguished.
Short-lived keys, separate keys per issuing system and keys held in hardware security modules limit
both the likelihood and the effect of a theft ([Issuing documents](https://dkds.org/docs/issuing#storing-private-keys)).
An issuer that replaces its key at a fixed interval and destroys each earlier private key leaves only
the current key to be stolen, so that a revocation affects only the stamps of the current interval
([Replacing a key](https://dkds.org/docs/issuing#replacing-a-key)).

### Forged DNS answers

An attacker who can alter DNS answers on the path to a verifier can substitute a key. Where the
issuer's zone is signed with DNSSEC, a validating resolver rejects the forged answer and the outcome
is `unavailable`. Verifiers report whether an answer was validated, and compare the answers of two
independent resolvers, which makes an attack on a single resolver detectable.

### Changed DNS records

Whoever can change the issuer's DNS records, through a compromised account at the registrar or the DNS
provider or through access granted for another purpose, can publish a key and sign stamps that
verify as `valid`. DNSSEC does not prevent this, because the zone signs the records it holds. A key
added under a new key ID leaves the existing records unchanged and causes no warning in verifiers
that remember keys. Issuers restrict who can change their records and check the published records on a schedule
([Protecting the DNS](https://dkds.org/docs/issuing#protecting-the-dns)).

### Lapsed and transferred domains

Whoever holds a domain can publish keys under it and sign stamps with any time of issue. When a domain
lapses or is transferred, the new holder can therefore create stamps that verify as `valid`. A valid
stamp means that the current holder of the domain vouches for it. Issuers keep a domain registered for
as long as documents signed under it are used.

### Copied stamps

A stamp can be copied from one document onto another. The copy verifies as `valid`, but its fields
describe the original document. The reader detects this by comparing the fields with the document.
Issuer requirement 10.4, which asks for fields that identify the subject and the document, makes the
comparison meaningful.

### Untrue content

A stamp shows who made a statement, not whether it is correct. An issuer can sign false facts, and
the stamp is valid. DKDS makes such a statement attributable to the domain that signed it.

### Repudiation

An issuer might publish a weak key, under which any signature verifies, in order to deny later that
it signed a stamp. The specification rejects keys of small order, including the identity point
([section 6.3](https://dkds.org/docs/specification#6-3-ed25519)), so that a valid stamp can be attributed to the
holder of the domain. Verifiers built on Ed25519 libraries that omit these checks lose this property.

### Hostile input

A stamp is untrusted input from a camera. Every length in the envelope is bounded, decompression
stops at 16,384 bytes, no DNS query is made for a malformed stamp, and the payload is decompressed
and parsed only after the signature has been verified. The test vectors include each limit, a
decompression bomb and invalid UTF-8.

### Display spoofing

Text can be made to display differently from its content, for example with bidirectional overrides
or invisible characters, and two names that differ only by an invisible character display the same.
Such code points are forbidden in field names, field values and the Unicode form of the domain
([Appendix B](https://dkds.org/docs/specification#appendix-b-forbidden-code-points)), as are full stops other than
`.` in the labels of a domain. The separation of the
verifier's statements from the issuer's fields ([section 9.1](https://dkds.org/docs/specification#9-1-presentation)),
on screen and in results returned to software, prevents a field from imitating the verifier.

### Denial of verification

If the issuer's DNS is unreachable, verification ends with `unavailable`, which is distinct from a
failed verification and indicates that the stamp may be checked again later. An attacker who blocks
DNS traffic can prevent verification but cannot make a stamp appear valid.

## Privacy

A stamp has no confidentiality: anyone who scans it can read every field. Issuers place in a stamp
only facts that are printed on the document anyway.

Verification itself discloses information. The DNS query for `<key_id>._dkds.<domain>` reveals to
the resolvers, and to the operator of the issuer's DNS, that a stamp of that issuer is being
verified, together with the network address of the verifier or its resolver. The fields of the stamp
are not disclosed by the query. Verifiers that remember keys and domains hold a record of the issuers
a reader has checked, which is kept by the verifier, on the device or in the system on which it runs.

## Cryptographic agility

A sufficiently large quantum computer could forge Ed25519 signatures. The key record names the
algorithm, so a post-quantum algorithm can be introduced as a new `k` value without changing the
envelope ([section 11](https://dkds.org/docs/specification#11-versioning)). Within the limit of 1,088 bytes per
envelope, only algorithms with small signatures are suitable.

## Responsibilities

| Party | Responsibility |
|---|---|
| Issuer | Protects the private key and access to the DNS; includes identifying fields and every fact acted on; writes values as printed; replaces keys at a fixed interval and revokes a compromised key; keeps old records published; signs the zone with DNSSEC where possible |
| Verifier | Follows the procedure without exception; queries two resolvers; reports the DNSSEC status; presents the fields separately from its own statements; warns about lookalikes |
| Reader | Checks that the domain is the one known for the issuer; compares every field with the document; acts only on facts among the fields |
