AUTHENTICATION OF THE MESSAGE, not of the user. Nothing here has anything to
do with SMTP AUTH; this is the inbound gate that decides whether a message
really comes from where its From: header claims, and the outbound step that
lets someone else make the same decision about ours.
TWO HALVES:
* tSmtpMessageAuthenticator runs SPF over the connection, verifies every DKIM
signature on the message, and hands both to DMARC for the only judgement
that is actually about the visible sender. It returns a disposition and the
Authentication-Results field that records why.
* tSmtpDkimAgent signs on the way out. It is an iSmtpDeliveryAgent DECORATOR
around whatever agent would otherwise have delivered, so it slots into the
spool without the spool knowing anything about DKIM, and it runs on a spool
worker thread rather than on the reactor thread that is holding a client's
250.
WHY SIGNING HAPPENS AT DELIVERY AND NOT AT ACCEPTANCE: the spool may split one
accepted message across several destination domains, and each copy is
delivered on its own schedule. Signing per delivery gives each copy its own
t=, costs one signature per attempt, and - the point - keeps a public-key
operation off the thread that is still talking to the client.
ORDER MATTERS ON THE WAY IN. The body hash covers the message as received, so
verification must run BEFORE anything is prepended to it. The
Authentication-Results field is added afterwards, and a downstream verifier is
unaffected because DKIM selects header fields from the bottom up.
AND A WARNING ABOUT THAT FIELD: Authentication-Results is only meaningful if
the reader trusts the host that wrote it. This unit strips one that arrived
from outside (StripInboundResults, on by default) - otherwise a sender can
simply assert its own "dkim=pass" and anything downstream that reads headers
rather than re-verifying will believe it.
WHAT DNS DID NOT ANSWER IS SAID ON THE MESSAGE. Every check that went on
without its DNS answer is listed in tSmtpAuthReport.Relaxed, and
SmtpStampDnsWarnings turns the list into X-DNS-Warning fields, after
renaming every such field that arrived from outside naming this host.
AND SO IS WHAT WAS TAKEN AWAY. A field that arrived claiming to come from
this host - Authentication-Results, X-DNS-Warning or X-Stripped-Fields,
its first token read as RFC 8601 reads an authserv-id - is kept as
evidence under another name, cSmtpForgedFieldPrefix in front of its own,
so that nothing reads it as the field it was; an Authentication-Results
bearing a version this unit does not support, whoever it names, is
removed. One X-Stripped-Fields field says which, how many and why.
SmtpStripForgedFields does the renaming, the removing and the counting in
one place, so a host can score the forgeries (tSpamContext.ForgedStamps)
before it stamps anything.Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
inherits from Exception
(no public members)
HOW MANY FIELDS WERE TAKEN AWAY from one message, by name and reason. A field names this host when SmtpFieldNamesHost says so; the first three are those, the forgeries SmtpStrippedForged counts, each RENAMED with cSmtpForgedFieldPrefix; the fourth were removed. Zero it with FillChar before the first use: a host keeps one per message.
AuthResults: Integer;
DnsWarnings: Integer;
StripNotes: Integer;
UnsupportedVersion: Integer;
One check that went on without its DNS answer.
Check: string;
Name: string;
Relaxed: string;
Everything the checks concluded, kept whole so a policy handler can second guess any part of it.
Disposition: tSmtpAuthDisposition;
Code: Integer;
Text: string;
Reason: string;
FromDomain: string;
FromReason: string;
FromStatus: tDmarcFromStatus;
Spf: tSpfResult;
SpfDomain: string;
Dkim: tDkimVerdictArray;
Dmarc: tDmarcVerdict;
DkimPassed: Boolean;
DkimBroken: Boolean;
SpfTempErrorName: string;
Relaxed: tSmtpDnsRelaxations;
constructor Create(const aResolver: iDnsResolver);
function Authenticate(const aEnvelope: iSmtpEnvelope; const aData: tBytes): tSmtpAuthReport;
function BuildResultsHeader(const aReport: tSmtpAuthReport): string;
function StampMessage(const aData: tBytes; const aReport: tSmtpAuthReport): tBytes; overload;
function StampMessage(const aData: tBytes; const aReport: tSmtpAuthReport; var aStripped: tSmtpStrippedFields): tBytes;
property Receiver: string read fReceiver write fReceiver;
property RejectBrokenSignature: Boolean read fRejectBrokenSignature write fRejectBrokenSignature;
property RejectAnyBrokenSignature: Boolean read fRejectAnyBrokenSignature write fRejectAnyBrokenSignature;
property EnforceDmarc: Boolean read fEnforceDmarc write fEnforceDmarc;
property RequirePublishedPolicy: Boolean read fRequirePublishedPolicy write fRequirePublishedPolicy;
property CheckSpf: Boolean read fCheckSpf write fCheckSpf;
property StripInboundResults: Boolean read fStripInboundResults write fStripInboundResults;
property FailClosedOnTempError: Boolean read fFailClosedOnTempError write fFailClosedOnTempError;
property MinKeyBits: Integer read fMinKeyBits write fMinKeyBits;
property AllowBodyLength: Boolean read fAllowBodyLength write fAllowBodyLength;
property RejectMissingFrom: Boolean read fRejectMissingFrom write fRejectMissingFrom;
property Resolver: iDnsResolver read fResolver write fResolver;
property OnReport: tSmtpAuthReportEvent read fOnReport write fOnReport;
inherits from TInterfacedObject
implements iSmtpDeliveryAgent
Signs on the way out, then hands the signed octets to the agent that would otherwise have been called.
constructor Create(const aInner: iSmtpDeliveryAgent);
destructor Destroy; override;
function Deliver(const aEnvelope: iSmtpEnvelope; const aData: tBytes; var aError: string): tSmtpDeliveryOutcome;
property Signer: tDkimSigner read fSigner;
property Enabled: Boolean read fEnabled write fEnabled;
property Inner: iSmtpDeliveryAgent read fInner write fInner;
What the relay should do with the message.