DKIM
DKIM
- DKIM (Domain Keys Identified Mail) is a mechanism that authenticates all messages sent from a domain using asymmetric key cryptography.
- DKIM uses two keys; a private key used for signing, and a public key for verification
- The administrator publishes the public key to the DNS record
- The sending server signs all out-bound messages by using the private key to generate a hash from the message headers and body.
- Recipients verify the signed email against the public key
- The DKIM key is shared via a TXT record
- DKIM records are differentiated with key selectors, and each email server requires its own public/private key pair.
- You may have multiple DKIM records with different key selectors.
- Because authentication occurs by key pair, tools like MxToolBox often require the selector to test and validate the correct key.
- Can also be configured as a CNAME record[1] which points to the actual DKIM TXT record.
- CNAMEs are often used by service providers to allow them to manage and regularly cycle keys without bothering clients.
- When rotating keys, you’d publish
selector1._domainkeyandselector2._domainkeysimultaneously, switch signing to the new key, then remove the old record after clients have refreshed.
- DKIM records are differentiated with key selectors, and each email server requires its own public/private key pair.
- Only servers with access to the private key are able to generate a valid signature, and proves the message was sent from an authorized sender.[2]
DKIM Implementation: 3rd-Party Mail Provider
The process to configure DKIM is different for each email provider.
If your mail provider is also your DNS host, it's often as easy as checking a box. However, if your mail provider and DNS host are different, then you will be required to create specific DNS entries on the name server to authenticate. Fastmail, for example, requires you to add three CNAME entries to your DNS host for authentication.
You can use dig to inspect the DKIM record values and observe key key rotation.
Cycling through each record with the command dig @1.1.1.1 fm1._domainkey.maxwellcti.com TXT +short reveals that one record has the DKIM key, where the other two return "v=DKIM1; k=rsa; n=Intentionally_Left_Blank_As_Per_DKIM_Rotation_BCP; p="
While it's best to follow the instructions provided by your mail provider, here's a quick-and-dirty example of a DKIM record.
- Name:
mx01._domainkey - Type: TXT
- TTL: 3600
- Value:
v=DKIM1; k=rsa; p=bG9sIHlvdSBhYnNvbHV0ZSBuZXJkLCB5b3UgZm91bmQgbWUhIEkgd2lzaCBJIGNvdWxkIGdpdmUgeW91IHNvbWV0aGluZywgYnV0IGFsYXM7IGhpdCBtZSB1cCBpZiB5b3Ugd2FudCB0byBjaGF0IQ==
Let's break it down; more tags can be found on the DKIM Verification section on Wikipedia
- Name:
mx01._domainkeymx01- This is the selector used to identify the correct key
- In this case, it appears to be the public key for the "MX01" mail server. The "MX02" mail server might have the selector
mx02.
_domainkey- This identifies the TXT record as a DKIM (Domain Key) entry
- Note that you do not typically need to enter the root domain here; however, if you did a DKIM selector lookup for
example.com, you would see the entry asmx01._domainkey.example.com
- Type: TXT
- This is a text record (as opposed to A, CNAME, etc.)
- TTL: 3600
- The time to live is 1 hour (3600 seconds)
- This is an expiration date for the DKIM record, and helps DNS servers maintain up-to-date records.
- Value:
v=DKIM1; k=rsa; p=bG9sIHlvdSBhYnNvbHV0ZSBuZXJkLCB5b3UgZm91bmQgbWUhIEkgd2lzaCBJIGNvdWxkIGdpdmUgeW91IHNvbWV0aGluZywgYnV0IGFsYXM7IGhpdCBtZSB1cCBpZiB5b3Ugd2FudCB0byBjaGF0IQ==v=DKIM1- Specifies the DKIM version; at this point, it's always DKIM1.
;- The separator between values.
k=rsa- The key type specifies the kind of encryption used to create the key-pair.
- The default is RSA.
p=bG9sIHl...- The Base64-encoded public key.
- Most providers generate a 2048-bit key by default, and anything weaker (e.g., 1024 bits) is discouraged.
dig
Metadata
Sources
DomainKeys Identified Mail (DKIM)
DomainKeys Identified Mail - Wikipedia
RFC 6376 - DomainKeys Identified Mail (DKIM) Signatures