nx_email_dns.nx source
↩ module page · 47 lines · 2586 B
1// nx_email_dns.nx -- EMAIL DEPLOY: emit the DNS zone records for a domain.
2//
3// module: nishi-core.email.dns
4// depends: (none -- pure text builder)
5// capability: CORE_EMAIL
6//
7// Produces the exact records an operator publishes so the sovereign mail
8// server becomes reachable as real internet mail for <domain>:
9// MX -> the mail host (where senders deliver)
10// A -> the mail host's IPv4 (the public server)
11// SPF -> authorize the host (anti-spoof, RFC 7208)
12// DKIM -> the ed25519 public key (signature verify, RFC 8463)
13// DMARC -> the policy (RFC 7489)
14// The DKIM public key is generated + base64'd by the caller (composing
15// the sovereign ed25519); this file only formats the zone.
16//
17// license_tier: INDEPENDENT_REDERIVE
18// genealogy_id: international-research-sources/ietf/rfc_1035 + rfc_7208 + rfc_8463 + rfc_7489
19// lineage_id: nishi_email_dns_zone
20
21func dz_cat(out: *u8, oi: i64, s: *u8) -> i64 {
22 var k: i64 = 0
23 while s[k] != (0 as u8) { out[oi] = s[k]; oi = oi + 1; k = k + 1 }
24 return oi
25}
26
27// Emit the full zone (null-terminated args). Returns text length.
28func nx_dns_zone(domain: *u8, host: *u8, ip: *u8, selector: *u8, pub_b64: *u8, out: *u8, cap: i64) -> i64 {
29 var oi: i64 = 0
30 oi = dz_cat(out, oi, "; ===== Nishi sovereign mail DNS records for " as *u8)
31 oi = dz_cat(out, oi, domain)
32 oi = dz_cat(out, oi, " =====\n" as *u8)
33 oi = dz_cat(out, oi, "; Publish at your DNS provider. Replace the A-record IP with your server's PUBLIC IPv4.\n\n" as *u8)
34 // MX
35 oi = dz_cat(out, oi, domain); oi = dz_cat(out, oi, ".\t3600\tIN\tMX\t10 " as *u8); oi = dz_cat(out, oi, host); oi = dz_cat(out, oi, ".\n" as *u8)
36 // A
37 oi = dz_cat(out, oi, host); oi = dz_cat(out, oi, ".\t3600\tIN\tA\t" as *u8); oi = dz_cat(out, oi, ip); oi = dz_cat(out, oi, "\n" as *u8)
38 // SPF
39 oi = dz_cat(out, oi, domain); oi = dz_cat(out, oi, ".\t3600\tIN\tTXT\t\"v=spf1 a:" as *u8); oi = dz_cat(out, oi, host); oi = dz_cat(out, oi, " -all\"\n" as *u8)
40 // DKIM
41 oi = dz_cat(out, oi, selector); oi = dz_cat(out, oi, "._domainkey." as *u8); oi = dz_cat(out, oi, domain)
42 oi = dz_cat(out, oi, ".\t3600\tIN\tTXT\t\"v=DKIM1; k=ed25519; p=" as *u8); oi = dz_cat(out, oi, pub_b64); oi = dz_cat(out, oi, "\"\n" as *u8)
43 // DMARC
44 oi = dz_cat(out, oi, "_dmarc." as *u8); oi = dz_cat(out, oi, domain)
45 oi = dz_cat(out, oi, ".\t3600\tIN\tTXT\t\"v=DMARC1; p=quarantine; rua=mailto:postmaster@" as *u8); oi = dz_cat(out, oi, domain); oi = dz_cat(out, oi, "\"\n" as *u8)
46 return oi
47}