Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into multiple_relays
Browse files Browse the repository at this point in the history
  • Loading branch information
junkurihara committed Aug 7, 2024
2 parents e231068 + 56bc6e6 commit 14b2625
Show file tree
Hide file tree
Showing 369 changed files with 37,504 additions and 22,768 deletions.
17 changes: 17 additions & 0 deletions .ci/test-odoh-proxied.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server_names = ['odohtarget']
listen_addresses = ['127.0.0.1:5300']

[query_log]
file = 'query.log'

[static]
[static.'odohtarget']
stamp = 'sdns://BQcAAAAAAAAADm9kb2guY3J5cHRvLnN4Ci9kbnMtcXVlcnk'

[static.'odohrelay']
stamp = 'sdns://hQcAAAAAAAAADDg5LjM4LjEzMS4zOAAYb2RvaC1ubC5hbGVrYmVyZy5uZXQ6NDQzBi9wcm94eQ'

[anonymized_dns]
routes = [
{ server_name='odohtarget', via=['odohrelay'] }
]
2 changes: 1 addition & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
prerelease: false

- name: Upload release assets
uses: softprops/action-gh-release@d99959edae48b5ffffd7b00da66dcdb0a33a52ee
uses: softprops/action-gh-release@a74c6b72af54cfa997e81df42d94703d6313a2d0
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions dnscrypt-proxy/coldstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i
}

func addColdStartListener(
proxy *Proxy,
ipsMap *CaptivePortalMap,
listenAddrStr string,
captivePortalHandler *CaptivePortalHandler,
Expand Down Expand Up @@ -191,7 +190,7 @@ func ColdStart(proxy *Proxy) (*CaptivePortalHandler, error) {
}
ok := false
for _, listenAddrStr := range listenAddrStrs {
err = addColdStartListener(proxy, &ipsMap, listenAddrStr, &captivePortalHandler)
err = addColdStartListener(&ipsMap, listenAddrStr, &captivePortalHandler)
if err == nil {
ok = true
}
Expand Down
2 changes: 1 addition & 1 deletion dnscrypt-proxy/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func maybeWritableByOtherUsers(p string) (bool, string, error) {
return false, p, err
}
mode := st.Mode()
if mode&2 == 2 && !(st.IsDir() && mode&01000 == 01000) {
if mode.Perm()&2 != 0 && !(st.IsDir() && mode&os.ModeSticky == os.ModeSticky) {
return true, p, nil
}
p = path.Dir(p)
Expand Down
2 changes: 1 addition & 1 deletion dnscrypt-proxy/dnscrypt_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func FetchCurrentDNSCryptCert(
certCountStr = " - additional certificate"
}
if certInfo.CryptoConstruction == UndefinedConstruction {
return certInfo, 0, fragmentsBlocked, errors.New("No useable certificate found")
return certInfo, 0, fragmentsBlocked, errors.New("No usable certificate found")
}
return certInfo, int(rtt.Nanoseconds() / 1000000), fragmentsBlocked, nil
}
55 changes: 39 additions & 16 deletions dnscrypt-proxy/example-dnscrypt-proxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ http3 = false
## If you have a network with *a lot* of latency, you may need to
## increase this. Startup may be slower if you do so.
## Don't increase it too much. 10000 is the highest reasonable value.
## A timeout below 5000 is not recommended.

timeout = 5000

Expand Down Expand Up @@ -775,10 +776,43 @@ prefix = ''
### Another example source, with resolvers censoring some websites not appropriate for children
### This is a subset of the `public-resolvers` list, so enabling both is useless.

# [sources.parental-control]
# urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v3/parental-control.md', 'https://download.dnscrypt.info/resolvers-list/v3/parental-control.md']
# cache_file = 'parental-control.md'
# minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3'
# [sources.odoh-servers]
# urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v3/odoh-servers.md', 'https://download.dnscrypt.info/resolvers-list/v3/odoh-servers.md']
# cache_file = 'odoh-servers.md'
# minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3'
# refresh_delay = 24
# prefix = ''
# [sources.odoh-relays]
# urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v3/odoh-relays.md', 'https://download.dnscrypt.info/resolvers-list/v3/odoh-relays.md']
# cache_file = 'odoh-relays.md'
# minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3'
# refresh_delay = 24
# prefix = ''

### Quad9

# [sources.quad9-resolvers]
# urls = ['https://www.quad9.net/quad9-resolvers.md']
# minisign_key = 'RWTp2E4t64BrL651lEiDLNon+DqzPG4jhZ97pfdNkcq1VDdocLKvl5FW'
# cache_file = 'quad9-resolvers.md'
# prefix = 'quad9-'

### Another example source, with resolvers censoring some websites not appropriate for children
### This is a subset of the `public-resolvers` list, so enabling both is useless.

# [sources.parental-control]
# urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v3/parental-control.md', 'https://download.dnscrypt.info/resolvers-list/v3/parental-control.md']
# cache_file = 'parental-control.md'
# minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3'

### dnscry.pt servers - See https://www.dnscry.pt

# [sources.dnscry-pt-resolvers]
# urls = ["https://www.dnscry.pt/resolvers.md"]
# minisign_key = "RWQM31Nwkqh01x88SvrBL8djp1NH56Rb4mKLHz16K7qsXgEomnDv6ziQ"
# cache_file = "dnscry.pt-resolvers.md"
# refresh_delay = 72
# prefix = "dnscry.pt-"

### dnscry.pt servers - See https://www.dnscry.pt

Expand Down Expand Up @@ -810,18 +844,7 @@ prefix = ''
## The list below enables workarounds to make non-relayed usage more reliable
## until the servers are fixed.

fragments_blocked = [
'cisco',
'cisco-ipv6',
'cisco-familyshield',
'cisco-familyshield-ipv6',
'cleanbrowsing-adult',
'cleanbrowsing-adult-ipv6',
'cleanbrowsing-family',
'cleanbrowsing-family-ipv6',
'cleanbrowsing-security',
'cleanbrowsing-security-ipv6',
]
fragments_blocked = ['cisco', 'cisco-ipv6', 'cisco-familyshield', 'cisco-familyshield-ipv6', 'cisco-sandbox', 'cleanbrowsing-adult', 'cleanbrowsing-adult-ipv6', 'cleanbrowsing-family', 'cleanbrowsing-family-ipv6', 'cleanbrowsing-security', 'cleanbrowsing-security-ipv6']


#################################################################
Expand Down
1 change: 1 addition & 0 deletions dnscrypt-proxy/plugin_block_undelegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var undelegatedSet = []string{
"envoy",
"example",
"f.f.ip6.arpa",
"fritz.box",
"grp",
"gw==",
"home",
Expand Down
14 changes: 8 additions & 6 deletions dnscrypt-proxy/plugin_dns64.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ func (plugin *PluginDNS64) Init(proxy *Proxy) error {
if err != nil {
return err
}
dlog.Infof("Registered DNS64 prefix [%s]", pref.String())
dlog.Noticef("Registered DNS64 prefix [%s]", pref.String())
plugin.pref64 = append(plugin.pref64, pref)
}
} else if len(proxy.dns64Resolvers) != 0 {
plugin.dns64Resolvers = proxy.dns64Resolvers
if err := plugin.refreshPref64(); err != nil {
return err
}
} else {
return nil
}
dlog.Notice("DNS64 map enabled")

return nil
}
Expand Down Expand Up @@ -105,7 +108,7 @@ func (plugin *PluginDNS64) Eval(pluginsState *PluginsState, msg *dns.Msg) error
return err
}

if err != nil || resp.Rcode != dns.RcodeSuccess {
if resp.Rcode != dns.RcodeSuccess {
return nil
}

Expand Down Expand Up @@ -152,11 +155,10 @@ func (plugin *PluginDNS64) Eval(pluginsState *PluginsState, msg *dns.Msg) error
}
}

synth := EmptyResponseFromMessage(msg)
synth.Answer = append(synth.Answer, synth64...)
msg.Answer = synth64
msg.AuthenticatedData = false
msg.SetEdns0(uint16(MaxDNSUDPSafePacketSize), false)

pluginsState.synthResponse = synth
pluginsState.action = PluginsActionSynth
pluginsState.returnCode = PluginsReturnCodeCloak

return nil
Expand Down
5 changes: 3 additions & 2 deletions dnscrypt-proxy/plugin_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (plugin *PluginForward) Eval(pluginsState *PluginsState, msg *dns.Msg) erro
if candidateLen > qNameLen {
continue
}
if qName[qNameLen-candidateLen:] == candidate.domain &&
(candidateLen == qNameLen || (qName[qNameLen-candidateLen-1] == '.')) {
if (qName[qNameLen-candidateLen:] == candidate.domain &&
(candidateLen == qNameLen || (qName[qNameLen-candidateLen-1] == '.'))) ||
(candidate.domain == ".") {
servers = candidate.servers
break
}
Expand Down
1 change: 1 addition & 0 deletions dnscrypt-proxy/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func Resolve(server string, name string, singleResolver bool) {
fmt.Printf("Lying : ")
response, err := resolveQuery(server, nonexistentName, dns.TypeA, false)
if err != nil {
fmt.Printf("[%v]", err)
break
}
if response.Rcode == dns.RcodeSuccess {
Expand Down
2 changes: 1 addition & 1 deletion dnscrypt-proxy/serversInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func findFarthestRoute(proxy *Proxy, name string, relayStamps []*ServerStampWith
server := proxy.serversInfo.registeredServers[serverIdx]
proxy.serversInfo.RUnlock()

// Fall back to random relays until the logic is implementeed for non-DNSCrypt relays
// Fall back to random relays until the logic is implemented for non-DNSCrypt relays
if server.stamp.Proto == stamps.StampProtoTypeODoHTarget {
candidates := make([]int, 0)
for relayIdx, relayStamp := range relayStamps {
Expand Down
2 changes: 1 addition & 1 deletion dnscrypt-proxy/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (source *Source) parseURLs(urls []string) {
}

func fetchFromURL(xTransport *XTransport, u *url.URL) ([]byte, error) {
bin, _, _, _, err := xTransport.Get(u, "", DefaultTimeout)
bin, _, _, _, err := xTransport.GetWithCompression(u, "", DefaultTimeout)
return bin, err
}

Expand Down
6 changes: 3 additions & 3 deletions dnscrypt-proxy/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
TestStateReadSigErr // I/O error on reading .minisig (download only)
TestStateOpenErr // I/O error on opening files
TestStateOpenSigErr // I/O error on opening .minisig
TestStatePathErr // unparseable path to files (download only)
TestStatePathErr // unparsable path to files (download only)
)

type SourceTestData struct {
Expand Down Expand Up @@ -144,7 +144,7 @@ func loadTestSourceNames(t *testing.T, d *SourceTestData) {
}
}

func generateFixtureState(t *testing.T, d *SourceTestData, suffix, file string, state SourceTestState) {
func generateFixtureState(_ *testing.T, d *SourceTestData, suffix, file string, state SourceTestState) {
if _, ok := d.fixtures[state]; !ok {
d.fixtures[state] = map[string]SourceFixture{}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func prepSourceTestCache(t *testing.T, d *SourceTestData, e *SourceTestExpect, s
}

func prepSourceTestDownload(
t *testing.T,
_ *testing.T,
d *SourceTestData,
e *SourceTestExpect,
source string,
Expand Down
29 changes: 26 additions & 3 deletions dnscrypt-proxy/xtransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"compress/gzip"
"context"
"crypto/sha512"
"crypto/tls"
Expand Down Expand Up @@ -482,6 +483,7 @@ func (xTransport *XTransport) Fetch(
contentType string,
body *[]byte,
timeout time.Duration,
compress bool,
) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
if timeout <= 0 {
timeout = xTransport.timeout
Expand Down Expand Up @@ -530,6 +532,9 @@ func (xTransport *XTransport) Fetch(
)
return nil, 0, nil, 0, err
}
if compress && body == nil {
header["Accept-Encoding"] = []string{"gzip"}
}
req := &http.Request{
Method: method,
URL: url,
Expand Down Expand Up @@ -596,20 +601,38 @@ func (xTransport *XTransport) Fetch(
}
}
tls := resp.TLS
bin, err := io.ReadAll(io.LimitReader(resp.Body, MaxHTTPBodyLength))

var bodyReader io.ReadCloser = resp.Body
if compress && resp.Header.Get("Content-Encoding") == "gzip" {
bodyReader, err = gzip.NewReader(io.LimitReader(resp.Body, MaxHTTPBodyLength))
if err != nil {
return nil, statusCode, tls, rtt, err
}
defer bodyReader.Close()
}

bin, err := io.ReadAll(io.LimitReader(bodyReader, MaxHTTPBodyLength))
if err != nil {
return nil, statusCode, tls, rtt, err
}
resp.Body.Close()
return bin, statusCode, tls, rtt, err
}

func (xTransport *XTransport) GetWithCompression(
url *url.URL,
accept string,
timeout time.Duration,
) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
return xTransport.Fetch("GET", url, accept, "", nil, timeout, true)
}

func (xTransport *XTransport) Get(
url *url.URL,
accept string,
timeout time.Duration,
) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
return xTransport.Fetch("GET", url, accept, "", nil, timeout)
return xTransport.Fetch("GET", url, accept, "", nil, timeout, false)
}

func (xTransport *XTransport) Post(
Expand All @@ -619,7 +642,7 @@ func (xTransport *XTransport) Post(
body *[]byte,
timeout time.Duration,
) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
return xTransport.Fetch("POST", url, accept, contentType, body, timeout)
return xTransport.Fetch("POST", url, accept, contentType, body, timeout, false)
}

func (xTransport *XTransport) dohLikeQuery(
Expand Down
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ module github.com/junkurihara/dnscrypt-proxy-modns
go 1.22

require (
github.com/BurntSushi/toml v1.3.2
github.com/BurntSushi/toml v1.4.0
github.com/VividCortex/ewma v1.2.0
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185
github.com/hashicorp/go-immutable-radix v1.3.1
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb
github.com/jedisct1/dlog v0.0.0-20230811132706-443b333ff1b3
github.com/jedisct1/go-clocksmith v0.0.0-20230211133011-392c1afea73e
github.com/jedisct1/go-dnsstamps v0.0.0-20230211133001-124a632de565
github.com/jedisct1/go-dnsstamps v0.0.0-20240423203910-07a0735c7774
github.com/jedisct1/go-hpke-compact v0.0.0-20230811132953-4ee502b61f80
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267
github.com/jedisct1/xsecretbox v0.0.0-20230811132812-b950633f9f1f
github.com/k-sone/critbitgo v1.4.0
github.com/kardianos/service v1.2.2
github.com/miekg/dns v1.1.58
github.com/miekg/dns v1.1.61
github.com/opencoff/go-sieve v0.2.1
github.com/powerman/check v1.7.0
github.com/quic-go/quic-go v0.41.0
golang.org/x/crypto v0.19.0
golang.org/x/net v0.21.0
golang.org/x/sys v0.17.0
github.com/quic-go/quic-go v0.45.1
golang.org/x/crypto v0.25.0
golang.org/x/net v0.27.0
golang.org/x/sys v0.22.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

Expand All @@ -40,12 +40,13 @@ require (
github.com/powerman/deepequal v0.1.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
go.uber.org/mock v0.3.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit 14b2625

Please sign in to comment.