DELIVERY TO THE RECIPIENT'S OWN MAIL EXCHANGER, as an iSmtpDeliveryAgent the
spool can use in place of - or behind - tSmtpSmarthostAgent.
THE TLS PROBLEM THIS UNIT EXISTS TO GET RIGHT. Between MTAs there is no shared
configuration and no password, so the usual answers do not apply:
- Opportunistic STARTTLS protects against a PASSIVE observer and nothing
else. An active attacker strips STARTTLS from the EHLO response and the
sender delivers in the clear, by design.
- Verifying the certificate does NOT fix that, and asking for it is worse
than useless. The MX name came from UNSIGNED DNS, so whoever forged the MX
answer also chose the name that would be checked (RFC 7672 sec.1.3.1) -
while an attacker who simply strips STARTTLS is never asked for a
certificate at all. The check therefore catches only honest
misconfiguration, and hands the attacker a free denial of delivery: inject
any certificate, the delivery defers, retries expire, the mail bounces.
- MTA-STS (RFC 8461) is the answer, because the policy arrives over a
channel the DNS attacker does not control. StreamSec.Mail.MTASTS does the
discovery; this unit acts on it.
SO THE POLICY LADDER IS: whatever tSmtpMxTlsPolicy says, RAISED - never
lowered - by what MTA-STS says for the domain. A configured smtOpportunistic
becomes verification for a domain that publishes enforce, and stays
opportunistic for one that publishes nothing. The reverse can never happen:
a domain's own policy cannot be used to weaken the sender's.
PREFERRING A TLS-CAPABLE MX among the domain's published records would be
legitimate - all of them are receivers the domain itself designated - and this
unit deliberately does NOT offer it. Be clear about what it would buy:
robustness against one neglected backup MX, and nothing against an attacker,
who can strip STARTTLS from the second host exactly as easily as from the
first. What actually raises the posture is REQUIRING TLS, which is what
TLSPolicy is for and what a domain publishing MTA-STS enforce gets
automatically - so a preference switch would have been a second, weaker way to
ask for something the policy setting already says properly.
WHAT IS NOT OFFERED, AND WILL NOT BE: looking for some OTHER relay that
happens to support TLS. That means finding a host willing to relay for a
domain it does not serve - an open relay - and it is strictly worse than the
cleartext hop it replaces: the message is encrypted to a stranger who then
delivers it over the same unprotected last hop, having taken a plaintext copy
on the way.Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
inherits from Exception
(no public members)
inherits from TInterfacedObject
implements iMtaStsFetcher
THE REAL POLICY FETCHER. It is here rather than in StreamSec.Mail.MTASTS so that unit keeps no dependency on the HTTP stack and stays testable from a string - the seam exists for exactly that.
constructor Create(aTLSServer: TsmSimpleTLSInternalServer);
function Fetch(const aDomain: string; out aText: string; var aWhy: string): Boolean;
property TLSServer: TsmSimpleTLSInternalServer read fTLSServer write fTLSServer;
property Timeout: Cardinal read fTimeout write fTimeout;
inherits from TInterfacedObject
implements iSmtpDeliveryAgent
constructor Create(const aResolver: iDnsResolver);
destructor Destroy; override;
function Deliver(const aEnvelope: iSmtpEnvelope; const aData: tBytes; var aError: string): tSmtpDeliveryOutcome;
property MtaSts: tMtaStsResolver read fMtaSts write fMtaSts;
property TLSServer: TsmSimpleTLSInternalServer read fTLSServer write fTLSServer;
property TLSPolicy: tSmtpMxTlsPolicy read fTLSPolicy write fTLSPolicy;
property HeloName: string read fHeloName write fHeloName;
property SourceIP: string read fSourceIP write fSourceIP;
property Port: Word read fPort write fPort;
property ConnectTimeout: Cardinal read fConnectTimeout write fConnectTimeout;
property OnLog: tSmtpMxLogEvent read fOnLog write fOnLog;
property OnAttempt: tSmtpMxAttemptEvent read fOnAttempt write fOnAttempt;
property OnConfigure: tSmtpMxConfigureEvent read fOnConfigure write fOnConfigure;
HOW MUCH TLS THE MX LEG INSISTS ON. Deliberately NOT tSmtpDeliveryTlsMode: that one describes a smarthost, where implicit TLS on 465 is available and is the right default. An MX is port 25 and STARTTLS or nothing, so the questions are different ones.
One line of the agent's progress: the MTA-STS verdict for a domain, an MX skipped or failed, a delivery. An exception the handler raises is swallowed and changes nothing about the delivery: neither MX fallback, nor the outcome, nor whether a failure is permanent.
Per-delivery access to the client, after everything else is set.
One call for each MX attempt that has a client: every attempt but one whose CreateClient raised or returned nil. After a delivery aDelivered is True and aError nil, and the call comes before the QUIT, with the session still open. A failed attempt is reported after the client has sent QUIT (when the session was open) and disconnected, so Secure is False, and its reply code and reply text are what its last read of a reply left: they need not describe the failure. aError does - its message, and the ReplyCode of an eSMTPClientError or the ErrorCode of an EstSocketError - and aClient.Stage says how far the attempt got. aClient and aError are LENT for the call: do not keep, free or raise either. An exception the handler raises is swallowed and changes nothing about the delivery.