Skip to content

Commit

Permalink
Respond case insensitively to A and SOA requests (#152)
Browse files Browse the repository at this point in the history
* When appending the SOA for authoritative NXDOMAIN responses, it needs to go in
the Authoritative section, not the Answer section.

This fixes the acme-dns validation for the lego Let's Encrypt client.

* Respond case-insensitively to A and SOA requests. Add corresponding tests.

This fixes the autocert feature with Let's Encrypt, because Let's Encrypt does
a lookup for the A record with a deliberately mangled case.
  • Loading branch information
cure authored and joohoi committed Feb 7, 2019
1 parent 41a1cff commit 37db83e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (d *DNSServer) readQuery(m *dns.Msg) {
func (d *DNSServer) getRecord(q dns.Question) ([]dns.RR, error) {
var rr []dns.RR
var cnames []dns.RR
domain, ok := d.Domains[q.Name]
domain, ok := d.Domains[strings.ToLower(q.Name)]
if !ok {
return rr, fmt.Errorf("No records for domain %s", q.Name)
}
Expand All @@ -133,15 +133,15 @@ func (d *DNSServer) getRecord(q dns.Question) ([]dns.RR, error) {

// answeringForDomain checks if we have any records for a domain
func (d *DNSServer) answeringForDomain(name string) bool {
_, ok := d.Domains[name]
_, ok := d.Domains[strings.ToLower(name)]
return ok
}

func (d *DNSServer) isAuthoritative(q dns.Question) bool {
if d.answeringForDomain(q.Name) {
return true
}
domainParts := strings.Split(q.Name, ".")
domainParts := strings.Split(strings.ToLower(q.Name), ".")
for i := range domainParts {
if d.answeringForDomain(strings.Join(domainParts[i:], ".")) {
return true
Expand Down
24 changes: 24 additions & 0 deletions dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,27 @@ func TestResolveTXT(t *testing.T) {
}
}
}

func TestCaseInsensitiveResolveA(t *testing.T) {
resolv := resolver{server: "127.0.0.1:15353"}
answer, err := resolv.lookup("aUtH.eXAmpLe.org", dns.TypeA)
if err != nil {
t.Errorf("%v", err)
}

if len(answer.Answer) == 0 {
t.Error("No answer for DNS query")
}
}

func TestCaseInsensitiveResolveSOA(t *testing.T) {
resolv := resolver{server: "127.0.0.1:15353"}
answer, _ := resolv.lookup("doesnotexist.aUtH.eXAmpLe.org", dns.TypeSOA)
if answer.Rcode != dns.RcodeNameError {
t.Errorf("Was expecing NXDOMAIN rcode, but got [%s] instead.", dns.RcodeToString[answer.Rcode])
}

if len(answer.Ns) == 0 {
t.Error("No SOA answer for DNS query")
}
}

0 comments on commit 37db83e

Please sign in to comment.