Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.Dmarc

WHY THIS EXISTS AT ALL: ALIGNMENT.

  SPF and DKIM each authenticate an identifier that a reader never sees. SPF
  authenticates the SMTP envelope sender; DKIM authenticates whatever domain put
  its name in d=. NEITHER of them says anything about the From: header, which is
  the only identity a human is shown.

  So a DKIM "pass" on its own is worth almost nothing as a policy input. An
  attacker registers attacker.example, publishes a key, signs their message
  perfectly, and puts "From: security@yourbank.example" in the header. Every
  signature check passes. RFC 7489 sec.3.1.1 puts it plainly: a message can bear
  a valid signature from ANY domain.

  DMARC is the missing half. It requires that an authenticated identifier be
  ALIGNED with the RFC5322.From domain, and it lets that domain publish what a
  receiver should do when nothing aligns. THE ALIGNMENT IS THE SECURITY
  PROPERTY; the signature check is only an input to it.

  A DMARC pass needs just ONE aligned pass - DKIM or SPF. That matters in both
  directions: rejecting on a DKIM failure alone would reject forwarded mail that
  SPF still covers, and accepting on an unaligned DKIM pass would accept the
  attack above.

  THE ORGANIZATIONAL DOMAIN IS THE WEAK SPOT. Relaxed alignment compares
  organizational domains, which formally requires the Public Suffix List. A
  compiled-in list would be stale the day it shipped, so this unit ships a
  short table of the common multi-label suffixes and an OnOrganizationalDomain
  hook for a real PSL. THE TABLE ERRS TOWARDS TREATING A SUFFIX AS PUBLIC,
  because the dangerous direction is the other one: if 'co.uk' were mistaken for
  an organizational domain, then evil.co.uk and victim.co.uk would align and one
  could sign for the other. Getting it wrong the safe way merely fails to align.

  Policy discovery, alignment and disposition are pure functions of their
  inputs plus one DNS lookup, so the whole of it runs against a scripted
  resolver with no network - which is how the vectors at the bottom test it.

Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)

Classes, interfaces and records

classeDmarcError

inherits from Exception

(no public members)

classtDmarcRecord

constructor Create; destructor Destroy; override; function Parse(const aText: string): Boolean; property Tags[const aName: string]: string read GetTag;

recordtDmarcVerdict

Result: tDmarcResult; Disposition: tDmarcDisposition; FromDomain: string;
The RFC5322.From domain - the identity the alignment is against.
PolicyDomain: string;
Where the policy record was actually found: the From domain, or the organizational domain it fell back to.
Policy: tDmarcPolicy; DkimAligned: Boolean; SpfAligned: Boolean; DkimDomain: string;
The d= that aligned, when one did.
Reason: string; TempErrorName: string;
The DNS name of the policy record that could not be retrieved - for dmrTempError, and for a dmrPass decided without the record (see Evaluate). Empty otherwise.
SpfUndecided: Boolean;
A FAIL THAT IS NOT SETTLED YET. Both are set only on dmrFail under a record that was retrieved, and say which answer that did not come could still turn it into a pass: SpfUndecided, an SPF temperror for a domain aligned with From: under the record's aspf=; DkimUndecidedDomain, the d= of the first... Full description »
DkimUndecidedDomain: string;

classtDmarcEvaluator

constructor Create(const aResolver: iDnsResolver); function Evaluate(const aFromDomain: string; const aDkim: tDkimVerdictArray; aSpf: tSpfResult; const aSpfDomain: string): tDmarcVerdict;
The whole evaluation. aDkim is every signature verdict from tDkimVerifier.Verify; aSpf/aSpfDomain are the SPF result and the domain it was computed for (the MAIL FROM domain, or the HELO name for a bounce).
property OnOrganizationalDomain: tDmarcOrgDomainEvent read fOnOrgDomain write fOnOrgDomain;
Plug a real Public Suffix List. Without one, relaxed alignment uses the built-in table - see the unit header for why that is a real limitation and which way it errs.
property FailClosedOnTempError: Boolean read fFailClosedOnTempError write fFailClosedOnTempError;
sec.6.6.3 leaves DNS failure to the receiver, and this decides it - save for a verified DKIM signature whose d= is the From domain itself, or an SPF pass for the From domain itself, which passes without the record whatever this says. False - the default - keeps mail flowing during a resolver outage; True turns it into a 4xx, which is safer but strands mail when DNS is the thing that is broken.
property Resolver: iDnsResolver read fResolver write fResolver;

Types (enumerations, sets, aliases)

enumtDmarcPolicy

RFC 7489 sec.6.3 p= / sp=.

  tDmarcPolicy = (dmpNone, dmpQuarantine, dmpReject);

enumtDmarcAlign

sec.3.1: relaxed compares ORGANIZATIONAL domains, strict compares the whole FQDN.

  tDmarcAlign = (dmaRelaxed, dmaStrict);

enumtDmarcFromStatus

WHY there is no From domain, which decides what a receiver may do about it.
dfsAmbiguous is categorically different from the other two: a message with two From: fields is not merely unusable, it is a message engineered so that a filter and a mail client can be made to disagree about who sent it.

  tDmarcFromStatus = (dfsOk, dfsMissing, dfsAmbiguous, dfsUnparsable);

enumtDmarcResult

  tDmarcResult = (
    { The From domain publishes no DMARC record, so DMARC says nothing. This is
      NOT a failure and must not be treated as one. }
    dmrNone,
    { At least one authenticated identifier aligned. }
    dmrPass,
    { A record exists and nothing aligned. }
    dmrFail,
    { DNS would not answer. Says nothing either way. }
    dmrTempError,
    { The record is unusable - malformed, or more than one published. }
    dmrPermError);

enumtDmarcDisposition

What the receiver should DO. Kept separate from the result because the two are not the same thing: a fail under p=none is still a delivery.

  tDmarcDisposition = (dmdAccept, dmdQuarantine, dmdReject, dmdTempFail);

proctDmarcOrgDomainEvent

  tDmarcOrgDomainEvent = procedure (Sender: TObject; const aDomain: string;
                                    var aOrgDomain: string) of object;

Routines