#!/usr/bin/env python3
"""Writes two SYNTHETIC DMARC aggregate reports (classic rua XML structure: feedback/report_metadata/
policy_published/record). Domain and IPs are documentation values. Nothing here is real mail data."""
import pathlib
OUT = pathlib.Path(__file__).parent / "reports"
def rec(ip, count, disp, dkim, spf, hfrom="company.test", dkim_dom="company.test", spf_dom="company.test", dkim_auth=None, spf_auth=None):
# dkim/spf = DMARC *alignment* result; dkim_auth/spf_auth = raw authentication result (can pass without aligning)
dkim_auth = dkim_auth or ("pass" if dkim == "pass" else "fail"); spf_auth = spf_auth or ("pass" if spf == "pass" else "fail")
return f""" {ip}{count}{disp}{dkim}{spf}
{hfrom}
{dkim_dom}{dkim_auth}{spf_dom}{spf_auth}"""
def report(rid, org, rows):
return f"""
{org}noreply-dmarc@{org}{rid}
17645472001764633599
company.testrrnone
none100
{chr(10).join(rows)}
"""
# Day 1 from receiver "mail.example-a.test", day 2 from "mail.example-b.test"
a = [
rec("203.0.113.10", 4210, "none", "pass", "pass"), # the company's own mail server: fully aligned
rec("198.51.100.20", 1830, "none", "pass", "fail", spf_dom="bounce.newsletter-vendor.test", spf_auth="pass"), # newsletter tool: DKIM signs with company.test (aligned); SPF passes for the vendor's bounce domain but does not align
rec("192.0.2.77", 640, "none", "fail", "fail", spf_dom="crm-vendor.test", dkim_dom="crm-vendor.test", dkim_auth="pass", spf_auth="pass"), # CRM sending as company.test: both checks PASS for the vendor domain, neither ALIGNS with company.test
rec("203.0.113.99", 37, "none", "fail", "fail", spf_dom="evil.test", dkim_dom=""), # unknown sender (looks like spoofing)
]
b = [
rec("203.0.113.10", 3985, "none", "pass", "pass"),
rec("198.51.100.20", 1544, "none", "pass", "fail", spf_dom="bounce.newsletter-vendor.test", spf_auth="pass"),
rec("192.0.2.77", 702, "none", "fail", "fail", spf_dom="crm-vendor.test", dkim_dom="crm-vendor.test", dkim_auth="pass", spf_auth="pass"),
rec("198.51.100.200", 12, "none", "fail", "fail", spf_dom="evil.test", dkim_dom=""),
]
(OUT / "example-a.test!company.test!1764547200!1764633599.xml").write_text(report("a-001", "example-a.test", a))
(OUT / "example-b.test!company.test!1764547200!1764633599.xml").write_text(report("b-001", "example-b.test", b))
print("wrote", len(list(OUT.glob('*.xml'))), "reports")