WHAT DKIM ANSWERS, AND WHERE IT DIFFERS FROM SPF.
A DKIM signature says: the domain in d= took responsibility for this message,
and the parts of it covered by h= plus the body have not changed since. Unlike
SPF (StreamSec.Mail.Spf) it survives forwarding, because it authenticates
CONTENT rather than a connection - which is also why it is the identity DMARC
can align against a human-visible From: header.
WHAT A PASS DOES NOT MEAN. It does not mean the message is honest, only that
d= signed it - and d= may be a domain the signer registered five minutes ago.
It does not cover anything absent from h=, so a header not listed there can be
ADDED by anyone downstream without breaking the signature. And it says nothing
about the envelope: the SMTP MAIL FROM is not signed.
THE VERIFIER IS THE ATTACK SURFACE, and three of its rules are load-bearing:
* From: MUST be covered. RFC 6376 sec.5.4 requires it, and a signature that
omits it authenticates a message whose apparent author anyone may rewrite.
This unit REFUSES such a signature rather than reporting a pass.
* l= is a body-length limit, and everything past it is unsigned - an attacker
can APPEND arbitrary content to a validly signed message. Mail clients show
the appended part. tDkimVerifier.AllowBodyLength is False here: an l=
signature is refused unless a caller deliberately turns it on.
* A header named in h= may occur MORE times in the message than h= accounts
for. The unsigned extra instance is the one many clients display. Header
fields are therefore taken from the BOTTOM UP (sec.5.4.2), and a name listed
more times than it occurs contributes NOTHING further - which is what makes
"oversigning" (listing a header more often than it appears) able to nail a
header down against later addition.
ALGORITHM FLOOR. rsa-sha1 is recognised only so it can be refused: RFC 8301
removed it from DKIM entirely. RSA keys below cDkimMinKeyBits are refused for
the same reason.
This unit uses only the DSI interfaces; the IMPLEMENTATIONS that register the
providers - StreamSec.DSI.IFC (RSA), StreamSec.DSI.EdDSA, StreamSec.DSI.Arith,
stSHA256 and stSHA512 - are linked by the APPLICATION, exactly as elsewhere in
this library.
Key lookup goes through iDnsResolver, so the whole verifier runs against a
scripted resolver with no network - and the vectors at the bottom are RFC 6376
Appendix A and RFC 8463 Appendix A, i.e. signatures produced by someone else.Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
inherits from Exception
(no public members)
A parsed DKIM-Signature field.
constructor Create;
destructor Destroy; override;
property Headers: TStringList read fHeaders;
property Tags[const aName: string]: string read GetTag;
A parsed <selector>._domainkey.<domain> TXT record.
constructor Create;
destructor Destroy; override;
function Parse(const aText: string): Boolean;
function Testing: Boolean;
function StrictIdentity: Boolean;
property Tags[const aName: string]: string read GetTag;
What a single signature came to, with enough detail to write an Authentication-Results header and to say WHY.
Result: tDkimResult;
Domain: string;
Selector: string;
Identity: string;
Algorithm: tDkimAlgorithm;
KeyBits: Integer;
Reason: string;
Testing: Boolean;
Verifies every DKIM-Signature on a message. ONE MESSAGE PER CALL; Verify resets everything it needs.
constructor Create(const aResolver: iDnsResolver);
function Verify(const aData: tBytes): tDkimVerdictArray;
function Summarise(const aVerdicts: tDkimVerdictArray): tDkimResult;
property AllowBodyLength: Boolean read fAllowBodyLength write fAllowBodyLength;
property RequireFromSigned: Boolean read fRequireFromSigned write fRequireFromSigned;
property MinKeyBits: Integer read fMinKeyBits write fMinKeyBits;
property MaxSignatures: Integer read fMaxSignatures write fMaxSignatures;
property CurrentTime: Int64 read fNow write fNow;
property Resolver: iDnsResolver read fResolver write fResolver;
Produces a DKIM-Signature header for an outbound message.
constructor Create;
destructor Destroy; override;
function Sign(const aData: tBytes): string;
function SignMessage(const aData: tBytes): tBytes;
property Domain: string read fDomain write fDomain;
property Selector: string read fSelector write fSelector;
property Identity: string read fIdentity write fIdentity;
property Algorithm: tDkimAlgorithm read fAlgorithm write fAlgorithm;
property HeaderCanon: tDkimCanon read fHeaderCanon write fHeaderCanon;
property BodyCanon: tDkimCanon read fBodyCanon write fBodyCanon;
property SignHeaders: TStringList read fSignHeaders;
property Oversign: Boolean read fOversign write fOversign;
property ExpirySeconds: Integer read fExpirySeconds write fExpirySeconds;
property Key: iUnknown read fKey write fKey;
property CurrentTime: Int64 read fNow write fNow;
RFC 8601 sec.2.7.1 - the values that go in an Authentication-Results header. The two errors are NOT interchangeable: drTempError is a DNS failure and may succeed later (a 4xx if anything), drPermError is a broken signature or policy and never will.