From 682f8a090418e060c4a8cef0f919bef02b5099ab Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Wed, 25 Oct 2023 12:49:39 +0200 Subject: [PATCH] dkim selectors shouldn't be interpreted as idna given they are not part of the domain name (to which idna applies). only the part after _domainkey may be idna. found after going through code after report about mx targets with underscores from richard g. --- dkim/parser.go | 8 ++++---- dkim/sig_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dkim/parser.go b/dkim/parser.go index 12cf2ee..7e60254 100644 --- a/dkim/parser.go +++ b/dkim/parser.go @@ -206,12 +206,12 @@ func (p *parser) xdomainselector(isselector bool) dns.Domain { for p.hasPrefix(".") { s += p.xtake(".") + p.xtakefn1(false, subdomain) } + if isselector { + // Not to be interpreted as IDNA. + return dns.Domain{ASCII: strings.ToLower(s)} + } d, err := dns.ParseDomain(s) if err != nil { - // ParseDomain does not allow underscore, work around it. - if strings.Contains(s, "_") && isselector && !moxvar.Pedantic { - return dns.Domain{ASCII: strings.ToLower(s)} - } p.xerrorf("parsing domain %q: %s", s, err) } return d diff --git a/dkim/sig_test.go b/dkim/sig_test.go index e69df0d..cc54fe8 100644 --- a/dkim/sig_test.go +++ b/dkim/sig_test.go @@ -91,7 +91,7 @@ func TestSig(t *testing.T) { BodyHash: xbase64("LjkN2rUhrS3zKXfH2vNgUzz5ERRJkgP9CURXBX0JP0Q="), Domain: xdomain("xn--mx-lka.example"), // møx.example SignedHeaders: []string{"from"}, - Selector: xdomain("xn--tst-bma"), // tést + Selector: dns.Domain{ASCII: "xn--tst-bma"}, Identity: &Identity{&ulp, xdomain("xn--tst-bma.xn--mx-lka.example")}, // tést.møx.example Canonicalization: "simple/simple", Length: -1,