DKIM: signing email
Updated
DKIM (DomainKeys Identified Mail) works like a wax seal on a letter. The sending server signs each message with a private key that only it holds. The signature is added to the message as a header. A receiving server looks up the matching public key in DNS and checks the signature. If it matches, the message really passed through a server holding that key and was not altered on the way.
Where the key is published
The signature names the signing domain (d=) and a selector (s=). The public key sits in a TXT record at the selector name, under _domainkey in that domain.
s1._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A..."
Selectors let a domain use several keys at once, for example one per email service, and replace a key without a gap. The p= value is the public key. An empty p= means the key has been revoked.
Strengths and limits
- A valid signature survives forwarding, which SPF does not
- Changing the message after signing, for example a mailing list adding a footer, can break the signature
- A signature proves the signing domain, which may not be the domain in the visible From line. DMARC checks that they match
- Use keys of at least 2048 bits where your provider allows it, and rotate them from time to time
Good to know. You cannot look up a DKIM key without knowing the selector. It is shown in the DKIM-Signature header of a message you received, in the s= part.
Related
- SPF: who may send mail for a domainHow an SPF record lists the servers allowed to send email for a domain, and the mistakes that break it.
- DMARC: policy and reportsHow DMARC ties SPF and DKIM to the visible From address, tells receivers what to do with failures, and sends you reports.
- Email headers: what they are and how to find themThe hidden lines at the top of every email that show who sent it, the servers it passed through and whether it passed its checks.
- Why a message gets flagged as spam or phishingThe things mail filters commonly react to, from failed sender checks to links that hide where they go, and which to fix first.