skip to content

DKIM

DKIM signs chosen headers and a body hash with a key published under a selector in DNS, so receivers can verify the d= domain and integrity. Interviewers ask why it survives forwarding.

on this pageshow

explore

questions

27

Given a DKIM-Signature with d=example.com and s=s2026a, where does a receiver look up the public key, and what must that record contain?

level: juniorimportance: must knowfreq 58%

answer

  1. two tags from the signature header
  2. a fixed underscore label
  3. selector first, signing domain last
  4. one tag REQUIRED, the rest default

basics

~20 s

The receiver queries the TXT record at s2026a._domainkey.example.com: the s= selector, the fixed _domainkey label, then the d= domain. The value is a tag list whose only required tag is p=, the base64 public key.

solid answer

~40 s

A verifier builds the query name from two tags of the signature, the selector `s=` and the signing domain `d=`, joined by the fixed label `_domainkey`: `s=s2026a; d=example.com` means a TXT lookup of `s2026a._domainkey.example.com` (RFC 6376 section 3.6.2.1). The value is a `tag=value` list. `p=` is REQUIRED and holds the base64 public key; an empty `p=` means the key was revoked. `v=DKIM1` is RECOMMENDED and, when present, must be the first tag; `k=` names the key type and defaults to `rsa`, with `ed25519` added by RFC 8463 in 2018. The key sits under the `d=` domain, which is not necessarily the From address's domain, and one domain can publish as many selectors as it has keys.

code

dns · 2 lines
dns
; public key for selector s2026a, signing domain example.com
s2026a._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...IDAQAB"

go deeper

for a junior

Recall the query name: selector, then _domainkey, then the d= domain. Know that p= is the one required tag and holds the base64 public key.

for a middle

Explain that the name comes from the signature's s= and d= tags, that k= defaults to rsa, and that v=DKIM1, when present, must be the first tag of the record.

for a senior

Show that you can check a live record against the selector a real message carries, read header.d and header.s in Authentication-Results, and spot a record published under the wrong domain.

for a principal

Treat the _domainkey namespace as an inventory you govern: every selector should map to a known signer and an owner, and an unexplained one is a finding to chase.

## Where the key lives **DKIM** (DomainKeys Identified Mail, RFC 6376, September 2011) lets a domain sign outgoing mail with a private key and publish the matching **public key in DNS**, so that any receiver can check the signature without a certificate authority or a prior relationship. The signature travels in a `DKIM-Signature` header field; the key lives in a **key record** that the receiver fetches at verification time. Two tags of the signature tell the receiver where to look: - `d=` is the **signing domain** (the SDID), the domain that takes responsibility for the message. - `s=` is the **selector**, a name that tells apart the several keys one domain may publish. RFC 6376 defines a single key-distribution method, DNS TXT records, signalled by the signature's optional `q=dns/txt` (its default). ## Building the query name Section 3.6.2.1 fixes the construction. For a signature carrying `d=example.com` and `s=s2026a`: 1. Take the selector exactly as written: `s2026a`. 2. Append the fixed label `_domainkey`. The leading underscore keeps this name apart from ordinary host names. 3. Append the `d=` value: `example.com`. 4. Query the TXT record at the result: `s2026a._domainkey.example.com`. A selector may contain periods, and each period becomes a DNS label boundary, so `s=march2026.eu` with `d=example.com` is looked up at `march2026.eu._domainkey.example.com`. The key is always found under `d=`, never under the From header's domain unless the two happen to be the same. A message whose From address is `[email protected]` but whose signature says `d=mailer.example.net` is checked against a key under `mailer.example.net`; whether that matters for the brand is a question for DMARC's alignment check, not for the key lookup. ## What the record holds The TXT value is a **tag list** (section 3.6.1). Tags the verifier does not understand MUST be ignored, which is how the format can grow. | Tag | Status | Default | Meaning | |---|---|---|---| | `v=` | RECOMMENDED | `DKIM1` | Record version; if present it must be exactly `DKIM1` and the first tag | | `k=` | OPTIONAL | `rsa` | Key type; `ed25519` added by RFC 8463 (September 2018) | | `p=` | **REQUIRED** | none | Base64 public key; an empty value means revoked | | `h=` | OPTIONAL | all allowed | Acceptable hash algorithms, colon-separated | | `s=` | OPTIONAL | `*` | Service types the key applies to, such as `email` | | `t=` | OPTIONAL | no flags | `y` = the domain is testing DKIM; `s` = no subdomain `i=` values | | `n=` | OPTIONAL | empty | Notes for a human; no program interprets them | A minimal working record is therefore `v=DKIM1; p=...`, and many domains add `k=rsa` for clarity even though it is the default. Two traps sit in this table: - **`s=` on the key record is the service type, not the selector.** The selector is part of the DNS name and never appears inside the record. - **`h=` on the key record lists hash algorithms**, not header fields; the signed-headers list is a different `h=`, inside the signature. ## What the record does not say The key record is deliberately thin. It says that whoever controls the `d=` domain stands behind messages signed with this key, and nothing more: - It names no sending server, IP address or From address; those belong to SPF and DMARC. - It carries no expiry date; a key is valid until the record is changed or removed. - It does not tell receivers what to do with unsigned or failing mail; that policy is DMARC's. - Under RFC 6376 it cannot restrict a key to particular local parts: the old `g=` tag of DomainKeys and RFC 4871 was dropped in 2011 and must now be ignored. ## Checking it yourself An administrator confirming a new selector does three things: 1. Query the TXT record at `<selector>._domainkey.<d= domain>` and read back the joined value. 2. Confirm the record starts with `v=DKIM1` if it carries a version, that `k=` matches the key type the signer uses, and that `p=` is complete. 3. Send an ordinary test message to a mailbox you control and read the receiver's `Authentication-Results` field: `dkim=pass` with `header.d=example.com` and `header.s=s2026a` (the selector property RFC 8601 registered) shows the receiver found and used exactly this record. If no record exists at the name, RFC 6376 treats the signature as a permanent failure; if the query cannot be answered, the receiver may defer and try again later. How a receiver turns those cases into results belongs with signature verification; for the domain owner, the lesson is that the record must exist at exactly the name the signer puts in `s=` and `d=`.

  • Why is the key looked up under d= rather than under the domain in the From header?
    DKIM authenticates the signing domain, the `d=` value the signer chooses: the author's domain, a subdomain of it, or an outside service's own domain. The key record only says that whoever controls `d=` vouches for messages signed with this key. Whether `d=` matches the From domain is a separate test, DMARC's alignment check, made after the signature has been verified.
  • What happens if the key record does not exist, or the DNS query times out?
    RFC 6376 separates the two. A key record that does not exist is a permanent failure (PERMFAIL, no key for signature). A query that gets no answer may be retried later (TEMPFAIL, key unavailable), and `Authentication-Results` records that case as `temperror`. A typo in the selector or a record published under the wrong domain therefore fails every message, not just some.

  • The key is published under the From header's domain, whatever d= says.
  • The selector is a secret that stops outsiders from verifying signatures.
  • A domain can publish only one DKIM key at a time.
  • v=DKIM1 is mandatory and the record is invalid without it.
  • On the key record, s= repeats the selector name.
open as a page

When a sending mail server DKIM-signs a message, what exactly does it hash, what does it sign, and where does each result go?

level: juniorimportance: must knowfreq 48%

basics

~20 s

A DKIM signer hashes the body into bh=, then hashes the header fields listed in h= plus its own DKIM-Signature field with b= left empty, signs that hash with the domain's private key, and writes the result into b=.

open as a page

What does a DKIM fail result tell a receiver about a message, and why is it treated like an unsigned message?

level: juniorimportance: must knowfreq 48%

basics

~20 s

DKIM fail means a checkable signature did not match the message as received, so it vouches for nothing. It is not proof of forgery: relays that modify mail break honest signatures, so RFC 6376 says treat it like an unsigned message.

open as a page

In DKIM, what exactly do the simple and relaxed canonicalization algorithms change for header fields and for the message body?

level: middleimportance: must knowfreq 40%

basics

~20 s

Simple hashes headers byte for byte; relaxed lowercases field names, unfolds lines, collapses whitespace runs to one space and trims it at the colon and value end. Both body algorithms drop trailing empty lines; relaxed also strips line-end whitespace and collapses runs.

open as a page

When rotating a DKIM signing key by selector, in what order do you publish, switch and retire, and why does the old record stay published?

level: middleimportance: must knowfreq 42%

basics

~20 s

Publish the new key under a new selector, confirm it resolves, switch signing, keep the old record until queued and late-verified mail has cleared, then revoke the old record with an empty p= and destroy the old private key.

open as a page

Which tags must every DKIM-Signature header field carry under RFC 6376, and which header field must its h= list always include?

level: middleimportance: must knowfreq 38%

basics

~10 s

RFC 6376 requires v=1, a=, b=, bh=, d=, h= and s= on every DKIM-Signature, and h= must list From. A verifier returns PERMFAIL for a signature missing a required tag or leaving From unsigned.

open as a page

How does a receiver verify a DKIM-Signature header field, in order, from parsing its tags to a pass result?

level: middleimportance: must knowfreq 40%

basics

~20 s

The verifier validates the DKIM-Signature tags, fetches the public key from the TXT record at s=._domainkey.d=, recomputes the body hash and compares it with bh=, then checks the b= signature over the h= header fields and the signature field itself.

open as a page

Why does the DKIM l= body-length tag let anyone handling a message append content that still verifies, and what should signers and verifiers do?

level: seniorimportance: must knowfreq 30%

basics

~20 s

DKIM's l= tag limits the body hash to the first N canonicalized body octets, so anything after them is unsigned and can be added without breaking the signature. Signers should omit it; verifiers may treat such signatures as invalid.

open as a page

A DKIM private key for example.com's selector s2025a was found committed to a public repository — what do you do, in what order, and what breaks?

level: seniorimportance: must knowfreq 34%

basics

~20 s

Treat the key as compromised from the commit: publish a new key under a new selector, switch signing, and revoke s2025a with an empty p= at once rather than after the usual overlap, accepting that mail still in flight fails DKIM.

open as a page

What is DKIM canonicalization for, and which algorithms apply when a DKIM-Signature has no c= tag or names only one?

level: juniorimportance: should knowfreq 32%

basics

~20 s

DKIM canonicalization normalises a message only for hashing, so tolerated transit edits do not break the signature; the delivered message is untouched. A missing c= means simple/simple; a single value such as c=relaxed means relaxed headers and a simple body.

open as a page

What does each tag in the DKIM key record "v=DKIM1; k=rsa; h=sha256; s=email; t=y:s; p=MIIB..." tell a verifier, and which are defaults?

level: middleimportance: should knowfreq 24%

basics

~20 s

v=DKIM1 is the version, k=rsa the key type, h=sha256 the only hash this key accepts, s=email the service, t=y a domain still testing and t=s no subdomain i= values; p= is the key. Only p= is required.

open as a page

Why would one domain publish several DKIM selectors at the same time, and what makes a good selector naming scheme?

level: middleimportance: should knowfreq 30%

basics

~20 s

Selectors let one d= domain hold many independent keys: one per signing system, outside service, region or algorithm, plus overlap during a change. Name them by signer and key generation, never reuse one for a new key, and leak no personal data.

open as a page

An audit flags example.com's DKIM selector as a 1024-bit RSA key — what does RFC 8301 require, and how do you move to 2048 bits?

level: middleimportance: should knowfreq 30%

basics

~20 s

RFC 8301 (January 2018) sets 1024 bits as the floor: signers MUST use at least 1024 and SHOULD use at least 2048. Upgrade by rotation: publish a 2048-bit key under a new selector, switch signing, then revoke the old one.

open as a page

Which a= algorithms may a DKIM signer use today, and why is rsa-sha1 no longer acceptable for signing or for verifying?

level: middleimportance: should knowfreq 30%

basics

~10 s

DKIM signers use rsa-sha256, which RFC 8301 (January 2018) made mandatory, and may add ed25519-sha256 from RFC 8463 (September 2018). RFC 8301 made rsa-sha1 historic: it MUST NOT be used for signing or verifying.

open as a page

A message carries two DKIM signatures, one rsa-sha1 and one rsa-sha256; under RFC 8301, how does a verifier evaluate them?

level: middleimportance: should knowfreq 22%

basics

~20 s

Each DKIM signature is judged on its own. Under RFC 8301 (January 2018) the rsa-sha1 one has permanently failed and is ignored; if the rsa-sha256 one verifies with an RSA key of at least 1024 bits, the message has a valid signature.

open as a page

When an outside sending service asks you to publish a CNAME at a DKIM selector under your domain, what do you hand over compared with publishing its key yourself?

level: seniorimportance: should knowfreq 34%

basics

~20 s

A CNAME-delegated selector hands the key record to the service: it holds the private key and writes p=, key length, flags and rotation timing in its own zone. Publishing its public key yourself keeps the record and revocation yours.

open as a page

Why do DKIM signers list From twice in h=, as in h=from:from:..., when the message carries only one From header field?

level: seniorimportance: should knowfreq 24%

basics

~20 s

Listing From one more time than it occurs makes the extra h= entry hash an absent field as nothing; if another From is added later, that entry now picks it up, the header hash changes and the DKIM signature fails.

open as a page

An inbound gateway logs intermittent DKIM temperror results on a partner's mail because the partner's DNS times out; why is that not a forgery, and how should the gateway respond?

level: seniorimportance: should knowfreq 30%

basics

~20 s

A timeout means the verifier never got the key, so it learned nothing about the signature: RFC 6376 calls that TEMPFAIL, recorded as temperror. Treat the mail as unverified, optionally defer it with 451 4.7.5, and never reject it as forged.

open as a page

As the lead for example.com's mail, how do you decide which outside senders get a DKIM selector under the domain, and on what terms?

level: principalimportance: should knowfreq 14%

basics

~20 s

Give a selector only to senders whose mail must sign as the domain, prefer a dedicated subdomain as d=, choose a self-published or CNAME-delegated record per sender, require signer-generated keys of 2048-bit RSA or Ed25519, and track each selector's owner and end date.

open as a page

Your domain's DKIM keys are rotated yearly and still 1024-bit RSA — as the lead, what key-length, algorithm and rotation-cadence policy would you set instead?

level: principalimportance: should knowfreq 16%

basics

~20 s

Make 2048-bit RSA the floor, add an Ed25519 signature beside it only if you can run two selectors per rotation, and keep a cadence you will really execute, yearly or faster, plus event triggers, under one named owner.

open as a page

Your team is adding DKIM signing to a self-hosted MTA for transactional mail; how do you decide which header fields go in h= and which to over-sign?

level: principalimportance: should knowfreq 16%

basics

~20 s

Sign From (mandatory) and every field a reader sees or acts on, such as Subject, Date, To, Reply-To and MIME fields; omit fields relays add or change, like Received and Return-Path; over-sign fields nothing on your paths adds.

open as a page

Why must a DKIM signer hash CRLF line endings and the final transfer encoding, even when it signs with c=relaxed/relaxed?

level: middleimportance: nice to knowfreq 12%

basics

~20 s

DKIM canonicalization assumes the message is already in network form: CRLF line endings and the transfer encoding it travels in. Relaxed neither converts bare LF nor undoes re-encoding, so a signer hashing a local form produces hashes verifiers cannot reproduce.

open as a page

On a DKIM key record, what does publishing an empty p= value do, and how does it differ from deleting the selector's record?

level: middleimportance: nice to knowfreq 20%

basics

~20 s

An empty p= marks the selector's key as revoked: verifiers must fail its signatures with PERMFAIL (key revoked). Deleting the record fails them too; the empty record only states the revocation explicitly and discourages reusing the selector.

open as a page

After a 2048-bit DKIM key is pasted into a DNS panel, signatures start failing; why does the key's length matter, and how do you check the record?

level: seniorimportance: nice to knowfreq 16%

basics

~20 s

A 2048-bit RSA key is about 392 base64 characters, more than one 255-octet TXT string holds, so it is published as several strings in one record, joined with no separator. Panels that truncate, quote or split it wrongly break p=.

open as a page

Your outbound DKIM signer sets x= one hour after t= and puts each sender's full address in i=; what do those tags assert, and what can go wrong?

level: seniorimportance: nice to knowfreq 12%

basics

~20 s

DKIM's t= is the signing time, x= an absolute expiry above t=, and i= the user d= signs for, within d= or a subdomain. A one-hour x= can expire legitimate mail delayed in retry queues.

open as a page

A legitimately DKIM-signed message is resent intact to thousands of new recipients and still passes; why does it verify, and what limits DKIM replay?

level: seniorimportance: nice to knowfreq 14%

basics

~20 s

DKIM signs the h= header fields and the body, not the SMTP envelope, so a signed message re-sent to new recipients still verifies. RFC 6376 offers only partial limits, reputation and spotting one signature on unusual volume, and x= is not one.

open as a page