diff --git a/cmdeploy/src/cmdeploy/opendkim/final.lua b/cmdeploy/src/cmdeploy/opendkim/final.lua index 133f7784..e68a486d 100644 --- a/cmdeploy/src/cmdeploy/opendkim/final.lua +++ b/cmdeploy/src/cmdeploy/opendkim/final.lua @@ -9,9 +9,10 @@ if nsigs == nil then return nil end +local valid = false for i = 1, nsigs do - sig = odkim.get_sighandle(ctx, i - 1) - sigres = odkim.sig_result(sig) + sig = odkim.get_sighandle(ctx, i - 1) + sigres = odkim.sig_result(sig) -- All signatures that do not correspond to From: -- were ignored in screen.lua and return sigres -1. @@ -19,10 +20,19 @@ for i = 1, nsigs do -- Any valid signature that was not ignored like this -- means the message is acceptable. if sigres == 0 then - return nil - end + valid = true + end +end + +if valid then + -- Strip all DKIM-Signature headers after successful validation + -- Delete in reverse order to avoid index shifting. + for i = nsigs, 1, -1 do + odkim.del_header(ctx, "DKIM-Signature", i) + end +else + odkim.set_reply(ctx, "554", "5.7.1", "No valid DKIM signature found") + odkim.set_result(ctx, SMFIS_REJECT) end -odkim.set_reply(ctx, "554", "5.7.1", "No valid DKIM signature found") -odkim.set_result(ctx, SMFIS_REJECT) return nil diff --git a/doc/source/overview.rst b/doc/source/overview.rst index 19e81b53..09bcbcad 100644 --- a/doc/source/overview.rst +++ b/doc/source/overview.rst @@ -273,9 +273,11 @@ Incoming emails must have a valid DKIM signature with Signing Domain Identifier (SDID, ``d=`` parameter in the DKIM-Signature header) equal to the ``From:`` header domain. This property is checked by OpenDKIM screen policy script before validating the signatures. This -correpsonds to strict :rfc:`DMARC <7489>` alignment (``adkim=s``). +corresponds to strict :rfc:`DMARC <7489>` alignment (``adkim=s``). If there is no valid DKIM signature on the incoming email, the sender receives a “5.7.1 No valid DKIM signature found” error. +After validating the DKIM signature, +the `final.lua` script strips all ``OpenDKIM:`` headers to reduce message size on disc. Note that chatmail relays