Skip to content

Commit

Permalink
Fix compatibility with the old dnscrypt-proxy version
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Apr 14, 2021
1 parent 27514f9 commit b7fd5d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ func generate(args GenerateArgs) {

log.Info("Configuration has been written to %s", args.Out)
log.Info("Go to https://dnscrypt.info/stamps to generate an SDNS stamp")
log.Info("You can run a DNSCrypt server using the following command:")
log.Info("dnscrypt server -c %s -f 8.8.8.8", args.Out)
}
10 changes: 8 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dnscrypt
import (
"context"
"net"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -158,7 +159,7 @@ func (s *Server) isStarted() bool {
return started
}

// serveDNS serves DNS response
// serveDNS serves a DNS response
func (s *Server) serveDNS(rw ResponseWriter, r *dns.Msg) error {
if r == nil || len(r.Question) != 1 || r.Response {
return ErrInvalidQuery
Expand Down Expand Up @@ -240,7 +241,8 @@ func (s *Server) handleHandshake(b []byte, certTxt string) ([]byte, error) {

q := m.Question[0]
providerName := dns.Fqdn(s.ProviderName)
if q.Qtype != dns.TypeTXT || q.Name != providerName {
qName := strings.ToLower(q.Name) // important, may be random case
if q.Qtype != dns.TypeTXT || qName != providerName {
// Invalid provider name or type, doing nothing
return nil, ErrInvalidQuery
}
Expand All @@ -259,6 +261,10 @@ func (s *Server) handleHandshake(b []byte, certTxt string) ([]byte, error) {
},
}
reply.Answer = append(reply.Answer, txt)

// These bits are important for the old dnscrypt-proxy versions
reply.Authoritative = true
reply.RecursionAvailable = true
return reply.Pack()
}

Expand Down

0 comments on commit b7fd5d3

Please sign in to comment.