mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-31 07:35:39 +00:00
Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ca6813801 | ||
|
|
033865e508 | ||
|
|
7e7cd1ee90 | ||
|
|
e19250dc99 | ||
|
|
a64df3f048 | ||
|
|
f54b49c090 | ||
|
|
87436b7cbf | ||
|
|
11056bcad5 | ||
|
|
ca33027e04 | ||
|
|
6ff0a6a9ab | ||
|
|
359c81a019 | ||
|
|
07143d5890 | ||
|
|
1d367cb7e7 | ||
|
|
b132de608f | ||
|
|
523b6120b9 | ||
|
|
82fe91395d | ||
|
|
06ce104d2a | ||
|
|
71b8c093c0 | ||
|
|
abdd033310 | ||
|
|
461d546082 | ||
|
|
51b065eed7 | ||
|
|
a58607dc3d | ||
|
|
cf94354b08 | ||
|
|
f2e3a642e3 | ||
|
|
88b3c95710 | ||
|
|
93b70f3941 | ||
|
|
76c40fb4dc | ||
|
|
174a465ac8 | ||
|
|
4cbe7c8c98 | ||
|
|
7839d2c7b1 | ||
|
|
c4b2236cf9 | ||
|
|
1b90731f20 | ||
|
|
20624acf20 | ||
|
|
01385b6d29 | ||
|
|
5afdee6315 | ||
|
|
874a3613e4 | ||
|
|
dc14a70e9d | ||
|
|
58e4018ab2 | ||
|
|
f4516429ee | ||
|
|
12df47f45f | ||
|
|
450c10a594 | ||
|
|
e7c4450787 | ||
|
|
bd5ef5d61e | ||
|
|
ff0e9529cb | ||
|
|
627e2d639d | ||
|
|
7d5cf98d2b | ||
|
|
34adf40b36 | ||
|
|
b9c1bcaad2 | ||
|
|
47df06b6e2 | ||
|
|
1abba72898 | ||
|
|
ce656ac3f7 | ||
|
|
83f20767ea | ||
|
|
07db7ba200 | ||
|
|
cdb8599c9f | ||
|
|
236f7931e6 | ||
|
|
196207631b | ||
|
|
9562c2fe5c | ||
|
|
0a107be362 | ||
|
|
efa272bc52 | ||
|
|
36da908686 | ||
|
|
8b45c99dfc | ||
|
|
68c3f30d14 | ||
|
|
7c4b818967 | ||
|
|
57c956594f | ||
|
|
542585b1ec | ||
|
|
1819deb6c0 |
106
Changelog.md
Normal file
106
Changelog.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# Changelog
|
||||
|
||||
This Changelog records major changes between versions.
|
||||
|
||||
Not all changes are recorded. Please check git log for details.
|
||||
|
||||
## Version 1.3.8
|
||||
|
||||
- Workaround a bug causing Firefox 61-62 to reject responses with Content-Type = application/dns-message
|
||||
- Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe
|
||||
- TransactionID is now preserved to maintain compatibility with some clients
|
||||
- Turn on `no_cookies` by default according to the IETF draft
|
||||
- Update Documentation
|
||||
|
||||
## Version 1.3.7
|
||||
|
||||
- Add CloudFlare DNS resolver for Tor to the preset
|
||||
- It is now able to print upstream information if error happens
|
||||
- Updated default configuration files are now installed to `*.conf.example`
|
||||
- Workaround a bug causing Unbound to refuse returning anything about the root
|
||||
- Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe
|
||||
|
||||
## Version 1.3.6
|
||||
|
||||
- We have a logger for macOS platform now, so logs can be sent to Console.app
|
||||
- Add an option to disable IPv6, this option is available to client only
|
||||
|
||||
## Version 1.3.5
|
||||
|
||||
- Limit the frequency of creating HTTP client on bad network condition
|
||||
|
||||
## Version 1.3.4
|
||||
|
||||
- doh-client now silently fails in case of network error to prevent caching of SERVFAIL
|
||||
- EDNS0 is now inserted to the beginning of OPT section, to ensure DNSSEC signatures are at the end
|
||||
- Improve building system
|
||||
- Update documents
|
||||
|
||||
## Version 1.3.3
|
||||
|
||||
- Take User-Agent out of common library, that would be better for packaging
|
||||
|
||||
## Version 1.3.2
|
||||
|
||||
- Fix version string in HTTP User-Agent
|
||||
|
||||
## Version 1.3.1
|
||||
|
||||
- Fix the "address already in use" issue
|
||||
|
||||
## Version 1.3.0
|
||||
|
||||
- Breaking change: Add client / server support for multiple listen address
|
||||
The `listen` option in the configuration file is a list now
|
||||
|
||||
## Version 1.2.1
|
||||
|
||||
- Update protocol to IETF draft-07
|
||||
- Update installation documentations for Ubuntu / Debian
|
||||
|
||||
## Version 1.2.0
|
||||
|
||||
- Add installation documentations for Ubuntu / Debian
|
||||
- Include CloudFlare DOH server (1.1.1.1, 1.0.0.1) in default configuration
|
||||
- Fix a problem causing `go get` to fail due to relative paths
|
||||
- Add documentation about `/etc/hosts` preloading
|
||||
|
||||
## Version 1.1.4
|
||||
|
||||
- Add `no_cookies` option
|
||||
- Add documentation on privacy issues
|
||||
- Adapt for CloudFlare DNS service
|
||||
- Fix a problem causing a single network failure blocking future requests
|
||||
- Add experimental macOS support
|
||||
|
||||
## Version 1.1.3
|
||||
|
||||
- Unsupported Content-Type now generates HTTP error code 415
|
||||
|
||||
## Version 1.1.2
|
||||
|
||||
- Adapt to IETF protocol
|
||||
- Optimize for HTTP caches
|
||||
|
||||
## Version 1.1.1
|
||||
|
||||
- Adapt to IETF protocol
|
||||
- Optimize for HTTP caches
|
||||
- Add documentation for uninstallation instructions
|
||||
- Fix build issues
|
||||
|
||||
## Version 1.1.0
|
||||
|
||||
- Adpat to IETF protocol
|
||||
- Fix issues regarding to HTTP caching
|
||||
- Require Go 1.9 to build now
|
||||
- Fix systemd issue
|
||||
|
||||
## Version 1.0.1
|
||||
|
||||
- Fix build issues
|
||||
|
||||
## Version 1.0.0
|
||||
|
||||
- First release
|
||||
- Relicense as MIT license
|
||||
53
Makefile
53
Makefile
@@ -2,31 +2,60 @@
|
||||
|
||||
GOBUILD=go build
|
||||
GOGET=go get -d -v
|
||||
GOGET_UPDATE=go get -d -u -v
|
||||
PREFIX=/usr/local
|
||||
ifeq ($(shell uname),Darwin)
|
||||
CONFDIR=/usr/local/etc/dns-over-https
|
||||
else
|
||||
CONFDIR=/etc/dns-over-https
|
||||
endif
|
||||
|
||||
all: doh-client/doh-client doh-server/doh-server
|
||||
if [ "`uname`" = "Darwin" ]; then \
|
||||
$(MAKE) -C darwin-wrapper; \
|
||||
fi
|
||||
|
||||
clean:
|
||||
rm -f doh-client/doh-client doh-server/doh-server
|
||||
if [ "`uname`" = "Darwin" ]; then \
|
||||
$(MAKE) -C darwin-wrapper clean; \
|
||||
fi
|
||||
|
||||
install: doh-client/doh-client doh-server/doh-server
|
||||
install -Dm0755 doh-client/doh-client "$(DESTDIR)$(PREFIX)/bin/doh-client"
|
||||
install -Dm0755 doh-server/doh-server "$(DESTDIR)$(PREFIX)/bin/doh-server"
|
||||
[ -e "$(DESTDIR)/etc/dns-over-https/doh-client.conf" ] || install -Dm0644 doh-client/doh-client.conf "$(DESTDIR)/etc/dns-over-https/doh-client.conf"
|
||||
[ -e "$(DESTDIR)/etc/dns-over-https/doh-server.conf" ] || install -Dm0644 doh-server/doh-server.conf "$(DESTDIR)/etc/dns-over-https/doh-server.conf"
|
||||
$(MAKE) -C systemd install "DESTDIR=$(DESTDIR)" "PREFIX=$(PREFIX)"
|
||||
$(MAKE) -C NetworkManager install "DESTDIR=$(DESTDIR)" "PREFIX=$(PREFIX)"
|
||||
install:
|
||||
[ -e doh-client/doh-client ] || $(MAKE) doh-client/doh-client
|
||||
[ -e doh-server/doh-server ] || $(MAKE) doh-server/doh-server
|
||||
mkdir -p "$(DESTDIR)$(PREFIX)/bin/"
|
||||
install -m0755 doh-client/doh-client "$(DESTDIR)$(PREFIX)/bin/doh-client"
|
||||
install -m0755 doh-server/doh-server "$(DESTDIR)$(PREFIX)/bin/doh-server"
|
||||
mkdir -p "$(DESTDIR)$(CONFDIR)/"
|
||||
install -m0644 doh-client/doh-client.conf "$(DESTDIR)$(CONFDIR)/doh-client.conf.example"
|
||||
install -m0644 doh-server/doh-server.conf "$(DESTDIR)$(CONFDIR)/doh-server.conf.example"
|
||||
[ -e "$(DESTDIR)$(CONFDIR)/doh-client.conf" ] || install -m0644 doh-client/doh-client.conf "$(DESTDIR)$(CONFDIR)/doh-client.conf"
|
||||
[ -e "$(DESTDIR)$(CONFDIR)/doh-server.conf" ] || install -m0644 doh-server/doh-server.conf "$(DESTDIR)$(CONFDIR)/doh-server.conf"
|
||||
if [ "`uname`" = "Linux" ]; then \
|
||||
$(MAKE) -C systemd install "DESTDIR=$(DESTDIR)"; \
|
||||
$(MAKE) -C NetworkManager install "DESTDIR=$(DESTDIR)"; \
|
||||
elif [ "`uname`" = "Darwin" ]; then \
|
||||
$(MAKE) -C darwin-wrapper install "DESTDIR=$(DESTDIR)" "PREFIX=$(PREFIX)"; \
|
||||
$(MAKE) -C launchd install "DESTDIR=$(DESTDIR)"; \
|
||||
fi
|
||||
|
||||
uninstall:
|
||||
rm -f "$(DESTDIR)$(PREFIX)/bin/doh-client" "$(DESTDIR)$(PREFIX)/bin/doh-server"
|
||||
$(MAKE) -C systemd uninstall "DESTDIR=$(DESTDIR)" "PREFIX=$(PREFIX)"
|
||||
$(MAKE) -C NetworkManager uninstall "DESTDIR=$(DESTDIR)" "PREFIX=$(PREFIX)"
|
||||
rm -f "$(DESTDIR)$(PREFIX)/bin/doh-client" "$(DESTDIR)$(PREFIX)/bin/doh-server" "$(DESTDIR)$(CONFDIR)/doh-client.conf.example" "$(DESTDIR)$(CONFDIR)/doh-server.conf.example"
|
||||
if [ "`uname`" = "Linux" ]; then \
|
||||
$(MAKE) -C systemd uninstall "DESTDIR=$(DESTDIR)"; \
|
||||
$(MAKE) -C NetworkManager uninstall "DESTDIR=$(DESTDIR)"; \
|
||||
elif [ "`uname`" = "Darwin" ]; then \
|
||||
$(MAKE) -C launchd uninstall "DESTDIR=$(DESTDIR)"; \
|
||||
fi
|
||||
|
||||
deps:
|
||||
@# I am not sure if it is the correct way to keep the common library updated
|
||||
$(GOGET_UPDATE) github.com/m13253/dns-over-https/json-dns
|
||||
$(GOGET) ./doh-client ./doh-server
|
||||
|
||||
doh-client/doh-client: deps doh-client/client.go doh-client/config.go doh-client/google.go doh-client/ietf.go doh-client/main.go json-dns/error.go json-dns/globalip.go json-dns/marshal.go json-dns/response.go json-dns/unmarshal.go
|
||||
doh-client/doh-client: deps doh-client/client.go doh-client/config.go doh-client/google.go doh-client/ietf.go doh-client/main.go doh-client/version.go json-dns/error.go json-dns/globalip.go json-dns/marshal.go json-dns/response.go json-dns/unmarshal.go
|
||||
cd doh-client && $(GOBUILD)
|
||||
|
||||
doh-server/doh-server: deps doh-server/config.go doh-server/google.go doh-server/ietf.go doh-server/main.go doh-server/server.go json-dns/error.go json-dns/globalip.go json-dns/marshal.go json-dns/response.go json-dns/unmarshal.go
|
||||
doh-server/doh-server: deps doh-server/config.go doh-server/google.go doh-server/ietf.go doh-server/main.go doh-server/server.go doh-server/version.go json-dns/error.go json-dns/globalip.go json-dns/marshal.go json-dns/response.go json-dns/unmarshal.go
|
||||
cd doh-server && $(GOBUILD)
|
||||
|
||||
17
Readme.md
17
Readme.md
@@ -70,6 +70,9 @@ The following is a typical DNS-over-HTTPS architecture:
|
||||
Although DNS-over-HTTPS can work alone, a HTTP service muxer would be useful as
|
||||
you can host DNS-over-HTTPS along with other HTTPS services.
|
||||
|
||||
HTTP/2 with at least TLS v1.3 is recommended. OCSP stapling must be enabled,
|
||||
otherwise DNS recursion may happen.
|
||||
|
||||
## DNSSEC
|
||||
|
||||
DNS-over-HTTPS is compatible with DNSSEC, and requests DNSSEC signatures by
|
||||
@@ -85,13 +88,15 @@ server. This is useful for GeoDNS and CDNs to work, and is exactly the same
|
||||
configuration as most public DNS servers.
|
||||
|
||||
Keep in mind that /24 is not enough to track a single user, although it is
|
||||
precise enough to know the city where the user is from. If you think
|
||||
precise enough to know the city where the user is located. If you think
|
||||
EDNS0-Client-Subnet is affecting your privacy, you can set `no_ecs = true` in
|
||||
`/etc/dns-over-https/doh-client.conf`, with the cost of slower video streaming
|
||||
or software downloading speed.
|
||||
|
||||
If your server is backed by `unbound` or `bind`, you probably want to enable
|
||||
the EDNS0-Client-Subnet feature in their configuration files as well.
|
||||
To ultilize ECS, `X-Forwarded-For` or `X-Real-IP` should be enabled on your
|
||||
HTTP service muxer. If your server is backed by `unbound` or `bind`, you
|
||||
probably want to configure it to enable the EDNS0-Client-Subnet feature as
|
||||
well.
|
||||
|
||||
## Protocol compatibility
|
||||
|
||||
@@ -116,6 +121,12 @@ Currently supported features are:
|
||||
- [X] EDNS0 large UDP packet (4 KiB by default)
|
||||
- [X] EDNS0-Client-Subnet (/24 for IPv4, /48 for IPv6 by default)
|
||||
|
||||
## The name of the project
|
||||
|
||||
This project is named "DNS-over-HTTPS" because it was written before the IETF DoH project. Although this project is compatible with IETF DoH, the project is not affiliated with IETF.
|
||||
|
||||
To avoid confusion, you may also call this project "m13253/DNS-over-HTTPS" or anything you like.
|
||||
|
||||
## License
|
||||
|
||||
DNS-over-HTTPS is licensed under the [MIT License](LICENSE). You are encouraged
|
||||
|
||||
19
darwin-wrapper/Makefile
Normal file
19
darwin-wrapper/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
.PHONY: all clean install uninstall
|
||||
|
||||
SWIFTC = swiftc
|
||||
PREFIX = /usr/local
|
||||
|
||||
all: doh-logger
|
||||
|
||||
doh-logger: doh-logger.swift
|
||||
$(SWIFTC) -o $@ -O $<
|
||||
|
||||
clean:
|
||||
rm -f doh-logger
|
||||
|
||||
install: doh-logger
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
install -m0755 doh-logger $(DESTDIR)$(PREFIX)/bin
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/doh-logger
|
||||
94
darwin-wrapper/doh-logger.swift
Normal file
94
darwin-wrapper/doh-logger.swift
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/swift
|
||||
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
|
||||
if CommandLine.arguments.count < 3 {
|
||||
let programName = CommandLine.arguments[0]
|
||||
print("Usage: \(programName) LOG_NAME PROGRAM [ARGUMENTS]\n")
|
||||
exit(1)
|
||||
}
|
||||
let logSubsystem = CommandLine.arguments[1]
|
||||
let logger = OSLog(subsystem: logSubsystem, category: "default")
|
||||
|
||||
let pipe = Pipe()
|
||||
var buffer = Data()
|
||||
NotificationCenter.default.addObserver(forName: FileHandle.readCompletionNotification, object: pipe.fileHandleForReading, queue: nil) { notification in
|
||||
let data = notification.userInfo?["NSFileHandleNotificationDataItem"] as? Data ?? Data()
|
||||
buffer.append(data)
|
||||
var lastIndex = 0
|
||||
for (i, byte) in buffer.enumerated() {
|
||||
if byte == 0x0a {
|
||||
let line = String(data: buffer.subdata(in: lastIndex..<i), encoding: .utf8) ?? ""
|
||||
print(line)
|
||||
os_log("%{public}@", log: logger, line)
|
||||
lastIndex = i + 1
|
||||
}
|
||||
}
|
||||
buffer = buffer.subdata(in: lastIndex..<buffer.count)
|
||||
if data.count == 0 && buffer.count != 0 {
|
||||
let line = String(data: buffer, encoding: .utf8) ?? ""
|
||||
print(line, terminator: "")
|
||||
os_log("%{public}@", log: logger, line)
|
||||
}
|
||||
pipe.fileHandleForReading.readInBackgroundAndNotify()
|
||||
}
|
||||
pipe.fileHandleForReading.readInBackgroundAndNotify()
|
||||
|
||||
let process = Process()
|
||||
process.arguments = Array(CommandLine.arguments[3...])
|
||||
process.executableURL = URL(fileURLWithPath: CommandLine.arguments[2])
|
||||
process.standardError = pipe.fileHandleForWriting
|
||||
process.standardInput = FileHandle.standardInput
|
||||
process.standardOutput = pipe.fileHandleForWriting
|
||||
NotificationCenter.default.addObserver(forName: Process.didTerminateNotification, object: process, queue: nil) { notification in
|
||||
if buffer.count != 0 {
|
||||
let line = String(data: buffer, encoding: .utf8) ?? ""
|
||||
print(line, terminator: "")
|
||||
os_log("%{public}@", log: logger, line)
|
||||
}
|
||||
exit(process.terminationStatus)
|
||||
}
|
||||
|
||||
let SIGINTSource = DispatchSource.makeSignalSource(signal: SIGINT)
|
||||
let SIGTERMSource = DispatchSource.makeSignalSource(signal: SIGTERM)
|
||||
SIGINTSource.setEventHandler(handler: process.interrupt)
|
||||
SIGTERMSource.setEventHandler(handler: process.terminate)
|
||||
signal(SIGINT, SIG_IGN)
|
||||
signal(SIGTERM, SIG_IGN)
|
||||
SIGINTSource.resume()
|
||||
SIGTERMSource.resume()
|
||||
|
||||
do {
|
||||
try process.run()
|
||||
} catch {
|
||||
let errorMessage = error.localizedDescription
|
||||
print(errorMessage)
|
||||
os_log("%{public}@", log: logger, type: .fault, errorMessage)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
RunLoop.current.run()
|
||||
@@ -31,20 +31,25 @@ import (
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"../json-dns"
|
||||
"github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
conf *config
|
||||
bootstrap []string
|
||||
udpServer *dns.Server
|
||||
tcpServer *dns.Server
|
||||
httpTransport *http.Transport
|
||||
httpClient *http.Client
|
||||
conf *config
|
||||
bootstrap []string
|
||||
udpServers []*dns.Server
|
||||
tcpServers []*dns.Server
|
||||
bootstrapResolver *net.Resolver
|
||||
cookieJar *cookiejar.Jar
|
||||
httpClientMux *sync.RWMutex
|
||||
httpTransport *http.Transport
|
||||
httpClient *http.Client
|
||||
httpClientLastCreate time.Time
|
||||
}
|
||||
|
||||
type DNSRequest struct {
|
||||
@@ -53,6 +58,7 @@ type DNSRequest struct {
|
||||
udpSize uint16
|
||||
ednsClientAddress net.IP
|
||||
ednsClientNetmask uint8
|
||||
currentUpstream string
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -60,18 +66,23 @@ func NewClient(conf *config) (c *Client, err error) {
|
||||
c = &Client{
|
||||
conf: conf,
|
||||
}
|
||||
c.udpServer = &dns.Server{
|
||||
Addr: conf.Listen,
|
||||
Net: "udp",
|
||||
Handler: dns.HandlerFunc(c.udpHandlerFunc),
|
||||
UDPSize: 4096,
|
||||
|
||||
udpHandler := dns.HandlerFunc(c.udpHandlerFunc)
|
||||
tcpHandler := dns.HandlerFunc(c.tcpHandlerFunc)
|
||||
for _, addr := range conf.Listen {
|
||||
c.udpServers = append(c.udpServers, &dns.Server{
|
||||
Addr: addr,
|
||||
Net: "udp",
|
||||
Handler: udpHandler,
|
||||
UDPSize: dns.DefaultMsgSize,
|
||||
})
|
||||
c.tcpServers = append(c.tcpServers, &dns.Server{
|
||||
Addr: addr,
|
||||
Net: "tcp",
|
||||
Handler: tcpHandler,
|
||||
})
|
||||
}
|
||||
c.tcpServer = &dns.Server{
|
||||
Addr: conf.Listen,
|
||||
Net: "tcp",
|
||||
Handler: dns.HandlerFunc(c.tcpHandlerFunc),
|
||||
}
|
||||
bootResolver := net.DefaultResolver
|
||||
c.bootstrapResolver = net.DefaultResolver
|
||||
if len(conf.Bootstrap) != 0 {
|
||||
c.bootstrap = make([]string, len(conf.Bootstrap))
|
||||
for i, bootstrap := range conf.Bootstrap {
|
||||
@@ -84,7 +95,7 @@ func NewClient(conf *config) (c *Client, err error) {
|
||||
}
|
||||
c.bootstrap[i] = bootstrapAddr.String()
|
||||
}
|
||||
bootResolver = &net.Resolver{
|
||||
c.bootstrapResolver = &net.Resolver{
|
||||
PreferGo: true,
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
var d net.Dialer
|
||||
@@ -95,57 +106,88 @@ func NewClient(conf *config) (c *Client, err error) {
|
||||
},
|
||||
}
|
||||
}
|
||||
c.httpTransport = new(http.Transport)
|
||||
// Most CDNs require Cookie support to prevent DDoS attack.
|
||||
// Disabling Cookie does not effectively prevent tracking,
|
||||
// so I will leave it on to make anti-DDoS services happy.
|
||||
if !c.conf.NoCookies {
|
||||
c.cookieJar, err = cookiejar.New(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.httpClientMux = new(sync.RWMutex)
|
||||
err = c.newHTTPClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *Client) newHTTPClient() error {
|
||||
c.httpClientMux.Lock()
|
||||
defer c.httpClientMux.Unlock()
|
||||
if !c.httpClientLastCreate.IsZero() && time.Now().Sub(c.httpClientLastCreate) < time.Duration(c.conf.Timeout)*time.Second {
|
||||
return nil
|
||||
}
|
||||
if c.httpTransport != nil {
|
||||
c.httpTransport.CloseIdleConnections()
|
||||
}
|
||||
dialer := &net.Dialer{
|
||||
Timeout: time.Duration(c.conf.Timeout) * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
DualStack: true,
|
||||
Resolver: c.bootstrapResolver,
|
||||
}
|
||||
c.httpTransport = &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: time.Duration(conf.Timeout) * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
DualStack: true,
|
||||
Resolver: bootResolver,
|
||||
}).DialContext,
|
||||
DialContext: dialer.DialContext,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 10,
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
ResponseHeaderTimeout: time.Duration(conf.Timeout) * time.Second,
|
||||
TLSHandshakeTimeout: time.Duration(conf.Timeout) * time.Second,
|
||||
ResponseHeaderTimeout: time.Duration(c.conf.Timeout) * time.Second,
|
||||
TLSHandshakeTimeout: time.Duration(c.conf.Timeout) * time.Second,
|
||||
}
|
||||
http2.ConfigureTransport(c.httpTransport)
|
||||
// Most CDNs require Cookie support to prevent DDoS attack
|
||||
cookieJar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.httpClient = &http.Client{
|
||||
Transport: c.httpTransport,
|
||||
Jar: cookieJar,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *Client) Start() error {
|
||||
result := make(chan error)
|
||||
go func() {
|
||||
err := c.udpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
if c.conf.NoIPv6 {
|
||||
c.httpTransport.DialContext = func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
if strings.HasPrefix(network, "tcp") {
|
||||
network = "tcp4"
|
||||
}
|
||||
return dialer.DialContext(ctx, network, address)
|
||||
}
|
||||
result <- err
|
||||
}()
|
||||
go func() {
|
||||
err := c.tcpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
result <- err
|
||||
}()
|
||||
err := <-result
|
||||
}
|
||||
err := http2.ConfigureTransport(c.httpTransport)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = <-result
|
||||
return err
|
||||
c.httpClient = &http.Client{
|
||||
Transport: c.httpTransport,
|
||||
Jar: c.cookieJar,
|
||||
}
|
||||
c.httpClientLastCreate = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) Start() error {
|
||||
results := make(chan error, len(c.udpServers)+len(c.tcpServers))
|
||||
for _, srv := range append(c.udpServers, c.tcpServers...) {
|
||||
go func(srv *dns.Server) {
|
||||
err := srv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
results <- err
|
||||
}(srv)
|
||||
}
|
||||
|
||||
for i := 0; i < cap(results); i++ {
|
||||
err := <-results
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
close(results)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
@@ -156,23 +198,23 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
|
||||
requestType := ""
|
||||
if len(c.conf.UpstreamIETF) == 0 {
|
||||
requestType = "application/x-www-form-urlencoded"
|
||||
requestType = "application/dns-json"
|
||||
} else if len(c.conf.UpstreamGoogle) == 0 {
|
||||
requestType = "application/dns-udpwireformat"
|
||||
requestType = "application/dns-message"
|
||||
} else {
|
||||
numServers := len(c.conf.UpstreamGoogle) + len(c.conf.UpstreamIETF)
|
||||
random := rand.Intn(numServers)
|
||||
if random < len(c.conf.UpstreamGoogle) {
|
||||
requestType = "application/x-www-form-urlencoded"
|
||||
requestType = "application/dns-json"
|
||||
} else {
|
||||
requestType = "application/dns-udpwireformat"
|
||||
requestType = "application/dns-message"
|
||||
}
|
||||
}
|
||||
|
||||
var req *DNSRequest
|
||||
if requestType == "application/x-www-form-urlencoded" {
|
||||
if requestType == "application/dns-json" {
|
||||
req = c.generateRequestGoogle(w, r, isTCP)
|
||||
} else if requestType == "application/dns-udpwireformat" {
|
||||
} else if requestType == "application/dns-message" {
|
||||
req = c.generateRequestIETF(w, r, isTCP)
|
||||
} else {
|
||||
panic("Unknown request Content-Type")
|
||||
@@ -186,19 +228,21 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
candidateType := strings.SplitN(req.response.Header.Get("Content-Type"), ";", 2)[0]
|
||||
if candidateType == "application/json" {
|
||||
contentType = "application/json"
|
||||
} else if candidateType == "application/dns-message" {
|
||||
contentType = "application/dns-message"
|
||||
} else if candidateType == "application/dns-udpwireformat" {
|
||||
contentType = "application/dns-udpwireformat"
|
||||
contentType = "application/dns-message"
|
||||
} else {
|
||||
if requestType == "application/x-www-form-urlencoded" {
|
||||
if requestType == "application/dns-json" {
|
||||
contentType = "application/json"
|
||||
} else if requestType == "application/dns-udpwireformat" {
|
||||
contentType = "application/dns-udpwireformat"
|
||||
} else if requestType == "application/dns-message" {
|
||||
contentType = "application/dns-message"
|
||||
}
|
||||
}
|
||||
|
||||
if contentType == "application/json" {
|
||||
c.parseResponseGoogle(w, r, isTCP, req)
|
||||
} else if contentType == "application/dns-udpwireformat" {
|
||||
} else if contentType == "application/dns-message" {
|
||||
c.parseResponseIETF(w, r, isTCP, req)
|
||||
} else {
|
||||
panic("Unknown response Content-Type")
|
||||
|
||||
@@ -30,12 +30,14 @@ import (
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Listen string `toml:"listen"`
|
||||
Listen []string `toml:"listen"`
|
||||
UpstreamGoogle []string `toml:"upstream_google"`
|
||||
UpstreamIETF []string `toml:"upstream_ietf"`
|
||||
Bootstrap []string `toml:"bootstrap"`
|
||||
Timeout uint `toml:"timeout"`
|
||||
NoCookies bool `toml:"no_cookies"`
|
||||
NoECS bool `toml:"no_ecs"`
|
||||
NoIPv6 bool `toml:"no_ipv6"`
|
||||
Verbose bool `toml:"verbose"`
|
||||
}
|
||||
|
||||
@@ -49,8 +51,8 @@ func loadConfig(path string) (*config, error) {
|
||||
return nil, &configError{fmt.Sprintf("unknown option %q", key.String())}
|
||||
}
|
||||
|
||||
if conf.Listen == "" {
|
||||
conf.Listen = "127.0.0.1:53"
|
||||
if len(conf.Listen) == 0 {
|
||||
conf.Listen = []string{"127.0.0.1:53", "[::1]:53"}
|
||||
}
|
||||
if len(conf.UpstreamGoogle) == 0 && len(conf.UpstreamIETF) == 0 {
|
||||
conf.UpstreamGoogle = []string{"https://dns.google.com/resolve"}
|
||||
|
||||
@@ -1,28 +1,87 @@
|
||||
# DNS listen port
|
||||
listen = "127.0.0.1:53"
|
||||
listen = [
|
||||
"127.0.0.1:53",
|
||||
"[::1]:53",
|
||||
]
|
||||
|
||||
# HTTP path for upstream resolver
|
||||
# If multiple servers are specified, a random one will be chosen each time.
|
||||
upstream_google = [
|
||||
|
||||
# Google's productive resolver, good ECS, bad DNSSEC
|
||||
"https://dns.google.com/resolve",
|
||||
|
||||
# CloudFlare's resolver, bad ECS, good DNSSEC
|
||||
#"https://cloudflare-dns.com/dns-query",
|
||||
#"https://1.1.1.1/dns-query",
|
||||
#"https://1.0.0.1/dns-query",
|
||||
|
||||
# CloudFlare's resolver for Tor, available only with Tor
|
||||
# Remember to disable ECS below when using Tor!
|
||||
# Blog: https://blog.cloudflare.com/welcome-hidden-resolver/
|
||||
#"https://dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.onion/dns-query",
|
||||
|
||||
]
|
||||
upstream_ietf = [
|
||||
|
||||
# Google's experimental resolver, good ECS, good DNSSEC
|
||||
#"https://dns.google.com/experimental",
|
||||
|
||||
# CloudFlare's resolver, bad ECS, good DNSSEC
|
||||
#"https://cloudflare-dns.com/dns-query",
|
||||
#"https://1.1.1.1/dns-query",
|
||||
#"https://1.0.0.1/dns-query",
|
||||
|
||||
# CloudFlare's resolver for Tor, available only with Tor
|
||||
# Remember to disable ECS below when using Tor!
|
||||
# Blog: https://blog.cloudflare.com/welcome-hidden-resolver/
|
||||
#"https://dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.onion/dns-query",
|
||||
|
||||
]
|
||||
|
||||
# Bootstrap DNS server to resolve the address of the upstream resolver
|
||||
# If multiple servers are specified, a random one will be chosen each time.
|
||||
# If empty, use the system DNS settings.
|
||||
# If you want to preload IP addresses in /etc/hosts instead of using a
|
||||
# bootstrap server, please make this list empty.
|
||||
bootstrap = [
|
||||
|
||||
# Google's resolver, bad ECS, good DNSSEC
|
||||
"8.8.8.8:53",
|
||||
"8.8.4.4:53",
|
||||
|
||||
# CloudFlare's resolver, bad ECS, good DNSSEC
|
||||
#"1.1.1.1:53",
|
||||
#"1.0.0.1:53",
|
||||
|
||||
]
|
||||
|
||||
# Timeout for upstream request
|
||||
timeout = 10
|
||||
timeout = 30
|
||||
|
||||
# Disable EDNS0-Client-Subnet, do not send client's IP address
|
||||
# Disable HTTP Cookies
|
||||
#
|
||||
# Cookies may be useful if your upstream resolver is protected by some
|
||||
# anti-DDoS services to identify clients.
|
||||
# Note that DNS Cookies (an DNS protocol extension to DNS) also has the ability
|
||||
# to track uesrs and is not controlled by doh-client.
|
||||
no_cookies = true
|
||||
|
||||
# Disable EDNS0-Client-Subnet (ECS)
|
||||
#
|
||||
# DNS-over-HTTPS supports EDNS0-Client-Subnet protocol, which submits part of
|
||||
# the client's IP address (/24 for IPv4, /48 for IPv6 by default) to the
|
||||
# upstream server. This is useful for GeoDNS and CDNs to work, and is exactly
|
||||
# the same configuration as most public DNS servers.
|
||||
no_ecs = false
|
||||
|
||||
# Disable IPv6 when querying upstream
|
||||
#
|
||||
# Only enable this if you really have trouble connecting.
|
||||
# Doh-client uses both IPv4 and IPv6 by default and should not have problems
|
||||
# with an IPv4-only environment.
|
||||
# Note that DNS listening and bootstrapping is not controlled by this option.
|
||||
no_ipv6 = false
|
||||
|
||||
# Enable logging
|
||||
verbose = false
|
||||
|
||||
@@ -35,7 +35,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"../json-dns"
|
||||
"github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -51,8 +51,7 @@ func (c *Client) generateRequestGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP b
|
||||
}
|
||||
}
|
||||
question := &r.Question[0]
|
||||
// knot-resolver scrambles capitalization, I think it is unfriendly to cache
|
||||
questionName := strings.ToLower(question.Name)
|
||||
questionName := question.Name
|
||||
questionType := ""
|
||||
if qtype, ok := dns.TypeToString[question.Qtype]; ok {
|
||||
questionType = qtype
|
||||
@@ -66,7 +65,7 @@ func (c *Client) generateRequestGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP b
|
||||
|
||||
numServers := len(c.conf.UpstreamGoogle)
|
||||
upstream := c.conf.UpstreamGoogle[rand.Intn(numServers)]
|
||||
requestURL := fmt.Sprintf("%s?name=%s&type=%s", upstream, url.QueryEscape(questionName), url.QueryEscape(questionType))
|
||||
requestURL := fmt.Sprintf("%s?ct=application/dns-json&name=%s&type=%s", upstream, url.QueryEscape(questionName), url.QueryEscape(questionType))
|
||||
|
||||
if r.CheckingDisabled {
|
||||
requestURL += "&cd=1"
|
||||
@@ -91,14 +90,19 @@ func (c *Client) generateRequestGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP b
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
req.Header.Set("Accept", "application/json, application/dns-udpwireformat")
|
||||
req.Header.Set("User-Agent", "DNS-over-HTTPS/1.1 (+https://github.com/m13253/dns-over-https)")
|
||||
req.Header.Set("Accept", "application/json, application/dns-message, application/dns-udpwireformat")
|
||||
req.Header.Set("User-Agent", USER_AGENT)
|
||||
c.httpClientMux.RLock()
|
||||
resp, err := c.httpClient.Do(req)
|
||||
c.httpClientMux.RUnlock()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
c.httpTransport.CloseIdleConnections()
|
||||
err1 := c.newHTTPClient()
|
||||
if err1 != nil {
|
||||
log.Fatalln(err1)
|
||||
}
|
||||
return &DNSRequest{
|
||||
err: err,
|
||||
}
|
||||
@@ -110,12 +114,13 @@ func (c *Client) generateRequestGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP b
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
currentUpstream: upstream,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) parseResponseGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP bool, req *DNSRequest) {
|
||||
if req.response.StatusCode != 200 {
|
||||
log.Printf("HTTP error: %s\n", req.response.Status)
|
||||
log.Printf("HTTP error from upstream %s: %s\n", req.currentUpstream, req.response.Status)
|
||||
req.reply.Rcode = dns.RcodeServerFailure
|
||||
contentType := req.response.Header.Get("Content-Type")
|
||||
if contentType != "application/json" && !strings.HasPrefix(contentType, "application/json;") {
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"../json-dns"
|
||||
"github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -53,8 +53,7 @@ func (c *Client) generateRequestIETF(w dns.ResponseWriter, r *dns.Msg, isTCP boo
|
||||
}
|
||||
|
||||
question := &r.Question[0]
|
||||
// knot-resolver scrambles capitalization, I think it is unfriendly to cache
|
||||
questionName := strings.ToLower(question.Name)
|
||||
questionName := question.Name
|
||||
questionType := ""
|
||||
if qtype, ok := dns.TypeToString[question.Qtype]; ok {
|
||||
questionType = qtype
|
||||
@@ -73,9 +72,9 @@ func (c *Client) generateRequestIETF(w dns.ResponseWriter, r *dns.Msg, isTCP boo
|
||||
opt = new(dns.OPT)
|
||||
opt.Hdr.Name = "."
|
||||
opt.Hdr.Rrtype = dns.TypeOPT
|
||||
opt.SetUDPSize(4096)
|
||||
opt.SetUDPSize(dns.DefaultMsgSize)
|
||||
opt.SetDo(false)
|
||||
r.Extra = append(r.Extra, opt)
|
||||
r.Extra = append([]dns.RR{opt}, r.Extra...)
|
||||
} else {
|
||||
udpSize = opt.UDPSize()
|
||||
}
|
||||
@@ -128,14 +127,14 @@ func (c *Client) generateRequestIETF(w dns.ResponseWriter, r *dns.Msg, isTCP boo
|
||||
numServers := len(c.conf.UpstreamIETF)
|
||||
upstream := c.conf.UpstreamIETF[rand.Intn(numServers)]
|
||||
requestURL := fmt.Sprintf("%s?ct=application/dns-udpwireformat&dns=%s", upstream, requestBase64)
|
||||
//requestURL := fmt.Sprintf("%s?ct=application/dns-message&dns=%s", upstream, requestBase64)
|
||||
|
||||
var req *http.Request
|
||||
if len(requestURL) < 2048 {
|
||||
req, err = http.NewRequest("GET", requestURL, nil)
|
||||
if err != nil {
|
||||
// Do not respond, silently fail to prevent caching of SERVFAIL
|
||||
log.Println(err)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
err: err,
|
||||
}
|
||||
@@ -143,23 +142,27 @@ func (c *Client) generateRequestIETF(w dns.ResponseWriter, r *dns.Msg, isTCP boo
|
||||
} else {
|
||||
req, err = http.NewRequest("POST", upstream, bytes.NewReader(requestBinary))
|
||||
if err != nil {
|
||||
// Do not respond, silently fail to prevent caching of SERVFAIL
|
||||
log.Println(err)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
return &DNSRequest{
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/dns-udpwireformat")
|
||||
req.Header.Set("Content-Type", "application/dns-message")
|
||||
}
|
||||
req.Header.Set("Accept", "application/dns-udpwireformat, application/json")
|
||||
req.Header.Set("User-Agent", "DNS-over-HTTPS/1.1 (+https://github.com/m13253/dns-over-https)")
|
||||
req.Header.Set("Accept", "application/dns-message, application/dns-udpwireformat, application/json")
|
||||
req.Header.Set("User-Agent", USER_AGENT)
|
||||
c.httpClientMux.RLock()
|
||||
resp, err := c.httpClient.Do(req)
|
||||
c.httpClientMux.RUnlock()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply.Rcode = dns.RcodeServerFailure
|
||||
w.WriteMsg(reply)
|
||||
c.httpTransport.CloseIdleConnections()
|
||||
err1 := c.newHTTPClient()
|
||||
if err1 != nil {
|
||||
log.Fatalln(err1)
|
||||
}
|
||||
return &DNSRequest{
|
||||
err: err,
|
||||
}
|
||||
@@ -171,15 +174,16 @@ func (c *Client) generateRequestIETF(w dns.ResponseWriter, r *dns.Msg, isTCP boo
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
currentUpstream: upstream,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) parseResponseIETF(w dns.ResponseWriter, r *dns.Msg, isTCP bool, req *DNSRequest) {
|
||||
if req.response.StatusCode != 200 {
|
||||
log.Printf("HTTP error: %s\n", req.response.Status)
|
||||
log.Printf("HTTP error from upstream %s: %s\n", req.currentUpstream, req.response.Status)
|
||||
req.reply.Rcode = dns.RcodeServerFailure
|
||||
contentType := req.response.Header.Get("Content-Type")
|
||||
if contentType != "application/dns-udpwireformat" && !strings.HasPrefix(contentType, "application/dns-udpwireformat;") {
|
||||
if contentType != "application/dns-message" && !strings.HasPrefix(contentType, "application/dns-message;") {
|
||||
w.WriteMsg(req.reply)
|
||||
return
|
||||
}
|
||||
|
||||
29
doh-client/version.go
Normal file
29
doh-client/version.go
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
VERSION = "1.3.8"
|
||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||
)
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Listen string `toml:"listen"`
|
||||
Listen []string `toml:"listen"`
|
||||
Cert string `toml:"cert"`
|
||||
Key string `toml:"key"`
|
||||
Path string `toml:"path"`
|
||||
@@ -51,9 +51,10 @@ func loadConfig(path string) (*config, error) {
|
||||
return nil, &configError{fmt.Sprintf("unknown option %q", key.String())}
|
||||
}
|
||||
|
||||
if conf.Listen == "" {
|
||||
conf.Listen = "127.0.0.1:8053"
|
||||
if len(conf.Listen) == 0 {
|
||||
conf.Listen = []string{"127.0.0.1:8053", "[::1]:8053"}
|
||||
}
|
||||
|
||||
if conf.Path == "" {
|
||||
conf.Path = "/dns-query"
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
# HTTP listen port
|
||||
listen = "127.0.0.1:8053"
|
||||
listen = [
|
||||
"127.0.0.1:8053",
|
||||
"[::1]:8053",
|
||||
]
|
||||
|
||||
# TLS certification file
|
||||
# If left empty, plain-text HTTP will be used.
|
||||
# Please be informed that this program does not do OCSP Stapling, which is
|
||||
# necessary for some clients to bootstrap itself.
|
||||
# You are recommended to use a server load balancer (Caddy, Nginx) and set up
|
||||
# TLS there.
|
||||
cert = ""
|
||||
|
||||
# TLS key file
|
||||
# TLS private key file
|
||||
key = ""
|
||||
|
||||
# HTTP path for resolve application
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"../json-dns"
|
||||
"github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
@@ -46,7 +46,6 @@ func (s *Server) parseRequestGoogle(w http.ResponseWriter, r *http.Request) *DNS
|
||||
errtext: "Invalid argument value: \"name\"",
|
||||
}
|
||||
}
|
||||
name = strings.ToLower(name)
|
||||
if punycode, err := idna.ToASCII(name); err == nil {
|
||||
name = punycode
|
||||
} else {
|
||||
@@ -150,7 +149,7 @@ func (s *Server) parseRequestGoogle(w http.ResponseWriter, r *http.Request) *DNS
|
||||
opt := new(dns.OPT)
|
||||
opt.Hdr.Name = "."
|
||||
opt.Hdr.Rrtype = dns.TypeOPT
|
||||
opt.SetUDPSize(4096)
|
||||
opt.SetUDPSize(dns.DefaultMsgSize)
|
||||
opt.SetDo(true)
|
||||
if ednsClientAddress != nil {
|
||||
edns0Subnet := new(dns.EDNS0_SUBNET)
|
||||
@@ -182,6 +181,7 @@ func (s *Server) generateResponseGoogle(w http.ResponseWriter, r *http.Request,
|
||||
now := time.Now().UTC().Format(http.TimeFormat)
|
||||
w.Header().Set("Date", now)
|
||||
w.Header().Set("Last-Modified", now)
|
||||
w.Header().Set("Vary", "Accept")
|
||||
if respJSON.HaveTTL {
|
||||
if req.isTailored {
|
||||
w.Header().Set("Cache-Control", "private, max-age="+strconv.Itoa(int(respJSON.LeastTTL)))
|
||||
|
||||
@@ -24,15 +24,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"../json-dns"
|
||||
"github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -45,7 +47,7 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe
|
||||
errtext: fmt.Sprintf("Invalid argument value: \"dns\" = %q", requestBase64),
|
||||
}
|
||||
}
|
||||
if len(requestBinary) == 0 && r.Header.Get("Content-Type") == "application/dns-udpwireformat" {
|
||||
if len(requestBinary) == 0 && (r.Header.Get("Content-Type") == "application/dns-message" || r.Header.Get("Content-Type") == "application/dns-udpwireformat") {
|
||||
requestBinary, err = ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return &DNSRequest{
|
||||
@@ -60,6 +62,13 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe
|
||||
errtext: fmt.Sprintf("Invalid argument value: \"dns\""),
|
||||
}
|
||||
}
|
||||
|
||||
if s.patchDNSCryptProxyReqID(w, r, requestBinary) {
|
||||
return &DNSRequest{
|
||||
errcode: 444,
|
||||
}
|
||||
}
|
||||
|
||||
msg := new(dns.Msg)
|
||||
err = msg.Unpack(requestBinary)
|
||||
if err != nil {
|
||||
@@ -87,15 +96,16 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe
|
||||
fmt.Printf("%s - - [%s] \"%s %s %s\"\n", r.RemoteAddr, time.Now().Format("02/Jan/2006:15:04:05 -0700"), questionName, questionClass, questionType)
|
||||
}
|
||||
|
||||
transactionID := msg.Id
|
||||
msg.Id = dns.Id()
|
||||
opt := msg.IsEdns0()
|
||||
if opt == nil {
|
||||
opt = new(dns.OPT)
|
||||
opt.Hdr.Name = "."
|
||||
opt.Hdr.Rrtype = dns.TypeOPT
|
||||
opt.SetUDPSize(4096)
|
||||
opt.SetUDPSize(dns.DefaultMsgSize)
|
||||
opt.SetDo(false)
|
||||
msg.Extra = append(msg.Extra, opt)
|
||||
msg.Extra = append([]dns.RR{opt}, msg.Extra...)
|
||||
}
|
||||
var edns0Subnet *dns.EDNS0_SUBNET
|
||||
for _, option := range opt.Option {
|
||||
@@ -129,14 +139,15 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe
|
||||
}
|
||||
|
||||
return &DNSRequest{
|
||||
request: msg,
|
||||
isTailored: isTailored,
|
||||
request: msg,
|
||||
transactionID: transactionID,
|
||||
isTailored: isTailored,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) generateResponseIETF(w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||
respJSON := jsonDNS.Marshal(req.response)
|
||||
req.response.Id = 0
|
||||
req.response.Id = req.transactionID
|
||||
respBytes, err := req.response.Pack()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -144,10 +155,14 @@ func (s *Server) generateResponseIETF(w http.ResponseWriter, r *http.Request, re
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/dns-udpwireformat")
|
||||
w.Header().Set("Content-Type", "application/dns-message")
|
||||
now := time.Now().UTC().Format(http.TimeFormat)
|
||||
w.Header().Set("Date", now)
|
||||
w.Header().Set("Last-Modified", now)
|
||||
w.Header().Set("Vary", "Accept")
|
||||
|
||||
_ = s.patchFirefoxContentType(w, r, req)
|
||||
|
||||
if respJSON.HaveTTL {
|
||||
if req.isTailored {
|
||||
w.Header().Set("Cache-Control", "private, max-age="+strconv.Itoa(int(respJSON.LeastTTL)))
|
||||
@@ -156,8 +171,35 @@ func (s *Server) generateResponseIETF(w http.ResponseWriter, r *http.Request, re
|
||||
}
|
||||
w.Header().Set("Expires", respJSON.EarliestExpires.Format(http.TimeFormat))
|
||||
}
|
||||
|
||||
if respJSON.Status == dns.RcodeServerFailure {
|
||||
w.WriteHeader(503)
|
||||
}
|
||||
w.Write(respBytes)
|
||||
}
|
||||
|
||||
// Workaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe
|
||||
func (s *Server) patchDNSCryptProxyReqID(w http.ResponseWriter, r *http.Request, requestBinary []byte) bool {
|
||||
if strings.Contains(r.UserAgent(), "dnscrypt-proxy") && 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/dns-message")
|
||||
w.Header().Set("Vary", "Accept, User-Agent")
|
||||
now := time.Now().UTC().Format(http.TimeFormat)
|
||||
w.Header().Set("Date", now)
|
||||
w.Write([]byte("\xca\xfe\x81\x05\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x02\x00\x01\x00\x00\x10\x00\x01\x00\x00\x00\x00\x00\xa8\xa7\r\nWorkaround a bug causing DNSCrypt-Proxy to expect a response with TransactionID = 0xcafe\r\nRefer to https://github.com/jedisct1/dnscrypt-proxy/issues/526 for details."))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Workaround a bug causing Firefox 61-62 to reject responses with Content-Type = application/dns-message
|
||||
func (s *Server) patchFirefoxContentType(w http.ResponseWriter, r *http.Request, req *DNSRequest) bool {
|
||||
if strings.Contains(r.UserAgent(), "Firefox") && strings.Contains(r.Header.Get("Accept"), "application/dns-udpwireformat") && !strings.Contains(r.Header.Get("Accept"), "application/dns-message") {
|
||||
log.Println("Firefox 61-62 detected. Patching response.")
|
||||
w.Header().Set("Content-Type", "application/dns-udpwireformat")
|
||||
w.Header().Set("Vary", "Accept, User-Agent")
|
||||
req.isTailored = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -43,8 +43,5 @@ func main() {
|
||||
}
|
||||
|
||||
server := NewServer(conf)
|
||||
err = server.Start()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
_ = server.Start()
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"../json-dns"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/m13253/dns-over-https/json-dns"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -46,11 +46,13 @@ type Server struct {
|
||||
}
|
||||
|
||||
type DNSRequest struct {
|
||||
request *dns.Msg
|
||||
response *dns.Msg
|
||||
isTailored bool
|
||||
errcode int
|
||||
errtext string
|
||||
request *dns.Msg
|
||||
response *dns.Msg
|
||||
transactionID uint16
|
||||
currentUpstream string
|
||||
isTailored bool
|
||||
errcode int
|
||||
errtext string
|
||||
}
|
||||
|
||||
func NewServer(conf *config) (s *Server) {
|
||||
@@ -58,6 +60,7 @@ func NewServer(conf *config) (s *Server) {
|
||||
conf: conf,
|
||||
udpClient: &dns.Client{
|
||||
Net: "udp",
|
||||
UDPSize: dns.DefaultMsgSize,
|
||||
Timeout: time.Duration(conf.Timeout) * time.Second,
|
||||
},
|
||||
tcpClient: &dns.Client{
|
||||
@@ -75,15 +78,35 @@ func (s *Server) Start() error {
|
||||
if s.conf.Verbose {
|
||||
servemux = handlers.CombinedLoggingHandler(os.Stdout, servemux)
|
||||
}
|
||||
if s.conf.Cert != "" || s.conf.Key != "" {
|
||||
return http.ListenAndServeTLS(s.conf.Listen, s.conf.Cert, s.conf.Key, servemux)
|
||||
results := make(chan error, len(s.conf.Listen))
|
||||
for _, addr := range s.conf.Listen {
|
||||
go func(addr string) {
|
||||
var err error
|
||||
if s.conf.Cert != "" || s.conf.Key != "" {
|
||||
err = http.ListenAndServeTLS(addr, s.conf.Cert, s.conf.Key, servemux)
|
||||
} else {
|
||||
err = http.ListenAndServe(addr, servemux)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
results <- err
|
||||
}(addr)
|
||||
}
|
||||
return http.ListenAndServe(s.conf.Listen, servemux)
|
||||
// wait for all handlers
|
||||
for i := 0; i < cap(results); i++ {
|
||||
err := <-results
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
close(results)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Server", "DNS-over-HTTPS/1.1 (+https://github.com/m13253/dns-over-https)")
|
||||
w.Header().Set("X-Powered-By", "DNS-over-HTTPS/1.1 (+https://github.com/m13253/dns-over-https)")
|
||||
w.Header().Set("Server", USER_AGENT)
|
||||
w.Header().Set("X-Powered-By", USER_AGENT)
|
||||
|
||||
if r.Form == nil {
|
||||
const maxMemory = 32 << 20 // 32 MB
|
||||
@@ -96,47 +119,59 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if contentType == "" {
|
||||
// Guess request Content-Type based on other parameters
|
||||
if r.FormValue("name") != "" {
|
||||
contentType = "application/x-www-form-urlencoded"
|
||||
contentType = "application/dns-json"
|
||||
} else if r.FormValue("dns") != "" {
|
||||
contentType = "application/dns-udpwireformat"
|
||||
contentType = "application/dns-message"
|
||||
}
|
||||
}
|
||||
var responseType string
|
||||
for _, responseCandidate := range strings.Split(r.Header.Get("Accept"), ",") {
|
||||
responseCandidate = strings.ToLower(strings.SplitN(responseCandidate, ";", 2)[0])
|
||||
responseCandidate = strings.SplitN(responseCandidate, ";", 2)[0]
|
||||
if responseCandidate == "application/json" {
|
||||
responseType = "application/json"
|
||||
break
|
||||
} else if responseCandidate == "application/dns-udpwireformat" {
|
||||
responseType = "application/dns-udpwireformat"
|
||||
responseType = "application/dns-message"
|
||||
break
|
||||
} else if responseCandidate == "application/dns-message" {
|
||||
responseType = "application/dns-message"
|
||||
break
|
||||
}
|
||||
}
|
||||
if responseType == "" {
|
||||
// Guess response Content-Type based on request Content-Type
|
||||
if contentType == "application/x-www-form-urlencoded" {
|
||||
if contentType == "application/dns-json" {
|
||||
responseType = "application/json"
|
||||
} else if contentType == "application/dns-message" {
|
||||
responseType = "application/dns-message"
|
||||
} else if contentType == "application/dns-udpwireformat" {
|
||||
responseType = "application/dns-udpwireformat"
|
||||
responseType = "application/dns-message"
|
||||
}
|
||||
}
|
||||
|
||||
var req *DNSRequest
|
||||
if contentType == "application/x-www-form-urlencoded" {
|
||||
if contentType == "application/dns-json" {
|
||||
req = s.parseRequestGoogle(w, r)
|
||||
} else if contentType == "application/dns-message" {
|
||||
req = s.parseRequestIETF(w, r)
|
||||
} else if contentType == "application/dns-udpwireformat" {
|
||||
req = s.parseRequestIETF(w, r)
|
||||
} else {
|
||||
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
|
||||
}
|
||||
|
||||
req = s.patchRootRD(req)
|
||||
|
||||
var err error
|
||||
req.response, err = s.doDNSQuery(req.request)
|
||||
req, err = s.doDNSQuery(req)
|
||||
if err != nil {
|
||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
||||
return
|
||||
@@ -144,7 +179,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if responseType == "application/json" {
|
||||
s.generateResponseGoogle(w, r, req)
|
||||
} else if responseType == "application/dns-udpwireformat" {
|
||||
} else if responseType == "application/dns-message" {
|
||||
s.generateResponseIETF(w, r, req)
|
||||
} else {
|
||||
panic("Unknown response Content-Type")
|
||||
@@ -180,23 +215,33 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) doDNSQuery(msg *dns.Msg) (resp *dns.Msg, err error) {
|
||||
// Workaround a bug causing Unbound to refuse returning anything about the root
|
||||
func (s *Server) patchRootRD(req *DNSRequest) *DNSRequest {
|
||||
for _, question := range req.request.Question {
|
||||
if question.Name == "." {
|
||||
req.request.RecursionDesired = true
|
||||
}
|
||||
}
|
||||
return req
|
||||
}
|
||||
|
||||
func (s *Server) doDNSQuery(req *DNSRequest) (resp *DNSRequest, err error) {
|
||||
numServers := len(s.conf.Upstream)
|
||||
for i := uint(0); i < s.conf.Tries; i++ {
|
||||
server := s.conf.Upstream[rand.Intn(numServers)]
|
||||
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
|
||||
if !s.conf.TCPOnly {
|
||||
resp, _, err = s.udpClient.Exchange(msg, server)
|
||||
req.response, _, err = s.udpClient.Exchange(req.request, req.currentUpstream)
|
||||
if err == dns.ErrTruncated {
|
||||
log.Println(err)
|
||||
resp, _, err = s.tcpClient.Exchange(msg, server)
|
||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
||||
}
|
||||
} else {
|
||||
resp, _, err = s.tcpClient.Exchange(msg, server)
|
||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
||||
}
|
||||
if err == nil {
|
||||
return
|
||||
return req, nil
|
||||
}
|
||||
log.Println(err)
|
||||
log.Printf("DNS error from upstream %s: %s\n", req.currentUpstream, err.Error())
|
||||
}
|
||||
return
|
||||
return req, err
|
||||
}
|
||||
|
||||
29
doh-server/version.go
Normal file
29
doh-server/version.go
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
VERSION = "1.3.8"
|
||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||
)
|
||||
16
launchd/Makefile
Normal file
16
launchd/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
.PHONY: install uninstall
|
||||
|
||||
PREFIX = /usr/local
|
||||
LAUNCHD_DIR = /Library/LaunchDaemons
|
||||
|
||||
install:
|
||||
mkdir -p "$(DESTDIR)$(LAUNCHD_DIR)"
|
||||
install -m0644 doh-client.plist "$(DESTDIR)$(LAUNCHD_DIR)/doh-client.plist"
|
||||
install -m0644 doh-server.plist "$(DESTDIR)$(LAUNCHD_DIR)/doh-server.plist"
|
||||
@echo
|
||||
@echo 'Note:'
|
||||
@echo ' Use "sudo launchctl load $(DESTDIR)$(LAUNCHD_DIR)/doh-client.plist" to start doh-client,'
|
||||
@echo ' use "sudo launchctl load -w $(DESTDIR)$(LAUNCHD_DIR)/doh-server.plist" to enable doh-server.'
|
||||
|
||||
uninstall:
|
||||
rm -f "$(DESTDIR)$(LAUNCHD_DIR)/doh-client.plist" "$(DESTDIR)$(LAUNCHD_DIR)/doh-server.plist"
|
||||
29
launchd/doh-client.plist
Normal file
29
launchd/doh-client.plist
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>org.eu.starlab.doh.client</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/bin/doh-logger</string>
|
||||
<string>doh-client</string>
|
||||
<string>/usr/local/bin/doh-client</string>
|
||||
<string>-conf</string>
|
||||
<string>/usr/local/etc/dns-over-https/doh-client.conf</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>UserName</key>
|
||||
<string>root</string>
|
||||
<key>GroupName</key>
|
||||
<string>wheel</string>
|
||||
<key>KeepAlive</key>
|
||||
<dict>
|
||||
<key>SuccessfulExit</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<key>ThrottleInterval</key>
|
||||
<integer>5</integer>
|
||||
</dict>
|
||||
</plist>
|
||||
31
launchd/doh-server.plist
Normal file
31
launchd/doh-server.plist
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>org.eu.starlab.doh.server</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/bin/doh-logger</string>
|
||||
<string>doh-server</string>
|
||||
<string>/usr/local/bin/doh-server</string>
|
||||
<string>-conf</string>
|
||||
<string>/usr/local/etc/dns-over-https/doh-server.conf</string>
|
||||
</array>
|
||||
<key>Disabled</key>
|
||||
<true/>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>UserName</key>
|
||||
<string>root</string>
|
||||
<key>GroupName</key>
|
||||
<string>wheel</string>
|
||||
<key>KeepAlive</key>
|
||||
<dict>
|
||||
<key>SuccessfulExit</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<key>ThrottleInterval</key>
|
||||
<integer>5</integer>
|
||||
</dict>
|
||||
</plist>
|
||||
51
linux-install.md
Normal file
51
linux-install.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Ubuntu Install
|
||||
> Tested on a clean install of `Ubuntu 16.04 LTS`
|
||||
|
||||
## Intalling go
|
||||
Install `Go >= 1.9`
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install golang-1.10 -y
|
||||
```
|
||||
|
||||
Add the newly install `go` to the path
|
||||
|
||||
```bash
|
||||
export PATH=$PATH:/usr/lib/go-1.10/bin
|
||||
```
|
||||
|
||||
Test to make sure that you can execute `go`
|
||||
|
||||
```bash
|
||||
go version
|
||||
```
|
||||
which should output something like
|
||||
|
||||
```bash
|
||||
go version go1.10.1 linux/amd64
|
||||
```
|
||||
|
||||
## Installing dns-over-https
|
||||
|
||||
Clone this repo
|
||||
|
||||
|
||||
```bash
|
||||
git clone https://github.com/m13253/dns-over-https.git
|
||||
```
|
||||
|
||||
Change directory to the cloned repo
|
||||
|
||||
```bash
|
||||
cd dns-over-https
|
||||
```
|
||||
|
||||
make and install
|
||||
|
||||
```bash
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
|
||||
13
linux-install.sh
Executable file
13
linux-install.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# See the linux-install.md (README) first.
|
||||
set -e
|
||||
|
||||
sudo apt update
|
||||
sudo apt install golang-1.10 git -y
|
||||
export PATH=$PATH:/usr/lib/go-1.10/bin
|
||||
cd /tmp
|
||||
git clone https://github.com/m13253/dns-over-https.git
|
||||
cd dns-over-https
|
||||
make
|
||||
sudo make install
|
||||
@@ -1,6 +1,5 @@
|
||||
.PHONY: install uninstall
|
||||
|
||||
PREFIX = /usr/local
|
||||
SYSTEMD_DIR = /usr/lib/systemd
|
||||
SYSTEMD_UNIT_DIR = $(SYSTEMD_DIR)/system
|
||||
|
||||
|
||||
Reference in New Issue
Block a user