RFC 6376
DomainKeys Identified Mail (DKIM) Signatures
DomainKeys Identified Mail (DKIM) Signatures ๐
Okay bestie, so this one is RFC 6376, filed under the IETF (Internet Engineering Task Force) ๐ It was written by D. Crocker (Ed.) at Brandenburg InternetWorking, T. Hansen (Ed.) at AT&T Laboratories, and M. Kucherawy (Ed.) at Cloudmark. It's published as a Standards Track document, ISSN 2070-1721, dated September 2011. It obsoletes RFC 4871 and RFC 5672 ๐ so those older versions are officially retired. It doesn't update anything else.
Abstract โจ
DomainKeys Identified Mail (DKIM) lets a person, role, or organization that owns the signing domain claim some responsibility for a message by linking that domain to the message ๐ฆ This can be an author's organization, an operational relay, or one of their agents. DKIM keeps the question of who the Signer is separate from who the purported author is, which is so smart ๐ง The claim gets checked with a cryptographic signature, and the Verifier looks up the Signer's domain directly to grab the right public key. Messages usually travel from author to recipient through relays that don't really change the content, so the DKIM signature survives the trip ๐ธ
This memo obsoletes RFC 4871 and RFC 5672.
Status of This Memo
This is an Internet Standards Track document.
This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It went through public review and was approved for publication by the Internet Engineering Steering Group (IESG). For more on Internet Standards, check out Section 2 of RFC 5741 ๐
For the current status, any errata, and how to send feedback, go to http://www.rfc-editor.org/info/rfc6376 ๐
Copyright Notice
Copyright (c) 2011 IETF Trust and the persons identified as the document authors. All rights reserved. ๐
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as in effect on the date this document was published. Please actually read these carefully, because they spell out your rights and restrictions for this document ๐ Any Code Components pulled out of this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they come with no warranty, as described in the Simplified BSD License.
This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The people controlling the copyright in some of that material may not have given the IETF Trust permission to allow modifications outside the IETF Standards Process. So, without an adequate license from those copyright holders, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process. The exceptions are formatting it for publication as an RFC or translating it into languages other than English ๐ซถ
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1. DKIM Architecture Documents . . . . . . . . . . . . . . . 5
1.2. Signing Identity . . . . . . . . . . . . . . . . . . . . . 5
1.3. Scalability . . . . . . . . . . . . . . . . . . . . . . . 5
1.4. Simple Key Management . . . . . . . . . . . . . . . . . . 6
1.5. Data Integrity . . . . . . . . . . . . . . . . . . . . . . 6
2. Terminology and Definitions . . . . . . . . . . . . . . . . . 6
2.1. Signers . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2. Verifiers . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3. Identity . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4. Identifier . . . . . . . . . . . . . . . . . . . . . . . . 7
2.5. Signing Domain Identifier (SDID) . . . . . . . . . . . . . 7
2.6. Agent or User Identifier (AUID) . . . . . . . . . . . . . 7
2.7. Identity Assessor . . . . . . . . . . . . . . . . . . . . 7
2.8. Whitespace . . . . . . . . . . . . . . . . . . . . . . . . 8
2.9. Imported ABNF Tokens . . . . . . . . . . . . . . . . . . . 8
2.10. Common ABNF Tokens . . . . . . . . . . . . . . . . . . . . 9
2.11. DKIM-Quoted-Printable . . . . . . . . . . . . . . . . . . 9
3. Protocol Elements . . . . . . . . . . . . . . . . . . . . . . 10
3.1. Selectors . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2. Tag=Value Lists . . . . . . . . . . . . . . . . . . . . . 12
3.3. Signing and Verification Algorithms . . . . . . . . . . . 13
3.4. Canonicalization . . . . . . . . . . . . . . . . . . . . . 14
3.5. The DKIM-Signature Header Field . . . . . . . . . . . . . 18
3.6. Key Management and Representation . . . . . . . . . . . . 26
3.7. Computing the Message Hashes . . . . . . . . . . . . . . . 29
3.8. Input Requirements . . . . . . . . . . . . . . . . . . . . 32
3.9. Output Requirements . . . . . . . . . . . . . . . . . . . 32
3.10. Signing by Parent Domains . . . . . . . . . . . . . . . . 33
3.11. Relationship between SDID and AUID . . . . . . . . . . . . 33
4. Semantics of Multiple Signatures . . . . . . . . . . . . . . . 34
4.1. Example Scenarios . . . . . . . . . . . . . . . . . . . . 34
4.2. Interpretation . . . . . . . . . . . . . . . . . . . . . . 35
5. Signer Actions . . . . . . . . . . . . . . . . . . . . . . . . 36
5.1. Determine Whether the Email Should Be Signed and by
Whom . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.2. Select a Private Key and Corresponding Selector
Information . . . . . . . . . . . . . . . . . . . . . . . 37
5.3. Normalize the Message to Prevent Transport Conversions . . 37
5.4. Determine the Header Fields to Sign . . . . . . . . . . . 38
5.5. Compute the Message Hash and Signature . . . . . . . . . . 43
5.6. Insert the DKIM-Signature Header Field . . . . . . . . . . 43
6. Verifier Actions . . . . . . . . . . . . . . . . . . . . . . . 43
6.1. Extract Signatures from the Message . . . . . . . . . . . 44
6.2. Communicate Verification Results . . . . . . . . . . . . . 49
6.3. Interpret Results/Apply Local Policy . . . . . . . . . . . 50
7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 51
7.1. Email Authentication Methods Registry . . . . . . . . . . 51
7.2. DKIM-Signature Tag Specifications . . . . . . . . . . . . 51
7.3. DKIM-Signature Query Method Registry . . . . . . . . . . . 52
7.4. DKIM-Signature Canonicalization Registry . . . . . . . . . 52
7.5. _domainkey DNS TXT Resource Record Tag Specifications . . 53
7.6. DKIM Key Type Registry . . . . . . . . . . . . . . . . . . 53
7.7. DKIM Hash Algorithms Registry . . . . . . . . . . . . . . 54
7.8. DKIM Service Types Registry . . . . . . . . . . . . . . . 54
7.9. DKIM Selector Flags Registry . . . . . . . . . . . . . . . 55
7.10. DKIM-Signature Header Field . . . . . . . . . . . . . . . 55
8. Security Considerations . . . . . . . . . . . . . . . . . . . 55
8.1. ASCII Art Attacks . . . . . . . . . . . . . . . . . . . . 55
8.2. Misuse of Body Length Limits ("l=" Tag) . . . . . . . . . 55
8.3. Misappropriated Private Key . . . . . . . . . . . . . . . 56
8.4. Key Server Denial-of-Service Attacks . . . . . . . . . . . 56
8.5. Attacks against the DNS . . . . . . . . . . . . . . . . . 57
8.6. Replay/Spam Attacks . . . . . . . . . . . . . . . . . . . 57
8.7. Limits on Revoking Keys . . . . . . . . . . . . . . . . . 58
8.8. Intentionally Malformed Key Records . . . . . . . . . . . 58
8.9. Intentionally Malformed DKIM-Signature Header Fields . . . 58
8.10. Information Leakage . . . . . . . . . . . . . . . . . . . 58
8.11. Remote Timing Attacks . . . . . . . . . . . . . . . . . . 59
8.12. Reordered Header Fields . . . . . . . . . . . . . . . . . 59
8.13. RSA Attacks . . . . . . . . . . . . . . . . . . . . . . . 59
8.14. Inappropriate Signing by Parent Domains . . . . . . . . . 59
8.15. Attacks Involving Extra Header Fields . . . . . . . . . . 60
9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 61
9.1. Normative References . . . . . . . . . . . . . . . . . . . 61
9.2. Informative References . . . . . . . . . . . . . . . . . . 62
Appendix A. Example of Use (INFORMATIVE) . . . . . . . . . . . . 64
A.1. The User Composes an Email . . . . . . . . . . . . . . . . 64
A.2. The Email is Signed . . . . . . . . . . . . . . . . . . . 65
A.3. The Email Signature is Verified . . . . . . . . . . . . . 66
Appendix B. Usage Examples (INFORMATIVE) . . . . . . . . . . . . 67
B.1. Alternate Submission Scenarios . . . . . . . . . . . . . . 67
B.2. Alternate Delivery Scenarios . . . . . . . . . . . . . . . 69
Appendix C. Creating a Public Key (INFORMATIVE) . . . . . . . . . 71
C.1. Compatibility with DomainKeys Key Records . . . . . . . . 72
C.2. RFC 4871 Compatibility . . . . . . . . . . . . . . . . . . 73
Appendix D. MUA Considerations (INFORMATIVE) . . . . . . . . . . 73
Appendix E. Changes since RFC 4871 . . . . . . . . . . . . . . . 73
Appendix F. Acknowledgments . . . . . . . . . . . . . . . . . . . 75
1. Introduction โจ
So DKIM (DomainKeys Identified Mail) lets a person, role, or organization claim some responsibility for a message by tying a domain name [RFC1034] to the message [RFC5322], as long as they're authorized to use that domain ๐ It can be the author's organization, an operational relay, or one of their agents. The claim gets validated with a cryptographic signature, and the Signer's domain gets queried directly for the right public key. Messages usually pass from author to recipient through relays that don't make big content changes, so the DKIM signature sticks around ๐ง A single message can carry multiple signatures, from the same or different organizations involved with it. Literally so iconic ๐
DKIM's approach is different from older message-signing approaches, like Secure/Multipurpose Internet Mail Extensions (S/MIME) [RFC5751] and OpenPGP [RFC4880]. Here's how it's different:
- the message signature is written as a message header field, so neither human recipients nor existing MUA (Mail User Agent) software gets confused by signature stuff showing up in the message body ๐
- nothing depends on public and private key pairs being issued by well-known, trusted certificate authorities ๐
- nothing depends on deploying any new Internet protocols or services for public-key distribution or revocation โจ
- a signature verification failure does not force rejection of the message ๐ฆ
- no attempt is made to include encryption as part of the mechanism ๐ โโ๏ธ
- message archiving is not a design goal ๐๏ธ
And DKIM is also:
- compatible with the existing email infrastructure and transparent to the fullest extent possible ๐
- minimal on new infrastructure requirements ๐ท
- something that can be implemented independently of clients, so deployment can be faster ๐
- something that can be deployed incrementally ๐
- something that allows delegation of signing to third parties ๐ซถ
More of the spec is coming in the next part, so stay tuned, bestie ๐
1.1. DKIM Architecture Documents ๐
Okay bestie, before we get into it you need to be familiar with [RFC4686], [RFC5585], and [RFC5863]. They're the background reading ๐ค: [RFC4686] covers the background for DKIM, [RFC5585] gives an overview of the service, and [RFC5863] has the deployment and operations guidance and advice.
1.2. Signing Identity ๐ชช
DKIM splits up two questions: who the Signer of the message is, and who the purported author of the message is. A signature includes the identity of the Signer ๐ , and Verifiers can use that signing info to decide how they want to process the message. The signing identity lives inside the signature header field.
INFORMATIVE RATIONALE: The signing identity specified by a DKIM signature is not required to match an address in any particular header field because of the broad methods of interpretation by recipient mail systems, including MUAs.
1.3. Scalability ๐
DKIM is built for the extreme scalability needs of the email identification problem. There are many millions of domains and an even bigger pile of individual addresses ๐ญ.
DKIM also keeps the good stuff about today's email setup, like the ability for anyone to talk to anyone else without an introduction ๐.
1.4. Simple Key Management ๐
DKIM is different from traditional hierarchical public-key systems, because no certificate authority infrastructure is required. The Verifier asks a repository in the domain of the claimed Signer directly for the public key, instead of going to a third party. No middleman, no drama ๐ โโ๏ธ.
The DNS is proposed as the initial mechanism for the public keys. So DKIM currently depends on DNS administration and the security of the DNS system. It's designed to be extensible to other key fetching services as they become available โจ.
1.5. Data Integrity ๐ก๏ธ
A DKIM signature associates the "d=" name with the computed hash of some or all of the message (see Section 3.7), so the signature can't just be reused with different messages. Verifying the signature tells you the hashed content has not changed since it was signed. It says nothing else about "protecting" the end-to-end integrity of the message ๐.
2. Terminology and Definitions ๐
This section defines terms used in the rest of the document.
DKIM is designed to operate within the Internet Mail service, as defined in [RFC5598]. Basic email terminology is taken from that specification.
Syntax descriptions use Augmented BNF (ABNF) [RFC5234].
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. These words take their normative meanings only when they are presented in ALL UPPERCASE ๐ .
2.1. Signers โ๏ธ
Elements in the mail system that sign messages on behalf of a domain are called Signers. These may be MUAs (Mail User Agents), MSAs (Mail Submission Agents), MTAs (Mail Transfer Agents), or other agents such as mailing list exploders. Generally, any Signer will be involved in injecting a message into the message system somehow. The key issue is that a message must be signed before it leaves the administrative domain of the Signer ๐ช.
2.2. Verifiers ๐
Elements in the mail system that verify signatures are called Verifiers. These may be MTAs, Mail Delivery Agents (MDAs), or MUAs. In most cases, Verifiers are expected to sit close to an end user (reader) of the message, or to some consuming agent such as a mailing list exploder.
2.3. Identity ๐ง
A person, role, or organization. In the context of DKIM, examples include the author, the author's organization, an ISP along the handling path, an independent trust assessment service, and a mailing list operator ๐.
2.4. Identifier ๐ท๏ธ
A label that refers to an identity.
2.5. Signing Domain Identifier (SDID) ๐
A single domain name that is the mandatory payload output of DKIM and that refers to the identity claiming some responsibility for the message by signing it. It is specified in Section 3.5.
2.6. Agent or User Identifier (AUID) ๐ฆ
A single identifier that refers to the agent or user on whose behalf the Signing Domain Identifier (SDID) has taken responsibility. The AUID comprises a domain name and an optional <local-part>. The domain name is the same as the one used for the SDID, or is a subdomain of it. For DKIM processing, the domain name portion of the AUID only has basic domain name semantics. Any possible owner-specific semantics are outside the scope of DKIM ๐
โโ๏ธ. It is specified in Section 3.5.
Note that acceptable values for the AUID may be constrained via a flag in the public-key record. (See Section 3.6.1.) ๐ก
2.7. Identity Assessor ๐ต๏ธโโ๏ธ
An element in the mail system that consumes DKIM's payload, which is the responsible Signing Domain Identifier (SDID). The Identity Assessor is dedicated to the assessment of the delivered identifier.
Other DKIM (and non-DKIM) values can also be used by the Identity Assessor, if they're available, to provide a more general message evaluation filtering engine. However, that extra activity is outside the scope of this specification ๐ธ.
2.8. Whitespace ๐ซง
There are three forms of whitespace:
- WSP represents simple whitespace, i.e., a space or a tab character (formal definition in [RFC5234]).
- LWSP is linear whitespace, defined as WSP plus CRLF (formal definition in [RFC5234]).
- FWS is folding whitespace. It allows multiple lines separated by CRLF, followed by at least one whitespace, to be joined.
The formal ABNF for these are (WSP and LWSP are given for information only):
WSP = SP / HTAB
LWSP = *(WSP / CRLF WSP)
FWS = [*WSP CRLF] 1*WSP
The definition of FWS is identical to that in [RFC5322] except for the exclusion of obs-FWS. ๐งฉ
2.9. Imported ABNF Tokens ๐ฆ
The following tokens are imported from other RFCs as noted. Those RFCs should be considered definitive.
The following tokens are imported from [RFC5321]:
- "local-part" (implementation warning: this permits quoted strings)
- "sub-domain"
The following tokens are imported from [RFC5322]:
- "field-name" (name of a header field)
- "dot-atom-text" (in the local-part of an email address)
The following tokens are imported from [RFC2045]:
- "qp-section" (a single line of quoted-printable-encoded text)
- "hex-octet" (a quoted-printable encoded octet)
INFORMATIVE NOTE: Be aware that the ABNF in [RFC2045] does not obey the rules of [RFC5234] and must be interpreted accordingly, particularly as regards case folding. โ ๏ธ
Other tokens not defined herein are imported from [RFC5234]. These are intuitive primitives such as SP, HTAB, WSP, ALPHA, DIGIT, CRLF, etc. ๐งธ
2.10. Common ABNF Tokens ๐งพ
The following ABNF tokens are used elsewhere in this document:
hyphenated-word = ALPHA [ *(ALPHA / DIGIT / "-") (ALPHA / DIGIT) ]
ALPHADIGITPS = (ALPHA / DIGIT / "+" / "/")
base64string = ALPHADIGITPS *([FWS] ALPHADIGITPS)
[ [FWS] "=" [ [FWS] "=" ] ]
hdr-name = field-name
qp-hdr-value = dkim-quoted-printable ; with "|" encoded
2.11. DKIM-Quoted-Printable ๐ท
The DKIM-Quoted-Printable encoding syntax is kind of a cousin of Quoted-Printable [RFC2045], Section 6.7 ๐. Any character MAY be encoded as an "=" followed by two hexadecimal digits from the alphabet "0123456789ABCDEF" (no lowercase characters permitted), representing the hexadecimal-encoded integer value of that character. All control characters (those with values < %x20), 8-bit characters (values > %x7F), and the characters DEL (%x7F), SPACE (%x20), and semicolon (";", %x3B) MUST be encoded. Note that all whitespace, including SPACE, CR, and LF characters, MUST be encoded. After encoding, FWS MAY be added at arbitrary locations in order to avoid excessively long lines. Such whitespace is not part of the value, and MUST be removed before decoding. Use of characters not listed as "mail-safe" in [RFC2049] is NOT RECOMMENDED ๐ซ.
ABNF:
dkim-quoted-printable = *(FWS / hex-octet / dkim-safe-char)
; hex-octet is from RFC2045
dkim-safe-char = %x21-3A / %x3C / %x3E-7E
; '!' - ':', '<', '>' - '~'
INFORMATIVE NOTE: DKIM-Quoted-Printable differs from Quoted-Printable as defined in [RFC2045] in several important ways: 1. Whitespace in the input text, including CR and LF, must be encoded. [RFC2045] does not require such encoding, and does not permit encoding of CR or LF characters that are part of a CRLF line break. 2. Whitespace in the encoded text is ignored. This is to allow tags encoded using DKIM-Quoted-Printable to be wrapped as needed. In particular, [RFC2045] requires that line breaks in the input be represented as physical line breaks; that is not the case here. 3. The "soft line break" syntax ("=" as the last non-whitespace character on the line) does not apply. 4. DKIM-Quoted-Printable does not require that encoded lines be no more than 76 characters long (although there may be other requirements depending on the context in which the encoded text is being used).
3. Protocol Elements โ๏ธ
Protocol Elements are conceptual parts of the protocol that are not specific to either Signers or Verifiers. The protocol descriptions for Signers and Verifiers are described in later sections ("Signer Actions" (Section 5) and "Verifier Actions" (Section 6)). NOTE: This section must be read in the context of those sections. ๐ซถ
3.1. Selectors ๐๏ธ
Okay so, to have a bunch of public keys hanging out for one signing domain at the same time, the key namespace gets split up using "selectors" ๐ . A selector could be an office location (like "sanfrancisco", "coolumbeach", and "reykjavik"), the signing date (like "january2005", "february2005", etc.), or even an individual user ๐ซถ.
Selectors are needed for some seriously important use cases:
- Domains that want to delegate signing capability for a specific address for a given duration to a partner, such as an advertising provider or other outsourced function.
- Domains that want to allow frequent travelers to send messages locally without the need to connect with a particular MSA.
- "Affinity" domains (e.g., college alumni associations) that provide forwarding of incoming mail, but that do not operate a mail submission agent for outgoing mail.
Periods are allowed in selectors and act as component separators ๐ง. When keys are retrieved from the DNS, periods in selectors define DNS label boundaries, kind of like how periods work in regular domain names. Selector components can be used to combine dates with locations, for example, "march2005.reykjavik". In a DNS implementation, this lets you delegate a portion of the selector namespace ๐.
ABNF:
selector = sub-domain *( "." sub-domain )
Each domain's owner decides how many public keys and matching selectors it has ๐. Lots of owners will be totally happy with just one selector, but administratively distributed organizations can manage different selectors and key pairs in different regions or on different email servers ๐.
Selectors also make it possible to swap out public keys on a regular basis, no drama ๐ฆ. Say a domain wants to switch from the public key tied to selector "january2005" to the one tied to selector "february2005". It just makes sure both public keys are advertised in the public-key repository at the same time for the transition period, since email may still be in transit before it gets verified. At the start of the transition period, the outbound email servers are set up to sign with the "february2005" private key. At the end of the transition period, the "january2005" public key is removed from the public-key repository โจ.
INFORMATIVE NOTE: A key may also be revoked as described below. The distinction between revoking and removing a key selector record is subtle. When phasing out keys as described above, a signing domain would probably simply remove the key record after the transition period. However, a signing domain could elect to revoke the key (but maintain the key record) for a further period. There is no defined semantic difference between a revoked key and a removed key. ๐ค
Some domains may want their selector values to be well-known, but others will want to be careful not to name selectors in a way that lets outside parties harvest data ๐. For example, if per-user keys are issued, the domain owner has to decide whether to tie the selector directly to a registered end user's name, or to make it some unassociated random value, such as a fingerprint of the public key.
INFORMATIVE OPERATIONS NOTE: Reusing a selector with a new key (for example, changing the key associated with a user's name) makes it impossible to tell the difference between a message that didn't verify because the key is no longer valid and a message that is actually forged. For this reason, Signers are ill-advised to reuse selectors for new keys. A better strategy is to assign new keys to new selectors. ๐
3.2. Tag=Value Lists ๐
DKIM uses a simple "tag=value" syntax in several places, including in messages and domain signature records ๐.
Values are a series of strings containing either plain text, "base64" text (as defined in [RFC2045], Section 6.8), "qp-section" (ibid, Section 6.7), or "dkim-quoted-printable" (as defined in Section 2.11). The name of the tag decides how each value gets encoded. Unencoded semicolon (";") characters MUST NOT occur in the tag value, since that's what separates tag-specs, so no sneaking them in ๐ซ.
INFORMATIVE IMPLEMENTATION NOTE: Although the "plain text" defined below (as "tag-value") only includes 7-bit characters, an implementation that wished to anticipate future standards would be advised not to preclude the use of UTF-8-encoded ([RFC3629]) text in tag=value lists. ๐ธ
Here are the formal ABNF syntax rules:
tag-list = tag-spec *( ";" tag-spec ) [ ";" ]
tag-spec = [FWS] tag-name [FWS] "=" [FWS] tag-value [FWS]
tag-name = ALPHA *ALNUMPUNC
tag-value = [ tval *( 1*(WSP / FWS) tval ) ]
; Prohibits WSP and FWS at beginning and end
tval = 1*VALCHAR
VALCHAR = %x21-3A / %x3C-7E
; EXCLAMATION to TILDE except SEMICOLON
ALNUMPUNC = ALPHA / DIGIT / "_"
WSP is allowed anywhere around tags. Specifically, any WSP after the "=" and any WSP before the ending ";" is not part of the value, but WSP inside the value is significant ๐ง.
Tags MUST be interpreted in a case-sensitive manner. Values MUST be processed as case sensitive unless the specific tag description of semantics says otherwise ๐ .
Tags with duplicate names MUST NOT occur within a single tag-list. If a tag name shows up more than once, the entire tag-list is invalid ๐ .
Whitespace within a value MUST be retained unless the specific tag description explicitly excludes it ๐.
Tag=value pairs that represent the default value MAY be included to aid legibility ๐ฆ.
Unrecognized tags MUST be ignored ๐.
Tags that have an empty value are not the same as omitted tags. An omitted tag is treated as having the default value, while a tag with an empty value explicitly designates the empty string as the value. Big difference, bestie ๐.
3.3. Signing and Verification Algorithms โจ
DKIM supports multiple digital signature algorithms. This specification defines two of them so far: rsa-sha1 and rsa-sha256. Signers MUST implement and SHOULD sign using rsa-sha256. Verifiers MUST implement both rsa-sha1 and rsa-sha256 ๐.
INFORMATIVE NOTE: Although rsa-sha256 is strongly encouraged, some senders might prefer to use rsa-sha1 when balancing security strength against performance, complexity, or other needs. In general, however, rsa-sha256 should always be used whenever possible. ๐ฅ
3.3.1. The rsa-sha1 Signing Algorithm ๐
The rsa-sha1 Signing Algorithm computes a message hash as described in Section 3.7, using SHA-1 [FIPS-180-3-2008] as the hash-alg. The Signer then signs that hash using the RSA algorithm (defined in Public-Key Cryptography Standards (PKCS) #1 version 1.5 [RFC3447]) as the crypt-alg and the Signer's private key. The hash MUST NOT be truncated or converted into any form other than the native binary form before being signed. The signing algorithm SHOULD use a public exponent of 65537 ๐ง .
3.3.2. The rsa-sha256 Signing Algorithm ๐
The rsa-sha256 Signing Algorithm computes a message hash as described in Section 3.7, using SHA-256 [FIPS-180-3-2008] as the hash-alg. The Signer then signs that hash using the RSA algorithm (defined in PKCS#1 version 1.5 [RFC3447]) as the crypt-alg and the Signer's private key. The hash MUST NOT be truncated or converted into any form other than the native binary form before being signed. The signing algorithm SHOULD use a public exponent of 65537 ๐ .
3.3.3. Key Sizes ๐
Picking the right key size is a trade-off between cost, performance, and risk. Short RSA keys more easily fall to off-line attacks, so Signers MUST use RSA keys of at least 1024 bits for long-lived keys ๐ก๏ธ. Verifiers MUST be able to validate signatures with keys ranging from 512 bits to 2048 bits, and they MAY be able to validate signatures with larger keys. Verifier policies may use the length of the signing key as one metric for deciding whether a signature is acceptable ๐ซถ.
Factors that should influence the key size choice include the following:
- The practical constraint that large (e.g., 4096-bit) keys might not fit within a 512-byte DNS UDP response packet
- The security constraint that keys smaller than 1024 bits are subject to off-line attacks
- Larger keys impose higher CPU costs to verify and sign email
- Keys can be replaced on a regular basis; thus, their lifetime can be relatively short
- The security goals of this specification are modest compared to typical goals of other systems that employ digital signatures
See [RFC3766] for further discussion on selecting key sizes ๐.
3.3.4. Other Algorithms ๐ง
Other algorithms MAY be defined in the future. Verifiers MUST ignore any signatures using algorithms that they do not implement ๐.
3.4. Canonicalization ๐ฆ
Some mail systems modify email in transit, which can invalidate a signature ๐ญ. For most Signers, mild modification of email doesn't matter for validating the DKIM domain name's use. For those Signers, a canonicalization algorithm that survives modest in-transit modification is preferred ๐ธ.
Other Signers demand that any modification of the email, however minor, result in a signature verification failure. These Signers prefer a canonicalization algorithm that does not tolerate in-transit modification of the signed email ๐.
Some Signers may be willing to accept modifications to header fields that stay within the bounds of email standards such as [RFC5322], but they are unwilling to accept any modification to the body of messages ๐.
To cover all of these needs, two canonicalization algorithms are defined for each of the header and the body. The "simple" algorithm tolerates almost no modification, and the "relaxed" algorithm tolerates common changes such as whitespace replacement and header field line rewrapping โจ. A Signer MAY specify either algorithm for the header or body when signing an email. If the Signer doesn't specify a canonicalization algorithm, the "simple" algorithm is the default for both header and body. Verifiers MUST implement both canonicalization algorithms. The header and body may use different canonicalization algorithms. Further canonicalization algorithms MAY be defined in the future, and Verifiers MUST ignore any signatures that use unrecognized canonicalization algorithms ๐.
Canonicalization simply prepares the email for presentation to the signing or verification algorithm. It MUST NOT change the transmitted data in any way ๐ซ. Canonicalization of header fields and body is described below ๐.
NOTE: This section assumes that the message is already in "network normal" format (text is ASCII encoded, lines are separated with CRLF characters, etc.). See also Section 5.3 for information about normalizing the message ๐.
3.4.1. The "simple" Header Canonicalization Algorithm ๐ง
The "simple" header canonicalization algorithm does not change header fields in any way. Header fields MUST be presented to the signing or verification algorithm exactly as they are in the message being signed or verified. In particular, header field names MUST NOT be case folded and whitespace MUST NOT be changed ๐ฅ.
3.4.2. The "relaxed" Header Canonicalization Algorithm โจ
okay so the "relaxed" header canonicalization algorithm MUST apply these steps in order ๐
- Convert all header field names (not the header field values) to lowercase. For example, convert
"SUBJect: AbC"to"subject: AbC"๐ - Unfold all header field continuation lines as described in [RFC5322]. In particular, lines with terminators embedded in continued header field values (that is, CRLF sequences followed by WSP) MUST be interpreted without the CRLF. Implementations MUST NOT remove the CRLF at the end of the header field value ๐ฆ
- Convert all sequences of one or more WSP characters to a single SP character. WSP characters here include those before and after a line folding boundary โจ
- Delete all WSP characters at the end of each unfolded header field value ๐ซถ
- Delete any WSP characters remaining before and after the colon separating the header field name from the header field value. The colon separator MUST be retained ๐
3.4.3. The "simple" Body Canonicalization Algorithm ๐ธ
The "simple" body canonicalization algorithm ignores all empty lines at the end of the message body. An empty line is a line of zero length after removal of the line terminator. If there is no body or no trailing CRLF on the message body, a CRLF is added. It makes no other changes to the message body. In more formal terms, the "simple" body canonicalization algorithm converts *CRLF at the end of the body to a single "CRLF" ๐ง
Note that a completely empty or missing body is canonicalized as a single "CRLF". That means the canonicalized length will be 2 octets ๐
The SHA-1 value (in base64) for an empty body (canonicalized to a "CRLF") is:
uoq1oCgLlTqpdDX/iUbLy7J1Wic=
The SHA-256 value is:
frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=
3.4.4. The "relaxed" Body Canonicalization Algorithm ๐
The "relaxed" body canonicalization algorithm MUST apply the following steps (a) and (b) in order:
- a. Reduce whitespace:
- Ignore all whitespace at the end of lines. Implementations MUST NOT remove the CRLF at the end of the line ๐
- Reduce all sequences of WSP within a line to a single SP character โจ
- b. Ignore all empty lines at the end of the message body. "Empty line" is defined in Section 3.4.3. If the body is non-empty but does not end with a CRLF, a CRLF is added. (For email, this is only possible when using extensions to SMTP or non-SMTP transport mechanisms.) ๐ฆ
The SHA-1 value (in base64) for an empty body (canonicalized to a null input) is:
2jmj7l5rSw0yVb/vlWAYkK/YBwk=
The SHA-256 value is:
47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
3.4.5. Canonicalization Examples (INFORMATIVE) ๐
okay these examples are giving "show, don't tell" ๐ In the following examples, actual whitespace is used only for clarity. The actual input and output text is designated using bracketed descriptors: "<SP>" for a space character, "<HTAB>" for a tab character, and "<CRLF>" for a carriage-return/line-feed sequence. For example, "X <SP> Y" and "X<SP>Y" represent the same three characters ๐
Example 1: A message reading:
A: <SP> X <CRLF>
B <SP> : <SP> Y <HTAB><CRLF>
<HTAB> Z <SP><SP><CRLF>
<CRLF>
<SP> C <SP><CRLF>
D <SP><HTAB><SP> E <CRLF>
<CRLF>
<CRLF>
when canonicalized using relaxed canonicalization for both header and body, it results in a header reading:
a:X <CRLF>
b:Y <SP> Z <CRLF>
and a body reading:
<SP> C <CRLF>
D <SP> E <CRLF>
Example 2: The same message canonicalized using simple canonicalization for both header and body results in a header reading:
A: <SP> X <CRLF>
B <SP> : <SP> Y <HTAB><CRLF>
<HTAB> Z <SP><SP><CRLF>
and a body reading:
<SP> C <SP><CRLF>
D <SP><HTAB><SP> E <CRLF>
Example 3: When processed using relaxed header canonicalization and simple body canonicalization, the canonicalized version has a header of:
a:X <CRLF>
b:Y <SP> Z <CRLF>
and a body reading:
<SP> C <SP><CRLF>
D <SP><HTAB><SP> E <CRLF>
3.5. The DKIM-Signature Header Field ๐
The signature of the email is stored in the DKIM-Signature header field. This header field contains all of the signature and key-fetching data. The DKIM-Signature value is a tag-list as described in Section 3.2 โจ
The DKIM-Signature header field SHOULD be treated as though it were a trace header field as defined in Section 3.6 of [RFC5322], and hence SHOULD NOT be reordered and SHOULD be prepended to the message ๐ง
The DKIM-Signature header field being created or verified is always included in the signature calculation, after the rest of the header fields being signed. However, when calculating or verifying the signature, the value of the "b=" tag (signature value) of that DKIM-Signature header field MUST be treated as though it were an empty string. Unknown tags in the DKIM-Signature header field MUST be included in the signature calculation but MUST be otherwise ignored by Verifiers. Other DKIM-Signature header fields that are included in the signature should be treated as normal header fields. In particular, the "b=" tag is not treated specially ๐ฆ
The encodings for each field type are listed below. Tags described as qp-section are encoded as described in Section 6.7 of MIME Part One [RFC2045], with the additional conversion of semicolon characters to "=3B". Intuitively, this is one line of quoted-printable encoded text. The dkim-quoted-printable syntax is defined in Section 2.11 ๐ธ
Tags on the DKIM-Signature header field, along with their type and requirement status, are shown below. Unrecognized tags MUST be ignored ๐
v= Version (plain-text; REQUIRED). This tag defines the version of this specification that applies to the signature record. It MUST have the value "1" for implementations compliant with this version of DKIM ๐
sig-v-tag = %x76 [FWS] "=" [FWS] 1*DIGIT
INFORMATIVE NOTE: DKIM-Signature version numbers may increase arithmetically as new versions of this specification are released.
a= The algorithm used to generate the signature (plain-text; REQUIRED). Verifiers MUST support "rsa-sha1" and "rsa-sha256". Signers SHOULD sign using "rsa-sha256". See Section 3.3 for a description of the algorithms ๐ฅ
sig-a-tag = %x61 [FWS] "=" [FWS] sig-a-tag-alg
sig-a-tag-alg = sig-a-tag-k "-" sig-a-tag-h
sig-a-tag-k = "rsa" / x-sig-a-tag-k
sig-a-tag-h = "sha1" / "sha256" / x-sig-a-tag-h
x-sig-a-tag-k = ALPHA *(ALPHA / DIGIT)
; for later extension
x-sig-a-tag-h = ALPHA *(ALPHA / DIGIT)
; for later extension
b= The signature data (base64; REQUIRED). Whitespace is ignored in this value and MUST be ignored when reassembling the original signature. In particular, the signing process can safely insert FWS in this value in arbitrary places to conform to line-length limits. See "Signer Actions" (Section 5) for how the signature is computed ๐
sig-b-tag = %x62 [FWS] "=" [FWS] sig-b-tag-data
sig-b-tag-data = base64string
bh= The hash of the canonicalized body part of the message as limited by the "l=" tag (base64; REQUIRED). Whitespace is ignored in this value and MUST be ignored when reassembling the original signature. In particular, the signing process can safely insert FWS in this value in arbitrary places to conform to line-length limits. See Section 3.7 for how the body hash is computed ๐
sig-bh-tag = %x62 %x68 [FWS] "=" [FWS] sig-bh-tag-data
sig-bh-tag-data = base64string
c= Message canonicalization (plain-text; OPTIONAL, default is "simple/simple"). This tag informs the Verifier of the type of canonicalization used to prepare the message for signing. It consists of two names separated by a "slash" (%d47) character, corresponding to the header and body canonicalization algorithms, respectively. These algorithms are described in Section 3.4. If only one algorithm is named, that algorithm is used for the header and "simple" is used for the body. For example, "c=relaxed" is treated the same as "c=relaxed/simple" โจ
sig-c-tag = %x63 [FWS] "=" [FWS] sig-c-tag-alg
["/" sig-c-tag-alg]
sig-c-tag-alg = "simple" / "relaxed" / x-sig-c-tag-alg
x-sig-c-tag-alg = hyphenated-word ; for later extension
d= The SDID claiming responsibility for an introduction of a message into the mail stream (plain-text; REQUIRED). Hence, the SDID value is used to form the query for the public key. The SDID MUST correspond to a valid DNS name under which the DKIM key record is published. The conventions and semantics used by a Signer to create and use a specific SDID are outside the scope of this specification, as is any use of those conventions and semantics. When presented with a signature that does not meet these requirements, Verifiers MUST consider the signature invalid ๐ธ
Internationalized domain names MUST be encoded as A-labels, as described in Section 2.3 of [RFC5890] ๐
sig-d-tag = %x64 [FWS] "=" [FWS] domain-name
domain-name = sub-domain 1*("." sub-domain)
; from [RFC5321] Domain,
; excluding address-literal
h= Signed header fields (plain-text, but see description; REQUIRED). A colon-separated list of header field names that identify the header fields presented to the signing algorithm. The field MUST contain the complete list of header fields in the order presented to the signing algorithm. The field MAY contain names of header fields that do not exist when signed. Nonexistent header fields do not contribute to the signature computation (that is, they are treated as the null input, including the header field name, the separating colon, the header field value, and any CRLF terminator). The field MAY contain multiple instances of a header field name, meaning multiple occurrences of the corresponding header field are included in the header hash. The field MUST NOT include the DKIM-Signature header field that is being created or verified, but may include others. Folding whitespace (FWS) MAY be included on either side of the colon separator. Header field names MUST be compared against actual header field names in a case-insensitive manner. This list MUST NOT be empty. See Section 5.4 for a discussion of choosing header fields to sign and Section 5.4.2 for requirements when signing multiple instances of a single field ๐ฅ
sig-h-tag = %x68 [FWS] "=" [FWS] hdr-name
*( [FWS] ":" [FWS] hdr-name )
INFORMATIVE EXPLANATION: By "signing" header fields that do not actually exist, a Signer can allow a Verifier to detect insertion of those header fields after signing. However, since a Signer cannot possibly know what header fields might be defined in the future, this mechanism cannot be used to prevent the addition of any possible unknown header fields ๐
INFORMATIVE NOTE: "Signing" fields that are not present at the time of signing not only prevents fields and values from being added but also prevents adding fields with no values ๐
i= is the Agent or User Identifier (AUID), the identity the SDID is taking responsibility for. It's dkim-quoted-printable and OPTIONAL. If you leave it out, the default is an empty local-part, then an "@", then the domain from the d= tag. So basically @yourdomain.com ๐
The syntax is a standard email address where the local-part MAY be omitted ๐ฆ The domain part MUST be the same as, or a subdomain of, the d= value, so you can't just wander off to some random domain ๐
โโ๏ธ Internationalized domain names MUST be encoded as A-labels, as described in Section 2.3 of [RFC5890].
ABNF:
sig-i-tag = %x69 [FWS] "=" [FWS] [ Local-part ]
"@" domain-name
Okay, this part is lowkey fascinating โจ The AUID has the same syntax as an email address, but it need not have the same semantics. Notably, the domain name need not be registered in the DNS, so it might not resolve in a query, and the local-part MAY be drawn from a namespace unrelated to any mailbox ๐ The Signer decides the structure and semantics of that namespace. Any knowledge or use of those details by Verifiers or Assessors is outside the scope of this specification. The Signer MAY choose to use the same namespace for its AUIDs as its users' email addresses, or MAY choose other means of representing its users ๐ However, the Signer SHOULD use the same AUID for each message intended to be evaluated as being within the same sphere of responsibility, if it wants to give receivers the option of using the AUID as a stable identifier that is finer grained than the SDID ๐ซถ
INFORMATIVE NOTE: The local-part of the "i=" tag is optional because in some cases a Signer may not be able to establish a verified individual identity. In such cases, the Signer might wish to assert that although it is willing to go as far as signing for the domain, it is unable or unwilling to commit to an individual user name within the domain. It can do so by including the domain part but not the local-part of the identity.
INFORMATIVE DISCUSSION: This specification does not require the value of the "i=" tag to match the identity in any message header fields. This is considered to be a Verifier policy issue. Constraints between the value of the "i=" tag and other identities in other header fields seek to apply basic authentication into the semantics of trust associated with a role such as content author. Trust is a broad and complex topic, and trust mechanisms are subject to highly creative attacks. The real-world efficacy of any but the most basic bindings between the "i=" value and other identities is not well established, nor is its vulnerability to subversion by an attacker. Hence, reliance on the use of these options should be strictly limited. In particular, it is not at all clear to what extent a typical end-user recipient can rely on any assurances that might be made by successful use of the "i=" options. ๐ญ๐
l= is the body length count. It's a plain-text unsigned decimal integer and OPTIONAL, and the default is the entire body ๐ It tells the Verifier how many octets in the body of the email, after canonicalization, are included in the cryptographic hash. Counting starts at 0 immediately after the CRLF that comes before the body. This value MUST NOT be larger than the actual number of octets in the canonicalized message body. See further discussion in Section 8.2.
INFORMATIVE NOTE: The value of the "l=" tag is constrained to 76 decimal digits. This constraint is not intended to predict the size of future messages or to require implementations to use an integer representation large enough to represent the maximum possible value, but is intended to remind the implementer to check the length of this and all other tags during verification and to test for integer overflow when decoding the value. Implementers may need to limit the actual value expressed to a value smaller than 10^76, e.g., to allow a message to fit within the available storage space. ๐งฎ
ABNF:
sig-l-tag = %x6c [FWS] "=" [FWS]
1*76DIGIT
q= is a colon-separated list of query methods used to retrieve the public key. It's plain-text and OPTIONAL, with a default of "dns/txt" ๐ Each query method looks like type[/options], and the syntax and semantics of the options depend on the type and the specified options. If there are multiple query mechanisms listed, the choice of query mechanism MUST NOT change the interpretation of the signature. Implementations MUST use the recognized query mechanisms in the order presented. Unrecognized query mechanisms MUST be ignored. Basically, order matters, but unknown stuff just gets skipped ๐
Currently, the only valid value is "dns/txt", which defines the DNS TXT resource record (RR) lookup algorithm described elsewhere in this document. The only option defined for the "dns" query type is "txt", which MUST be included. Verifiers and Signers MUST support "dns/txt" ๐
ABNF:
sig-q-tag = %x71 [FWS] "=" [FWS] sig-q-tag-method
*([FWS] ":" [FWS] sig-q-tag-method)
sig-q-tag-method = "dns/txt" / x-sig-q-tag-type
["/" x-sig-q-tag-args]
x-sig-q-tag-type = hyphenated-word ; for future extension
x-sig-q-tag-args = qp-hdr-value
s= is the selector, which subdivides the namespace for the d= (domain) tag. It's plain-text and REQUIRED ๐ธ Internationalized selector names MUST be encoded as A-labels, as described in Section 2.3 of [RFC5890].
ABNF:
sig-s-tag = %x73 [FWS] "=" [FWS] selector
t= is the Signature Timestamp, a plain-text unsigned decimal integer that's RECOMMENDED. The default is an unknown creation time โฐ It's the time the signature was created, counted as seconds since 00:00:00 on January 1, 1970 in the UTC time zone. The value is an unsigned integer in decimal ASCII, and it is not constrained to fit into a 31- or 32-bit integer. Implementations SHOULD be prepared to handle values up to at least 10^12 (until approximately AD 200,000; this fits into 40 bits). To avoid denial-of-service attacks, implementations MAY consider any value longer than 12 digits to be infinite. Leap seconds are not counted. Implementations MAY ignore signatures that have a timestamp in the future ๐ธ
ABNF:
sig-t-tag = %x74 [FWS] "=" [FWS] 1*12DIGIT
x= is the Signature Expiration, also plain-text unsigned decimal and RECOMMENDED. The default is no expiration โ The format is the same as t=, but it's an absolute date, not a time delta from the signing timestamp. It's an unsigned integer in decimal ASCII, with the same constraints as t=. Signatures MAY be considered invalid if the verification time at the Verifier is past the expiration date. The verification time should be the time the message was first received at the administrative domain of the Verifier, if that time is reliably available. Otherwise, the current time should be used. The value of the x= tag MUST be greater than the value of the t= tag if both are present ๐งพ
INFORMATIVE NOTE: The "x=" tag is not intended as an anti-replay defense.
INFORMATIVE NOTE: Due to clock drift, the receiver's notion of when to consider the signature expired may not exactly match what the sender is expecting. Receivers MAY add a 'fudge factor' to allow for such possible drift. ๐ฐ๏ธ
ABNF:
sig-x-tag = %x78 [FWS] "=" [FWS]
1*12DIGIT
z= is the copied header fields tag. It's dkim-quoted-printable, but see the description below, and it's OPTIONAL with a default of null ๐ It's a vertical-bar-separated list of selected header fields that were present when the message was signed, including both the field name and the value. It's not required to include all header fields present at signing time, and it doesn't need to contain the same header fields listed in the h= tag. The vertical bar (|, %x7C) is a meta-character in here, so any actual vertical bars in a copied header field must be encoded. Note that all whitespace must be encoded, including whitespace between the colon and the header field value. After encoding, FWS MAY be added at arbitrary locations to keep lines from getting too long, but that whitespace is NOT part of the value of the header field and MUST be removed before decoding. ๐งฉ
The header fields referenced by the h= tag refer to the fields in the [RFC5322] header of the message, not to any copied fields in the z= tag. Copied header field values are for diagnostic use. ๐
ABNF:
sig-z-tag = %x7A [FWS] "=" [FWS] sig-z-tag-copy
*( "|" [FWS] sig-z-tag-copy )
sig-z-tag-copy = hdr-name [FWS] ":" qp-hdr-value
INFORMATIVE EXAMPLE of a signature header field spread across multiple continuation lines:
DKIM-Signature: v=1; a=rsa-sha256; d=example.net; s=brisbane;
c=simple; q=dns/txt; i=@eng.example.net;
t=1117574938; x=1118006938;
h=from:to:subject:date;
z=From:foo@eng.example.net|To:joe@example.com|
Subject:demo=20run|Date:July=205,=202005=203:44:08=20PM=20-0700;
bh=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=;
b=dzdVyOfAKCdLXdJOc9G2q8LoXSlEniSbav+yuU4zGeeruD00lszZVoG4ZHRNiYzR
3.6. Key Management and Representation
Signature applications need some level of assurance that the verification public key is associated with the claimed Signer. Lots of applications get that by using public-key certificates issued by a trusted third party ๐ค DKIM can reach a sufficient level of security with way better scalability, though, by having the Verifier query the purported Signer's DNS entry (or some security-equivalent) to retrieve the public key. Iconic efficiency ๐ฆ
DKIM keys can potentially be stored in multiple types of key servers and in multiple formats. The storage and format of keys are irrelevant to the rest of the DKIM algorithm ๐
The parameters to the key lookup algorithm are the type of the lookup (the q= tag), the domain of the Signer (the d= tag of the DKIM-Signature header field), and the selector (the s= tag) ๐
public_key = dkim_find_key(q_val, d_val, s_val)
This document defines a single binding, using DNS TXT RRs to distribute the keys. Other bindings may be defined in the future โจ
3.6.1. Textual Representation ๐โจ
Okay so, lots of key servers are gonna store keys as plain unstructured text. (An XML form doesn't count as unstructured text for this, just FYI ๐ .) For any DKIM key stored in that kind of plain text, you MUST use the definition below ๐.
The overall syntax is a tag-list, the same kind described in Section 3.2. The tags are listed below. Other tags MAY show up too, and any implementation that doesn't understand them MUST ignore them ๐ซถ.
v= Version of the DKIM key record (plain-text; RECOMMENDED, default is "DKIM1") ๐ธ. If you include it, it MUST be set to "DKIM1" (no quotes). It MUST be the first tag in the record. Any record starting with a "v=" tag set to anything else MUST be discarded ๐. Verifiers have to do a string comparison on this value, so "DKIM1" is NOT the same as "DKIM1.0" ๐. Not the same at all!
ABNF:
key-v-tag = %x76 [FWS] "=" [FWS] %x44.4B.49.4D.31
h= Acceptable hash algorithms (plain-text; OPTIONAL, defaults to allowing all algorithms) ๐ฆ. It's a colon-separated list of hash algorithms that might get used. Unrecognized algorithms MUST be ignored. Check Section 3.3 for the hash algorithms that Signers and Verifiers actually implement. Which algorithms go in this tag is an operational choice the Signer gets to make ๐.
ABNF:
key-h-tag = %x68 [FWS] "=" [FWS] key-h-tag-alg
*( [FWS] ":" [FWS] key-h-tag-alg )
key-h-tag-alg = "sha1" / "sha256" / x-key-h-tag-alg
x-key-h-tag-alg = hyphenated-word ; for future extension
k= Key type (plain-text; OPTIONAL, default is "rsa") ๐. Signers and Verifiers MUST support the "rsa" key type. The "rsa" key type means an ASN.1 DER-encoded [ITU-X660-1997] RSAPublicKey (see [RFC3447], Sections 3.1 and A.1.1) is being used in the "p=" tag. (Heads up: the "p=" tag also encodes that value in base64 ๐.) Unrecognized key types MUST be ignored.
ABNF:
key-k-tag = %x76 [FWS] "=" [FWS] key-k-tag-type
key-k-tag-type = "rsa" / x-key-k-tag-type
x-key-k-tag-type = hyphenated-word ; for future extension
n= Notes that might be of interest to a human (qp-section; OPTIONAL, default is empty) ๐. No program interprets these at all. Use this tag sparingly in any key server mechanism with limited space (DNS, I'm looking at you ๐). It's meant for administrators, not end users.
ABNF:
key-n-tag = %x6e [FWS] "=" [FWS] qp-section
p= Public-key data (base64; REQUIRED) ๐. An empty value means this public key has been revoked. The syntax and semantics of this tag's value, before it gets base64-encoded, are defined by the "k=" tag.
INFORMATIVE RATIONALE: If a private key has been compromised or otherwise disabled (say, an outsourcing contract got terminated ๐ฌ), a Signer might want to say outright that it knows about the selector, but every message using that selector should fail verification. Verifiers SHOULD return an error code for any DKIM-Signature header field whose selector points at a revoked key. (See Section 6.1.2 for details.)
ABNF:
key-p-tag = %x70 [FWS] "=" [ [FWS] base64string]
INFORMATIVE NOTE: A base64string is allowed to include whitespace (FWS) at arbitrary places. Any CRLFs, though, MUST be followed by at least one WSP character ๐ง. Implementers and administrators are cautioned to make sure their selector TXT RRs follow this spec. Please be careful, bestie!
s= Service Type (plain-text; OPTIONAL; default is "*") ๐. A colon-separated list of service types this record applies to. Verifiers for a given service type MUST ignore this record if the matching type isn't listed. Unrecognized service types MUST be ignored. The currently defined service types are:
*matches all service typesemailelectronic mail (not necessarily limited to SMTP)
This tag exists to limit how keys get used for other purposes, in case other services end up defining their own use of DKIM later on โจ.
ABNF:
key-s-tag = %x73 [FWS] "=" [FWS] key-s-tag-type
*( [FWS] ":" [FWS] key-s-tag-type )
key-s-tag-type = "email" / "*" / x-key-s-tag-type
x-key-s-tag-type = hyphenated-word ; for future extension
t= Flags, represented as a colon-separated list of names (plain-text; OPTIONAL, default is no flags set) ๐ฉ. Unrecognized flags MUST be ignored. The defined flags are:
yThis domain is testing DKIM. Verifiers MUST NOT treat messages from Signers in testing mode any differently from unsigned email, even if the signature fails to verify ๐ . Verifiers MAY want to track testing mode results to help the Signer out.sAny DKIM-Signature header fields using the "i=" tag MUST have the same domain value on the right-hand side of the "@" in the "i=" tag as the value of the "d=" tag. In other words, the "i=" domain MUST NOT be a subdomain of "d=". Using this flag is RECOMMENDED unless subdomaining is required ๐.
ABNF:
key-t-tag = %x74 [FWS] "=" [FWS] key-t-tag-flag
*( [FWS] ":" [FWS] key-t-tag-flag )
key-t-tag-flag = "y" / "s" / x-key-t-tag-flag
x-key-t-tag-flag = hyphenated-word ; for future extension
3.6.2. DNS Binding ๐
Here's the DNS TXT RR binding, which is how keys get stored as a key service. Every implementation MUST support this binding ๐.
3.6.2.1. Namespace ๐๏ธ
All DKIM keys live in a subdomain called "_domainkey" ๐ . Say you've got a DKIM-Signature field with a "d=" tag of "example.com" and an "s=" tag of "foo.bar". The DNS query will be for foo.bar._domainkey.example.com ๐ญ.
3.6.2.2. Resource Record Types for Key Storage ๐ฆ
The DNS Resource Record type gets picked by an option to the query-type ("q=") tag. The only option defined in this base spec is "txt", which means a TXT RR is used. A later extension of this standard might define another RR type ๐ฎ.
Strings in a TXT RR MUST be concatenated together before use, with no whitespace in between ๐งต. TXT RRs MUST be unique for a particular selector name. So if there are multiple records in an RRset, the results are undefined ๐.
TXT RRs are encoded as described in Section 3.6.1 ๐ .
3.7. Computing the Message Hashes ๐งฎโจ
okay so, signing AND verifying both start with the same first step: computing two cryptographic hashes over the message ๐ Signers pick the signature parameters as described in "Signer Actions" (Section 5), and Verifiers use the parameters from the DKIM-Signature header field they're checking ๐. The tag names in that DKIM-Signature header field are what we're talking about here, whether it already exists (verifying) or is about to be created (signing) ๐ And canonicalization (Section 3.4) is only a prep step for signing or verifying. It doesn't touch the transmitted email at all ๐ซถ
The Signer/Verifier MUST compute two hashes: one over the body of the message and one over the selected header fields of the message ๐ฅ
Signers MUST compute them in the order shown. Verifiers MAY compute them in any order that's convenient for them, as long as the result is semantically identical to what they'd get if they'd computed them in that order ๐ธ
Hash step 1: the Signer/Verifier MUST hash the message body, canonicalized using the body canonicalization algorithm from the c= tag, and then truncated to the length in the l= tag. That hash gets converted to base64 and then inserted into (Signers) or compared to (Verifiers) the bh= tag of the DKIM-Signature header field ๐
Hash step 2: the Signer/Verifier MUST pass the following to the hash algorithm, in this order ๐
- The header fields listed in the
h=tag, in the order that tag specifies, canonicalized using the header canonicalization algorithm from thec=tag. Each header field MUST be terminated with a single CRLF. - The DKIM-Signature header field that exists (verifying) or will be inserted (signing) in the message, with the value of the
b=tag (including all surrounding whitespace) deleted (so it's treated as the empty string), canonicalized using the header canonicalization algorithm from thec=tag, and without a trailing CRLF.
All tags and their values in the DKIM-Signature header field get included in the cryptographic hash, with one exception: the value portion of the b= (signature) tag, which MUST be treated as the null string ๐ All tags MUST be included even if the Verifier doesn't understand them. The header field MUST be presented to the hash algorithm after the body of the message rather than with the rest of the header fields, and it MUST be canonicalized as specified in the c= (canonicalization) tag. The DKIM-Signature header field MUST NOT be included in its own h= tag, although other DKIM-Signature header fields MAY be signed (see Section 4) โจ
When hashing messages that will be sent using base64 or quoted-printable encoding, Signers MUST compute the hash after the encoding. Likewise, the Verifier MUST incorporate the values into the hash before decoding the base64 or quoted-printable text. However, the hash MUST be computed before transport-level encodings like SMTP "dot-stuffing" (the change where lines starting with a "." get modified so they don't get mixed up with the SMTP end-of-message marker, as specified in [RFC5321]) ๐ฆ
Apart from the canonicalization procedure in Section 3.4, the DKIM signing process treats the body of messages as just a string of octets ๐ง DKIM messages MAY be either plain-text or MIME format, and no special treatment is given to MIME content. Message attachments in MIME format MUST be included in the content that is signed ๐
More formally, the pseudo-code for the signature algorithm is:
body-hash = hash-alg (canon-body, l-param)
data-hash = hash-alg (h-headers, D-SIG, body-hash)
signature = sig-alg (d-domain, selector, data-hash)
where:
body-hash: is the output from hashing the body, using hash-alg.hash-alg: is the hashing algorithm specified in theaparameter.canon-body: is a canonicalized representation of the body, produced using the body algorithm specified in thecparameter, as defined in Section 3.4 and excluding the DKIM-Signature field.l-param: is the length-of-body value of thelparameter.data-hash: is the output from using the hash-alg algorithm, to hash the header including the DKIM-Signature header, and the body hash.h-headers: is the list of headers to be signed, as specified in thehparameter.D-SIG: is the canonicalized DKIM-Signature field itself without the signature value portion of the parameter, that is, an empty parameter value.signature: is the signature value produced by the signing algorithm.sig-alg: is the signature algorithm specified by theaparameter.d-domain: is the domain name specified in thedparameter.selector: is the selector value specified in thesparameter.
NOTE: Lots of digital signature APIs do both the hashing and the application of the RSA private key with one single sign() primitive. When you use one of those, the last two steps in the algorithm would probably get merged into a single call that does both the a-hash-alg and the sig-alg ๐ค
3.8. Input Requirements ๐ฌ
A message that isn't compliant with [RFC5322], [RFC2045], and [RFC2047] can get hit with attempts by intermediaries to "fix" or interpret it ๐ See Section 8 of [RFC4409] for examples of the changes that usually happen. Those "corrections" can invalidate DKIM signatures or cause other undesirable effects, including some that change how a message looks to the end user ๐ญ
So, DKIM's design is built on the assumption of valid input ๐ Therefore, Signers and Verifiers SHOULD take reasonable steps to make sure the messages they process are valid according to [RFC5322], [RFC2045], and any other relevant message format standards ๐ซถ
See Section 8.15 for additional discussion.
3.9. Output Requirements ๐
Evaluating each signature ends in one of three states, which this document refers to like this:
SUCCESS: a successful verificationPERMFAIL: a permanent, non-recoverable error such as a signature verification failureTEMPFAIL: a temporary, recoverable error such as a DNS query timeout
For each signature that verifies successfully or produces a TEMPFAIL result, the output of the DKIM algorithm MUST include the set of:
- The domain name, taken from the
d=signature tag; and - The result of the verification attempt for that signature.
The output MAY include other signature properties or result metadata, including PERMFAILed or otherwise ignored signatures, for use by modules that consume those results ๐
See Section 6.1 for discussion of signature validation result codes.
3.10. Signing by Parent Domains ๐ก
Sometimes a domain wants to sign on behalf of its subdomains without having to maintain separate selectors (key records) in each one ๐ By default, private keys that match key records can be used to sign messages for any subdomain of the domain they live in. For example, a key record for the domain example.com can be used to verify messages where the AUID (the i= tag of the signature) is sub.example.com, or even sub1.sub2.example.com. To limit what these keys can do when that's not the plan, the "s" flag MAY be set in the t= tag of the key record, to constrain the validity of the domain of the AUID ๐ If the referenced key record contains the "s" flag as part of the t= tag, the domain of the AUID (the i= flag) MUST be the same as the SDID (d=) domain. If this flag is absent, the domain of the AUID MUST be the same as, or a subdomain of, the SDID ๐ง
3.11. Relationship between SDID and AUID ๐ชช
DKIM's main job is to communicate a single Signing Domain Identifier (SDID) from the Signer to a recipient-side Identity Assessor. The SDID refers to a responsible identity ๐ฆ DKIM MAY optionally provide a single responsible Agent or User Identifier (AUID) as well.
So DKIM's mandatory output to a receive-side Identity Assessor is a single domain name. Within the scope of its use as DKIM output, the name only has basic domain name semantics. Any possible owner-specific semantics are outside the scope of DKIM. In other words, when it's acting as a DKIM identifier, an Identity Assessor can't assume any extra semantics โจ
Once a receive-side DKIM Verifier has successfully verified the signature, it MUST communicate the Signing Domain Identifier (d=) to a consuming Identity Assessor module, and it MAY communicate the Agent or User Identifier (i=) if it's present ๐
If a receiver tries to intuit any structured semantics for either identifier, that's a heuristic function, and it's outside the scope of DKIM's specification and semantics ๐ค So it gets handed off to a higher-level service, like a delivery-handling filter that takes in a bunch of inputs and runs heuristic analysis on them ๐ง
INFORMATIVE DISCUSSION: This document doesn't require the value of the SDID or AUID to match an identifier in any other message header field. That's an Assessor policy issue instead. The point of that kind of linkage would be to authenticate the value in that other header field, and that's the basis for a trust assessment based on the identifier value. Trust is a broad, complicated topic, and trust mechanisms are open to highly creative attacks ๐ฌ The real-world efficacy of anything beyond the most basic bindings between the SDID or AUID and other identities isn't well established, and neither is how vulnerable it is to subversion by an attacker. So reliance on those bindings should be strictly limited. In particular, it isn't at all clear how far a typical end-user recipient can rely on any assurances that a successful use of the SDID or AUID might seem to make ๐
4. Semantics of Multiple Signatures ๐ธ๐
4.1. Example Scenarios โจ
okay so there are SO many reasons a message could end up with multiple signatures ๐
like imagine SHA-256 gets found to be not strong enough (rip ๐) and DKIM moves over to SHA-1024. A Signer could sign with the new algo right away but ALSO keep signing with the old one for Verifiers that haven't upgraded yet ๐ซถ. It does this by adding two DKIM-Signature header fields, one per algorithm. Older Verifiers that don't recognize SHA-1024 as acceptable just skip that signature and use the older one ๐ฆ. Newer Verifiers can use either signature at their option and, all other things being equal, might not even bother checking the other one โจ
Similarly, a Signer might sign a message with ALL the header fields and no l= tag (to satisfy strict Verifiers ๐), and then sign it a second time with a limited set of header fields and an l= tag (in anticipation of possible message modifications en route to other Verifiers ๐ธ). Verifiers can then pick whichever signature they prefer. main character energy ๐
Of course, a message might also have multiple signatures because it passed through multiple Signers ๐ฆ. A super common case is a signed message going through a mailing list that ALSO signs everything ๐ฌ. Assuming both of those signatures verify, a recipient might accept the message if either signature is known to come from a trusted source ๐ซถ
Recipients might even whitelist mailing lists they've subscribed to that have acceptable anti-abuse policies ๐ก๏ธ so they accept messages sent to that list even from unknown authors ๐ . They could also subscribe to less trusted mailing lists (e.g., ones without anti-abuse protection) and be willing to accept all messages from specific authors, but insist on doing additional abuse scanning for everything else ๐ (boundaries are everything, bestie ๐)
Another related example of multiple Signers is forwarding services, like the ones commonly tied to academic alumni sites ๐. For example, a recipient might have an address at members.example.org, a site with anti-abuse protection that's somewhat less effective than the recipient would like ๐ฌ. That recipient might have specific authors whose messages are trusted absolutely, while messages from unknown authors that passed the forwarder's scrutiny would only get medium trust โญ
4.2. Interpretation ๐ง
okay so a Signer adding a signature to a message just creates a new DKIM-Signature header, using the usual semantics of the h= option ๐. A Signer MAY sign previously existing DKIM-Signature header fields using the method described in Section 5.4 to sign trace header fields ๐ฆ
Note that Signers should be cognizant that signing DKIM-Signature header fields may result in signature failures with intermediaries that do not recognize that DKIM-Signature header fields are trace header fields and unwittingly reorder them, thus breaking such signatures. For this reason, signing existing DKIM-Signature header fields is unadvised, albeit legal. ๐ญ
INFORMATIVE NOTE: If a header field with multiple instances is signed, those header fields are always signed from the bottom up. Thus, it is not possible to sign only specific DKIM-Signature header fields. For example, if the message being signed already contains three DKIM-Signature header fields A, B, and C, it is possible to sign all of them, B and C only, or C only, but not A only, B only, A and B only, or A and C only. ๐งฉ
A Signer MAY add more than one DKIM-Signature header field using different parameters ๐. For example, during a transition period, a Signer might want to produce signatures using two different hash algorithms ๐ฅ
Signers SHOULD NOT remove any DKIM-Signature header fields from messages they are signing, even if they know that the signatures cannot be verified ๐ โโ๏ธ (receipts are receipts, periodt ๐ )
When evaluating a message with multiple signatures, a Verifier SHOULD evaluate signatures independently and on their own merits โจ. For example, a Verifier that by policy chooses not to accept signatures with deprecated cryptographic algorithms would consider those signatures invalid ๐ซ. Verifiers MAY process signatures in any order of their choice; for example, some Verifiers might choose to process signatures corresponding to the From field in the message header before other signatures ๐. See Section 6.1 for more information about signature choices ๐
INFORMATIVE IMPLEMENTATION NOTE: Verifier attempts to correlate valid signatures with invalid signatures in an attempt to guess why a signature failed are ill-advised. In particular, there is no general way that a Verifier can determine that an invalid signature was ever valid. ๐
Verifiers SHOULD continue to check signatures until a signature successfully verifies to the satisfaction of the Verifier ๐ซถ. To limit potential denial-of-service attacks, Verifiers MAY limit the total number of signatures they will attempt to verify ๐ก๏ธ
If a Verifier module reports signatures whose evaluations produced PERMFAIL results, Identity Assessors SHOULD ignore those signatures (see Section 6.1), acting as though they were not present in the message ๐ป
5. Signer Actions ๐๏ธ
The following steps are performed in order by Signers ๐
5.1. Determine Whether the Email Should Be Signed and by Whom ๐ค
A Signer can obviously only sign email for domains it has a private key for, plus the necessary knowledge of the corresponding public key and selector information ๐. But there are a number of other reasons beyond a missing private key why a Signer could choose NOT to sign an email ๐ โโ๏ธ
INFORMATIVE NOTE: A Signer can be implemented as part of any portion of the mail system as deemed appropriate, including an MUA, a SUBMISSION server, or an MTA. Wherever implemented, Signers should beware of signing (and thereby asserting responsibility for) messages that may be problematic. In particular, within a trusted enclave, the signing domain might be derived from the header according to local policy; SUBMISSION servers might only sign messages from users that are properly authenticated and authorized. ๐
INFORMATIVE IMPLEMENTER ADVICE: SUBMISSION servers should not sign Received header fields if the outgoing gateway MTA obfuscates Received header fields, for example, to hide the details of internal topology. ๐ต๏ธโโ๏ธ
If an email cannot be signed for some reason, it's a local policy decision what to do with that email ๐
5.2. Select a Private Key and Corresponding Selector Information ๐๏ธ
This specification does NOT define the basis by which a Signer should choose which private key and selector information to use ๐คทโโ๏ธ. Currently, all selectors are equal as far as this specification is concerned, so the decision should mostly be about administrative convenience ๐๏ธ. Distribution and management of private keys is also outside the scope of this document ๐
INFORMATIVE OPERATIONS ADVICE: A Signer should not sign with a private key when the selector containing the corresponding public key is expected to be revoked or removed before the Verifier has an opportunity to validate the signature. The Signer should anticipate that Verifiers can choose to defer validation, perhaps until the message is actually read by the final recipient. In particular, when rotating to a new key pair, signing should immediately commence with the new private key, and the old public key should be retained for a reasonable validation interval before being removed from the key server. ๐๐
5.3. Normalize the Message to Prevent Transport Conversions ๐งผ
Some messages, especially ones using 8-bit characters, get modified in transit, notably converted to 7-bit form ๐ฉ. Those conversions will break DKIM signatures ๐. To minimize the chances of that breakage, Signers SHOULD convert the message to a suitable MIME content-transfer encoding, such as quoted-printable or base64 as described in [RFC2045], before signing ๐. That conversion is outside the scope of DKIM; the actual message SHOULD be converted to 7-bit MIME by an MUA or MSA before it's presented to the DKIM algorithm ๐
If the message is submitted to the Signer with any local encoding that will be modified before transmission, that modification to canonical [RFC5322] form MUST be done before signing ๐ ๏ธ. In particular, bare CR or LF characters (which some systems use as a local line separator convention) MUST be converted to the SMTP-standard CRLF sequence before the message is signed ๐. Any conversion of this sort SHOULD be applied to the message actually sent to the recipient(s), not just to the version presented to the signing algorithm ๐จ
More generally, the Signer MUST sign the message as it is expected to be received by the Verifier, rather than in some local or internal form ๐ซถ (what the Verifier sees is what gets signed, no cap ๐)
5.3.1. Body Length Limits โ๏ธ
A body length count MAY be specified to limit the signature calculation to an initial prefix of the body text, measured in octets. If the body length count is not specified, the entire message body is signed ๐
INFORMATIVE RATIONALE: This capability is provided because it is very common for mailing lists to add trailers to messages (e.g., instructions on how to get off the list). Until those messages are also signed, the body length count is a useful tool for the Verifier, since it can, as a matter of policy, accept messages having valid signatures with extraneous data. ๐ฌโจ
The length actually hashed should be inserted in the l= tag of the DKIM-Signature header field. (See Section 3.5.) ๐ท๏ธ
The body length count allows the Signer of a message to permit data to be appended to the end of the body of a signed message. The body length count MUST be calculated following the canonicalization algorithm; for example, any whitespace ignored by a canonicalization algorithm is NOT included as part of the body length count ๐งฎ
A body length count of zero means that the body is completely unsigned ๐
Signers wishing to ensure that no modification of any sort can occur should specify the "simple" canonicalization algorithm for both header and body and omit the body length count ๐ (maximum protection, zero flexibility, that's the tea ๐ต)
See Section 8.2 for further discussion ๐
5.4. Determine the Header Fields to Sign ๐
bestie, the From header field MUST be signed, which means it has to show up in the h= tag of the DKIM-Signature header field ๐ซถ Signers SHOULD NOT sign an existing header field that's likely to get legitimately changed or removed in transit. [RFC5321] explicitly allows the Return-Path header field to be modified or removed in transit, so that one is a no-go ๐ Signers MAY include any other header fields that are present at signing time, totally up to the Signer ๐
INFORMATIVE OPERATIONS NOTE ๐ฅ: Picking which header fields to sign is lowkey tricky. One strategy is to sign all existing, non-repeatable header fields. Another is to sign only the header fields that the receiver is likely to display or that are likely to affect how the message gets processed. A third strategy is to sign only "well-known" headers. Also, Verifiers may treat unsigned header fields with extreme skepticism, which can mean refusing to display them to the end user or even ignoring the signature if it doesn't cover certain header fields ๐ So signing fields that are in the message, like Date, Subject, Reply-To, Sender, and all MIME header fields, is highly advised โจ
The DKIM-Signature header field is always implicitly signed, so it MUST NOT be included in the h= tag, except to say that other preexisting signatures are also signed ๐ฆ
Signers MAY claim to have signed header fields that don't actually exist. In other words, Signers MAY include the header field name in the h= tag even when that header field isn't in the message ๐ง When the signature is computed, the nonexisting header field MUST be treated as the null string, which means the header field name, the header field value, all the punctuation, and the trailing CRLF all count as nothing ๐ธ
INFORMATIVE RATIONALE ๐: This lets Signers explicitly assert that a header field is absent. If that header field gets added later, the signature will fail. Iconic, honestly ๐
INFORMATIVE NOTE ๐: A header field name only needs to be listed once more than the actual number of that header field in the message at signing time to block any further additions. For example, if there's a single Comments header field when you sign, listing Comments twice in theh=tag is enough to stop any number of Comments header fields from being appended. It's not necessary (but it is legal) to list Comments three or more times in theh=tag ๐
Refer to Section 5.4.2 for the procedure to follow when canonicalizing a header with more than one instance of a particular header field name ๐
Signers need to be careful about signing header fields that might get more instances added later in the delivery process, since those can be inserted after the signed instance or otherwise reordered ๐ญ Trace header fields (like Received) and Resent-* blocks are the only fields that [RFC5322] prohibits from being reordered. And since DKIM-Signature header fields can be reordered by some intermediate MTAs, signing existing DKIM-Signature header fields is error-prone ๐
INFORMATIVE ADMONITION ๐จ: Even though [RFC5322] doesn't prohibit reordering header fields, reordering signed header fields that have multiple instances by intermediate MTAs will break DKIM signatures. That's antisocial behavior, and it should be avoided ๐
INFORMATIVE IMPLEMENTER'S NOTE ๐ซถ: Although this specification doesn't require it, all end-user visible header fields should be signed to avoid possible "indirect spamming". For example, if the Subject header field isn't signed, a spammer can resend a previously signed mail and swap in a one-line spam subject. Not it ๐ค
5.4.1. Recommended Signature Content โจ
Okay so the whole point of the DKIM cryptographic algorithm is to attach an identifier to the message in a way that's both robust against normal transit-related changes and resistant to replay attacks ๐ Choosing which header fields go into the hash and which ones stay out is a huge part of making that work, no cap.
The basic rule for picking fields to include is to select the ones that make up the "core" of the message content. That way, any replay attack has to include these too in order for the signature to succeed. And with those fields included, the core of the message is still valid, even if it gets sent on to new recipients ๐ฆ
Common examples of fields with addresses, and fields with textual content related to the body, are:
- From (REQUIRED; see Section 5.4)
- Reply-To
- Subject
- Date
- To, Cc
- Resent-Date, Resent-From, Resent-To, Resent-Cc
- In-Reply-To, References
- List-Id, List-Help, List-Unsubscribe, List-Subscribe, List-Post, List-Owner, List-Archive
If the l= signature tag is in use (see Section 3.5), the Content-Type field is also a candidate for inclusion, since it could be replaced in a way that causes completely different content to be rendered to the receiving user ๐
There are trade-offs when deciding what counts as the "core" of the message, and for some fields that's pretty subjective ๐ธ Including fields like "Message-ID", for example, is useful if you think a mechanism for telling apart separate instances of the same message counts as core content. Similarly, "In-Reply-To" and "References" might be worth including if you think message threading is a core part of the message ๐งต
Another class of fields that might be interesting are the ones that carry security-related information about the message, like Authentication-Results [RFC5451] ๐ฅ
The basic rule for picking fields to exclude is to select the fields that have multiple fields with the same name, and the fields that get modified in transit. Examples of these are:
- Return-Path
- Received
- Comments, Keywords
Note that the DKIM-Signature field is also excluded from the header hash, because its handling is specified separately ๐
Typically, it's better to exclude other optional fields, because additional fields of the same name might legitimately get added or reordered before verification. There are likely to be legitimate exceptions to this, because there's a wide variety of application-specific header fields that might be applied to a message, and some of them are unlikely to be duplicated, modified, or reordered ๐
Signers SHOULD choose canonicalization algorithms based on the types of messages they process and how much risk they're okay with ๐ For example, e-commerce sites that mostly send purchase receipts, which aren't expected to be processed by mailing lists or other software likely to modify messages, will generally prefer "simple" canonicalization ๐๏ธ
Sites sending mostly person-to-person email will likely prefer to be more resilient to modification during transport, so they'll probably go with "relaxed" canonicalization ๐ซถ
Unless mail is processed through intermediaries, like mailing lists that might add "unsubscribe" instructions to the bottom of the message body, the l= tag is likely to give no extra benefit while opening up an avenue for unauthorized addition of text to a message ๐จ Using l=0 takes this to the extreme, allowing the complete alteration of the message text without invalidating the signature ๐ Moreover, a Verifier would be within its rights to consider a partly signed message body as unacceptable. Judicious use is advised, bestie ๐
5.4.2. Signatures Involving Multiple Instances of a Field ๐ง
Signers who choose to sign an existing header field that occurs more than once in the message (like Received) MUST sign the physically last instance of that header field in the header block ๐ฆ Signers who want to sign multiple instances of such a header field MUST include the header field name multiple times in the h= tag of the DKIM-Signature header field, and MUST sign those header fields in order from the bottom of the header field block to the top ๐ The Signer MAY include more instances of a header field name in h= than there are actual corresponding header fields, so that the signature won't verify if additional header fields of that name get added ๐
INFORMATIVE EXAMPLE ๐: If the Signer wants to sign two existing Received header fields, and the existing header contains:Received: <A> Received: <B> Received: <C>then the resulting DKIM-Signature header field should read:DKIM-Signature: ... h=Received : Received :...and Received header fields <C> and <B> will be signed in that order ๐
5.5. Compute the Message Hash and Signature ๐ฅ
The Signer MUST compute the message hash as described in Section 3.7, and then sign it using the selected public-key algorithm ๐งฎ This results in a DKIM-Signature header field that includes the body hash and a signature of the header hash, where that header includes the DKIM-Signature header field itself ๐คฏ
Entities like mailing list managers that implement DKIM and that modify the message or a header field (for example, inserting unsubscribe information) before retransmitting the message SHOULD check any existing signature on input, and MUST make such modifications before re-signing the message ๐
5.6. Insert the DKIM-Signature Header Field ๐
Finally, the Signer MUST insert the DKIM-Signature header field created in the previous step before transmitting the email ๐ The DKIM-Signature header field MUST be the same as the one used to compute the hash described above, except that the value of the b= tag MUST be the appropriately signed hash computed in the previous step. That hash gets signed using the algorithm specified in the a= tag of the DKIM-Signature header field, and using the private key that corresponds to the selector given in the s= tag of the DKIM-Signature header field, as chosen above in Section 5.2 ๐
The DKIM-Signature header field MUST be inserted before any other DKIM-Signature fields in the header block ๐ฅ
INFORMATIVE IMPLEMENTATION NOTE ๐: The easiest way to do this is to insert the DKIM-Signature header field at the beginning of the header block. In particular, it can go before any existing Received header fields. This is consistent with treating DKIM-Signature as a trace header field, which is giving very organized energy โจ
6. Verifier Actions โจ
okay so bestie, a Signer MAY remove or revoke a public key at any time ๐, which is why it's advised that verification happens in a timely manner โฐ. In lots of configurations, the most timely spot is during acceptance by the border MTA or shortly after. Deferring verification until the end user opens the message is discouraged ๐ โโ๏ธ, and honestly that's giving red flag energy.
A border or intermediate MTA MAY verify the message signature(s). An MTA who has performed verification MAY communicate the result of that verification by adding a verification header field to incoming messages. This simplifies things considerably for the user, who can now use an existing mail user agent ๐. Most MUAs can filter messages based on message header fields or content, and those filters are how the user gets whatever policy they want for unsigned mail ๐ง.
A verifying MTA MAY implement a policy with respect to unverifiable mail, regardless of whether or not it applies the verification header field to signed messages โจ.
Verifiers MUST produce a result that is semantically equivalent to applying the steps listed in Sections 6.1, 6.1.1, and 6.1.2 in order. In practice, several of these steps can be performed in parallel to improve performance โก.
6.1. Extract Signatures from the Message
The order in which Verifiers try DKIM-Signature header fields is not defined, so Verifiers MAY try signatures in any order they like ๐. For example, one implementation might try the signatures in textual order, whereas another might try signatures by identities that match the contents of the From header field before trying other signatures. Verifiers MUST NOT attribute ultimate meaning to the order of multiple DKIM-Signature header fields. In particular, there is reason to believe that some relays will reorder the header fields in potentially arbitrary ways ๐.
INFORMATIVE IMPLEMENTATION NOTE: Verifiers might use the order as a clue to signing order in the absence of any other information. However, other clues as to the semantics of multiple signatures (such as correlating the signing host with Received header fields) might also be considered.
Survivability of signatures after transit is not guaranteed, and signatures can fail to verify through no fault of the Signer ๐ญ. Therefore, a Verifier SHOULD NOT treat a message that has one or more bad signatures and no good signatures differently from a message with no signature at all ๐ซถ.
When a signature successfully verifies, a Verifier will either stop processing or attempt to verify any other signatures, at the discretion of the implementation. A Verifier MAY limit the number of signatures it tries, in order to avoid denial-of-service attacks (see Section 8.4 for further discussion) ๐ก๏ธ.
In the following description, text reading "return status (explanation)" (where "status" is one of "PERMFAIL" or "TEMPFAIL") means that the Verifier MUST immediately cease processing that signature. The Verifier SHOULD proceed to the next signature, if one is present, and completely ignore the bad signature. If the status is "PERMFAIL", the signature failed and should not be reconsidered. If the status is "TEMPFAIL", the signature could not be verified at this time but may be tried again later. A Verifier MAY either arrange to defer the message for later processing or try another signature; if no good signature is found and any of the signatures resulted in a TEMPFAIL status, the Verifier MAY arrange to defer the message for later processing. The "(explanation)" is not normative text; it is provided solely for clarification ๐ .
Verifiers that are prepared to validate multiple signature header fields SHOULD proceed to the next signature header field, if one exists. However, Verifiers MAY make note of the fact that an invalid signature was present for consideration at a later step ๐.
INFORMATIVE NOTE: The rationale of this requirement is to permit messages that have invalid signatures but also a valid signature to work. For example, a mailing list exploder might opt to leave the original submitter signature in place even though the exploder knows that it is modifying the message in some way that will break that signature, and the exploder inserts its own signature. In this case, the message should succeed even in the presence of the known-broken signature ๐ฆ.
For each signature to be validated, the following steps should be performed in such a manner as to produce a result that is semantically equivalent to performing them in the indicated order ๐ธ.
6.1.1. Validate the Signature Header Field
Implementers MUST meticulously validate the format and values in the DKIM-Signature header field. Any inconsistency or unexpected values MUST cause the header field to be completely ignored and the Verifier to return PERMFAIL (signature syntax error). Being "liberal in what you accept" is definitely a bad strategy in this security context ๐จ. Note, however, that this does not include the existence of unknown tags in a DKIM-Signature header field, which are explicitly permitted ๐ง. Verifiers MUST return PERMFAIL (incompatible version) when presented a DKIM-Signature header field with a v= tag that is inconsistent with this specification.
INFORMATIVE IMPLEMENTATION NOTE: An implementation may, of course, choose to also verify signatures generated by older versions of this specification.
If any tag listed as "required" in Section 3.5 is omitted from the DKIM-Signature header field, the Verifier MUST ignore the DKIM-Signature header field and return PERMFAIL (signature missing required tag).
INFORMATIVE NOTE: The tags listed as required in Section 3.5 arev=,a=,b=,bh=,d=,h=, ands=. Should there be a conflict between this note and Section 3.5, Section 3.5 is normative.
If the DKIM-Signature header field does not contain the i= tag, the Verifier MUST behave as though the value of that tag were @d, where d is the value from the d= tag ๐.
Verifiers MUST confirm that the domain specified in the d= tag is the same as or a parent domain of the domain part of the i= tag. If not, the DKIM-Signature header field MUST be ignored, and the Verifier should return PERMFAIL (domain mismatch) ๐.
If the h= tag does not include the From header field, the Verifier MUST ignore the DKIM-Signature header field and return PERMFAIL (From field not signed) ๐.
Verifiers MAY ignore the DKIM-Signature header field and return PERMFAIL (signature expired) if it contains an x= tag and the signature has expired โณ.
Verifiers MAY ignore the DKIM-Signature header field if the domain used by the Signer in the d= tag is not associated with a valid signing entity. For example, signatures with d= values such as "com" and "co.uk" could be ignored. The list of unacceptable domains SHOULD be configurable ๐.
Verifiers MAY ignore the DKIM-Signature header field and return PERMFAIL (unacceptable signature header) for any other reason, for example, if the signature does not sign header fields that the Verifier views to be essential. As a case in point, if MIME header fields are not signed, certain attacks may be possible that the Verifier would prefer to avoid ๐ต๏ธโโ๏ธ.
6.1.2. Get the Public Key
The public key for a signature is needed to complete the verification process. The process of retrieving the public key depends on the query type as defined by the q= tag in the DKIM-Signature header field. Obviously, a public key need only be retrieved if the process of extracting the signature information is completely successful ๐.
Details of key management and representation are described in Section 3.6. The Verifier MUST validate the key record and MUST ignore any public-key records that are malformed ๐งพ.
NOTE: The use of a wildcard TXT RR that covers a queried DKIM domain name will produce a response to a DKIM query that is unlikely to be a valid DKIM key record. This problem is not specific to DKIM and applies to many other types of queries. Client software that processes DNS responses needs to take this problem into account.
When validating a message, a Verifier MUST perform the following steps in a manner that is semantically the same as performing them in the order indicated. In some cases, the implementation may parallelize or reorder these steps, as long as the semantics remain unchanged ๐งฉ:
- The Verifier retrieves the public key as described in Section 3.6 using the algorithm in the
q=tag, the domain from thed=tag, and the selector from thes=tag. - If the query for the public key fails to respond, the Verifier MAY seek a later verification attempt by returning TEMPFAIL (key unavailable).
- If the query for the public key fails because the corresponding key record does not exist, the Verifier MUST immediately return PERMFAIL (no key for signature).
- If the query for the public key returns multiple key records, the Verifier can choose one of the key records or may cycle through the key records, performing the remainder of these steps on each record at the discretion of the implementer. The order of the key records is unspecified. If the Verifier chooses to cycle through the key records, then the "return ..." wording in the remainder of this section means "try the next key record, if any; if none, return to try another signature in the usual way" ๐.
- If the result returned from the query does not adhere to the format defined in this specification, the Verifier MUST ignore the key record and return PERMFAIL (key syntax error). Verifiers are urged to validate the syntax of key records carefully to avoid attempted attacks. In particular, the Verifier MUST ignore keys with a version code (
v=tag) that they do not implement ๐ซ. - If the
h=tag exists in the public-key record and the hash algorithm implied by thea=tag in the DKIM-Signature header field is not included in the contents of theh=tag, the Verifier MUST ignore the key record and return PERMFAIL (inappropriate hash algorithm) ๐งช. - If the public-key data (the
p=tag) is empty, then this key has been revoked and the Verifier MUST treat this as a failed signature check and return PERMFAIL (key revoked). There is no defined semantic difference between a key that has been revoked and a key record that has been removed ๐. - If the public-key data is not suitable for use with the algorithm and key types defined by the
a=andk=tags in the DKIM-Signature header field, the Verifier MUST immediately return PERMFAIL (inappropriate key algorithm) ๐ โโ๏ธ.
6.1.3. Compute the Verification โจ
Okay bestie, verifying a signature is basically a checklist ๐๐ . Given a Signer and a public key, the steps below are semantically equivalent to what the verifier does, so you don't have to follow this exact order, but the result has to match.
- Using the algorithm from the
c=tag, the body length from thel=tag, and the header field names from theh=tag, make a canonicalized version of the message as described in Section 3.7. This copy is just for checking. It does not replace the original content ๐ โโ๏ธ. When you match the names in theh=tag against the real header fields, the comparison MUST be case-insensitive ๐ค. - Using the algorithm from the
a=tag, compute the message hashes from that canonical copy, as described in Section 3.7 ๐งฎ. - Check that the body hash you just computed matches the value in the
bh=tag. If it doesn't, the Verifier SHOULD ignore the signature and returnPERMFAIL(body hash did not verify) ๐. - Use the signature in the
b=tag to check it against the header hash, using the mechanism for the public-key algorithm named in thea=tag. If the signature doesn't validate, the Verifier SHOULD ignore the signature and returnPERMFAIL(signature did not verify) ๐ญ. - Otherwise, the signature has correctly verified โ .
INFORMATIVE IMPLEMENTER'S NOTE: Implementations might wish to start the public-key query at the same time as the hash calculation, since the public key isn't needed until the final decryption step ๐ง. Implementations may also verify the signature on the message header before checking that the body hash in the bh= tag matches the actual message body. However, if the body hash doesn't match, the entire signature must be considered to have failed ๐.
A body length in the l= tag limits how many bytes of the body get passed to the verification algorithm ๐. Anything past that limit isn't validated by DKIM at all ๐. So a Verifier might look at a message that has bytes beyond the indicated body length with suspicion ๐ต๏ธโโ๏ธ, and it can choose to treat the signature as invalid, for example by returning PERMFAIL (unsigned content). Main character energy for being careful ๐
.
If the algorithm gets this far, the verification has succeeded, and DKIM reports SUCCESS for this signature ๐๐ฆ.
6.2. Communicate Verification Results
Verifiers can share the results with other parts of the mail system however they like ๐ธ. For example, an implementation might add an email header field to the message before passing it along. Any header field like that SHOULD be inserted before any existing DKIM-Signature or preexisting authentication status header fields in the header field block ๐. The Authentication-Results: header field ([RFC5451]) MAY be used for this purpose โจ.
INFORMATIVE ADVICE to MUA filter writers: If you're writing patterns that look for results header fields so you can visibly mark authenticated mail for end users, you should check that the header field was added by the right verifying domain, and that the verified identity matches the author identity the MUA displays ๐. MUA filters shouldn't get fooled by fake results header fields added by attackers ๐ค. To shut that down, Verifiers MAY wish to request deletion of existing results header fields after verification and before adding a new one ๐งน.
6.3. Interpret Results/Apply Local Policy
What an Identity Assessor actually does with the results is out of scope for this spec ๐. Still, mail carrying a validated SDID gives an Identity Assessor an opportunity that unauthenticated email doesn't. An authenticated email creates a predictable identifier that other decisions, like trust and reputation, can reliably hang off of ๐ซถ. Unauthenticated email doesn't have a reliable identifier to attach trust or reputation to. So it's reasonable to treat unauthenticated email as having no trust and no positive reputation ๐ฅ.
In general, modules that use DKIM verification output SHOULD NOT decide whether a message is acceptable based only on a missing signature or an unverifiable signature ๐ โโ๏ธ. That kind of rejection would cause serious interoperability problems ๐ฅ. If an MTA does want to reject these messages during an SMTP session, say when it's talking to a peer who has agreed in advance to only send signed messages ๐ค, and a signature is missing or doesn't verify, the handling MTA SHOULD use a 550/5.7.x reply code ๐ซ.
If the Verifier is built into the MTA and it can't fetch the public key, maybe because the key server is down ๐ฅบ, a temporary failure message MAY be generated using a 451/4.7.5 reply code, like this:
451 4.7.5 Unable to verify signature - key server unavailable
Temporary failures, like not being able to reach the key server or another external service, are the only situations that SHOULD use a 4xx SMTP reply code โณ. Cryptographic signature verification failures MUST NOT provoke 4xx SMTP replies ๐จ. Those are permanent, not temporary, bestie.
Once the signature has been verified, that information MUST be passed on to the Identity Assessor (such as an explicit allow/whitelist or a reputation system) and/or to the end user ๐ฌ. If the SDID is not the same as the address in the From: header field, the mail system SHOULD take pains to make sure the reader can clearly see the actual SDID ๐โจ.
Figuring out a failure can be tricky even though the symptom is obvious, which is that the signature doesn't verify ๐ฉ. Was the selector missing because it got removed, or did the value get changed somehow in transit? If the signature line is gone, was it never there, or did an overzealous filter remove it? For diagnostic purposes, the exact reason the verification failed SHOULD be made available, and possibly recorded in the system logs ๐๐.
If an email can't be verified, it SHOULD be treated the same as all unverified email, whether or not it looks like it was signed ๐๐ซ .
See Section 8.15 for additional discussion ๐.
7. IANA Considerations ๐
DKIM has registered namespaces with IANA ๐๏ธ. In every case, new values are only assigned for values that have been documented in a published RFC that has IETF Consensus [RFC5226] ๐.
This memo updates these registries as described below โจ. The big new thing is a "status" column. Every registration into these namespaces MUST include the name being registered, the document where it was registered or updated, and an indication of its current status. That status MUST be one of "active" (in current use) or "historic" (no longer in current use) ๐ท๏ธ.
No new tags are defined in this specification compared to [RFC4871], but one has been marked as "historic" ๐ชฆ.
The "Email Authentication Methods" registry is also revised to point to this update ๐.
7.1. Email Authentication Methods Registry
The "Email Authentication Methods" registry is updated to show that "dkim" is defined in this memo ๐.
7.2. DKIM-Signature Tag Specifications
A DKIM-Signature gives you a list of tag specifications ๐. IANA has set up the "DKIM-Signature Tag Specifications" registry for tag specifications that can be used in DKIM-Signature fields ๐ .
+------+-----------------+--------+
| TYPE | REFERENCE | STATUS |
+------+-----------------+--------+
| v | (this document) | active |
| a | (this document) | active |
| b | (this document) | active |
| bh | (this document) | active |
| c | (this document) | active |
| d | (this document) | active |
| h | (this document) | active |
| i | (this document) | active |
| l | (this document) | active |
| q | (this document) | active |
| s | (this document) | active |
| t | (this document) | active |
| x | (this document) | active |
| z | (this document) | active |
+------+-----------------+--------+
Table 1: DKIM-Signature Tag Specifications Registry Updated Values
7.3. DKIM-Signature Query Method Registry
The q= tag-spec (specified in Section 3.5) gives you a list of query methods ๐. IANA has set up the "DKIM-Signature Query Method" registry for mechanisms that can be used to fetch the key needed to validate a message signed with DKIM ๐.
+------+--------+-----------------+--------+
| TYPE | OPTION | REFERENCE | STATUS |
+------+--------+-----------------+--------+
| dns | txt | (this document) | active |
+------+--------+-----------------+--------+
Table 2: DKIM-Signature Query Method Registry Updated Values
7.4. DKIM-Signature Canonicalization Registry
The c= tag-spec (specified in Section 3.5) gives you a specifier for the canonicalization algorithms used on the header and body of the message ๐งผ. IANA has set up the "DKIM-Signature Canonicalization Header" Registry for algorithms that convert a message into a canonical form before it's signed or verified with DKIM ๐ธ.
+---------+-----------------+--------+
| TYPE | REFERENCE | STATUS |
+---------+-----------------+--------+
| simple | (this document) | active |
| relaxed | (this document) | active |
+---------+-----------------+--------+
Table 3: DKIM-Signature Canonicalization Header Registry Updated
Values
+---------+-----------------+--------+
| TYPE | REFERENCE | STATUS |
+---------+-----------------+--------+
| simple | (this document) | active |
| relaxed | (this document) | active |
+---------+-----------------+--------+
Table 4: DKIM-Signature Canonicalization Body Registry Updated Values
7.5. _domainkey DNS TXT Resource Record Tag Specifications
okay so a _domainkey DNS TXT RR is basically a little list of tag specs ๐โจ IANA set up the DKIM "_domainkey DNS TXT Record Tag Specifications" registry for the tag specs that can live in DNS TXT resource records ๐
+------+-----------------+----------+
| TYPE | REFERENCE | STATUS |
+------+-----------------+----------+
| v | (this document) | active |
| g | [RFC4871] | historic |
| h | (this document) | active |
| k | (this document) | active |
| n | (this document) | active |
| p | (this document) | active |
| s | (this document) | active |
| t | (this document) | active |
+------+-----------------+----------+
Table 5: _domainkey DNS TXT Record Tag Specifications Registry Updated Values
7.6. DKIM Key Type Registry
the k= <key-k-tag> (specced in Section 3.6.1) and the a= <sig-a-tag-k> (specced in Section 3.5) tags both give you a list of mechanisms that can decode a DKIM signature ๐๐
IANA made the "DKIM Key Type" registry to hold those mechanisms ๐ธ
+------+-----------+--------+
| TYPE | REFERENCE | STATUS |
+------+-----------+--------+
| rsa | [RFC3447] | active |
+------+-----------+--------+
Table 6: DKIM Key Type Registry Updated Values
7.7. DKIM Hash Algorithms Registry
the h= <key-h-tag> (Section 3.6.1) and the a= <sig-a-tag-h> (Section 3.5) tags are the ones that give you a list of mechanisms for making a digest of message data ๐ง
IANA made the "DKIM Hash Algorithms" registry for exactly that ๐ฆ
+--------+-------------------+--------+
| TYPE | REFERENCE | STATUS |
+--------+-------------------+--------+
| sha1 | [FIPS-180-3-2008] | active |
| sha256 | [FIPS-180-3-2008] | active |
+--------+-------------------+--------+
Table 7: DKIM Hash Algorithms Registry Updated Values
7.8. DKIM Service Types Registry
the s= <key-s-tag> tag (Section 3.6.1) lists the service types this selector might apply to ๐
IANA made the "DKIM Service Types" registry for service types โจ
+-------+-----------------+--------+
| TYPE | REFERENCE | STATUS |
+-------+-----------------+--------+
| email | (this document) | active |
| * | (this document) | active |
+-------+-----------------+--------+
Table 8: DKIM Service Types Registry Updated Values
7.9. DKIM Selector Flags Registry
the t= <key-t-tag> tag (Section 3.6.1) gives you a list of flags that tweak how the selector gets read ๐
IANA made the "DKIM Selector Flags" registry for those extra flags ๐
+------+-----------------+--------+
| TYPE | REFERENCE | STATUS |
+------+-----------------+--------+
| y | (this document) | active |
| s | (this document) | active |
+------+-----------------+--------+
Table 9: DKIM Selector Flags Registry Updated Values
7.10. DKIM-Signature Header Field
IANA added DKIM-Signature to the "Permanent Message Header Field Names" registry (see [RFC3864]) for the "mail" protocol, and this document is the reference ๐๐ซถ
8. Security Considerations
bestie, this section is SERIOUS ๐ญ๐ฅ it's giving "hacker movie" energy, so read it carefully.
It has been observed that any new mechanism trying to stop the flow of spam is going to get hit with intense attacks ๐ DKIM needs a careful look so we can find the possible attack vectors and how vulnerable it is to each one. See also [RFC4686].
8.1. ASCII Art Attacks
ngl this one is kinda wild ๐ the relaxed body canonicalization algorithm might allow some super crude "ASCII Art" attacks, where a message gets its meaning from how the spacing between words is adjusted. If that's a worry for you, the "simple" body canonicalization algorithm should be used instead ๐
8.2. Misuse of Body Length Limits ("l=" Tag)
highkey, the l= tag can let fraudulent content show up without any proper warning for end users ๐ฑ The l= tag is meant to make signatures more robust when mail goes to mailing lists that both change the content and don't sign their modified messages. BUT using the l= tag also opens the door for attacks, where a sneaky intermediary with bad intentions edits a message to add content that only helps the attacker ๐ The appended content can totally replace the original content in the end recipient's eyes, and it can get past duplicate message detection algorithms too.
One example of this kind of attack is messing with the MIME structure, taking advantage of lax HTML parsing in the MUA, and getting past duplicate message detection algorithms ๐ธ๏ธ
To dodge this attack, Signers should be extremely wary of using this tag, and Assessors might wish to ignore signatures that use the tag ๐ก๏ธ
8.3. Misappropriated Private Key
as with any security app that uses private/public key pairs, DKIM needs real caution around how keys get handled and protected ๐ A compromised private key, or just access to one, means an intruder or malware can send mail signed by the domain that publishes the matching public key ๐ฐ
so private keys handed out to individual users, instead of one used by an ADministrative Management Domain (ADMD) itself, bring the usual headache of securing data on personal resources that can still affect the ADMD ๐ป
A more secure setup involves sending messages through an outgoing MTA that can authenticate the submitter with existing techniques (e.g., SMTP Authentication), possibly validate the message itself (e.g., check that the header is legit and that the content passes a spam content check), and sign the message with a key that fits the submitter's address โจ That kind of MTA can also limit how much outgoing mail each user is allowed to send, which helps cut down how much bulk email malware can churn out ๐ช
8.4. Key Server Denial-of-Service Attacks
the key servers are distributed (and could be separate for each domain), so the number of servers someone would have to attack to break this mechanism Internet-wide is very large ๐ Still, key servers for individual domains could get attacked, which would slow down verification of messages from that domain ๐ค That's not hugely different from an attacker denying service to the mail exchangers for a domain, except this one affects outgoing mail instead of incoming ๐ค
there's also a variation where a huge amount of mail gets sent using spoofed signatures from a domain, and the key servers for that domain get swamped with requests in a denial-of-service attack (see [RFC4732]) ๐ญ BUT verification has low overhead compared to handling the email message itself, so an attack like that would be pretty hard to pull off ๐
8.5. Attacks against the DNS
bestie, the DNS is a required binding for key services, so specific attacks against the DNS have to be considered ๐ง
the DNS is currently insecure [RFC3833], and these security problems are the reason DNS Security (DNSSEC) [RFC4033] exists, so every DNS user gets to benefit from that work ๐
DKIM is only meant to be a "sufficient" method of proving authenticity ๐ซถ It's not designed to give strong cryptographic proof about who wrote something or what it says. OpenPGP [RFC4880] and S/MIME [RFC5751] handle those needs instead ๐
a second DNS security issue is the extra DNS traffic from fetching selector-based data and also fetching signing domain policy ๐ Widespread DKIM deployment will cause a big jump in DNS queries to the claimed signing domain. If forgeries happen at large scale, DNS servers could see a serious spike in queries ๐ฑ
one specific DNS security issue DKIM Verifiers should think about is the name chaining attack described in Section 2.3 of [RFC3833] ๐ท๏ธ A DKIM Verifier, while checking a DKIM-Signature header field, could get tricked into fetching a key record the attacker picked. This threat can be cut down by making sure the name servers the Verifier uses, including recursive name servers, strictly check "glue" and other additional information in DNS responses, so they aren't vulnerable to this attack ๐ก๏ธ
8.6. Replay/Spam Attacks
this one is a classic ๐ A spammer sends a piece of spam through an MTA that signs it, banking on the reputation of the signing domain (e.g., a big popular mailbox provider) instead of their own. Then they re-send that message to a huge number of intended recipients. The recipients see the valid signature from the well-known domain, which boosts their trust in the message and makes it more likely to get delivered and shown to the user ๐ฌ
some partial fixes involve reputation services that share the fact that a specific email address is being used for spam, and that messages from that Signer are likely to be spam. This needs real-time detection to react fast enough โก But those measures might be open to abuse. For example, an attacker could re-send a bunch of messages received from a victim just to make the victim look like a spammer ๐ค
Large Verifiers might be able to spot unusually large volumes of mail with the same signature in a short time period ๐ Smaller Verifiers can get basically the same info through existing collaborative systems ๐ค
8.7. Limits on Revoking Keys
when a big domain catches one of its users doing something undesirable, it might want to revoke the key that signs that user's messages, to disavow responsibility for messages that haven't been verified yet or that are part of a replay attack ๐ โโ๏ธ BUT the domain's ability to do that can be limited if the same key is used to sign messages for lots of other users, because of scalability reasons ๐ฌ Mechanisms for explicitly revoking keys on a per-address basis have been proposed, but they need more study to figure out how useful they are and what DNS load they'd create ๐ง
8.8. Intentionally Malformed Key Records
okay this is the scary one ๐ An attacker can publish key records in DNS that are intentionally malformed, aiming to cause a denial-of-service attack on a non-robust Verifier implementation. The attacker can then get a Verifier to read the malformed key record just by sending a message to one of its users that references the malformed record in a (not necessarily valid) signature ๐ฑ So Verifiers MUST thoroughly verify all key records retrieved from the DNS, and they MUST be robust against intentionally as well as unintentionally malformed key records ๐ก๏ธ๐ฅ
8.9. Intentionally Malformed DKIM-Signature Header Fields ๐
okay so verifiers MUST be prepared to get messages with malformed DKIM-Signature header fields, and they MUST thoroughly check the header field before trusting any of its contents ๐ซถ no shortcuts, bestie!
8.10. Information Leakage ๐ต๏ธโโ๏ธ
this one is kinda sneaky ngl ๐ an attacker could figure out when a particular signature got verified by using a per-message selector and then watching their DNS traffic for the key lookup. it's giving "web bug" but for the verification time instead of the time the message was actually read ๐ญ
8.11. Remote Timing Attacks โฑ๏ธ
in some cases it may be possible to pull out private keys using a remote timing attack [BONEH03] ๐ implementations should consider obfuscating the timing to prevent these attacks. lowkey a must-think-about moment ๐ง
8.12. Reordered Header Fields ๐
existing standards let intermediate MTAs reorder header fields, which is so chaotic ๐ if a Signer signs two or more header fields of the same name, that can cause spurious verification errors on messages that are totally legit. especially for Signers that sign any existing DKIM-Signature fields: they run the risk of having messages incorrectly fail to verify ๐ญ not fair!!
8.13. RSA Attacks ๐งฎ
an attacker could create a large RSA signing key with a small exponent, which means the verification key has to have a large exponent. this forces Verifiers to burn a lot of computing resources to verify the signature ๐ฅ Verifiers might avoid this by refusing to verify signatures that reference selectors with public keys that have unreasonable exponents. smart!
in general, an attacker might try to overwhelm a Verifier by flooding it with messages that need verifying. this is similar to other MTA denial-of-service attacks, so it should be dealt with in a similar way ๐
8.14. Inappropriate Signing by Parent Domains ๐ณ
the trust relationship from Section 3.10 could conceivably be used by a parent domain to sign messages with identities in a subdomain that isn't administratively related to the parent. for example, the ".com" registry could create messages with signatures using an i= value in the example.com domain ๐ซ there's no general solution to this problem, since the administrative cut could happen anywhere in the domain name. like, in "example.podunk.ca.us" there are three administrative cuts (podunk.ca.us, ca.us, and us), and any of them could create messages with an identity in the full domain ๐คฏ
INFORMATIVE NOTE: This is considered an acceptable risk for the same reason that it is acceptable for domain delegation. For example, in the case above, any of the domains could potentially simply delegate "example.podunk.ca.us" to a server of their choice and completely replace all DNS-served information. Note that a Verifier MAY ignore signatures that come from an unlikely domain such as ".com", as discussed in Section 6.1.1. โจ
8.15. Attacks Involving Extra Header Fields ๐จ
so many email components (MTAs, MSAs, MUAs, and filtering modules) only check message format loosely ๐ that's from years of industry pressure to be liberal about what gets into the mail stream, so support costs stay low. improperly formed messages often get silently fixed in transit, delivered unrepaired, or displayed weirdly (like only showing the first of multiple From: fields) ๐
agents that evaluate or apply DKIM output need to be aware that a DKIM Signer can sign messages that are malformed (for example, they violate [RFC5322] by having multiple instances of a field that's only allowed once), that become malformed in transit, or that contain header or body content that isn't true or valid. using DKIM on those messages might be an attack on a receiver, especially when extra credence gets given to a signed message without proper evaluation of the Signer ๐ค
these can be serious attacks, but they have nothing to do with DKIM. they're attacks on the recipient or on the wrongly identified author ๐ฅบ
also, an agent would be wrong to assume that every instance of a header field is signed just because one of them is ๐ โโ๏ธ
a genuine signature from the domain under attack can be obtained by legitimate means, but extra header fields can then be added, either by interception or by replay. in this situation DKIM can help detect the addition of specific fields in transit ๐ต๏ธ the way it works is the Signer lists the field name(s) in the h= tag an extra time (for example, h=from:from:... for a message with one From field), so adding an instance of that field downstream will make the signature impossible to verify. (see Section 3.5 for details.) in essence, this is an explicit signal that the Signer disowns responsibility for that malformed message ๐ซก
DKIM signs and validates the data it's told to and works correctly. so in this case DKIM has done its job of delivering a validated domain (the "d=" value). and given what a DKIM signature means, the Signer has basically taken some responsibility for a problematic message ๐ฌ it's up to the Identity Assessor or some other later agent to act on these messages as needed, like lowering the trust in the message (or even the Signer), warning the recipient, or refusing delivery altogether ๐ซ
all components of the mail system that loosely enforce other mail standards will need to revisit that posture when they bring in DKIM, especially when thinking about potential attacks like the ones described here ๐
9. References ๐
9.1. Normative References ๐
- [FIPS-180-3-2008] U.S. Department of Commerce, "Secure Hash Standard", FIPS PUB 180-3, October 2008.
- [ITU-X660-1997] "Information Technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)", 1997.
- [RFC1034] Mockapetris, P., "Domain names - concepts and facilities", STD 13, RFC 1034, November 1987.
- [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", RFC 2045, November 1996.
- [RFC2049] Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples", RFC 2049, November 1996.
- [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
- [RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1", RFC 3447, February 2003.
- [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, January 2008.
- [RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321, October 2008.
- [RFC5322] Resnick, P., Ed., "Internet Message Format", RFC 5322, October 2008.
- [RFC5598] Crocker, D., "Internet Mail Architecture", RFC 5598, July 2009.
- [RFC5890] Klensin, J., "Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework", RFC 5890, August 2010.
9.2. Informative References ๐ธ
- [BONEH03] "Remote Timing Attacks are Practical", Proceedings 12th USENIX Security Symposium, 2003.
- [RFC2047] Moore, K., "MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text", RFC 2047, November 1996.
- [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, November 2003.
- [RFC3766] Orman, H. and P. Hoffman, "Determining Strengths For Public Keys Used For Exchanging Symmetric Keys", BCP 86, RFC 3766, April 2004.
- [RFC3833] Atkins, D. and R. Austein, "Threat Analysis of the Domain Name System (DNS)", RFC 3833, August 2004.
- [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration Procedures for Message Header Fields", BCP 90, RFC 3864, September 2004.
- [RFC4033] Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, "DNS Security Introduction and Requirements", RFC 4033, March 2005.
- [RFC4409] Gellens, R. and J. Klensin, "Message Submission for Mail", RFC 4409, April 2006.
- [RFC4686] Fenton, J., "Analysis of Threats Motivating DomainKeys Identified Mail (DKIM)", RFC 4686, September 2006.
- [RFC4732] Handley, M., Rescorla, E., and IAB, "Internet Denial-of-Service Considerations", RFC 4732, December 2006.
- [RFC4870] Delany, M., "Domain-Based Email Authentication Using Public Keys Advertised in the DNS (DomainKeys)", RFC 4870, May 2007.
- [RFC4871] Allman, E., Callas, J., Delany, M., Libbey, M., Fenton, J., and M. Thomas, "DomainKeys Identified Mail (DKIM) Signatures", RFC 4871, May 2007.
- [RFC4880] Callas, J., Donnerhacke, L., Finney, H., Shaw, D., and R. Thayer, "OpenPGP Message Format", RFC 4880, November 2007.
- [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 5226, May 2008.
- [RFC5451] Kucherawy, M., "Message Header Field for Indicating Message Authentication Status", RFC 5451, April 2009.
- [RFC5585] Hansen, T., Crocker, D., and P. Hallam-Baker, "DomainKeys Identified Mail (DKIM) Service Overview", RFC 5585, July 2009.
- [RFC5672] Crocker, D., "RFC 4871 DomainKeys Identified Mail (DKIM) Signatures -- Update", RFC 5672, August 2009.
- [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet Mail Extensions (S/MIME) Version 3.2 Message Specification", RFC 5751, January 2010.
- [RFC5863] Hansen, T., Siegel, E., Hallam-Baker, P., and D. Crocker, "DomainKeys Identified Mail (DKIM) Development, Deployment, and Operations", RFC 5863, May 2010.
- [RFC6377] Kucherawy, M., "DomainKeys Identified Mail (DKIM) and Mailing Lists", RFC 6377, September 2011.
Appendix A. Example of Use (INFORMATIVE) ๐
this section walks through the complete flow of an email from submission all the way to final delivery, showing how all the pieces fit together ๐งฉ the key used in this example is shown in Appendix C. ๐
A.1. The User Composes an Email โ๏ธ
From: Joe SixPack <joe@football.example.com>
To: Suzie Q <suzie@shopping.example.net>
Subject: Is dinner ready?
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
Message-ID: <20030712040037.46341.5F8J@football.example.com>
Hi.
We lost the game. Are you hungry yet?
Joe.
Figure 1: The User Composes an Email ๐
A.2. The Email is Signed โจ
Okay so the example.com outbound email server signs this email, and now it looks like this ๐ง
DKIM-Signature: v=1; a=rsa-sha256; s=brisbane; d=example.com;
c=simple/simple; q=dns/txt; i=joe@football.example.com;
h=Received : From : To : Subject : Date : Message-ID;
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB
4nujc7YopdG5dWLSdNg6xNAZpOPr+kHxt1IrE+NahM6L/LbvaHut
KVdkLLkpVaVVQPzeRDI009SO2Il5Lu7rDNH6mZckBdrIx0orEtZV
4bmp/YzhwvcubU4=;
Received: from client1.football.example.com [192.0.2.1]
by submitserver.example.com with SUBMISSION;
Fri, 11 Jul 2003 21:01:54 -0700 (PDT)
From: Joe SixPack <joe@football.example.com>
To: Suzie Q <suzie@shopping.example.net>
Subject: Is dinner ready?
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
Message-ID: <20030712040037.46341.5F8J@football.example.com>
Hi.
We lost the game. Are you hungry yet?
Joe.
Figure 2: The Email is Signed
The signing email server needs access to the private key tied to the "brisbane" selector to make this signature. Main character energy for that key ๐๐
A.3. The Email Signature is Verified ๐
The signature is usually verified by an inbound SMTP server or maybe the final delivery agent. BUT intervening MTAs can also do the verification if they want to ๐ The verification process takes the domain "example.com" from the d= tag and the selector "brisbane" from the s= tag in the DKIM-Signature header field, and uses them to form the DNS DKIM query for:
brisbane._domainkey.example.com
Signature verification starts with the physically last Received header field, then the From header field, and so on, in the order listed in the h= tag. Then it moves on to a single CRLF followed by the body (starting with "Hi."). The email gets canonically prepared for verifying with the "simple" method. The result of the query and the signature check gets stored (in this example) in the X-Authentication-Results header field line. After a successful verification, the email looks like this ๐
X-Authentication-Results: shopping.example.net
header.from=joe@football.example.com; dkim=pass
Received: from mout23.football.example.com (192.168.1.1)
by shopping.example.net with SMTP;
Fri, 11 Jul 2003 21:01:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; s=brisbane; d=example.com;
c=simple/simple; q=dns/txt; i=joe@football.example.com;
h=Received : From : To : Subject : Date : Message-ID;
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB
4nujc7YopdG5dWLSdNg6xNAZpOPr+kHxt1IrE+NahM6L/LbvaHut
KVdkLLkpVaVVQPzeRDI009SO2Il5Lu7rDNH6mZckBdrIx0orEtZV
4bmp/YzhwvcubU4=;
Received: from client1.football.example.com [192.0.2.1]
by submitserver.example.com with SUBMISSION;
Fri, 11 Jul 2003 21:01:54 -0700 (PDT)
From: Joe SixPack <joe@football.example.com>
To: Suzie Q <suzie@shopping.example.net>
Subject: Is dinner ready?
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
Message-ID: <20030712040037.46341.5F8J@football.example.com>
Hi.
We lost the game. Are you hungry yet?
Joe.
Figure 3: Successful Verification
Appendix B. Usage Examples (INFORMATIVE) ๐ธ
DKIM signing and validating can be used in different ways, for different operational scenarios. This Appendix talks through some common examples, so let's go ๐
NOTE: Descriptions in this Appendix are for informational purposes only. They describe various ways that DKIM can be used, given particular constraints and needs. In no case are these examples intended to be taken as providing explanation or guidance concerning DKIM specification details when creating an implementation.
B.1. Alternate Submission Scenarios ๐ฎ
In the most simple scenario, a user's MUA, MSA, and Internet (boundary) MTA are all in the same administrative environment, using the same domain name. So all of the components involved in submission and initial transfer are related. Lowkey easy. BUT it's pretty common for two or more of those components to be under independent administrative control, and that creates challenges for choosing and administering the domain name to use for signing, and for how it relates to the common email identity header fields ๐ญ
B.1.1. Delegated Business Functions ๐งพ
Some organizations hand specific business functions to discrete groups, inside or outside the organization. The goal is to authorize that group to sign some mail, but to constrain what signatures they can generate. DKIM selectors (the "s=" signature tag) make this kind of restricted authorization possible. Examples of these outsourced business functions are legitimate email marketing providers and corporate benefits providers.
Here, the delegated group needs to be able to send messages that are signed, using the email domain of the client company. At the same time, the client is often reluctant to register a key for the provider that grants the ability to send messages for arbitrary addresses in the domain. Understandable, honestly ๐
There are multiple ways to administer these usage scenarios. In one case, the client organization handles all of the public query service (for example, DNS) administration. In another, it uses DNS delegation so the delegated group can handle all ongoing administration of the DKIM key record.
If the client organization keeps responsibility for all of the DNS administration, the outsourcing company can generate a key pair, then give the public key to the client company, which registers it in the query service using a unique selector. The client company stays in control of the delegated key, because it can revoke the key at any time ๐
If the client wants the delegated group to do the DNS administration, it can have the domain name specified with the selector point to the provider's DNS server. The provider then creates and maintains all of the DKIM signature information for that selector. So the client cannot put constraints on the local-part of addresses that get signed, but it can revoke the provider's signing rights by removing the DNS delegation record ๐
B.1.2. PDAs and Similar Devices ๐ฑ
PDAs show why you'd want multiple keys per domain ๐ซถ Say John Doe wants to send messages using his corporate email address, jdoe@example.com, but his email device can't make a Virtual Private Network (VPN) connection to the corporate network. That could be because the device is limited, or because his Internet access provider enforces restrictions. If the device has a private key registered for jdoe@example.com by the administrator of the example.com domain, plus software that can sign messages, John could sign the message on the device itself before it goes out through the outgoing network of the access service provider. Iconic ๐
B.1.3. Roaming Users โ๏ธ
Roaming users often end up in situations where it's convenient or necessary to use an SMTP server other than their home server. Examples are conferences and many hotels. In those cases, a signature added by the submission service will use an identity that's different from the user's home system.
Ideally, roaming users would connect back to their home server using either a VPN or a SUBMISSION server running with SMTP AUTHentication on port 587. If the signing can happen on the roaming user's laptop, they can sign before submission, although the risk of further modification is high. If neither of those is possible, these roaming users won't be able to send mail signed with their own domain key. Not ideal, bestie ๐ฅบ
B.1.4. Independent (Kiosk) Message Submission ๐ฅ๏ธ
Stand-alone services, like walk-up kiosks and web-based information services, have no lasting email service relationship with the user. But users sometimes ask for mail to be sent on their behalf. For example, a news website often lets the reader forward a copy of an article to a friend. This is usually done with the reader's own email address, to show who the author is. This is sometimes called the "Evite" problem, named after the website of the same name that lets a user send invitations to friends ๐
A common way to handle this is to keep the reader's email address in the From header field of the message, but put an address owned by the email posting site into the Sender header field. The posting site can then sign the message, using the domain that is in the Sender field. This gives the receiving email site useful information, because it can correlate the signing domain with the initial submission email role ๐ง
Receiving sites often want to tell their end users about mail that is mediated this way. Although the real efficacy of different approaches is a subject for human factors usability research, one technique is for the verifying system to rewrite the From header field to show the address that was verified. For example: From: John Doe via news@news-site.example <jdoe@example.com>. (Note that such rewriting will break a signature, unless it is done after the verification pass is complete.) Heads up, this one's a sneaky trap ๐โ ๏ธ
B.2. Alternate Delivery Scenarios ๐ฌ
Email is often received at a mailbox with an address that's different from the one used during initial submission. In these cases, an intermediary mechanism operates at the address originally used, and then passes the message on to the final destination. This mediation process presents some challenges for DKIM signatures ๐
B.2.1. Affinity Addresses ๐
"Affinity addresses" let a user have an email address that stays stable, even as they move between different email providers. They're typically tied to college alumni associations, professional organizations, and recreational organizations that the user expects a long-term relationship with. These domains usually forward incoming email, and they often have an associated Web application that authenticates the user and lets them change the forwarding address. However, these services usually depend on users sending outgoing messages through their own service provider's MTAs. So mail signed with the domain of the affinity address isn't signed by an entity administered by the organization that owns that domain ๐ฅน
With DKIM, affinity domains could use the Web application to let users register per-user keys, to sign messages on behalf of their affinity address. The user would take away the secret half of the key pair for signing, and the affinity domain would publish the public half in DNS for access by Verifiers โจ
This is another application that takes advantage of user-level keying, and domains used for affinity addresses would typically have a very large number of user-level keys. Alternatively, the affinity domain could handle outgoing mail, running a mail submission agent that authenticates users before accepting and signing messages for them. Of course, this depends on the user's service provider not blocking the relevant TCP ports used for mail submission. Big if, but that's the plan ๐ซถ๐
B.2.2. Simple Address Aliasing (.forward) ๐
okay so sometimes a recipient is allowed to set up an email address so messages get automatically redirected from the original address to another one, like with a Unix .forward file ๐ฌ. In that case, the mail handling service of the recipient's domain usually passes the message along without changing it, except it adds a Received header field and swaps out the envelope recipient address ๐ฆ. So the person at the final mailbox can usually still verify the original signature, bc the signed content hasn't changed, and DKIM can validate the message signature โจ. Slay, no cap ๐
B.2.3. Mailing Lists and Re-Posters ๐ฃ
ngl this section is messy in the best way ๐ญ. There's a whole range of behaviours for services that take in a message and then resubmit it. The main example is mailing lists (the original calls them "forwarders" below, so I will too ๐). They go from ones that don't touch the message at all, except adding a Received header field and changing the envelope info, all the way to ones that add header fields, change the Subject header field, stick content onto the body (usually at the end), or reformat the body somehow ๐. The simple ones end up looking a lot like those automated alias services. The fancier systems basically make a brand new message ๐
A Forwarder that doesn't modify the body or signed header fields of a message is likely to keep the existing signature valid ๐ซถ. It could also choose to add its own signature to the message โจ.
Forwarders that change a message in a way that could make an existing signature invalid are the ones that really should add their own signatures (for example, mailing-list-name@example.net) ๐ฅ. Signing means taking responsibility for the content, so these signing forwarders tend to be picky. They only forward or re-sign a message if it came in with a valid signature, or if they have some other basis for knowing it isn't spoofed ๐ง.
A common move for systems that are mostly redistributors of mail is to add a Sender header field to the message, which identifies the address being used to sign it ๐
. This practice removes any Sender header field that was already there, as required by [RFC5322] ๐. The forwarder then applies a new DKIM-Signature header field with the signature, public key, and related info of the forwarder ๐.
See [RFC6377] for additional related topics and discussion ๐ธ.
Appendix C. Creating a Public Key (INFORMATIVE) ๐
The default signature is an RSA-signed SHA-256 digest of the complete email ๐. To make things easier to follow, the openssl command is used to describe how keys and signatures get managed ๐ ๏ธ. One way to generate a 1024-bit, unencrypted private key suitable for DKIM is to use openssl like this:
$ openssl genrsa -out rsa.private 1024
For extra security, the -passin parameter can also be added to encrypt the private key ๐. Heads up: using it means you'll be typing in a password for several of the following steps ๐. Servers may prefer to use hardware cryptographic support ๐.
The genrsa step results in a file called rsa.private containing key info that looks similar to this ๐๏ธ:
-----BEGIN RSA PRIVATE KEY-----
MIICXwIBAAKBgQDwIRP/UC3SBsEmGqZ9ZJW3/DkMoGeLnQg1fWn7/zYtIxN2SnFC
jxOCKG9v3b4jYfcTNh5ijSsq631uBItLa7od+v/RtdC2UzJ1lWT947qR+Rcac2gb
to/NMqJ0fzfVjH4OuKhitdY9tf6mcwGjaNBcWToIMmPSPDdQPNUYckcQ2QIDAQAB
AoGBALmn+XwWk7akvkUlqb+dOxyLB9i5VBVfje89Teolwc9YJT36BGN/l4e0l6QX
/1//6DWUTB3KI6wFcm7TWJcxbS0tcKZX7FsJvUz1SbQnkS54DJck1EZO/BLa5ckJ
gAYIaqlA9C0ZwM6i58lLlPadX/rtHb7pWzeNcZHjKrjM461ZAkEA+itss2nRlmyO
n1/5yDyCluST4dQfO8kAB3toSEVc7DeFeDhnC1mZdjASZNvdHS4gbLIA1hUGEF9m
3hKsGUMMPwJBAPW5v/U+AWTADFCS22t72NUurgzeAbzb1HWMqO4y4+9Hpjk5wvL/
eVYizyuce3/fGke7aRYw/ADKygMJdW8H/OcCQQDz5OQb4j2QDpPZc0Nc4QlbvMsj
7p7otWRO5xRa6SzXqqV3+F0VpqvDmshEBkoCydaYwc2o6WQ5EBmExeV8124XAkEA
qZzGsIxVP+sEVRWZmW6KNFSdVUpk3qzK0Tz/WjQMe5z0UunY9Ax9/4PVhp/j61bf
eAYXunajbBSOLlx4D+TunwJBANkPI5S9iylsbLs6NkaMHV6k5ioHBBmgCak95JGX
GMot/L2x0IYyMLAz6oLWh2hm7zwtb0CgOrPo1ke44hFYnfc=
-----END RSA PRIVATE KEY-----
To pull out the public-key component from the private key, use openssl like this ๐ช:
$ openssl rsa -in rsa.private -out rsa.public -pubout -outform PEM
That gives you a file called rsa.public with key info that looks similar to this โจ:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDwIRP/UC3SBsEmGqZ9ZJW3/DkM
oGeLnQg1fWn7/zYtIxN2SnFCjxOCKG9v3b4jYfcTNh5ijSsq631uBItLa7od+v/R
tdC2UzJ1lWT947qR+Rcac2gbto/NMqJ0fzfVjH4OuKhitdY9tf6mcwGjaNBcWToI
MmPSPDdQPNUYckcQ2QIDAQAB
-----END PUBLIC KEY-----
This public-key data (without the BEGIN and END tags) goes into the DNS ๐:
$ORIGIN _domainkey.example.org.
brisbane IN TXT ("v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQ"
"KBgQDwIRP/UC3SBsEmGqZ9ZJW3/DkMoGeLnQg1fWn7/zYt"
"IxN2SnFCjxOCKG9v3b4jYfcTNh5ijSsq631uBItLa7od+v"
"/RtdC2UzJ1lWT947qR+Rcac2gbto/NMqJ0fzfVjH4OuKhi"
"tdY9tf6mcwGjaNBcWToIMmPSPDdQPNUYckcQ2QIDAQAB")
C.1. Compatibility with DomainKeys Key Records ๐๏ธ
DKIM key records were designed to be backward compatible in many cases with the key records used by DomainKeys [RFC4870] (sometimes called "selector records" in the DomainKeys context) ๐. One area of incompatibility deserves special attention ๐. The g= tag may be used in DomainKeys and [RFC4871] key records to give finer granularity over the validity of a key record for a specific local-part ๐. A null g= value in DomainKeys is valid for all addresses in the domain. This differs from the usage in the original DKIM specification ([RFC4871]), where a null g= value is not valid for any address ๐. For the example public-key record, see Section 3.2.3 of [RFC4870] ๐.
C.2. RFC 4871 Compatibility ๐
Although the g= tag has been deprecated in this version of the DKIM specification (and so it MUST now be ignored), Signers are advised not to include the g= tag in key records ๐
. That's because some [RFC4871]-compliant Verifiers will be in use for a considerable period to come โณ.
Appendix D. MUA Considerations (INFORMATIVE) ๐ฑ
When a DKIM signature is verified, the processing system sometimes makes the result available to the recipient user's MUA ๐. How to present this info in a way that actually helps people is still a matter of ongoing human factors usability research ๐ง . The tendency is to have the MUA highlight the SDID, so the user can see which identity is claiming responsibility for the message ๐. An MUA might do this with visual cues like graphics, might include the address in an alternate view, or might even rewrite the original From address using the verified info โจ. Some MUAs might indicate which header fields were protected by the validated DKIM signature ๐ก๏ธ. This could be done with a positive indication on the signed header fields, a negative indication on the unsigned header fields, by visually hiding the unsigned header fields, or some combo of these ๐
. If an MUA uses visual indications for signed header fields, it probably needs to be careful not to display unsigned header fields in a way the end user might think were signed ๐. If the message has an l= tag whose value does not extend to the end of the message, the MUA might also hide or mark the portion of the message body that was not signed ๐ฉ.
The information above is not meant to be exhaustive ๐ธ. The MUA can choose to highlight, accentuate, hide, or otherwise display any other information that the MUA author thinks is important to the end user ๐ฆ.
Appendix E. Changes since RFC 4871 ๐
- Abstract and introduction refined based on accumulated experience โจ.
- Various references updated.
- Several errata resolved (see
http://www.rfc-editor.org/):- 1376 applied
- 1377 applied
- 1378 applied
- 1379 applied
- 1380 applied
- 1381 applied
- 1382 applied
- 1383 discarded (no longer applies)
- 1384 applied
- 1386 applied
- 1461 applied
- 1487 applied
- 1532 applied
- 1596 applied
- Introductory section enumerating relevant architectural documents added.
- Introductory section briefly discussing the matter of data integrity added.
- Allowed tolerance of some clock drift.
- Dropped
g=tag from key records. The implementation report indicates that it is not in use. - Removed errant note about wildcards in the DNS.
- Removed SMTP-specific advice in most places.
- Reduced (non-normative) recommended signature content list, and reworked the text in that section.
- Clarified signature generation algorithm by rewriting its pseudo-code.
- Numerous terminology subsections added, imported from [RFC5672]. Also, began using these terms throughout the document (e.g., SDID, AUID).
- Sections added that specify input and output requirements. Input requirements address a security concern raised by the working group (see also new sections in Security Considerations). Output requirements are imported from [RFC5672].
- Appendix subsection added discussing compatibility with DomainKeys ([RFC4870]) records.
- Referred to [RFC5451] as an example method of communicating the results of DKIM verification.
- Removed advice about possible uses of the
l=signature tag. - IANA registry updated.
- Added two new Security Considerations sections talking about malformed message attacks.
- Various copy editing.
Appendix F. Acknowledgments ๐
The previous IETF version of DKIM [RFC4871] was edited by Eric Allman, Jon Callas, Mark Delany, Miles Libbey, Jim Fenton, and Michael Thomas ๐ซ.
That specification was the result of an extended collaborative effort, including participation by Russ Allbery, Edwin Aoki, Claus Assmann, Steve Atkins, Rob Austein, Fred Baker, Mark Baugher, Steve Bellovin, Nathaniel Borenstein, Dave Crocker, Michael Cudahy, Dennis Dayman, Jutta Degener, Frank Ellermann, Patrik Faeltstroem, Mark Fanto, Stephen Farrell, Duncan Findlay, Elliot Gillum, Olafur Gudmundsson, Phillip Hallam-Baker, Tony Hansen, Sam Hartman, Arvel Hathcock, Amir Herzberg, Paul Hoffman, Russ Housley, Craig Hughes, Cullen Jennings, Don Johnsen, Harry Katz, Murray S. Kucherawy, Barry Leiba, John Levine, Charles Lindsey, Simon Longsdale, David Margrave, Justin Mason, David Mayne, Thierry Moreau, Steve Murphy, Russell Nelson, Dave Oran, Doug Otis, Shamim Pirzada, Juan Altmayer Pizzorno, Sanjay Pol, Blake Ramsdell, Christian Renaud, Scott Renfro, Neil Rerup, Eric Rescorla, Dave Rossetti, Hector Santos, Jim Schaad, the Spamhaus.org team, Malte S. Stretz, Robert Sanders, Rand Wacker, Sam Weiler, and Dan Wing ๐.
The earlier DomainKeys was a primary source from which DKIM was derived. Further information about DomainKeys is at [RFC4870] ๐ฆ.
This revision received contributions from Steve Atkins, Mark Delany, J.D. Falk, Jim Fenton, Michael Hammer, Barry Leiba, John Levine, Charles Lindsey, Jeff Macdonald, Franck Martin, Brett McDowell, Doug Otis, Bill Oxley, Hector Santos, Rolf Sonneveld, Michael Thomas, and Alessandro Vesely ๐โจ
Authors' Addresses โจ
Okay bestie, this is the final stop! ๐ง These are the editors who put the whole spec together, so if you ever want to slide into their inbox about DKIM, here's where to find them ๐ Their contact details are below, exactly as they're written in the original.
Dave Crocker (editor) ๐
Dave Crocker (editor)
Brandenburg InternetWorking
675 Spruce Dr.
Sunnyvale, CA 94086
USA
Phone: +1.408.246.8253
EMail: dcrocker@bbiw.net
URI: http://bbiw.net
Tony Hansen (editor) ๐ฆ
Tony Hansen (editor)
AT&T Laboratories
200 Laurel Ave. South
Middletown, NJ 07748
USA
EMail: tony+dkimsig@maillennium.att.com
Murray S. Kucherawy (editor) ๐ซถ
Murray S. Kucherawy (editor)
Cloudmark
128 King St., 2nd Floor
San Francisco, CA 94107
USA
EMail: msk@cloudmark.com
That's the whole spec, babe! ๐๐ Three editors, one signature standard, and zero cap that they're all iconic. ๐
๐ฆ where this page comes from
- ietf: rfc6376 2011-09
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms