diff --git a/doh-server/ietf.go b/doh-server/ietf.go index 869e5cb..017bcb1 100644 --- a/doh-server/ietf.go +++ b/doh-server/ietf.go @@ -24,6 +24,7 @@ package main import ( + "bytes" "encoding/base64" "fmt" "io/ioutil" @@ -60,6 +61,13 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe errtext: fmt.Sprintf("Invalid argument value: \"dns\""), } } + + if s.patchDNSCryptProxyReqID(requestBinary, w) { + return &DNSRequest{ + errcode: 444, + } + } + msg := new(dns.Msg) err = msg.Unpack(requestBinary) if err != nil { @@ -161,3 +169,16 @@ func (s *Server) generateResponseIETF(w http.ResponseWriter, r *http.Request, re } w.Write(respBytes) } + +// Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe +func (s *Server) patchDNSCryptProxyReqID(requestBinary []byte, w http.ResponseWriter) bool { + if bytes.Equal(requestBinary, []byte("\xca\xfe\x01\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\x00\x02\x00\x01\x00\x00\x29\x10\x00\x00\x00\x80\x00\x00\x00")) { + log.Println("DNSCrypt-Proxy detected. Patching response.") + w.Header().Set("Content-Type", "application/octet-stream") + now := time.Now().UTC().Format(http.TimeFormat) + w.Header().Set("Date", now) + w.Write([]byte("\xca\xfe\x81\x01\x00\x01\r\nWorkaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe\r\nDo you know it is a violation of the protocol you fxxking DNSCrypt-Proxy?!\r\n")) + return true + } + return false +} diff --git a/doh-server/server.go b/doh-server/server.go index e2c98d6..404a8cb 100644 --- a/doh-server/server.go +++ b/doh-server/server.go @@ -159,6 +159,9 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) { jsonDNS.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415) return } + if req.errcode == 444 { + return + } if req.errcode != 0 { jsonDNS.FormatError(w, req.errtext, req.errcode) return