From 583ab609ea14d84a528c8acb58dd0cc8892fb819 Mon Sep 17 00:00:00 2001 From: Brian Cunnie Date: Sat, 23 Jul 2022 12:50:55 -0400 Subject: [PATCH] Laying the groundwork for passed-in configuration The massive 80+ line `Customizations` variable is a hard-coded monstrosity, and I've fallen out of love with it. I'd like the customizations to be passed in from the caller, in this case, `main.go`. To that end, I've created a `default.json`, which should contain all the customizations with the exception of the key-value functionality, which I don't have a good way to deal with just yet. --- src/sslip.io-dns-server/default.json | 85 ++++++++++++++++++++++++++++ src/sslip.io-dns-server/xip/xip.go | 29 +++++----- 2 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 src/sslip.io-dns-server/default.json diff --git a/src/sslip.io-dns-server/default.json b/src/sslip.io-dns-server/default.json new file mode 100644 index 0000000..b04ad82 --- /dev/null +++ b/src/sslip.io-dns-server/default.json @@ -0,0 +1,85 @@ +[ + { + "sslip.io.": { + "A": [ + "78.46.204.247" + ], + "AAAA": [ + "2a01:4f8:c17:b8f::2" + ], + "MX": [ + { + "Pref": 10, + "MX": "mail.protonmail.ch." + }, + { + "Pref": 10, + "MX": "mailsec.protonmail.ch." + } + ], + "TXT": [ + "TXTSslipIoSPF" + ] + }, + "k-v.io.": { + "A": [ + "104.155.144.4" + ] + }, + "_acme-challenge.k-v.io.": { + "TXT": [] + }, + "ns.sslip.io.": { + "A": [ + "52.0.56.137", + "52.187.42.158", + "104.155.144.4" + ], + "AAAA": [ + "2600:1f18:aaf:6900::a" + ] + }, + "ns-aws.sslip.io.": { + "A": [ + "52.0.56.137" + ], + "AAAA": [ + "2600:1f18:aaf:6900::a" + ] + }, + "ns-azure.sslip.io.": { + "A": [ + "52.187.42.158" + ] + }, + "ns-gce.sslip.io.": { + "A": [ + "104.155.144.4" + ] + }, + "protonmail._domainkey.sslip.io.": { + "CNAME": "protonmail.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch." + }, + "protonmail2._domainkey.sslip.io.": { + "CNAME": "protonmail2.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch." + }, + "protonmail3._domainkey.sslip.io.": { + "CNAME": "protonmail3.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch." + }, + "ip.sslip.io.": { + "TXT": [ + "TXTIp" + ] + }, + "version.status.sslip.io.": { + "TXT": [ + "TXTVersion" + ] + }, + "metrics.status.sslip.io.": { + "TXT": [ + "TXTMetrics" + ] + } + } +] diff --git a/src/sslip.io-dns-server/xip/xip.go b/src/sslip.io-dns-server/xip/xip.go index 400682b..d71c138 100644 --- a/src/sslip.io-dns-server/xip/xip.go +++ b/src/sslip.io-dns-server/xip/xip.go @@ -153,15 +153,7 @@ var ( MX: mx2, }, }, - TXT: func(_ *Xip, _ net.IP) ([]dnsmessage.TXTResource, error) { - // Although multiple TXT records with multiple strings are allowed, we're sticking - // with a multiple TXT records with a single string apiece because that's what ProtonMail requires - // and that's what google.com does. - return []dnsmessage.TXTResource{ - {TXT: []string{"protonmail-verification=ce0ca3f5010aa7a2cf8bcc693778338ffde73e26"}}, // ProtonMail verification; don't delete - {TXT: []string{"v=spf1 include:_spf.protonmail.ch mx ~all"}}, - }, nil // Sender Policy Framework - }, + TXT: TXTSslipIoSPF, }, "k-v.io.": { A: []dnsmessage.AResource{ @@ -208,7 +200,7 @@ var ( }, // Special-purpose TXT records "ip.sslip.io.": { - TXT: ipSslipIo, + TXT: TXTIp, }, "version.status.sslip.io.": { TXT: func(x *Xip, _ net.IP) ([]dnsmessage.TXTResource, error) { @@ -221,7 +213,7 @@ var ( }, }, "metrics.status.sslip.io.": { - TXT: metricsSslipIo, + TXT: TXTMetrics, }, } ) @@ -900,14 +892,25 @@ func (x *Xip) PTRResource(fqdn []byte) *dnsmessage.PTRResource { return nil } +// SFP records for sslio.io +func TXTSslipIoSPF(_ *Xip, _ net.IP) ([]dnsmessage.TXTResource, error) { + // Although multiple TXT records with multiple strings are allowed, we're sticking + // with a multiple TXT records with a single string apiece because that's what ProtonMail requires + // and that's what google.com does. + return []dnsmessage.TXTResource{ + {TXT: []string{"protonmail-verification=ce0ca3f5010aa7a2cf8bcc693778338ffde73e26"}}, // ProtonMail verification; don't delete + {TXT: []string{"v=spf1 include:_spf.protonmail.ch mx ~all"}}, + }, nil // Sender Policy Framework +} + // when TXT for "ip.sslip.io" is queried, return the IP address of the querier -func ipSslipIo(x *Xip, srcAddr net.IP) ([]dnsmessage.TXTResource, error) { +func TXTIp(x *Xip, srcAddr net.IP) ([]dnsmessage.TXTResource, error) { x.Metrics.AnsweredTXTSrcIPQueries++ return []dnsmessage.TXTResource{{TXT: []string{srcAddr.String()}}}, nil } // when TXT for "metrics.sslip.io" is queried, return the cumulative metrics -func metricsSslipIo(x *Xip, _ net.IP) (txtResources []dnsmessage.TXTResource, err error) { +func TXTMetrics(x *Xip, _ net.IP) (txtResources []dnsmessage.TXTResource, err error) { <-x.DnsAmplificationAttackDelay var metrics []string uptime := time.Since(x.Metrics.Start)