Skip to content

DKIM oversigning

Important headers should also be protected against additional header instances inserted after signing.

Setup

Prerequisite: your values and Debian packages. Run as root and merge changes into existing configuration; personal signing keys belong in the signing user's account.

Configure OpenDKIM first. Both lists must match:

set -euo pipefail
sed -i '/^SignHeaders /d; /^OversignHeaders /d' /etc/opendkim/mailserver.conf
cat >> /etc/opendkim/mailserver.conf <<'EOF'
SignHeaders From,To,Cc,Subject,Date,Message-ID,Reply-To,Sender,MIME-Version,Content-Type,Content-Transfer-Encoding,Resent-Date,Resent-From,Resent-To,Resent-Cc,In-Reply-To,References,List-ID,List-Help,List-Unsubscribe,List-Subscribe,List-Post,List-Owner,List-Archive
OversignHeaders From,To,Cc,Subject,Date,Message-ID,Reply-To,Sender,MIME-Version,Content-Type,Content-Transfer-Encoding,Resent-Date,Resent-From,Resent-To,Resent-Cc,In-Reply-To,References,List-ID,List-Help,List-Unsubscribe,List-Subscribe,List-Post,List-Owner,List-Archive
EOF
opendkim -n -x /etc/opendkim/mailserver.conf
systemctl restart opendkim

Then rerun the DKIM mail test so the saved test message reflects the new settings.

Test

set -euo pipefail
python3 - <<'PY'
from collections import Counter
from email.parser import BytesParser
from email.policy import default
from pathlib import Path
import re
message = BytesParser(policy=default).parsebytes(Path("/root/mail-tests/dkim.eml").read_bytes())
signature = str(message["DKIM-Signature"])
match = re.search(r"(?:^|;)\s*h=([^;]+)", signature)
assert match, "Missing h= list"
signed = Counter(value.strip().lower() for value in match[1].split(":"))
for header in ("from", "subject", "date", "message-id", "reply-to"):
    count = len(message.get_all(header, []))
    assert signed[header] > count, (header, signed[header], count)
print("PASS: additional instances of the checked headers are also protected.")
PY

Configuration alone is insufficient: the test inspects the actual h= list of a message signed by the MTA.