Key discovery (CKD)
CKD, the Cipher Key Directory, maps an email address to a public key. With it you can encrypt for someone by email, with no key exchange beforehand:
mdstn-cipher encrypt report.pdf --for alice@example.comThe hosted directory is keys.mdstn.dev. Lookups are always free.
Publish your key
Verify your email at keys.mdstn.dev and copy the directory token it gives you.
Publish your default X25519 key:
mdstn-cipher keys publish --email alice@example.com --kd-token "$KD_TOKEN" mdstn-cipher keys status # is my default key published?
The token can also come from the KD_TOKEN environment variable. The CLI never stores it. To take
your key down:
mdstn-cipher keys unpublish --email alice@example.com --kd-token "$KD_TOKEN"Rotating a key. Once an email is bound to a key, publishing a different key needs proof that
you hold the current binding. The directory answers 409 with the current_fingerprint. The CLI
shows it, and you publish again with --fingerprint <current_fingerprint>. The CLI never retries
on its own. A binding conflict exits with code 5.
Look up a key
mdstn-cipher lookup alice@example.com
mdstn-cipher lookup alice@example.com --save # also save it to the local cache
mdstn-cipher lookup alice@example.com --jsonencrypt --for and the MCP lookup_key tool use the same lookup.
Where a key can come from
On a cache miss, Cipher asks four sources at the same time:
| Order | Source | Where |
|---|---|---|
| 1 | TXT pointer | DNS TXT _mdstn-cipher.example.com = v=ckd1; url=https://keys.example.com |
| 2 | Discovery subdomain | https://mdstn-cipher.example.com/.well-known/mdstn-cipher/{hash} |
| 3 | Apex path | https://example.com/.well-known/mdstn-cipher/{hash} |
| 4 | Hosted directory | https://keys.mdstn.dev/.well-known/mdstn-cipher/{hash} |
{hash} is the SHA-256 of the lowercased, trimmed email, in hex. The first domain answer wins, in
the order above. The hosted directory answers only when no domain source does. If a domain answer
and the hosted directory disagree, the domain’s key is used and Cipher warns that the two differ.
Every answer reports its source.
The lookup is strict:
- A TXT pointer may name only the email’s own domain, one of its subdomains, or the hosted directory. Any other host is rejected, so DNS spoofing alone can’t redirect a lookup.
- Redirects are never followed, responses are capped at 16 KiB, and the response’s email must match the one requested.
- Domain sources are used only for ASCII domains. Other domains fall back to the hosted directory.
- Lookups never log the email address.
Privacy: because the hosted directory is asked in parallel with the domain sources, every lookup sends the email hash to keys.mdstn.dev. An unsalted hash of a common address can be guessed with a dictionary, so the hosted directory limits rates and refuses enumeration.
Signed answers from the hosted directory
Answers from keys.mdstn.dev carry an ed25519 signature over email_hash + "\n" + response body.
Cipher checks it against a pinned service key before it uses or caches the answer. A missing or bad
signature, an unknown key ID, or an unknown key type fails the lookup as an integrity error (exit
code 6), and nothing is cached.
Pinned keys (trust on first use)
The first key Cipher sees for an email is pinned in the local cache. Later lookups use the pin and never replace it with a network answer, so a key swapped on a server later is not picked up silently. To check for a change on purpose:
mdstn-cipher lookup alice@example.com --refresh # shows any change, asks before replacing
mdstn-cipher lookup alice@example.com --refresh --yes # accept a change without asking--refresh reports unchanged, changed (old and new fingerprints, then
Replace the pinned key? [y/N]) or not found (the pin is kept).
Serve keys for your own domain
An organization can answer lookups for its own addresses. Pick one:
- TXT pointer (recommended): publish
_mdstn-cipher.example.com. 3600 IN TXT "v=ckd1; url=https://keys.example.com", with exactly onev=ckd1record, and serve/.well-known/mdstn-cipher/{hash}on that host with a valid certificate. - Discovery subdomain: point
mdstn-cipher.example.comat a server for the.well-knownpath, with valid TLS. No TXT record is needed. - Apex path: serve the
.well-knownpath from your main website through its reverse proxy. - Delegation, no infrastructure: verify the domain on keys.mdstn.dev and point the TXT record at
https://keys.mdstn.dev. Answers for your domain then count as domain answers.
Each source returns:
{
"email": "alice@example.com",
"public_key": "<base64 public key>",
"fingerprint": "<sha256 hex of the public key>",
"created_at": "2026-06-11T12:00:00Z"
}An optional key_type field defaults to x25519. Check a published key resolves:
HASH=$(printf 'alice@example.com' | shasum -a 256 | cut -d' ' -f1)
curl -s "https://keys.example.com/.well-known/mdstn-cipher/$HASH"Environment variables
| Variable | Effect |
|---|---|
KD_TOKEN | Directory token for keys publish, unpublish and status (--kd-token wins) |
CIPHER_SERVER_URL | Directory for publish, unpublish and status (--server-url wins); default https://keys.mdstn.dev |
CIPHER_CKD_URL | Hosted directory used by lookups, for staging or local tests |