Lably
Skip to content

DomainKeys Identified Mail

Email authentication method designed to associate a domain with a message stream

  • 17 min read
  • 5 chapters

Related on Lably

Through Digital signature, Email spam and Phishing

The receiver can check that an email that claimed to have come from a specific domain was indeed authorized by the owner of that domain. It achieves this by affixing a digital signature, linked to a domain name, to each outgoing email message. The recipient system can verify this by looking up the sender's public key published in the DNS. A valid signature also guarantees that some parts of the email (possibly including attachments) have not been modified since the signature was affixed. Usually, DKIM signatures are not visible to end-users, and are affixed or verified by the infrastructure rather than the message's authors and recipients.

DKIM is an Internet Standard. It is defined in RFC 6376, dated September 2011, with updates in RFC 8301, RFC 8463, RFC 8553, and RFC 8616.

Overview

The need for email validated identification arises because forged addresses and content are otherwise easily created—and widely used in spam, phishing and other email-based fraud. For example, a fraudster may send a message claiming to be from [email protected], with the goal of convincing the recipient to accept and to read the email—and it is difficult for recipients to establish whether to trust this message. System administrators also have to deal with complaints about malicious emails that appear to have originated from their systems, but did not.

DKIM provides the ability to sign a message, and allows the signer (author organization) to communicate which email it considers legitimate. It does not directly prevent or disclose abusive behavior.

DKIM also provides a process for verifying a signed message. Verifying modules typically act on behalf of the receiver organization, possibly at each hop.

All of this is independent of Simple Mail Transfer Protocol (SMTP) routing aspects, in that it operates on the RFC 5322 message—the transported mail's header and body—not the SMTP "envelope" defined in RFC 5321. Hence, DKIM signatures survive basic relaying across multiple message transfer agents.

Technical details

Signing

The signing organization can be a direct handler of the message, such as the author, mail submission agent, site, or further intermediary along the transit path, or an indirect handler such as an independent service that is providing assistance to a direct handler.

Signing modules insert one or more DKIM-Signature: header fields, possibly on behalf of the author organization or the originating service provider. The specification allows signers to choose which header fields they sign, but the From: field must always be signed. The resulting header field consists of a list of tag=value parts as in the example below:

<span id="mwTQ"></span><span class="nt" id="mwTg">DKIM-Signature:</span><span class="w" id="mwTw"> </span>v=1;<span class="w" id="mwUA"> </span>a=rsa-sha256;<span class="w" id="mwUQ"> </span>d=<span class="nf" id="mwUg">example.net</span>;<span class="w" id="mwUw"> </span>s=brisbane; <span class="w" id="mwVA"> </span>c=relaxed/simple;<span class="w" id="mwVQ"> </span>q=dns/txt;<span class="w" id="mwVg"> </span><span class="nl" id="mwVw">[email protected]</span>; <span class="w" id="mwWA"> </span>t=1117574938;<span class="w" id="mwWQ"> </span>x=1118006938;<span class="w" id="mwWg"> </span>l=200; <span class="w" id="mwWw"> </span>h=from:to:subject:date:keywords:keywords; <span class="w" id="mwXA"> </span>z=From:<span class="nl" id="mwXQ">[email protected]</span>|To:<span class="nl" id="mwXg">[email protected]</span>| <span class="w" id="mwXw"> </span>Subject:demo=20run|Date:July=205,=202005=203:44:08=20PM=20-0700; <span class="w" id="mwYA"> </span>bh=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=; <span class="w" id="mwYQ"> </span>b=dzdVyOfAKCdLXdJOc9G2q8LoXSlEniSbav+yuU4zGeeruD00lszZ <span class="w" id="mwYg"> </span>VoG4ZHRNiYzR

where the tags used are:

  • v (required), version
  • a (required), signing algorithm
  • d (required), Signing Domain Identifier (SDID)
  • s (required), selector
  • c (optional), canonicalization algorithm(s) for header and body
  • q (optional), default query method
  • i (optional), Agent or User Identifier (AUID)
  • t (recommended), signature timestamp
  • x (recommended), expire time
  • l (optional), body length
  • h (required), header fields - list of those that have been signed
  • z (optional), header fields - copy of selected header fields and values
  • bh (required), body hash
  • b (required), signature of headers and body

The most relevant ones are b for the actual digital signature of the contents (headers and body) of the mail message, bh for the body hash (optionally limited to the first l octets of the body), d for the signing domain, and s for the selector.

An Agent or User Identifier (AUID) can optionally be included. The format is an email address with an optional local-part. The domain must be equal to, or a subdomain of, the signing domain. The semantics of the AUID are intentionally left undefined, and may be used by the signing domain to establish a more fine-grained sphere of responsibility.

Both header and body contribute to the signature. First, the message body is hashed, always from the beginning, possibly truncated to a given length l (which may be zero). Second, selected header fields are hashed, in the order given by h. Repeated field names are matched from the bottom of the header upward, which is the order in which Received: fields are inserted in the header. A non-existing field matches the empty string, so that adding a field with that name will break the signature. The DKIM-Signature: field of the signature being created, with bh equal to the computed body hash and b equal to the empty string, is implicitly added to the second hash, albeit its name must not appear in h — if it does, it refers to another, preexisting signature. For both hashes, text is canonicalized according to the relevant c algorithms. The result, after encryption with the signer's private key and encoding using Base64, is b.

In addition to the list of header fields listed in h, a list of header fields (including both field name and value) present at the time of signing may be provided in z. This list need not match the list of headers in h.

Algorithms, fields, and body length are meant to be chosen so as to assure unambiguous message identification while still allowing signatures to survive the unavoidable changes which are going to occur in transit. No end-to-end data integrity is implied.

Verification

A receiving SMTP server wanting to verify uses the domain name and the selector to perform a DNS lookup. For example, given the example signature above: the d tag gives the author domain to be verified against, example.net ; the s tag the selector, brisbane. The string _domainkey is a fixed part of the specification. This gives the TXT resource record to be looked up as:

brisbane._domainkey.example.net

Note that the selector and the domain name can be UTF-8 in internationalized email. In that case the label must be encoded according to IDNA before lookup. The data returned from the query of this record is also a list of tag-value pairs. It includes the domain's public key, along with other key usage tokens and flags (e.g. from a command line: nslookup -q=TXT brisbane._domainkey.example.net) as in this example:

"k=rsa; t=s; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDmzRmJRQxLEuyYiyMg4suA2Sy MwR5MGHpP9diNT1hRiwUd/mZp1ro7kIDTKS8ttkI6z6eTRW9e9dDOxzSxNuXmume60Cjbu08gOyhPG3 GfWdg7QkdN6kR4V75MFlw624VY35DaXBvnlTJTgRg/EW72O1DiYVThkyCgpSYS8nmEQIDAQAB"

The available tags are:

  • v (recommended), version (default DKIM1, must be the first tag if present)
  • h (optional), acceptable hash algorithms (default all)
  • k (optional), key type (default rsa)
  • n (optional), human-readable administrator notes
  • p (required), public key data (base64 encoded, or empty if the public key has been revoked)
  • s (optional), service type (default *, else email)
  • t (optional), toggle flags (colon-separated list, default none, may include y for testing DKIM without rejecting failed signature verifications, and/or s which is recommended for subdomain strictness as explained in the RFC)

A CNAME record can also be used to point at a different TXT record, for example when one organization sends email on behalf of another.

The receiver can use the public key (value of the p tag) to then validate the signature on the hash value in the header field, and check it against the hash value for the mail message (headers and body) that was received. If the two values match, this cryptographically proves that the mail was signed by the indicated domain and has not been tampered with in transit.

Signature verification failure does not force rejection of the message. Instead, the precise reasons why the authenticity of the message could not be proven should be made available to downstream and upstream processes. Methods for doing so may include sending back an FBL message, or adding an Authentication-Results: header field to the message as described in RFC 7001.

Patent

DomainKeys was covered by U.S. patent 6,986,049, now expired. Yahoo! licensed its patent claims under a dual license scheme: the DomainKeys Patent License Agreement v1.2, or GNU General Public License v2.0 (and no other version).

Relationship to SPF and DMARC

In essence, both DKIM and SPF provide different measures of email authenticity. DMARC provides the ability for an organisation to publish a policy that specifies which mechanism (DKIM, SPF, or both) is employed when sending email from that domain; how to check the From: field presented to end users; how the receiver should deal with failures—and a reporting mechanism for actions performed under those policies.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication