docstring_tokens stringlengths 0 76.5k | code_tokens stringlengths 75 1.81M | label_window listlengths 4 2.12k | html_url stringlengths 74 116 | file_name stringlengths 3 311 |
|---|---|---|---|---|
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 | <mask> github.com/spf13/cobra v1.1.1 // indirect
<mask> github.com/stretchr/testify v1.6.1
<mask> github.com/u-root/u-root v7.0.0+incompatible
<mask> go.etcd.io/bbolt v1.3.5
<mask> golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
<mask> golang.org/x/net v0.0.0-20201216054612-986b41b23924
<mask> golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
<mask> golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e
<mask> golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
<mask> gopkg.in/natefinch/lumberjack.v2 v2.0.0
</s> Pull request: 2225 daily freeze fix
Merge in DNS/adguard-home from 2225-fix-freezes to master
Updates #2225.
Squashed commit of the following:
commit 02a472120e9b4a0bc13129adb85eed5d9fd810a2
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Dec 17 14:10:20 2020 +0300
all: go mod tidy
commit 6cfc23b780cf5da58719620ea5cd1fd3980c631e
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Dec 17 14:06:28 2020 +0300
all: upd dnsproxy dependency </s> remove github.com/AdguardTeam/dnsproxy v0.33.5 h1:YTfY16lFgFqBzC3pdKalQSaeb7hjm4VvGqdksO0AoVI=
github.com/AdguardTeam/dnsproxy v0.33.5/go.mod h1:dkI9VWh43XlOzF2XogDm1EmoVl7PANOR4isQV6X9LZs=
</s> add github.com/AdguardTeam/dnsproxy v0.33.6 h1:qoYQbyiVqqFL/O6EvIVnxnDC5vBCFoWz40vlYdfZ+lI=
github.com/AdguardTeam/dnsproxy v0.33.6/go.mod h1:dkI9VWh43XlOzF2XogDm1EmoVl7PANOR4isQV6X9LZs= </s> remove github.com/AdguardTeam/dnsproxy v0.33.5
</s> add github.com/AdguardTeam/dnsproxy v0.33.6 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fd7b061dd6583ff41607d21821854e09f089a218 | go.mod |
github.com/AdguardTeam/dnsproxy v0.33.6 h1:qoYQbyiVqqFL/O6EvIVnxnDC5vBCFoWz40vlYdfZ+lI=
github.com/AdguardTeam/dnsproxy v0.33.6/go.mod h1:dkI9VWh43XlOzF2XogDm1EmoVl7PANOR4isQV6X9LZs= | <mask> dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU=
<mask> dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
<mask> dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
<mask> git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
<mask> github.com/AdguardTeam/dnsproxy v0.33.5 h1:YTfY16lFgFqBzC3pdKalQSaeb7hjm4VvGqdksO0AoVI=
<mask> github.com/AdguardTeam/dnsproxy v0.33.5/go.mod h1:dkI9VWh43XlOzF2XogDm1EmoVl7PANOR4isQV6X9LZs=
<mask> github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
<mask> github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o=
<mask> github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
<mask> github.com/AdguardTeam/golibs v0.4.4 h1:cM9UySQiYFW79zo5XRwnaIWVzfW4eNXmZktMrWbthpw=
<mask> github.com/AdguardTeam/golibs v0.4.4/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
</s> Pull request: 2225 daily freeze fix
Merge in DNS/adguard-home from 2225-fix-freezes to master
Updates #2225.
Squashed commit of the following:
commit 02a472120e9b4a0bc13129adb85eed5d9fd810a2
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Dec 17 14:10:20 2020 +0300
all: go mod tidy
commit 6cfc23b780cf5da58719620ea5cd1fd3980c631e
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Dec 17 14:06:28 2020 +0300
all: upd dnsproxy dependency </s> remove golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
</s> add golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 </s> remove github.com/AdguardTeam/dnsproxy v0.33.5
</s> add github.com/AdguardTeam/dnsproxy v0.33.6 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fd7b061dd6583ff41607d21821854e09f089a218 | go.sum |
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 h1:3wPMTskHO3+O6jqTEXyFcsnuxMQOqYSaHsDxcbUXpqA=
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= | <mask> golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
<mask> golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
<mask> golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604=
<mask> golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
<mask> golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
<mask> golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
<mask> golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
<mask> golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
<mask> golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
</s> Pull request: 2225 daily freeze fix
Merge in DNS/adguard-home from 2225-fix-freezes to master
Updates #2225.
Squashed commit of the following:
commit 02a472120e9b4a0bc13129adb85eed5d9fd810a2
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Dec 17 14:10:20 2020 +0300
all: go mod tidy
commit 6cfc23b780cf5da58719620ea5cd1fd3980c631e
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Thu Dec 17 14:06:28 2020 +0300
all: upd dnsproxy dependency </s> remove github.com/AdguardTeam/dnsproxy v0.33.5 h1:YTfY16lFgFqBzC3pdKalQSaeb7hjm4VvGqdksO0AoVI=
github.com/AdguardTeam/dnsproxy v0.33.5/go.mod h1:dkI9VWh43XlOzF2XogDm1EmoVl7PANOR4isQV6X9LZs=
</s> add github.com/AdguardTeam/dnsproxy v0.33.6 h1:qoYQbyiVqqFL/O6EvIVnxnDC5vBCFoWz40vlYdfZ+lI=
github.com/AdguardTeam/dnsproxy v0.33.6/go.mod h1:dkI9VWh43XlOzF2XogDm1EmoVl7PANOR4isQV6X9LZs= </s> remove golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
</s> add golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 </s> remove github.com/AdguardTeam/dnsproxy v0.33.5
</s> add github.com/AdguardTeam/dnsproxy v0.33.6 | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fd7b061dd6583ff41607d21821854e09f089a218 | go.sum |
<mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/dnsforward"
<mask> "github.com/AdguardTeam/dnsproxy/upstream"
<mask> "github.com/davecgh/go-spew/spew"
<mask> "github.com/hmage/golibs/log"
<mask> "github.com/miekg/dns"
<mask> govalidator "gopkg.in/asaskevich/govalidator.v4"
<mask> )
<mask>
</s> get rid of go-spew and cleanup go.mod from unused packages </s> remove golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
</s> add </s> remove github.com/davecgh/go-spew v1.1.1
</s> add </s> remove spew.Dump(newSettings)
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fe671152c2d07ee6741b4afa97d52dcdbd416fd3 | control.go | |
<mask> httpError(w, http.StatusBadRequest, "Failed to parse new DHCP config json: %s", err)
<mask> return
<mask> }
<mask>
<mask> spew.Dump(newSettings)
<mask> // validate that hosts and ports are bindable
<mask>
<mask> if !checkPortAvailable(newSettings.Web.IP, newSettings.Web.Port) {
<mask> httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s", net.JoinHostPort(newSettings.Web.IP, strconv.Itoa(newSettings.Web.Port)))
<mask> return
</s> get rid of go-spew and cleanup go.mod from unused packages </s> remove github.com/davecgh/go-spew v1.1.1
</s> add </s> remove golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
</s> add </s> remove "github.com/davecgh/go-spew/spew"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fe671152c2d07ee6741b4afa97d52dcdbd416fd3 | control.go | |
<mask> require (
<mask> github.com/AdguardTeam/dnsproxy v0.9.10
<mask> github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect
<mask> github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7
<mask> github.com/davecgh/go-spew v1.1.1
<mask> github.com/go-ole/go-ole v1.2.1 // indirect
<mask> github.com/go-test/deep v1.0.1
<mask> github.com/gobuffalo/packr v1.19.0
<mask> github.com/hmage/golibs v0.0.0-20181229160906-c8491df0bfc4
<mask> github.com/joomcode/errorx v0.1.0
</s> get rid of go-spew and cleanup go.mod from unused packages </s> remove golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
</s> add </s> remove spew.Dump(newSettings)
</s> add </s> remove "github.com/davecgh/go-spew/spew"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fe671152c2d07ee6741b4afa97d52dcdbd416fd3 | go.mod | |
<mask> github.com/miekg/dns v1.1.1
<mask> github.com/shirou/gopsutil v2.18.10+incompatible
<mask> github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
<mask> go.uber.org/goleak v0.10.0
<mask> golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
<mask> golang.org/x/net v0.0.0-20181220203305-927f97764cc3
<mask> golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb
<mask> gopkg.in/asaskevich/govalidator.v4 v4.0.0-20160518190739-766470278477
<mask> gopkg.in/yaml.v2 v2.2.1
<mask> )
</s> get rid of go-spew and cleanup go.mod from unused packages </s> remove github.com/davecgh/go-spew v1.1.1
</s> add </s> remove spew.Dump(newSettings)
</s> add </s> remove "github.com/davecgh/go-spew/spew"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fe671152c2d07ee6741b4afa97d52dcdbd416fd3 | go.mod | |
<mask> package main
<mask>
<mask> import (
<mask> "bytes"
<mask> "io/ioutil"
<mask> "log"
<mask> "os"
<mask> "path/filepath"
<mask> "regexp"
</s> Unplug coreDNS and plug dnsforward library. </s> remove "regexp"
</s> add </s> remove "os"
"path/filepath"
"sync" // Include all plugins.
</s> add "net" </s> remove "text/template"
</s> add </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} | [
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | config.go | |
<mask> "io/ioutil"
<mask> "log"
<mask> "os"
<mask> "path/filepath"
<mask> "regexp"
<mask> "sync"
<mask> "text/template"
<mask> "time"
<mask>
<mask> "gopkg.in/yaml.v2"
</s> Unplug coreDNS and plug dnsforward library. </s> remove "text/template"
</s> add </s> remove "bytes"
</s> add </s> remove "os"
"path/filepath"
"sync" // Include all plugins.
</s> add "net" </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | config.go | |
<mask> "os"
<mask> "path/filepath"
<mask> "regexp"
<mask> "sync"
<mask> "text/template"
<mask> "time"
<mask>
<mask> "gopkg.in/yaml.v2"
<mask> )
<mask>
</s> Unplug coreDNS and plug dnsforward library. </s> remove "regexp"
</s> add </s> remove "bytes"
</s> add </s> remove "os"
"path/filepath"
"sync" // Include all plugins.
</s> add "net" </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" </s> remove isCoreDNSRunningLock.Lock()
value := isCoreDNSRunning
isCoreDNSRunningLock.Unlock()
return value
</s> add return dnsServer.IsRunning() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | config.go | |
BlockedResponseTTL uint32 `yaml:"blocked_response_ttl"` | <mask> SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"`
<mask> SafeSearchEnabled bool `yaml:"safesearch_enabled"`
<mask> ParentalEnabled bool `yaml:"parental_enabled"`
<mask> ParentalSensitivity int `yaml:"parental_sensitivity"`
<mask> BlockedResponseTTL int `yaml:"blocked_response_ttl"`
<mask> QueryLogEnabled bool `yaml:"querylog_enabled"`
<mask> Ratelimit int `yaml:"ratelimit"`
<mask> RefuseAny bool `yaml:"refuse_any"`
<mask> Pprof string `yaml:"-"`
<mask> Cache string `yaml:"-"`
</s> Unplug coreDNS and plug dnsforward library. </s> remove isCoreDNSRunningLock.Lock()
value := isCoreDNSRunning
isCoreDNSRunningLock.Unlock()
return value
</s> add return dnsServer.IsRunning() </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" </s> remove "regexp"
</s> add </s> remove "text/template"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | config.go |
<mask>
<mask> return nil
<mask> }
<mask>
<mask> // --------------
<mask> // coredns config
<mask> // --------------
<mask> func writeCoreDNSConfig() error {
<mask> coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
<mask> log.Printf("Writing DNS config: %s", coreFile)
<mask> configText, err := generateCoreDNSConfigText()
<mask> if err != nil {
<mask> log.Printf("Couldn't generate DNS config: %s", err)
<mask> return err
<mask> }
<mask> err = safeWriteFile(coreFile, []byte(configText))
<mask> if err != nil {
<mask> log.Printf("Couldn't save DNS config: %s", err)
<mask> return err
<mask> }
<mask> return nil
<mask> }
<mask>
<mask> func writeAllConfigs() error {
<mask> err := config.write()
<mask> if err != nil {
<mask> log.Printf("Couldn't write our config: %s", err)
<mask> return err
</s> Unplug coreDNS and plug dnsforward library. </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") </s> remove err := writeCoreDNSConfig()
</s> add err := dnsServer.Start(&newconfig) </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove isCoreDNSRunningLock.Lock()
value := isCoreDNSRunning
isCoreDNSRunningLock.Unlock()
return value
</s> add return dnsServer.IsRunning() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
... | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | config.go | |
return config.write() | <mask> return nil
<mask> }
<mask>
<mask> func writeAllConfigs() error {
<mask> err := config.write()
<mask> if err != nil {
<mask> log.Printf("Couldn't write our config: %s", err)
<mask> return err
<mask> }
<mask> err = writeCoreDNSConfig()
<mask> if err != nil {
<mask> log.Printf("Couldn't write DNS config: %s", err)
<mask> return err
<mask> }
<mask> return nil
<mask> }
<mask>
<mask> const coreDNSConfigTemplate = `.:{{.Port}} {
<mask> {{if .ProtectionEnabled}}dnsfilter {
<mask> {{if .SafeBrowsingEnabled}}safebrowsing{{end}}
<mask> {{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
<mask> {{if .SafeSearchEnabled}}safesearch{{end}}
<mask> {{if .QueryLogEnabled}}querylog{{end}}
<mask> blocked_ttl {{.BlockedResponseTTL}}
<mask> {{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
<mask> filter {{.ID}} "{{.Path}}"
<mask> {{end}}{{end}}{{end}}
<mask> }{{end}}
<mask> {{.Pprof}}
<mask> {{if .RefuseAny}}refuseany{{end}}
<mask> {{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
<mask> hosts {
<mask> fallthrough
<mask> }
<mask> {{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
<mask> {{.Cache}}
<mask> {{.Prometheus}}
<mask> }
<mask> `
<mask>
<mask> var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
<mask>
<mask> // generate CoreDNS config text
<mask> func generateCoreDNSConfigText() (string, error) {
<mask> t, err := template.New("config").Parse(coreDNSConfigTemplate)
<mask> if err != nil {
<mask> log.Printf("Couldn't generate DNS config: %s", err)
<mask> return "", err
<mask> }
<mask>
<mask> var configBytes bytes.Buffer
<mask> temporaryConfig := config.CoreDNS
<mask>
<mask> // generate temporary filter list, needed to put userfilter in coredns config
<mask> filters := []filter{}
<mask>
<mask> // first of all, append the user filter
<mask> userFilter := userFilter()
<mask>
<mask> filters = append(filters, userFilter)
<mask>
<mask> // then go through other filters
<mask> filters = append(filters, config.Filters...)
<mask> temporaryConfig.Filters = filters
<mask>
<mask> // run the template
<mask> err = t.Execute(&configBytes, &temporaryConfig)
<mask> if err != nil {
<mask> log.Printf("Couldn't generate DNS config: %s", err)
<mask> return "", err
<mask> }
<mask> configText := configBytes.String()
<mask>
<mask> // remove empty lines from generated config
<mask> configText = removeEmptyLines.ReplaceAllString(configText, "\n")
<mask> return configText, nil
<mask> }
<mask>
<mask> // Set the next filter ID to max(filter.ID) + 1
<mask> func updateUniqueFilterID(filters []filter) {
<mask> for _, filter := range filters {
</s> Unplug coreDNS and plug dnsforward library. </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") </s> remove err := writeCoreDNSConfig()
</s> add err := dnsServer.Start(&newconfig) </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | config.go |
"net" | <mask>
<mask> import (
<mask> "fmt"
<mask> "log"
<mask> "os"
<mask> "path/filepath"
<mask> "sync" // Include all plugins.
<mask>
<mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
<mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
<mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
<mask> _ "github.com/AdguardTeam/AdGuardHome/upstream"
</s> Unplug coreDNS and plug dnsforward library. </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" </s> remove "bytes"
</s> add </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} </s> remove "regexp"
</s> add </s> remove "text/template"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
"github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" | <mask> "os"
<mask> "path/filepath"
<mask> "sync" // Include all plugins.
<mask>
<mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
<mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
<mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
<mask> _ "github.com/AdguardTeam/AdGuardHome/upstream"
<mask> "github.com/coredns/coredns/core/dnsserver"
<mask> "github.com/coredns/coredns/coremain"
<mask> _ "github.com/coredns/coredns/plugin/auto"
<mask> _ "github.com/coredns/coredns/plugin/autopath"
<mask> _ "github.com/coredns/coredns/plugin/bind"
<mask> _ "github.com/coredns/coredns/plugin/cache"
<mask> _ "github.com/coredns/coredns/plugin/chaos"
<mask> _ "github.com/coredns/coredns/plugin/debug"
<mask> _ "github.com/coredns/coredns/plugin/dnssec"
<mask> _ "github.com/coredns/coredns/plugin/dnstap"
<mask> _ "github.com/coredns/coredns/plugin/erratic"
<mask> _ "github.com/coredns/coredns/plugin/errors"
<mask> _ "github.com/coredns/coredns/plugin/file"
<mask> _ "github.com/coredns/coredns/plugin/forward"
<mask> _ "github.com/coredns/coredns/plugin/health"
<mask> _ "github.com/coredns/coredns/plugin/hosts"
<mask> _ "github.com/coredns/coredns/plugin/loadbalance"
<mask> _ "github.com/coredns/coredns/plugin/log"
<mask> _ "github.com/coredns/coredns/plugin/loop"
<mask> _ "github.com/coredns/coredns/plugin/metadata"
<mask> _ "github.com/coredns/coredns/plugin/metrics"
<mask> _ "github.com/coredns/coredns/plugin/nsid"
<mask> _ "github.com/coredns/coredns/plugin/pprof"
<mask> _ "github.com/coredns/coredns/plugin/proxy"
<mask> _ "github.com/coredns/coredns/plugin/reload"
<mask> _ "github.com/coredns/coredns/plugin/rewrite"
<mask> _ "github.com/coredns/coredns/plugin/root"
<mask> _ "github.com/coredns/coredns/plugin/secondary"
<mask> _ "github.com/coredns/coredns/plugin/template"
<mask> _ "github.com/coredns/coredns/plugin/tls"
<mask> _ "github.com/coredns/coredns/plugin/whoami"
<mask> _ "github.com/mholt/caddy/onevent"
<mask> )
<mask>
<mask> // Directives are registered in the order they should be
<mask> // executed.
<mask> //
</s> Unplug coreDNS and plug dnsforward library. </s> remove "os"
"path/filepath"
"sync" // Include all plugins.
</s> add "net" </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} </s> remove "text/template"
</s> add </s> remove "regexp"
</s> add </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
var dnsServer = dnsforward.Server{} | <mask> _ "github.com/coredns/coredns/plugin/whoami"
<mask> _ "github.com/mholt/caddy/onevent"
<mask> )
<mask>
<mask> // Directives are registered in the order they should be
<mask> // executed.
<mask> //
<mask> // Ordering is VERY important. Every plugin will
<mask> // feel the effects of all other plugin below
<mask> // (after) them during a request, but they must not
<mask> // care what plugin above them are doing.
<mask>
<mask> var directives = []string{
<mask> "metadata",
<mask> "tls",
<mask> "reload",
<mask> "nsid",
<mask> "root",
<mask> "bind",
<mask> "debug",
<mask> "health",
<mask> "pprof",
<mask> "prometheus",
<mask> "errors",
<mask> "log",
<mask> "refuseany",
<mask> "ratelimit",
<mask> "dnsfilter",
<mask> "dnstap",
<mask> "chaos",
<mask> "loadbalance",
<mask> "cache",
<mask> "rewrite",
<mask> "dnssec",
<mask> "autopath",
<mask> "template",
<mask> "hosts",
<mask> "file",
<mask> "auto",
<mask> "secondary",
<mask> "loop",
<mask> "forward",
<mask> "proxy",
<mask> "upstream",
<mask> "erratic",
<mask> "whoami",
<mask> "on",
<mask> }
<mask>
<mask> func init() {
<mask> dnsserver.Directives = directives
<mask> }
<mask>
<mask> var (
<mask> isCoreDNSRunningLock sync.Mutex
<mask> isCoreDNSRunning = false
<mask> )
<mask>
<mask> func isRunning() bool {
<mask> isCoreDNSRunningLock.Lock()
<mask> value := isCoreDNSRunning
<mask> isCoreDNSRunningLock.Unlock()
</s> Unplug coreDNS and plug dnsforward library. </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" </s> remove isCoreDNSRunningLock.Lock()
value := isCoreDNSRunning
isCoreDNSRunningLock.Unlock()
return value
</s> add return dnsServer.IsRunning() </s> remove "os"
"path/filepath"
"sync" // Include all plugins.
</s> add "net" </s> remove isCoreDNSRunningLock.Lock()
if isCoreDNSRunning {
isCoreDNSRunningLock.Unlock()
</s> add if isRunning() { </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
return dnsServer.IsRunning() | <mask> isCoreDNSRunning = false
<mask> )
<mask>
<mask> func isRunning() bool {
<mask> isCoreDNSRunningLock.Lock()
<mask> value := isCoreDNSRunning
<mask> isCoreDNSRunningLock.Unlock()
<mask> return value
<mask> }
<mask>
<mask> func startDNSServer() error {
<mask> isCoreDNSRunningLock.Lock()
<mask> if isCoreDNSRunning {
</s> Unplug coreDNS and plug dnsforward library. </s> remove isCoreDNSRunningLock.Lock()
if isCoreDNSRunning {
isCoreDNSRunningLock.Unlock()
</s> add if isRunning() { </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} </s> remove isCoreDNSRunning = true
isCoreDNSRunningLock.Unlock()
</s> add </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
if isRunning() { | <mask> return value
<mask> }
<mask>
<mask> func startDNSServer() error {
<mask> isCoreDNSRunningLock.Lock()
<mask> if isCoreDNSRunning {
<mask> isCoreDNSRunningLock.Unlock()
<mask> return fmt.Errorf("Unable to start coreDNS: Already running")
<mask> }
<mask> isCoreDNSRunning = true
<mask> isCoreDNSRunningLock.Unlock()
<mask>
</s> Unplug coreDNS and plug dnsforward library. </s> remove isCoreDNSRunning = true
isCoreDNSRunningLock.Unlock()
</s> add </s> remove isCoreDNSRunningLock.Lock()
value := isCoreDNSRunning
isCoreDNSRunningLock.Unlock()
return value
</s> add return dnsServer.IsRunning() </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
<mask> if isCoreDNSRunning {
<mask> isCoreDNSRunningLock.Unlock()
<mask> return fmt.Errorf("Unable to start coreDNS: Already running")
<mask> }
<mask> isCoreDNSRunning = true
<mask> isCoreDNSRunningLock.Unlock()
<mask>
<mask> configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
<mask> os.Args = os.Args[:1]
<mask> os.Args = append(os.Args, "-conf")
<mask> os.Args = append(os.Args, configpath)
</s> Unplug coreDNS and plug dnsforward library. </s> remove isCoreDNSRunningLock.Lock()
if isCoreDNSRunning {
isCoreDNSRunningLock.Unlock()
</s> add if isRunning() { </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove err := writeCoreDNSConfig()
</s> add err := dnsServer.Start(&newconfig) </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") </s> remove isCoreDNSRunningLock.Lock()
value := isCoreDNSRunning
isCoreDNSRunningLock.Unlock()
return value
</s> add return dnsServer.IsRunning() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go | |
filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} | <mask> }
<mask> isCoreDNSRunning = true
<mask> isCoreDNSRunningLock.Unlock()
<mask>
<mask> configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
<mask> os.Args = os.Args[:1]
<mask> os.Args = append(os.Args, "-conf")
<mask> os.Args = append(os.Args, configpath)
<mask>
<mask> err := writeCoreDNSConfig()
<mask> if err != nil {
<mask> errortext := fmt.Errorf("Unable to write coredns config: %s", err)
<mask> log.Println(errortext)
</s> Unplug coreDNS and plug dnsforward library. </s> remove err := writeCoreDNSConfig()
</s> add err := dnsServer.Start(&newconfig) </s> remove isCoreDNSRunning = true
isCoreDNSRunningLock.Unlock()
</s> add </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
err := dnsServer.Start(&newconfig) | <mask> os.Args = os.Args[:1]
<mask> os.Args = append(os.Args, "-conf")
<mask> os.Args = append(os.Args, configpath)
<mask>
<mask> err := writeCoreDNSConfig()
<mask> if err != nil {
<mask> errortext := fmt.Errorf("Unable to write coredns config: %s", err)
<mask> log.Println(errortext)
<mask> return errortext
<mask> }
</s> Unplug coreDNS and plug dnsforward library. </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove isCoreDNSRunning = true
isCoreDNSRunningLock.Unlock()
</s> add </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
return errorx.Decorate(err, "Couldn't start forwarding DNS server") | <mask> os.Args = append(os.Args, configpath)
<mask>
<mask> err := writeCoreDNSConfig()
<mask> if err != nil {
<mask> errortext := fmt.Errorf("Unable to write coredns config: %s", err)
<mask> log.Println(errortext)
<mask> return errortext
<mask> }
<mask>
<mask> go coremain.Run()
<mask> return nil
<mask> }
</s> Unplug coreDNS and plug dnsforward library. </s> remove err := writeCoreDNSConfig()
</s> add err := dnsServer.Start(&newconfig) </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add </s> remove go coremain.Run()
</s> add </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go |
<mask> log.Println(errortext)
<mask> return errortext
<mask> }
<mask>
<mask> go coremain.Run()
<mask> return nil
<mask> }
</s> Unplug coreDNS and plug dnsforward library. </s> remove errortext := fmt.Errorf("Unable to write coredns config: %s", err)
log.Println(errortext)
return errortext
</s> add return errorx.Decorate(err, "Couldn't start forwarding DNS server") </s> remove err := writeCoreDNSConfig()
</s> add err := dnsServer.Start(&newconfig) </s> remove configpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
os.Args = os.Args[:1]
os.Args = append(os.Args, "-conf")
os.Args = append(os.Args, configpath)
</s> add filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
ID: filter.ID,
Rules: filter.Rules,
})
}
newconfig := dnsforward.ServerConfig{
UDPListenAddr: &net.UDPAddr{Port: config.CoreDNS.Port},
BlockedTTL: config.CoreDNS.BlockedResponseTTL,
Filters: filters,
}
for _, u := range config.CoreDNS.UpstreamDNS {
upstream, err := dnsforward.GetUpstream(u)
if err != nil {
log.Printf("Couldn't get upstream: %s", err)
// continue, just ignore the upstream
continue
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
} </s> remove err := config.write()
if err != nil {
log.Printf("Couldn't write our config: %s", err)
return err
}
err = writeCoreDNSConfig()
if err != nil {
log.Printf("Couldn't write DNS config: %s", err)
return err
}
return nil
}
const coreDNSConfigTemplate = `.:{{.Port}} {
{{if .ProtectionEnabled}}dnsfilter {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}}
blocked_ttl {{.BlockedResponseTTL}}
{{if .FilteringEnabled}}{{range .Filters}}{{if and .Enabled .Contents}}
filter {{.ID}} "{{.Path}}"
{{end}}{{end}}{{end}}
}{{end}}
{{.Pprof}}
{{if .RefuseAny}}refuseany{{end}}
{{if gt .Ratelimit 0}}ratelimit {{.Ratelimit}}{{end}}
hosts {
fallthrough
}
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap {{.BootstrapDNS}} }{{end}}
{{.Cache}}
{{.Prometheus}}
}
`
var removeEmptyLines = regexp.MustCompile("([\t ]*\n)+")
// generate CoreDNS config text
func generateCoreDNSConfigText() (string, error) {
t, err := template.New("config").Parse(coreDNSConfigTemplate)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
var configBytes bytes.Buffer
temporaryConfig := config.CoreDNS
// generate temporary filter list, needed to put userfilter in coredns config
filters := []filter{}
// first of all, append the user filter
userFilter := userFilter()
filters = append(filters, userFilter)
// then go through other filters
filters = append(filters, config.Filters...)
temporaryConfig.Filters = filters
// run the template
err = t.Execute(&configBytes, &temporaryConfig)
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return "", err
}
configText := configBytes.String()
// remove empty lines from generated config
configText = removeEmptyLines.ReplaceAllString(configText, "\n")
return configText, nil
</s> add return config.write() </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | coredns.go | |
github.com/joomcode/errorx v0.1.0 | <mask> github.com/go-test/deep v1.0.1
<mask> github.com/gobuffalo/packr v1.19.0
<mask> github.com/google/uuid v1.0.0 // indirect
<mask> github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
<mask> github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
<mask> github.com/mholt/caddy v0.11.0
<mask> github.com/miekg/dns v1.0.15
<mask> github.com/opentracing/opentracing-go v1.0.2 // indirect
</s> Unplug coreDNS and plug dnsforward library. </s> remove // Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what plugin above them are doing.
var directives = []string{
"metadata",
"tls",
"reload",
"nsid",
"root",
"bind",
"debug",
"health",
"pprof",
"prometheus",
"errors",
"log",
"refuseany",
"ratelimit",
"dnsfilter",
"dnstap",
"chaos",
"loadbalance",
"cache",
"rewrite",
"dnssec",
"autopath",
"template",
"hosts",
"file",
"auto",
"secondary",
"loop",
"forward",
"proxy",
"upstream",
"erratic",
"whoami",
"on",
}
func init() {
dnsserver.Directives = directives
}
var (
isCoreDNSRunningLock sync.Mutex
isCoreDNSRunning = false
)
</s> add var dnsServer = dnsforward.Server{} </s> remove _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/ratelimit"
_ "github.com/AdguardTeam/AdGuardHome/coredns_plugin/refuseany"
_ "github.com/AdguardTeam/AdGuardHome/upstream"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/forward"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/loop"
_ "github.com/coredns/coredns/plugin/metadata"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/nsid"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reload"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/template"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/onevent"
</s> add "github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/joomcode/errorx" </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add </s> remove "os"
"path/filepath"
"sync" // Include all plugins.
</s> add "net" | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | go.mod |
github.com/joomcode/errorx v0.1.0 h1:QmJMiI1DE1UFje2aI1ZWO/VMT5a32qBoXUclGOt8vsc=
github.com/joomcode/errorx v0.1.0/go.mod h1:kgco15ekB6cs+4Xjzo7SPeXzx38PbJzBwbnu9qfVNHQ= | <mask> github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
<mask> github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
<mask> github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
<mask> github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 h1:Mlji5gkcpzkqTROyE4ZxZ8hN7osunMb2RuGVrbvMvCc=
<mask> github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
<mask> github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
</s> Unplug coreDNS and plug dnsforward library. </s> remove "regexp"
</s> add </s> remove "text/template"
</s> add </s> remove BlockedResponseTTL int `yaml:"blocked_response_ttl"`
</s> add BlockedResponseTTL uint32 `yaml:"blocked_response_ttl"` </s> remove // --------------
// coredns config
// --------------
func writeCoreDNSConfig() error {
coreFile := filepath.Join(config.ourBinaryDir, config.CoreDNS.coreFile)
log.Printf("Writing DNS config: %s", coreFile)
configText, err := generateCoreDNSConfigText()
if err != nil {
log.Printf("Couldn't generate DNS config: %s", err)
return err
}
err = safeWriteFile(coreFile, []byte(configText))
if err != nil {
log.Printf("Couldn't save DNS config: %s", err)
return err
}
return nil
}
</s> add | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/feabc21864dd8d08b2ceed359169f542ac866e92 | go.sum |
err = startMods() | <mask> // TODO(e.burkov): StartMods() should be put in a separate goroutine at the
<mask> // moment we'll allow setting up TLS in the initial configuration or the
<mask> // configuration itself will use HTTPS protocol, because the underlying
<mask> // functions potentially restart the HTTPS server.
<mask> err = StartMods()
<mask> if err != nil {
<mask> Context.firstRun = true
<mask> copyInstallSettings(config, curConfig)
<mask> aghhttp.Error(r, w, http.StatusInternalServerError, "%s", err)
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.web.TLSConfigChanged(context.Background(), data.tlsConfigSettings)
</s> add Context.web.TLSConfigChanged(context.Background(), req.tlsConfigSettings) </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` </s> remove // StartMods initializes and starts the DNS server after installation.
func StartMods() error {
</s> add // startMods initializes and starts the DNS server after installation.
func startMods() error { </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/controlinstall.go |
tls *tlsManager // TLS module | <mask> dhcpServer dhcpd.Interface // DHCP module
<mask> auth *Auth // HTTP authentication module
<mask> filters *filtering.DNSFilter // DNS filtering module
<mask> web *Web // Web (HTTP, HTTPS) module
<mask> tls *TLSMod // TLS module
<mask> // etcHosts is an IP-hostname pairs set taken from system configuration
<mask> // (e.g. /etc/hosts) files.
<mask> etcHosts *aghnet.HostsContainer
<mask> // hostsWatcher is the watcher to detect changes in the hosts files.
<mask> hostsWatcher aghos.FSWatcher
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove var tlsWebHandlersRegistered = false
// TLSMod - TLS module object
type TLSMod struct {
certLastMod time.Time // last modification time of the certificate file
status tlsConfigStatus
confLock sync.Mutex
conf tlsConfigSettings
}
</s> add // tlsManager contains the current configuration and state of AdGuard Home TLS
// encryption.
type tlsManager struct {
// status is the current status of the configuration. It is never nil.
status *tlsConfigStatus </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove t.status = data
return true
</s> add return m, nil </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
Context.tls.reload() | <mask> log.Info("Received signal %q", sig)
<mask> switch sig {
<mask> case syscall.SIGHUP:
<mask> Context.clients.Reload()
<mask> Context.tls.Reload()
<mask>
<mask> default:
<mask> cleanup(context.Background())
<mask> cleanupAlways()
<mask> os.Exit(0)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove log.Info("Stopped")
</s> add log.Info("stopped") </s> remove if data.Enabled {
</s> add if req.Enabled { </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove Context.tls.Start()
</s> add Context.tls.start() </s> remove if data.PrivateKeySaved {
data.PrivateKey = t.conf.PrivateKey
</s> add if req.PrivateKeySaved {
req.PrivateKey = m.conf.PrivateKey | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
Context.tls, err = newTLSManager(config.TLS)
if err != nil {
log.Fatalf("initializing tls: %s", err) | <mask> log.Fatalf("Couldn't initialize Auth module")
<mask> }
<mask> config.Users = nil
<mask>
<mask> Context.tls = tlsCreate(config.TLS)
<mask> if Context.tls == nil {
<mask> log.Fatalf("Can't initialize TLS module")
<mask> }
<mask>
<mask> Context.web, err = initWeb(opts, clientBuildFS)
<mask> fatalOnError(err)
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls = &TLSMod{}
</s> add Context.tls = &tlsManager{} </s> remove Context.tls.Close()
</s> add </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove var parsedCerts []*x509.Certificate
for _, cert := range certs {
parsed, err := x509.ParseCertificate(cert.Bytes)
if err != nil {
data.WarningValidation = fmt.Sprintf("Failed to parse certificate: %s", err)
return errors.Error(data.WarningValidation)
}
parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
data.WarningValidation = "You have specified an empty certificate"
return errors.Error(data.WarningValidation)
</s> add parsedCerts, err := parsePEMCerts(certs)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
Context.tls.start() | <mask> if !Context.firstRun {
<mask> err = initDNSServer()
<mask> fatalOnError(err)
<mask>
<mask> Context.tls.Start()
<mask>
<mask> go func() {
<mask> serr := startDNSServer()
<mask> if serr != nil {
<mask> closeDNSServer()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls.Start()
</s> add Context.tls.start() </s> remove Context.tls = tlsCreate(config.TLS)
if Context.tls == nil {
log.Fatalf("Can't initialize TLS module")
</s> add Context.tls, err = newTLSManager(config.TLS)
if err != nil {
log.Fatalf("initializing tls: %s", err) </s> remove // StartMods initializes and starts the DNS server after installation.
func StartMods() error {
</s> add // startMods initializes and starts the DNS server after installation.
func startMods() error { </s> remove // go through all pem blocks, but take first valid pem block and drop the rest
</s> add parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
return nil, errors.Error("empty certificate")
}
return parsedCerts, nil
}
// validatePKey validates the private key and sets data in status. The returned
// error is also set in status.WarningValidation.
func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}()
var key *pem.Block
// Go through all pem blocks, but take first valid pem block and drop the
// rest. </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
// startMods initializes and starts the DNS server after installation.
func startMods() error { | <mask> // wait indefinitely for other go-routines to complete their job
<mask> select {}
<mask> }
<mask>
<mask> // StartMods initializes and starts the DNS server after installation.
<mask> func StartMods() error {
<mask> err := initDNSServer()
<mask> if err != nil {
<mask> return err
<mask> }
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, </s> remove func validatePkey(data *tlsConfigStatus, pkey string) error {
// now do a more extended validation
var key *pem.Block // PEM-encoded certificates
</s> add // parsePEMCerts parses multiple PEM-encoded certificates.
func parsePEMCerts(certs []*pem.Block) (parsedCerts []*x509.Certificate, err error) {
for i, cert := range certs {
var parsed *x509.Certificate
parsed, err = x509.ParseCertificate(cert.Bytes)
if err != nil {
return nil, fmt.Errorf("parsing certificate at index %d: %w", i, err)
} </s> remove var parsedCerts []*x509.Certificate
for _, cert := range certs {
parsed, err := x509.ParseCertificate(cert.Bytes)
if err != nil {
data.WarningValidation = fmt.Sprintf("Failed to parse certificate: %s", err)
return errors.Error(data.WarningValidation)
}
parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
data.WarningValidation = "You have specified an empty certificate"
return errors.Error(data.WarningValidation)
</s> add parsedCerts, err := parsePEMCerts(certs)
if err != nil {
return err </s> remove // parameters are optional. On error, validateCertificates returns a partially
// set object with field WarningValidation containing error description.
func validateCertificates(certChain, pkey, serverName string) tlsConfigStatus {
var data tlsConfigStatus
// check only public certificate separately from the key
if certChain != "" {
if verifyCertChain(&data, certChain, serverName) != nil {
return data
</s> add // parameters are optional. status must not be nil. The returned error is also
// set in status.WarningValidation.
func validateCertificates(
status *tlsConfigStatus,
certChain []byte,
pkey []byte,
serverName string,
) (err error) {
defer func() {
// Capitalize the warning for the UI. Assume that warnings are all
// ASCII-only.
//
// TODO(a.garipov): Figure out a better way to do this. Perhaps a
// custom string or error type.
if w := status.WarningValidation; w != "" {
status.WarningValidation = strings.ToUpper(w[:1]) + w[1:]
}
}()
// Check only the public certificate separately from the key.
if len(certChain) > 0 {
err = validateCertChain(status, certChain, serverName)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
Context.tls.start() | <mask> if err != nil {
<mask> return err
<mask> }
<mask>
<mask> Context.tls.Start()
<mask>
<mask> err = startDNSServer()
<mask> if err != nil {
<mask> closeDNSServer()
<mask> return err
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls.Start()
</s> add Context.tls.start() </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) </s> remove var parsedCerts []*x509.Certificate
for _, cert := range certs {
parsed, err := x509.ParseCertificate(cert.Bytes)
if err != nil {
data.WarningValidation = fmt.Sprintf("Failed to parse certificate: %s", err)
return errors.Error(data.WarningValidation)
}
parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
data.WarningValidation = "You have specified an empty certificate"
return errors.Error(data.WarningValidation)
</s> add parsedCerts, err := parsePEMCerts(certs)
if err != nil {
return err </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
<mask> }
<mask> }
<mask>
<mask> if Context.tls != nil {
<mask> Context.tls.Close()
<mask> Context.tls = nil
<mask> }
<mask> }
<mask>
<mask> // This function is called before application exits
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls = &TLSMod{}
</s> add Context.tls = &tlsManager{} </s> remove Context.tls = tlsCreate(config.TLS)
if Context.tls == nil {
log.Fatalf("Can't initialize TLS module")
</s> add Context.tls, err = newTLSManager(config.TLS)
if err != nil {
log.Fatalf("initializing tls: %s", err) </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove newConf.DNSCryptConfigFile = t.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = t.conf.PortDNSCrypt
if !cmp.Equal(t.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) {
</s> add newConf.DNSCryptConfigFile = m.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = m.conf.PortDNSCrypt
if !cmp.Equal(m.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go | |
log.Info("stopped") | <mask> func cleanupAlways() {
<mask> if len(Context.pidFileName) != 0 {
<mask> _ = os.Remove(Context.pidFileName)
<mask> }
<mask> log.Info("Stopped")
<mask> }
<mask>
<mask> func exitWithError() {
<mask> os.Exit(64)
<mask> }
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove func (t *TLSMod) setCertFileTime() {
if len(t.conf.CertificatePath) == 0 {
</s> add // setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove // if both are set, validate both in unison
if pkey != "" && certChain != "" {
_, err := tls.X509KeyPair([]byte(certChain), []byte(pkey))
</s> add // If both are set, validate together.
if len(certChain) > 0 && len(pkey) > 0 {
_, err = tls.X509KeyPair(certChain, pkey) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/home.go |
Context.tls = &tlsManager{} | <mask> Port: defaultPortDNS,
<mask> },
<mask> }
<mask>
<mask> Context.tls = &TLSMod{}
<mask> }
<mask>
<mask> func TestHandleMobileConfigDoH(t *testing.T) {
<mask> setupDNSIPs(t)
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove Context.tls.Close()
</s> add </s> remove Context.tls = tlsCreate(config.TLS)
if Context.tls == nil {
log.Fatalf("Can't initialize TLS module")
</s> add Context.tls, err = newTLSManager(config.TLS)
if err != nil {
log.Fatalf("initializing tls: %s", err) </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/mobileconfig_test.go |
Context.tls = &tlsManager{conf: tlsConfigSettings{}} | <mask> t.Run("error_no_host", func(t *testing.T) {
<mask> oldTLSConf := Context.tls
<mask> t.Cleanup(func() { Context.tls = oldTLSConf })
<mask>
<mask> Context.tls = &TLSMod{conf: tlsConfigSettings{}}
<mask>
<mask> r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/doh.mobileconfig", nil)
<mask> require.NoError(t, err)
<mask>
<mask> b := &bytes.Buffer{}
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove Context.tls = &TLSMod{}
</s> add Context.tls = &tlsManager{} </s> remove Context.tls = tlsCreate(config.TLS)
if Context.tls == nil {
log.Fatalf("Can't initialize TLS module")
</s> add Context.tls, err = newTLSManager(config.TLS)
if err != nil {
log.Fatalf("initializing tls: %s", err) </s> remove data := validateCertificates("", "bad priv key", "")
assert.NotEmpty(t, data.WarningValidation)
assert.False(t, data.ValidKey)
</s> add status := &tlsConfigStatus{}
err := validateCertificates(status, nil, []byte("bad priv key"), "")
assert.Error(t, err)
assert.NotEmpty(t, status.WarningValidation)
assert.False(t, status.ValidKey) </s> remove data := validateCertificates("bad cert", "", "")
assert.NotEmpty(t, data.WarningValidation)
assert.False(t, data.ValidCert)
assert.False(t, data.ValidChain)
</s> add status := &tlsConfigStatus{}
err := validateCertificates(status, []byte("bad cert"), nil, "")
assert.Error(t, err)
assert.NotEmpty(t, status.WarningValidation)
assert.False(t, status.ValidCert)
assert.False(t, status.ValidChain) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/mobileconfig_test.go |
Context.tls = &tlsManager{conf: tlsConfigSettings{}} | <mask> t.Run("error_no_host", func(t *testing.T) {
<mask> oldTLSConf := Context.tls
<mask> t.Cleanup(func() { Context.tls = oldTLSConf })
<mask>
<mask> Context.tls = &TLSMod{conf: tlsConfigSettings{}}
<mask>
<mask> r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/dot.mobileconfig", nil)
<mask> require.NoError(t, err)
<mask>
<mask> b := &bytes.Buffer{}
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove Context.tls = &TLSMod{conf: tlsConfigSettings{}}
</s> add Context.tls = &tlsManager{conf: tlsConfigSettings{}} </s> remove Context.tls = &TLSMod{}
</s> add Context.tls = &tlsManager{} </s> remove Context.tls = tlsCreate(config.TLS)
if Context.tls == nil {
log.Fatalf("Can't initialize TLS module")
</s> add Context.tls, err = newTLSManager(config.TLS)
if err != nil {
log.Fatalf("initializing tls: %s", err) </s> remove data := validateCertificates("", "bad priv key", "")
assert.NotEmpty(t, data.WarningValidation)
assert.False(t, data.ValidKey)
</s> add status := &tlsConfigStatus{}
err := validateCertificates(status, nil, []byte("bad priv key"), "")
assert.Error(t, err)
assert.NotEmpty(t, status.WarningValidation)
assert.False(t, status.ValidKey) </s> remove data := validateCertificates("bad cert", "", "")
assert.NotEmpty(t, data.WarningValidation)
assert.False(t, data.ValidCert)
assert.False(t, data.ValidChain)
</s> add status := &tlsConfigStatus{}
err := validateCertificates(status, []byte("bad cert"), nil, "")
assert.Error(t, err)
assert.NotEmpty(t, status.WarningValidation)
assert.False(t, status.ValidCert)
assert.False(t, status.ValidChain) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/mobileconfig_test.go |
// tlsManager contains the current configuration and state of AdGuard Home TLS
// encryption.
type tlsManager struct {
// status is the current status of the configuration. It is never nil.
status *tlsConfigStatus | <mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/google/go-cmp/cmp"
<mask> )
<mask>
<mask> var tlsWebHandlersRegistered = false
<mask>
<mask> // TLSMod - TLS module object
<mask> type TLSMod struct {
<mask> certLastMod time.Time // last modification time of the certificate file
<mask> status tlsConfigStatus
<mask> confLock sync.Mutex
<mask> conf tlsConfigSettings
<mask> }
<mask>
<mask> // Create TLS module
<mask> func tlsCreate(conf tlsConfigSettings) *TLSMod {
<mask> t := &TLSMod{}
<mask> t.conf = conf
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() </s> remove tls *TLSMod // TLS module
</s> add tls *tlsManager // TLS module </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings | <mask> confLock sync.Mutex
<mask> conf tlsConfigSettings
<mask> }
<mask>
<mask> // Create TLS module
<mask> func tlsCreate(conf tlsConfigSettings) *TLSMod {
<mask> t := &TLSMod{}
<mask> t.conf = conf
<mask> if t.conf.Enabled {
<mask> if !t.load() {
<mask> // Something is not valid - return an empty TLS config
<mask> return &TLSMod{conf: tlsConfigSettings{
<mask> Enabled: conf.Enabled,
<mask> ServerName: conf.ServerName,
<mask> PortHTTPS: conf.PortHTTPS,
<mask> PortDNSOverTLS: conf.PortDNSOverTLS,
<mask> PortDNSOverQUIC: conf.PortDNSOverQUIC,
<mask> AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
<mask> }}
<mask> }
<mask> t.setCertFileTime()
<mask> }
<mask> return t
<mask> }
<mask>
<mask> func (t *TLSMod) load() bool {
<mask> if !tlsLoadConfig(&t.conf, &t.status) {
<mask> log.Error("failed to load TLS config: %s", t.status.WarningValidation)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, </s> remove var tlsWebHandlersRegistered = false
// TLSMod - TLS module object
type TLSMod struct {
certLastMod time.Time // last modification time of the certificate file
status tlsConfigStatus
confLock sync.Mutex
conf tlsConfigSettings
}
</s> add // tlsManager contains the current configuration and state of AdGuard Home TLS
// encryption.
type tlsManager struct {
// status is the current status of the configuration. It is never nil.
status *tlsConfigStatus </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove // validate current TLS config and update warnings (it could have been loaded from file)
data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
if !data.ValidPair {
log.Error("failed to validate certificate: %s", data.WarningValidation)
return false
</s> add if m.conf.Enabled {
err = m.load()
if err != nil {
return nil, err
}
m.setCertFileTime() </s> remove t.status = data
return true
</s> add return m, nil | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
... | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, | <mask> }
<mask> return t
<mask> }
<mask>
<mask> func (t *TLSMod) load() bool {
<mask> if !tlsLoadConfig(&t.conf, &t.status) {
<mask> log.Error("failed to load TLS config: %s", t.status.WarningValidation)
<mask> return false
<mask> }
<mask>
<mask> // validate current TLS config and update warnings (it could have been loaded from file)
<mask> data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
<mask> if !data.ValidPair {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // validate current TLS config and update warnings (it could have been loaded from file)
data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
if !data.ValidPair {
log.Error("failed to validate certificate: %s", data.WarningValidation)
return false
</s> add if m.conf.Enabled {
err = m.load()
if err != nil {
return nil, err
}
m.setCertFileTime() </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings </s> remove t.status = data
return true
</s> add return m, nil </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
data, err := unmarshalTLS(r)
</s> add func (m *tlsManager) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
req, err := unmarshalTLS(r) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
if m.conf.Enabled {
err = m.load()
if err != nil {
return nil, err
}
m.setCertFileTime() | <mask> log.Error("failed to load TLS config: %s", t.status.WarningValidation)
<mask> return false
<mask> }
<mask>
<mask> // validate current TLS config and update warnings (it could have been loaded from file)
<mask> data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
<mask> if !data.ValidPair {
<mask> log.Error("failed to validate certificate: %s", data.WarningValidation)
<mask> return false
<mask> }
<mask> t.status = data
<mask> return true
<mask> }
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, </s> remove t.status = data
return true
</s> add return m, nil </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove var parsedCerts []*x509.Certificate
for _, cert := range certs {
parsed, err := x509.ParseCertificate(cert.Bytes)
if err != nil {
data.WarningValidation = fmt.Sprintf("Failed to parse certificate: %s", err)
return errors.Error(data.WarningValidation)
}
parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
data.WarningValidation = "You have specified an empty certificate"
return errors.Error(data.WarningValidation)
</s> add parsedCerts, err := parsePEMCerts(certs)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
return m, nil | <mask> if !data.ValidPair {
<mask> log.Error("failed to validate certificate: %s", data.WarningValidation)
<mask> return false
<mask> }
<mask> t.status = data
<mask> return true
<mask> }
<mask>
<mask> // Close - close module
<mask> func (t *TLSMod) Close() {
<mask> }
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // validate current TLS config and update warnings (it could have been loaded from file)
data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
if !data.ValidPair {
log.Error("failed to validate certificate: %s", data.WarningValidation)
return false
</s> add if m.conf.Enabled {
err = m.load()
if err != nil {
return nil, err
}
m.setCertFileTime() </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil | <mask> t.status = data
<mask> return true
<mask> }
<mask>
<mask> // Close - close module
<mask> func (t *TLSMod) Close() {
<mask> }
<mask>
<mask> // WriteDiskConfig - write config
<mask> func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
<mask> t.confLock.Lock()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove t.status = data
return true
</s> add return m, nil </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() | <mask> func (t *TLSMod) Close() {
<mask> }
<mask>
<mask> // WriteDiskConfig - write config
<mask> func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
<mask> t.confLock.Lock()
<mask> *conf = t.conf
<mask> t.confLock.Unlock()
<mask> }
<mask>
<mask> func (t *TLSMod) setCertFileTime() {
<mask> if len(t.conf.CertificatePath) == 0 {
<mask> return
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove func (t *TLSMod) setCertFileTime() {
if len(t.conf.CertificatePath) == 0 {
</s> add // setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) </s> remove t.status = data
return true
</s> add return m, nil </s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { | <mask> *conf = t.conf
<mask> t.confLock.Unlock()
<mask> }
<mask>
<mask> func (t *TLSMod) setCertFileTime() {
<mask> if len(t.conf.CertificatePath) == 0 {
<mask> return
<mask> }
<mask> fi, err := os.Stat(t.conf.CertificatePath)
<mask> if err != nil {
<mask> log.Error("TLS: %s", err)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
</s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: %s", err)
</s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
fi, err := os.Stat(m.conf.CertificatePath) | <mask> func (t *TLSMod) setCertFileTime() {
<mask> if len(t.conf.CertificatePath) == 0 {
<mask> return
<mask> }
<mask> fi, err := os.Stat(t.conf.CertificatePath)
<mask> if err != nil {
<mask> log.Error("TLS: %s", err)
<mask> return
<mask> }
<mask> t.certLastMod = fi.ModTime().UTC()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) setCertFileTime() {
if len(t.conf.CertificatePath) == 0 {
</s> add // setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
</s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: %s", err)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
log.Error("tls: looking up certificate path: %s", err)
| <mask> return
<mask> }
<mask> fi, err := os.Stat(t.conf.CertificatePath)
<mask> if err != nil {
<mask> log.Error("TLS: %s", err)
<mask> return
<mask> }
<mask> t.certLastMod = fi.ModTime().UTC()
<mask> }
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) </s> remove func (t *TLSMod) setCertFileTime() {
if len(t.conf.CertificatePath) == 0 {
</s> add // setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: %s", err)
</s> remove t.confLock.Lock()
r := t.load()
t.confLock.Unlock()
if !r {
</s> add log.Debug("tls: certificate file is modified")
m.confLock.Lock()
err = m.load()
m.confLock.Unlock()
if err != nil {
log.Error("tls: reloading: %s", err)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
m.certLastMod = fi.ModTime().UTC() | <mask> if err != nil {
<mask> log.Error("TLS: %s", err)
<mask> return
<mask> }
<mask> t.certLastMod = fi.ModTime().UTC()
<mask> }
<mask>
<mask> // Start updates the configuration of TLSMod and starts it.
<mask> func (t *TLSMod) Start() {
<mask> if !tlsWebHandlersRegistered {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() </s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
</s> remove func (t *TLSMod) setCertFileTime() {
if len(t.conf.CertificatePath) == 0 {
</s> add // setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() | <mask> }
<mask> t.certLastMod = fi.ModTime().UTC()
<mask> }
<mask>
<mask> // Start updates the configuration of TLSMod and starts it.
<mask> func (t *TLSMod) Start() {
<mask> if !tlsWebHandlersRegistered {
<mask> tlsWebHandlersRegistered = true
<mask> t.registerWebHandlers()
<mask> }
<mask>
<mask> t.confLock.Lock()
<mask> tlsConf := t.conf
<mask> t.confLock.Unlock()
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove // The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add // The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() | <mask> tlsWebHandlersRegistered = true
<mask> t.registerWebHandlers()
<mask> }
<mask>
<mask> t.confLock.Lock()
<mask> tlsConf := t.conf
<mask> t.confLock.Unlock()
<mask>
<mask> // The background context is used because the TLSConfigChanged wraps
<mask> // context with timeout on its own and shuts down the server, which
<mask> // handles current request.
<mask> Context.web.TLSConfigChanged(context.Background(), tlsConf)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add // The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove t.confLock.Lock()
tlsConf = t.conf
t.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add m.confLock.Lock()
tlsConf = m.conf
m.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. | <mask> t.confLock.Lock()
<mask> tlsConf := t.conf
<mask> t.confLock.Unlock()
<mask>
<mask> // The background context is used because the TLSConfigChanged wraps
<mask> // context with timeout on its own and shuts down the server, which
<mask> // handles current request.
<mask> Context.web.TLSConfigChanged(context.Background(), tlsConf)
<mask> }
<mask>
<mask> // Reload updates the configuration of TLSMod and restarts it.
<mask> func (t *TLSMod) Reload() {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove t.confLock.Lock()
tlsConf = t.conf
t.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add m.confLock.Lock()
tlsConf = m.conf
m.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() | <mask> // handles current request.
<mask> Context.web.TLSConfigChanged(context.Background(), tlsConf)
<mask> }
<mask>
<mask> // Reload updates the configuration of TLSMod and restarts it.
<mask> func (t *TLSMod) Reload() {
<mask> t.confLock.Lock()
<mask> tlsConf := t.conf
<mask> t.confLock.Unlock()
<mask>
<mask> if !tlsConf.Enabled || len(tlsConf.CertificatePath) == 0 {
<mask> return
<mask> }
<mask> fi, err := os.Stat(tlsConf.CertificatePath)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add // The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() </s> remove t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove func (t *TLSMod) setCertFileTime() {
if len(t.conf.CertificatePath) == 0 {
</s> add // setCertFileTime sets t.certLastMod from the certificate. If there are
// errors, setCertFileTime logs them.
func (m *tlsManager) setCertFileTime() {
if len(m.conf.CertificatePath) == 0 { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
log.Error("tls: %s", err)
| <mask> return
<mask> }
<mask> fi, err := os.Stat(tlsConf.CertificatePath)
<mask> if err != nil {
<mask> log.Error("TLS: %s", err)
<mask> return
<mask> }
<mask> if fi.ModTime().UTC().Equal(t.certLastMod) {
<mask> log.Debug("TLS: certificate file isn't modified")
<mask> return
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if fi.ModTime().UTC().Equal(t.certLastMod) {
log.Debug("TLS: certificate file isn't modified")
</s> add if fi.ModTime().UTC().Equal(m.certLastMod) {
log.Debug("tls: certificate file isn't modified")
</s> remove log.Debug("TLS: certificate file is modified")
</s> add </s> remove t.confLock.Lock()
r := t.load()
t.confLock.Unlock()
if !r {
</s> add log.Debug("tls: certificate file is modified")
m.confLock.Lock()
err = m.load()
m.confLock.Unlock()
if err != nil {
log.Error("tls: reloading: %s", err)
</s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
</s> remove fi, err := os.Stat(t.conf.CertificatePath)
</s> add fi, err := os.Stat(m.conf.CertificatePath) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
if fi.ModTime().UTC().Equal(m.certLastMod) {
log.Debug("tls: certificate file isn't modified")
| <mask> if err != nil {
<mask> log.Error("TLS: %s", err)
<mask> return
<mask> }
<mask> if fi.ModTime().UTC().Equal(t.certLastMod) {
<mask> log.Debug("TLS: certificate file isn't modified")
<mask> return
<mask> }
<mask> log.Debug("TLS: certificate file is modified")
<mask>
<mask> t.confLock.Lock()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove log.Debug("TLS: certificate file is modified")
</s> add </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: %s", err)
</s> remove t.confLock.Lock()
r := t.load()
t.confLock.Unlock()
if !r {
</s> add log.Debug("tls: certificate file is modified")
m.confLock.Lock()
err = m.load()
m.confLock.Unlock()
if err != nil {
log.Error("tls: reloading: %s", err)
</s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
</s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
<mask> if fi.ModTime().UTC().Equal(t.certLastMod) {
<mask> log.Debug("TLS: certificate file isn't modified")
<mask> return
<mask> }
<mask> log.Debug("TLS: certificate file is modified")
<mask>
<mask> t.confLock.Lock()
<mask> r := t.load()
<mask> t.confLock.Unlock()
<mask> if !r {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if fi.ModTime().UTC().Equal(t.certLastMod) {
log.Debug("TLS: certificate file isn't modified")
</s> add if fi.ModTime().UTC().Equal(m.certLastMod) {
log.Debug("tls: certificate file isn't modified")
</s> remove t.confLock.Lock()
r := t.load()
t.confLock.Unlock()
if !r {
</s> add log.Debug("tls: certificate file is modified")
m.confLock.Lock()
err = m.load()
m.confLock.Unlock()
if err != nil {
log.Error("tls: reloading: %s", err)
</s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: %s", err)
</s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go | |
log.Debug("tls: certificate file is modified")
m.confLock.Lock()
err = m.load()
m.confLock.Unlock()
if err != nil {
log.Error("tls: reloading: %s", err)
| <mask> return
<mask> }
<mask> log.Debug("TLS: certificate file is modified")
<mask>
<mask> t.confLock.Lock()
<mask> r := t.load()
<mask> t.confLock.Unlock()
<mask> if !r {
<mask> return
<mask> }
<mask>
<mask> t.certLastMod = fi.ModTime().UTC()
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove log.Debug("TLS: certificate file is modified")
</s> add </s> remove if fi.ModTime().UTC().Equal(t.certLastMod) {
log.Debug("TLS: certificate file isn't modified")
</s> add if fi.ModTime().UTC().Equal(m.certLastMod) {
log.Debug("tls: certificate file isn't modified")
</s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: %s", err)
</s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
m.certLastMod = fi.ModTime().UTC() | <mask> if !r {
<mask> return
<mask> }
<mask>
<mask> t.certLastMod = fi.ModTime().UTC()
<mask>
<mask> _ = reconfigureDNSServer()
<mask>
<mask> t.confLock.Lock()
<mask> tlsConf = t.conf
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove t.confLock.Lock()
r := t.load()
t.confLock.Unlock()
if !r {
</s> add log.Debug("tls: certificate file is modified")
m.confLock.Lock()
err = m.load()
m.confLock.Unlock()
if err != nil {
log.Error("tls: reloading: %s", err)
</s> remove t.confLock.Lock()
tlsConf = t.conf
t.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add m.confLock.Lock()
tlsConf = m.conf
m.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove // Start updates the configuration of TLSMod and starts it.
func (t *TLSMod) Start() {
if !tlsWebHandlersRegistered {
tlsWebHandlersRegistered = true
t.registerWebHandlers()
}
</s> add // start updates the configuration of t and starts it.
func (m *tlsManager) start() {
m.registerWebHandlers() </s> remove t.certLastMod = fi.ModTime().UTC()
</s> add m.certLastMod = fi.ModTime().UTC() </s> remove log.Error("TLS: %s", err)
</s> add log.Error("tls: looking up certificate path: %s", err)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
m.confLock.Lock()
tlsConf = m.conf
m.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. | <mask> t.certLastMod = fi.ModTime().UTC()
<mask>
<mask> _ = reconfigureDNSServer()
<mask>
<mask> t.confLock.Lock()
<mask> tlsConf = t.conf
<mask> t.confLock.Unlock()
<mask> // The background context is used because the TLSConfigChanged wraps
<mask> // context with timeout on its own and shuts down the server, which
<mask> // handles current request.
<mask> Context.web.TLSConfigChanged(context.Background(), tlsConf)
<mask> }
<mask>
<mask> // Set certificate and private key data
<mask> func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add // The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove // Set certificate and private key data
func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
tls.CertificateChainData = []byte(tls.CertificateChain)
tls.PrivateKeyData = []byte(tls.PrivateKey)
</s> add // loadTLSConf loads and validates the TLS configuration. The returned error is
// also set in status.WarningValidation.
func loadTLSConf(tlsConf *tlsConfigSettings, status *tlsConfigStatus) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove // Reload updates the configuration of TLSMod and restarts it.
func (t *TLSMod) Reload() {
t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add // reload updates the configuration and restarts t.
func (m *tlsManager) reload() {
m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// loadTLSConf loads and validates the TLS configuration. The returned error is
// also set in status.WarningValidation.
func loadTLSConf(tlsConf *tlsConfigSettings, status *tlsConfigStatus) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() | <mask> // handles current request.
<mask> Context.web.TLSConfigChanged(context.Background(), tlsConf)
<mask> }
<mask>
<mask> // Set certificate and private key data
<mask> func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
<mask> tls.CertificateChainData = []byte(tls.CertificateChain)
<mask> tls.PrivateKeyData = []byte(tls.PrivateKey)
<mask>
<mask> var err error
<mask> if tls.CertificatePath != "" {
<mask> if tls.CertificateChain != "" {
<mask> status.WarningValidation = "certificate data and file can't be set together"
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove var err error
if tls.CertificatePath != "" {
if tls.CertificateChain != "" {
status.WarningValidation = "certificate data and file can't be set together"
return false
</s> add tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove t.confLock.Lock()
tlsConf = t.conf
t.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add m.confLock.Lock()
tlsConf = m.conf
m.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
</s> add tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") | <mask> func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
<mask> tls.CertificateChainData = []byte(tls.CertificateChain)
<mask> tls.PrivateKeyData = []byte(tls.PrivateKey)
<mask>
<mask> var err error
<mask> if tls.CertificatePath != "" {
<mask> if tls.CertificateChain != "" {
<mask> status.WarningValidation = "certificate data and file can't be set together"
<mask> return false
<mask> }
<mask> tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
<mask> if err != nil {
<mask> status.WarningValidation = err.Error()
<mask> return false
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // Set certificate and private key data
func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
tls.CertificateChainData = []byte(tls.CertificateChain)
tls.PrivateKeyData = []byte(tls.PrivateKey)
</s> add // loadTLSConf loads and validates the TLS configuration. The returned error is
// also set in status.WarningValidation.
func loadTLSConf(tlsConf *tlsConfigSettings, status *tlsConfigStatus) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
</s> add tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) | <mask> if tls.CertificateChain != "" {
<mask> status.WarningValidation = "certificate data and file can't be set together"
<mask> return false
<mask> }
<mask> tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
<mask> if err != nil {
<mask> status.WarningValidation = err.Error()
<mask> return false
<mask> }
<mask> status.ValidCert = true
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove var err error
if tls.CertificatePath != "" {
if tls.CertificateChain != "" {
status.WarningValidation = "certificate data and file can't be set together"
return false
</s> add tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
</s> add tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) </s> remove // Set certificate and private key data
func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
tls.CertificateChainData = []byte(tls.CertificateChain)
tls.PrivateKeyData = []byte(tls.PrivateKey)
</s> add // loadTLSConf loads and validates the TLS configuration. The returned error is
// also set in status.WarningValidation.
func loadTLSConf(tlsConf *tlsConfigSettings, status *tlsConfigStatus) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
return fmt.Errorf("reading cert file: %w", err) | <mask> return false
<mask> }
<mask> tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
<mask> if err != nil {
<mask> status.WarningValidation = err.Error()
<mask> return false
<mask> }
<mask> status.ValidCert = true
<mask> }
<mask>
<mask> if tls.PrivateKeyPath != "" {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove var err error
if tls.CertificatePath != "" {
if tls.CertificateChain != "" {
status.WarningValidation = "certificate data and file can't be set together"
return false
</s> add tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") </s> remove tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
</s> add tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading key file: %w", err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") | <mask> }
<mask> status.ValidCert = true
<mask> }
<mask>
<mask> if tls.PrivateKeyPath != "" {
<mask> if tls.PrivateKey != "" {
<mask> status.WarningValidation = "private key data and file can't be set together"
<mask> return false
<mask> }
<mask> tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
<mask> if err != nil {
<mask> status.WarningValidation = err.Error()
<mask> return false
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
</s> add tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) </s> remove var err error
if tls.CertificatePath != "" {
if tls.CertificateChain != "" {
status.WarningValidation = "certificate data and file can't be set together"
return false
</s> add tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading key file: %w", err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) | <mask> if tls.PrivateKey != "" {
<mask> status.WarningValidation = "private key data and file can't be set together"
<mask> return false
<mask> }
<mask> tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
<mask> if err != nil {
<mask> status.WarningValidation = err.Error()
<mask> return false
<mask> }
<mask> status.ValidKey = true
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) </s> remove var err error
if tls.CertificatePath != "" {
if tls.CertificateChain != "" {
status.WarningValidation = "certificate data and file can't be set together"
return false
</s> add tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading key file: %w", err) </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
return fmt.Errorf("reading key file: %w", err) | <mask> return false
<mask> }
<mask> tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
<mask> if err != nil {
<mask> status.WarningValidation = err.Error()
<mask> return false
<mask> }
<mask> status.ValidKey = true
<mask> }
<mask>
<mask> return true
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
</s> add tlsConf.PrivateKeyData, err = os.ReadFile(tlsConf.PrivateKeyPath) </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) </s> remove tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
</s> add tlsConf.CertificateChainData, err = os.ReadFile(tlsConf.CertificatePath) </s> remove var err error
if tls.CertificatePath != "" {
if tls.CertificateChain != "" {
status.WarningValidation = "certificate data and file can't be set together"
return false
</s> add tlsConf.CertificateChainData = []byte(tlsConf.CertificateChain)
tlsConf.PrivateKeyData = []byte(tlsConf.PrivateKey)
if tlsConf.CertificatePath != "" {
if tlsConf.CertificateChain != "" {
return errors.Error("certificate data and file can't be set together") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
err = validateCertificates(
status,
tlsConf.CertificateChainData,
tlsConf.PrivateKeyData,
tlsConf.ServerName,
)
if err != nil {
return fmt.Errorf("validating certificate pair: %w", err)
}
return nil | <mask> }
<mask> status.ValidKey = true
<mask> }
<mask>
<mask> return true
<mask> }
<mask>
<mask> type tlsConfigStatus struct {
<mask> ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
<mask> ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` </s> remove func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
log.Tracef("TLS: got certificate: %d bytes", len(certChain))
</s> add // validateCertChain validates the certificate chain and sets data in status.
// The returned error is also set in status.WarningValidation.
func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove // If private key saved as a string, we set this flag to true
// and omit key from answer.
</s> add // PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// tlsConfigStatus contains the status of a certificate chain and key pair. | <mask> }
<mask>
<mask> type tlsConfigStatus struct {
<mask> // Subject is the subject of the first certificate in the chain.
<mask> Subject string `json:"subject,omitempty"`
<mask>
<mask> // Issuer is the issuer of the first certificate in the chain.
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` </s> remove var tlsWebHandlersRegistered = false
// TLSMod - TLS module object
type TLSMod struct {
certLastMod time.Time // last modification time of the certificate file
status tlsConfigStatus
confLock sync.Mutex
conf tlsConfigSettings
}
</s> add // tlsManager contains the current configuration and state of AdGuard Home TLS
// encryption.
type tlsManager struct {
// status is the current status of the configuration. It is never nil.
status *tlsConfigStatus </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. </s> remove return true
</s> add err = validateCertificates(
status,
tlsConf.CertificateChainData,
tlsConf.PrivateKeyData,
tlsConf.ServerName,
)
if err != nil {
return fmt.Errorf("validating certificate pair: %w", err)
}
return nil </s> remove Context.web.TLSConfigChanged(context.Background(), data.tlsConfigSettings)
</s> add Context.web.TLSConfigChanged(context.Background(), req.tlsConfigSettings) | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` | <mask> return true
<mask> }
<mask>
<mask> type tlsConfigStatus struct {
<mask> ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
<mask> ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
<mask> Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
<mask> Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
<mask> NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
<mask> NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
<mask> DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
<mask>
<mask> // key status
<mask> ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
<mask> KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
<mask>
<mask> // is usable? set by validator
<mask> ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
<mask>
<mask> // warnings
<mask> WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
<mask> }
<mask>
<mask> // field ordering is important -- yaml fields will mirror ordering from here
<mask> type tlsConfig struct {
<mask> tlsConfigStatus `json:",inline"`
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove return true
</s> add err = validateCertificates(
status,
tlsConf.CertificateChainData,
tlsConf.PrivateKeyData,
tlsConf.ServerName,
)
if err != nil {
return fmt.Errorf("validating certificate pair: %w", err)
}
return nil </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. </s> remove tlsConfigStatus `json:",inline"`
</s> add *tlsConfigStatus `json:",inline"` </s> remove // If private key saved as a string, we set this flag to true
// and omit key from answer.
</s> add // PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// tlsConfig is the TLS configuration and status response. | <mask> // warnings
<mask> WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
<mask> }
<mask>
<mask> // field ordering is important -- yaml fields will mirror ordering from here
<mask> type tlsConfig struct {
<mask> tlsConfigStatus `json:",inline"`
<mask> tlsConfigSettingsExt `json:",inline"`
<mask> }
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tlsConfigStatus `json:",inline"`
</s> add *tlsConfigStatus `json:",inline"` </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` </s> remove // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
// clients don't send and receive previously saved private keys.
</s> add // tlsConfigSettingsExt is used to (un)marshal the PrivateKeySaved field to
// ensure that clients don't send and receive previously saved private keys. </s> remove // If private key saved as a string, we set this flag to true
// and omit key from answer.
</s> add // PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. </s> remove // parameters are optional. On error, validateCertificates returns a partially
// set object with field WarningValidation containing error description.
func validateCertificates(certChain, pkey, serverName string) tlsConfigStatus {
var data tlsConfigStatus
// check only public certificate separately from the key
if certChain != "" {
if verifyCertChain(&data, certChain, serverName) != nil {
return data
</s> add // parameters are optional. status must not be nil. The returned error is also
// set in status.WarningValidation.
func validateCertificates(
status *tlsConfigStatus,
certChain []byte,
pkey []byte,
serverName string,
) (err error) {
defer func() {
// Capitalize the warning for the UI. Assume that warnings are all
// ASCII-only.
//
// TODO(a.garipov): Figure out a better way to do this. Perhaps a
// custom string or error type.
if w := status.WarningValidation; w != "" {
status.WarningValidation = strings.ToUpper(w[:1]) + w[1:]
}
}()
// Check only the public certificate separately from the key.
if len(certChain) > 0 {
err = validateCertChain(status, certChain, serverName)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
*tlsConfigStatus `json:",inline"` | <mask> }
<mask>
<mask> // field ordering is important -- yaml fields will mirror ordering from here
<mask> type tlsConfig struct {
<mask> tlsConfigStatus `json:",inline"`
<mask> tlsConfigSettingsExt `json:",inline"`
<mask> }
<mask>
<mask> // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
<mask> // clients don't send and receive previously saved private keys.
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
// clients don't send and receive previously saved private keys.
</s> add // tlsConfigSettingsExt is used to (un)marshal the PrivateKeySaved field to
// ensure that clients don't send and receive previously saved private keys. </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. </s> remove // If private key saved as a string, we set this flag to true
// and omit key from answer.
</s> add // PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// tlsConfigSettingsExt is used to (un)marshal the PrivateKeySaved field to
// ensure that clients don't send and receive previously saved private keys. | <mask> tlsConfigStatus `json:",inline"`
<mask> tlsConfigSettingsExt `json:",inline"`
<mask> }
<mask>
<mask> // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
<mask> // clients don't send and receive previously saved private keys.
<mask> type tlsConfigSettingsExt struct {
<mask> tlsConfigSettings `json:",inline"`
<mask> // If private key saved as a string, we set this flag to true
<mask> // and omit key from answer.
<mask> PrivateKeySaved bool `yaml:"-" json:"private_key_saved,inline"`
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // If private key saved as a string, we set this flag to true
// and omit key from answer.
</s> add // PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. </s> remove tlsConfigStatus `json:",inline"`
</s> add *tlsConfigStatus `json:",inline"` </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. </s> remove func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
t.confLock.Lock()
</s> add func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. | <mask> // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
<mask> // clients don't send and receive previously saved private keys.
<mask> type tlsConfigSettingsExt struct {
<mask> tlsConfigSettings `json:",inline"`
<mask> // If private key saved as a string, we set this flag to true
<mask> // and omit key from answer.
<mask> PrivateKeySaved bool `yaml:"-" json:"private_key_saved,inline"`
<mask> }
<mask>
<mask> func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
<mask> t.confLock.Lock()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
// clients don't send and receive previously saved private keys.
</s> add // tlsConfigSettingsExt is used to (un)marshal the PrivateKeySaved field to
// ensure that clients don't send and receive previously saved private keys. </s> remove tlsConfigStatus `json:",inline"`
</s> add *tlsConfigStatus `json:",inline"` </s> remove func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
t.confLock.Lock()
</s> add func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() </s> remove // field ordering is important -- yaml fields will mirror ordering from here
</s> add // tlsConfig is the TLS configuration and status response. </s> remove ValidCert bool `json:"valid_cert"` // ValidCert is true if the specified certificates chain is a valid chain of X509 certificates
ValidChain bool `json:"valid_chain"` // ValidChain is true if the specified certificates chain is verified and issued by a known CA
Subject string `json:"subject,omitempty"` // Subject is the subject of the first certificate in the chain
Issuer string `json:"issuer,omitempty"` // Issuer is the issuer of the first certificate in the chain
NotBefore time.Time `json:"not_before,omitempty"` // NotBefore is the NotBefore field of the first certificate in the chain
NotAfter time.Time `json:"not_after,omitempty"` // NotAfter is the NotAfter field of the first certificate in the chain
DNSNames []string `json:"dns_names"` // DNSNames is the value of SubjectAltNames field of the first certificate in the chain
// key status
ValidKey bool `json:"valid_key"` // ValidKey is true if the key is a valid private key
KeyType string `json:"key_type,omitempty"` // KeyType is one of RSA or ECDSA
// is usable? set by validator
ValidPair bool `json:"valid_pair"` // ValidPair is true if both certificate and private key are correct
// warnings
WarningValidation string `json:"warning_validation,omitempty"` // WarningValidation is a validation warning message with the issue description
</s> add // Subject is the subject of the first certificate in the chain.
Subject string `json:"subject,omitempty"`
// Issuer is the issuer of the first certificate in the chain.
Issuer string `json:"issuer,omitempty"`
// KeyType is the type of the private key.
KeyType string `json:"key_type,omitempty"`
// NotBefore is the NotBefore field of the first certificate in the chain.
NotBefore time.Time `json:"not_before,omitempty"`
// NotAfter is the NotAfter field of the first certificate in the chain.
NotAfter time.Time `json:"not_after,omitempty"`
// WarningValidation is a validation warning message with the issue
// description.
WarningValidation string `json:"warning_validation,omitempty"`
// DNSNames is the value of SubjectAltNames field of the first certificate
// in the chain.
DNSNames []string `json:"dns_names"`
// ValidCert is true if the specified certificate chain is a valid chain of
// X509 certificates.
ValidCert bool `json:"valid_cert"`
// ValidChain is true if the specified certificate chain is verified and
// issued by a known CA.
ValidChain bool `json:"valid_chain"`
// ValidKey is true if the key is a valid private key.
ValidKey bool `json:"valid_key"`
// ValidPair is true if both certificate and private key are correct for
// each other.
ValidPair bool `json:"valid_pair"` | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() | <mask> // and omit key from answer.
<mask> PrivateKeySaved bool `yaml:"-" json:"private_key_saved,inline"`
<mask> }
<mask>
<mask> func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
<mask> t.confLock.Lock()
<mask> data := tlsConfig{
<mask> tlsConfigSettingsExt: tlsConfigSettingsExt{
<mask> tlsConfigSettings: t.conf,
<mask> },
<mask> tlsConfigStatus: t.status,
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, </s> remove // If private key saved as a string, we set this flag to true
// and omit key from answer.
</s> add // PrivateKeySaved is true if the private key is saved as a string and omit
// key from answer. </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
</s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, </s> remove // tlsConfigSettingsExt is used to (un)marshal PrivateKeySaved to ensure that
// clients don't send and receive previously saved private keys.
</s> add // tlsConfigSettingsExt is used to (un)marshal the PrivateKeySaved field to
// ensure that clients don't send and receive previously saved private keys. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
tlsConfigSettings: m.conf, | <mask> func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
<mask> t.confLock.Lock()
<mask> data := tlsConfig{
<mask> tlsConfigSettingsExt: tlsConfigSettingsExt{
<mask> tlsConfigSettings: t.conf,
<mask> },
<mask> tlsConfigStatus: t.status,
<mask> }
<mask> t.confLock.Unlock()
<mask> marshalTLS(w, r, data)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
t.confLock.Lock()
</s> add func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
</s> remove func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
</s> add func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { </s> remove marshalTLS(w, r, data)
</s> add marshalTLS(w, r, resp) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
tlsConfigStatus: m.status, | <mask> data := tlsConfig{
<mask> tlsConfigSettingsExt: tlsConfigSettingsExt{
<mask> tlsConfigSettings: t.conf,
<mask> },
<mask> tlsConfigStatus: t.status,
<mask> }
<mask> t.confLock.Unlock()
<mask> marshalTLS(w, r, data)
<mask> }
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
</s> remove func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
t.confLock.Lock()
</s> add func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() </s> remove data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: m.status, </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
m.confLock.Unlock()
| <mask> tlsConfigSettings: t.conf,
<mask> },
<mask> tlsConfigStatus: t.status,
<mask> }
<mask> t.confLock.Unlock()
<mask> marshalTLS(w, r, data)
<mask> }
<mask>
<mask> func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
<mask> setts, err := unmarshalTLS(r)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, </s> remove func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
</s> add func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, </s> remove func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
t.confLock.Lock()
</s> add func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() </s> remove marshalTLS(w, r, data)
</s> add marshalTLS(w, r, resp) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { | <mask> t.confLock.Unlock()
<mask> marshalTLS(w, r, data)
<mask> }
<mask>
<mask> func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
<mask> setts, err := unmarshalTLS(r)
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusBadRequest, "Failed to unmarshal TLS config: %s", err)
<mask>
<mask> return
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
data, err := unmarshalTLS(r)
</s> add func (m *tlsManager) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
req, err := unmarshalTLS(r) </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
</s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, </s> remove marshalTLS(w, r, data)
</s> add marshalTLS(w, r, resp) </s> remove func (t *TLSMod) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
t.confLock.Lock()
</s> add func (m *tlsManager) handleTLSStatus(w http.ResponseWriter, r *http.Request) {
m.confLock.Lock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
setts.PrivateKey = m.conf.PrivateKey | <mask> return
<mask> }
<mask>
<mask> if setts.PrivateKeySaved {
<mask> setts.PrivateKey = t.conf.PrivateKey
<mask> }
<mask>
<mask> if setts.Enabled {
<mask> err = validatePorts(
<mask> tcpPort(config.BindPort),
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if data.PrivateKeySaved {
data.PrivateKey = t.conf.PrivateKey
</s> add if req.PrivateKeySaved {
req.PrivateKey = m.conf.PrivateKey </s> remove if data.Enabled {
</s> add if req.Enabled { </s> remove tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
tcpPort(data.PortDNSCrypt),
</s> add tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// Skip the error check, since we are only interested in the value of
// status.WarningValidation.
status := &tlsConfigStatus{}
_ = loadTLSConf(&setts.tlsConfigSettings, status)
resp := tlsConfig{ | <mask>
<mask> return
<mask> }
<mask>
<mask> status := tlsConfigStatus{}
<mask> if tlsLoadConfig(&setts.tlsConfigSettings, &status) {
<mask> status = validateCertificates(string(setts.CertificateChainData), string(setts.PrivateKeyData), setts.ServerName)
<mask> }
<mask>
<mask> data := tlsConfig{
<mask> tlsConfigSettingsExt: setts,
<mask> tlsConfigStatus: status,
<mask> }
<mask>
<mask> marshalTLS(w, r, data)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove status := tlsConfigStatus{}
if !tlsLoadConfig(&data.tlsConfigSettings, &status) {
data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add status := &tlsConfigStatus{}
err = loadTLSConf(&req.tlsConfigSettings, status)
if err != nil {
resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: status, </s> remove marshalTLS(w, r, data)
</s> add marshalTLS(w, r, resp) </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, </s> remove data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: m.status, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
marshalTLS(w, r, resp) | <mask> tlsConfigSettingsExt: setts,
<mask> tlsConfigStatus: status,
<mask> }
<mask>
<mask> marshalTLS(w, r, data)
<mask> }
<mask>
<mask> func (t *TLSMod) setConfig(newConf tlsConfigSettings, status tlsConfigStatus) (restartHTTPS bool) {
<mask> t.confLock.Lock()
<mask> defer t.confLock.Unlock()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) setConfig(newConf tlsConfigSettings, status tlsConfigStatus) (restartHTTPS bool) {
t.confLock.Lock()
defer t.confLock.Unlock()
</s> add func (m *tlsManager) setConfig(newConf tlsConfigSettings, status *tlsConfigStatus) (restartHTTPS bool) {
m.confLock.Lock()
defer m.confLock.Unlock() </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
</s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, </s> remove status := tlsConfigStatus{}
if tlsLoadConfig(&setts.tlsConfigSettings, &status) {
status = validateCertificates(string(setts.CertificateChainData), string(setts.PrivateKeyData), setts.ServerName)
}
data := tlsConfig{
</s> add // Skip the error check, since we are only interested in the value of
// status.WarningValidation.
status := &tlsConfigStatus{}
_ = loadTLSConf(&setts.tlsConfigSettings, status)
resp := tlsConfig{ </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
func (m *tlsManager) setConfig(newConf tlsConfigSettings, status *tlsConfigStatus) (restartHTTPS bool) {
m.confLock.Lock()
defer m.confLock.Unlock() | <mask>
<mask> marshalTLS(w, r, data)
<mask> }
<mask>
<mask> func (t *TLSMod) setConfig(newConf tlsConfigSettings, status tlsConfigStatus) (restartHTTPS bool) {
<mask> t.confLock.Lock()
<mask> defer t.confLock.Unlock()
<mask>
<mask> // Reset the DNSCrypt data before comparing, since we currently do not
<mask> // accept these from the frontend.
<mask> //
<mask> // TODO(a.garipov): Define a custom comparer for dnsforward.TLSConfig.
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove newConf.DNSCryptConfigFile = t.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = t.conf.PortDNSCrypt
if !cmp.Equal(t.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) {
</s> add newConf.DNSCryptConfigFile = m.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = m.conf.PortDNSCrypt
if !cmp.Equal(m.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) { </s> remove marshalTLS(w, r, data)
</s> add marshalTLS(w, r, resp) </s> remove status := tlsConfigStatus{}
if tlsLoadConfig(&setts.tlsConfigSettings, &status) {
status = validateCertificates(string(setts.CertificateChainData), string(setts.PrivateKeyData), setts.ServerName)
}
data := tlsConfig{
</s> add // Skip the error check, since we are only interested in the value of
// status.WarningValidation.
status := &tlsConfigStatus{}
_ = loadTLSConf(&setts.tlsConfigSettings, status)
resp := tlsConfig{ </s> remove // parameters are optional. On error, validateCertificates returns a partially
// set object with field WarningValidation containing error description.
func validateCertificates(certChain, pkey, serverName string) tlsConfigStatus {
var data tlsConfigStatus
// check only public certificate separately from the key
if certChain != "" {
if verifyCertChain(&data, certChain, serverName) != nil {
return data
</s> add // parameters are optional. status must not be nil. The returned error is also
// set in status.WarningValidation.
func validateCertificates(
status *tlsConfigStatus,
certChain []byte,
pkey []byte,
serverName string,
) (err error) {
defer func() {
// Capitalize the warning for the UI. Assume that warnings are all
// ASCII-only.
//
// TODO(a.garipov): Figure out a better way to do this. Perhaps a
// custom string or error type.
if w := status.WarningValidation; w != "" {
status.WarningValidation = strings.ToUpper(w[:1]) + w[1:]
}
}()
// Check only the public certificate separately from the key.
if len(certChain) > 0 {
err = validateCertChain(status, certChain, serverName)
if err != nil {
return err </s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
newConf.DNSCryptConfigFile = m.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = m.conf.PortDNSCrypt
if !cmp.Equal(m.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) { | <mask> // Reset the DNSCrypt data before comparing, since we currently do not
<mask> // accept these from the frontend.
<mask> //
<mask> // TODO(a.garipov): Define a custom comparer for dnsforward.TLSConfig.
<mask> newConf.DNSCryptConfigFile = t.conf.DNSCryptConfigFile
<mask> newConf.PortDNSCrypt = t.conf.PortDNSCrypt
<mask> if !cmp.Equal(t.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) {
<mask> log.Info("tls config has changed, restarting https server")
<mask> restartHTTPS = true
<mask> } else {
<mask> log.Info("tls config has not changed")
<mask> }
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove log.Info("tls config has not changed")
</s> add log.Info("tls: config has not changed") </s> remove func (t *TLSMod) setConfig(newConf tlsConfigSettings, status tlsConfigStatus) (restartHTTPS bool) {
t.confLock.Lock()
defer t.confLock.Unlock()
</s> add func (m *tlsManager) setConfig(newConf tlsConfigSettings, status *tlsConfigStatus) (restartHTTPS bool) {
m.confLock.Lock()
defer m.confLock.Unlock() </s> remove t.conf.Enabled = newConf.Enabled
t.conf.ServerName = newConf.ServerName
t.conf.ForceHTTPS = newConf.ForceHTTPS
t.conf.PortHTTPS = newConf.PortHTTPS
t.conf.PortDNSOverTLS = newConf.PortDNSOverTLS
t.conf.PortDNSOverQUIC = newConf.PortDNSOverQUIC
t.conf.CertificateChain = newConf.CertificateChain
t.conf.CertificatePath = newConf.CertificatePath
t.conf.CertificateChainData = newConf.CertificateChainData
t.conf.PrivateKey = newConf.PrivateKey
t.conf.PrivateKeyPath = newConf.PrivateKeyPath
t.conf.PrivateKeyData = newConf.PrivateKeyData
t.status = status
</s> add m.conf.Enabled = newConf.Enabled
m.conf.ServerName = newConf.ServerName
m.conf.ForceHTTPS = newConf.ForceHTTPS
m.conf.PortHTTPS = newConf.PortHTTPS
m.conf.PortDNSOverTLS = newConf.PortDNSOverTLS
m.conf.PortDNSOverQUIC = newConf.PortDNSOverQUIC
m.conf.CertificateChain = newConf.CertificateChain
m.conf.CertificatePath = newConf.CertificatePath
m.conf.CertificateChainData = newConf.CertificateChainData
m.conf.PrivateKey = newConf.PrivateKey
m.conf.PrivateKeyPath = newConf.PrivateKeyPath
m.conf.PrivateKeyData = newConf.PrivateKeyData
m.status = status </s> remove // Close - close module
func (t *TLSMod) Close() {
</s> add // load reloads the TLS configuration from files or data from the config file.
func (m *tlsManager) load() (err error) {
err = loadTLSConf(&m.conf, m.status)
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
return nil </s> remove // parameters are optional. On error, validateCertificates returns a partially
// set object with field WarningValidation containing error description.
func validateCertificates(certChain, pkey, serverName string) tlsConfigStatus {
var data tlsConfigStatus
// check only public certificate separately from the key
if certChain != "" {
if verifyCertChain(&data, certChain, serverName) != nil {
return data
</s> add // parameters are optional. status must not be nil. The returned error is also
// set in status.WarningValidation.
func validateCertificates(
status *tlsConfigStatus,
certChain []byte,
pkey []byte,
serverName string,
) (err error) {
defer func() {
// Capitalize the warning for the UI. Assume that warnings are all
// ASCII-only.
//
// TODO(a.garipov): Figure out a better way to do this. Perhaps a
// custom string or error type.
if w := status.WarningValidation; w != "" {
status.WarningValidation = strings.ToUpper(w[:1]) + w[1:]
}
}()
// Check only the public certificate separately from the key.
if len(certChain) > 0 {
err = validateCertChain(status, certChain, serverName)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
log.Info("tls: config has not changed") | <mask> if !cmp.Equal(t.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) {
<mask> log.Info("tls config has changed, restarting https server")
<mask> restartHTTPS = true
<mask> } else {
<mask> log.Info("tls config has not changed")
<mask> }
<mask>
<mask> // Note: don't do just `t.conf = data` because we must preserve all other members of t.conf
<mask> t.conf.Enabled = newConf.Enabled
<mask> t.conf.ServerName = newConf.ServerName
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove newConf.DNSCryptConfigFile = t.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = t.conf.PortDNSCrypt
if !cmp.Equal(t.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) {
</s> add newConf.DNSCryptConfigFile = m.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = m.conf.PortDNSCrypt
if !cmp.Equal(m.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) { </s> remove t.conf.Enabled = newConf.Enabled
t.conf.ServerName = newConf.ServerName
t.conf.ForceHTTPS = newConf.ForceHTTPS
t.conf.PortHTTPS = newConf.PortHTTPS
t.conf.PortDNSOverTLS = newConf.PortDNSOverTLS
t.conf.PortDNSOverQUIC = newConf.PortDNSOverQUIC
t.conf.CertificateChain = newConf.CertificateChain
t.conf.CertificatePath = newConf.CertificatePath
t.conf.CertificateChainData = newConf.CertificateChainData
t.conf.PrivateKey = newConf.PrivateKey
t.conf.PrivateKeyPath = newConf.PrivateKeyPath
t.conf.PrivateKeyData = newConf.PrivateKeyData
t.status = status
</s> add m.conf.Enabled = newConf.Enabled
m.conf.ServerName = newConf.ServerName
m.conf.ForceHTTPS = newConf.ForceHTTPS
m.conf.PortHTTPS = newConf.PortHTTPS
m.conf.PortDNSOverTLS = newConf.PortDNSOverTLS
m.conf.PortDNSOverQUIC = newConf.PortDNSOverQUIC
m.conf.CertificateChain = newConf.CertificateChain
m.conf.CertificatePath = newConf.CertificatePath
m.conf.CertificateChainData = newConf.CertificateChainData
m.conf.PrivateKey = newConf.PrivateKey
m.conf.PrivateKeyPath = newConf.PrivateKeyPath
m.conf.PrivateKeyData = newConf.PrivateKeyData
m.status = status </s> remove data.ValidChain = true
</s> add status.ValidChain = true </s> remove // spew.Dump(chains)
</s> add </s> remove // Create TLS module
func tlsCreate(conf tlsConfigSettings) *TLSMod {
t := &TLSMod{}
t.conf = conf
if t.conf.Enabled {
if !t.load() {
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
PortDNSOverQUIC: conf.PortDNSOverQUIC,
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
}}
}
t.setCertFileTime()
}
return t
</s> add // certLastMod is the last modification time of the certificate file.
certLastMod time.Time
confLock sync.Mutex
conf tlsConfigSettings | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
m.conf.Enabled = newConf.Enabled
m.conf.ServerName = newConf.ServerName
m.conf.ForceHTTPS = newConf.ForceHTTPS
m.conf.PortHTTPS = newConf.PortHTTPS
m.conf.PortDNSOverTLS = newConf.PortDNSOverTLS
m.conf.PortDNSOverQUIC = newConf.PortDNSOverQUIC
m.conf.CertificateChain = newConf.CertificateChain
m.conf.CertificatePath = newConf.CertificatePath
m.conf.CertificateChainData = newConf.CertificateChainData
m.conf.PrivateKey = newConf.PrivateKey
m.conf.PrivateKeyPath = newConf.PrivateKeyPath
m.conf.PrivateKeyData = newConf.PrivateKeyData
m.status = status | <mask> log.Info("tls config has not changed")
<mask> }
<mask>
<mask> // Note: don't do just `t.conf = data` because we must preserve all other members of t.conf
<mask> t.conf.Enabled = newConf.Enabled
<mask> t.conf.ServerName = newConf.ServerName
<mask> t.conf.ForceHTTPS = newConf.ForceHTTPS
<mask> t.conf.PortHTTPS = newConf.PortHTTPS
<mask> t.conf.PortDNSOverTLS = newConf.PortDNSOverTLS
<mask> t.conf.PortDNSOverQUIC = newConf.PortDNSOverQUIC
<mask> t.conf.CertificateChain = newConf.CertificateChain
<mask> t.conf.CertificatePath = newConf.CertificatePath
<mask> t.conf.CertificateChainData = newConf.CertificateChainData
<mask> t.conf.PrivateKey = newConf.PrivateKey
<mask> t.conf.PrivateKeyPath = newConf.PrivateKeyPath
<mask> t.conf.PrivateKeyData = newConf.PrivateKeyData
<mask> t.status = status
<mask>
<mask> return restartHTTPS
<mask> }
<mask>
<mask> func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove log.Info("tls config has not changed")
</s> add log.Info("tls: config has not changed") </s> remove newConf.DNSCryptConfigFile = t.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = t.conf.PortDNSCrypt
if !cmp.Equal(t.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) {
</s> add newConf.DNSCryptConfigFile = m.conf.DNSCryptConfigFile
newConf.PortDNSCrypt = m.conf.PortDNSCrypt
if !cmp.Equal(m.conf, newConf, cmp.AllowUnexported(dnsforward.TLSConfig{})) { </s> remove func (t *TLSMod) WriteDiskConfig(conf *tlsConfigSettings) {
t.confLock.Lock()
*conf = t.conf
t.confLock.Unlock()
</s> add func (m *tlsManager) WriteDiskConfig(conf *tlsConfigSettings) {
m.confLock.Lock()
*conf = m.conf
m.confLock.Unlock() </s> remove setts.PrivateKey = t.conf.PrivateKey
</s> add setts.PrivateKey = m.conf.PrivateKey </s> remove notAfter := mainCert.NotAfter
data.Subject = mainCert.Subject.String()
data.Issuer = mainCert.Issuer.String()
data.NotAfter = notAfter
data.NotBefore = mainCert.NotBefore
data.DNSNames = mainCert.DNSNames
</s> add status.Subject = mainCert.Subject.String()
status.Issuer = mainCert.Issuer.String()
status.NotAfter = mainCert.NotAfter
status.NotBefore = mainCert.NotBefore
status.DNSNames = mainCert.DNSNames | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
func (m *tlsManager) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
req, err := unmarshalTLS(r) | <mask>
<mask> return restartHTTPS
<mask> }
<mask>
<mask> func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
<mask> data, err := unmarshalTLS(r)
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusBadRequest, "Failed to unmarshal TLS config: %s", err)
<mask>
<mask> return
<mask> }
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
</s> add func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { </s> remove t.confLock.Unlock()
</s> add m.confLock.Unlock()
</s> remove status = validateCertificates(string(data.CertificateChainData), string(data.PrivateKeyData), data.ServerName)
restartHTTPS := t.setConfig(data.tlsConfigSettings, status)
t.setCertFileTime()
</s> add restartHTTPS := m.setConfig(req.tlsConfigSettings, status)
m.setCertFileTime() </s> remove // validate current TLS config and update warnings (it could have been loaded from file)
data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
if !data.ValidPair {
log.Error("failed to validate certificate: %s", data.WarningValidation)
return false
</s> add if m.conf.Enabled {
err = m.load()
if err != nil {
return nil, err
}
m.setCertFileTime() </s> remove func (t *TLSMod) load() bool {
if !tlsLoadConfig(&t.conf, &t.status) {
log.Error("failed to load TLS config: %s", t.status.WarningValidation)
return false
</s> add // newTLSManager initializes the TLS configuration.
func newTLSManager(conf tlsConfigSettings) (m *tlsManager, err error) {
m = &tlsManager{
status: &tlsConfigStatus{},
conf: conf, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
if req.PrivateKeySaved {
req.PrivateKey = m.conf.PrivateKey | <mask>
<mask> return
<mask> }
<mask>
<mask> if data.PrivateKeySaved {
<mask> data.PrivateKey = t.conf.PrivateKey
<mask> }
<mask>
<mask> if data.Enabled {
<mask> err = validatePorts(
<mask> tcpPort(config.BindPort),
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if data.Enabled {
</s> add if req.Enabled { </s> remove setts.PrivateKey = t.conf.PrivateKey
</s> add setts.PrivateKey = m.conf.PrivateKey </s> remove tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
tcpPort(data.PortDNSCrypt),
</s> add tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), </s> remove status.WarningValidation = err.Error()
return false
</s> add return fmt.Errorf("reading cert file: %w", err) </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
if req.Enabled { | <mask> if data.PrivateKeySaved {
<mask> data.PrivateKey = t.conf.PrivateKey
<mask> }
<mask>
<mask> if data.Enabled {
<mask> err = validatePorts(
<mask> tcpPort(config.BindPort),
<mask> tcpPort(config.BetaBindPort),
<mask> tcpPort(data.PortHTTPS),
<mask> tcpPort(data.PortDNSOverTLS),
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if data.PrivateKeySaved {
data.PrivateKey = t.conf.PrivateKey
</s> add if req.PrivateKeySaved {
req.PrivateKey = m.conf.PrivateKey </s> remove tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
tcpPort(data.PortDNSCrypt),
</s> add tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), </s> remove setts.PrivateKey = t.conf.PrivateKey
</s> add setts.PrivateKey = m.conf.PrivateKey </s> remove udpPort(data.PortDNSOverQUIC),
</s> add udpPort(req.PortDNSOverQUIC), </s> remove if tls.PrivateKeyPath != "" {
if tls.PrivateKey != "" {
status.WarningValidation = "private key data and file can't be set together"
return false
</s> add if tlsConf.PrivateKeyPath != "" {
if tlsConf.PrivateKey != "" {
return errors.Error("private key data and file can't be set together") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), | <mask> if data.Enabled {
<mask> err = validatePorts(
<mask> tcpPort(config.BindPort),
<mask> tcpPort(config.BetaBindPort),
<mask> tcpPort(data.PortHTTPS),
<mask> tcpPort(data.PortDNSOverTLS),
<mask> tcpPort(data.PortDNSCrypt),
<mask> udpPort(config.DNS.Port),
<mask> udpPort(data.PortDNSOverQUIC),
<mask> )
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove udpPort(data.PortDNSOverQUIC),
</s> add udpPort(req.PortDNSOverQUIC), </s> remove if data.Enabled {
</s> add if req.Enabled { </s> remove if data.PrivateKeySaved {
data.PrivateKey = t.conf.PrivateKey
</s> add if req.PrivateKeySaved {
req.PrivateKey = m.conf.PrivateKey </s> remove status = validateCertificates(string(data.CertificateChainData), string(data.PrivateKeyData), data.ServerName)
restartHTTPS := t.setConfig(data.tlsConfigSettings, status)
t.setCertFileTime()
</s> add restartHTTPS := m.setConfig(req.tlsConfigSettings, status)
m.setCertFileTime() </s> remove setts.PrivateKey = t.conf.PrivateKey
</s> add setts.PrivateKey = m.conf.PrivateKey | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
udpPort(req.PortDNSOverQUIC), | <mask> tcpPort(data.PortHTTPS),
<mask> tcpPort(data.PortDNSOverTLS),
<mask> tcpPort(data.PortDNSCrypt),
<mask> udpPort(config.DNS.Port),
<mask> udpPort(data.PortDNSOverQUIC),
<mask> )
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
<mask>
<mask> return
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
tcpPort(data.PortDNSCrypt),
</s> add tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), </s> remove status = validateCertificates(string(data.CertificateChainData), string(data.PrivateKeyData), data.ServerName)
restartHTTPS := t.setConfig(data.tlsConfigSettings, status)
t.setCertFileTime()
</s> add restartHTTPS := m.setConfig(req.tlsConfigSettings, status)
m.setCertFileTime() </s> remove func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
data, err := unmarshalTLS(r)
</s> add func (m *tlsManager) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
req, err := unmarshalTLS(r) </s> remove func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
</s> add func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { </s> remove if data.Enabled {
</s> add if req.Enabled { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
if !webCheckPortAvailable(req.PortHTTPS) { | <mask> }
<mask> }
<mask>
<mask> // TODO(e.burkov): Investigate and perhaps check other ports.
<mask> if !webCheckPortAvailable(data.PortHTTPS) {
<mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusBadRequest,
<mask> "port %d is not available, cannot enable HTTPS on it",
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove "port %d is not available, cannot enable HTTPS on it",
data.PortHTTPS,
</s> add "port %d is not available, cannot enable https on it",
req.PortHTTPS, </s> remove err = StartMods()
</s> add err = startMods() </s> remove func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
</s> add func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { </s> remove log.Info("tls config has not changed")
</s> add log.Info("tls: config has not changed") </s> remove // StartMods initializes and starts the DNS server after installation.
func StartMods() error {
</s> add // startMods initializes and starts the DNS server after installation.
func startMods() error { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
"port %d is not available, cannot enable https on it",
req.PortHTTPS, | <mask> aghhttp.Error(
<mask> r,
<mask> w,
<mask> http.StatusBadRequest,
<mask> "port %d is not available, cannot enable HTTPS on it",
<mask> data.PortHTTPS,
<mask> )
<mask>
<mask> return
<mask> }
<mask>
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove if !webCheckPortAvailable(data.PortHTTPS) {
</s> add if !webCheckPortAvailable(req.PortHTTPS) { </s> remove udpPort(data.PortDNSOverQUIC),
</s> add udpPort(req.PortDNSOverQUIC), </s> remove func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
</s> add func (m *tlsManager) handleTLSValidate(w http.ResponseWriter, r *http.Request) { </s> remove tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
tcpPort(data.PortDNSCrypt),
</s> add tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), </s> remove func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
data, err := unmarshalTLS(r)
</s> add func (m *tlsManager) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
req, err := unmarshalTLS(r) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
status := &tlsConfigStatus{}
err = loadTLSConf(&req.tlsConfigSettings, status)
if err != nil {
resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: status, | <mask>
<mask> return
<mask> }
<mask>
<mask> status := tlsConfigStatus{}
<mask> if !tlsLoadConfig(&data.tlsConfigSettings, &status) {
<mask> data2 := tlsConfig{
<mask> tlsConfigSettingsExt: data,
<mask> tlsConfigStatus: t.status,
<mask> }
<mask> marshalTLS(w, r, data2)
<mask>
<mask> return
<mask> }
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: m.status, </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove status := tlsConfigStatus{}
if tlsLoadConfig(&setts.tlsConfigSettings, &status) {
status = validateCertificates(string(setts.CertificateChainData), string(setts.PrivateKeyData), setts.ServerName)
}
data := tlsConfig{
</s> add // Skip the error check, since we are only interested in the value of
// status.WarningValidation.
status := &tlsConfigStatus{}
_ = loadTLSConf(&setts.tlsConfigSettings, status)
resp := tlsConfig{ </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
marshalTLS(w, r, resp) | <mask> data2 := tlsConfig{
<mask> tlsConfigSettingsExt: data,
<mask> tlsConfigStatus: t.status,
<mask> }
<mask> marshalTLS(w, r, data2)
<mask>
<mask> return
<mask> }
<mask>
<mask> status = validateCertificates(string(data.CertificateChainData), string(data.PrivateKeyData), data.ServerName)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: m.status, </s> remove status := tlsConfigStatus{}
if !tlsLoadConfig(&data.tlsConfigSettings, &status) {
data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add status := &tlsConfigStatus{}
err = loadTLSConf(&req.tlsConfigSettings, status)
if err != nil {
resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: status, </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, </s> remove status = validateCertificates(string(data.CertificateChainData), string(data.PrivateKeyData), data.ServerName)
restartHTTPS := t.setConfig(data.tlsConfigSettings, status)
t.setCertFileTime()
</s> add restartHTTPS := m.setConfig(req.tlsConfigSettings, status)
m.setCertFileTime() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
restartHTTPS := m.setConfig(req.tlsConfigSettings, status)
m.setCertFileTime() | <mask>
<mask> return
<mask> }
<mask>
<mask> status = validateCertificates(string(data.CertificateChainData), string(data.PrivateKeyData), data.ServerName)
<mask>
<mask> restartHTTPS := t.setConfig(data.tlsConfigSettings, status)
<mask> t.setCertFileTime()
<mask> onConfigModified()
<mask>
<mask> err = reconfigureDNSServer()
<mask> if err != nil {
<mask> aghhttp.Error(r, w, http.StatusInternalServerError, "%s", err)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
tcpPort(data.PortDNSCrypt),
</s> add tcpPort(req.PortHTTPS),
tcpPort(req.PortDNSOverTLS),
tcpPort(req.PortDNSCrypt), </s> remove udpPort(data.PortDNSOverQUIC),
</s> add udpPort(req.PortDNSOverQUIC), </s> remove func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
data, err := unmarshalTLS(r)
</s> add func (m *tlsManager) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
req, err := unmarshalTLS(r) </s> remove err = StartMods()
</s> add err = startMods() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: m.status, | <mask>
<mask> return
<mask> }
<mask>
<mask> data2 := tlsConfig{
<mask> tlsConfigSettingsExt: data,
<mask> tlsConfigStatus: t.status,
<mask> }
<mask>
<mask> marshalTLS(w, r, data2)
<mask> if f, ok := w.(http.Flusher); ok {
<mask> f.Flush()
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) </s> remove status := tlsConfigStatus{}
if !tlsLoadConfig(&data.tlsConfigSettings, &status) {
data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add status := &tlsConfigStatus{}
err = loadTLSConf(&req.tlsConfigSettings, status)
if err != nil {
resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: status, </s> remove tlsConfigStatus: t.status,
</s> add tlsConfigStatus: m.status, </s> remove tlsConfigSettings: t.conf,
</s> add tlsConfigSettings: m.conf, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
marshalTLS(w, r, resp) | <mask> tlsConfigSettingsExt: data,
<mask> tlsConfigStatus: t.status,
<mask> }
<mask>
<mask> marshalTLS(w, r, data2)
<mask> if f, ok := w.(http.Flusher); ok {
<mask> f.Flush()
<mask> }
<mask>
<mask> // The background context is used because the TLSConfigChanged wraps context
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove data2 := tlsConfig{
tlsConfigSettingsExt: data,
tlsConfigStatus: t.status,
</s> add resp := tlsConfig{
tlsConfigSettingsExt: req,
tlsConfigStatus: m.status, </s> remove // The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add // The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove t.confLock.Lock()
tlsConf = t.conf
t.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps
// context with timeout on its own and shuts down the server, which
// handles current request.
</s> add m.confLock.Lock()
tlsConf = m.conf
m.confLock.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request. </s> remove t.confLock.Lock()
tlsConf := t.conf
t.confLock.Unlock()
</s> add m.confLock.Lock()
tlsConf := m.conf
m.confLock.Unlock() </s> remove marshalTLS(w, r, data2)
</s> add marshalTLS(w, r, resp) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
Context.web.TLSConfigChanged(context.Background(), req.tlsConfigSettings) | <mask> // request. It is also should be done in a separate goroutine due to the
<mask> // same reason.
<mask> if restartHTTPS {
<mask> go func() {
<mask> Context.web.TLSConfigChanged(context.Background(), data.tlsConfigSettings)
<mask> }()
<mask> }
<mask> }
<mask>
<mask> // validatePorts validates the uniqueness of TCP and UDP ports for AdGuard Home
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // Set certificate and private key data
func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
tls.CertificateChainData = []byte(tls.CertificateChain)
tls.PrivateKeyData = []byte(tls.PrivateKey)
</s> add // loadTLSConf loads and validates the TLS configuration. The returned error is
// also set in status.WarningValidation.
func loadTLSConf(tlsConf *tlsConfigSettings, status *tlsConfigStatus) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove // go through all pem blocks, but take first valid pem block and drop the rest
</s> add parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
return nil, errors.Error("empty certificate")
}
return parsedCerts, nil
}
// validatePKey validates the private key and sets data in status. The returned
// error is also set in status.WarningValidation.
func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}()
var key *pem.Block
// Go through all pem blocks, but take first valid pem block and drop the
// rest. </s> remove func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
log.Tracef("TLS: got certificate: %d bytes", len(certChain))
</s> add // validateCertChain validates the certificate chain and sets data in status.
// The returned error is also set in status.WarningValidation.
func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove err = StartMods()
</s> add err = startMods() </s> remove var tlsWebHandlersRegistered = false
// TLSMod - TLS module object
type TLSMod struct {
certLastMod time.Time // last modification time of the certificate file
status tlsConfigStatus
confLock sync.Mutex
conf tlsConfigSettings
}
</s> add // tlsManager contains the current configuration and state of AdGuard Home TLS
// encryption.
type tlsManager struct {
// status is the current status of the configuration. It is never nil.
status *tlsConfigStatus | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
// validateCertChain validates the certificate chain and sets data in status.
// The returned error is also set in status.WarningValidation.
func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() | <mask>
<mask> return nil
<mask> }
<mask>
<mask> func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
<mask> log.Tracef("TLS: got certificate: %d bytes", len(certChain))
<mask>
<mask> // now do a more extended validation
<mask> var certs []*pem.Block // PEM-encoded certificates
<mask>
<mask> pemblock := []byte(certChain)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // now do a more extended validation
var certs []*pem.Block // PEM-encoded certificates
</s> add log.Debug("tls: got certificate chain: %d bytes", len(certChain)) </s> remove pemblock := []byte(certChain)
</s> add var certs []*pem.Block
pemblock := certChain </s> remove func validatePkey(data *tlsConfigStatus, pkey string) error {
// now do a more extended validation
var key *pem.Block // PEM-encoded certificates
</s> add // parsePEMCerts parses multiple PEM-encoded certificates.
func parsePEMCerts(certs []*pem.Block) (parsedCerts []*x509.Certificate, err error) {
for i, cert := range certs {
var parsed *x509.Certificate
parsed, err = x509.ParseCertificate(cert.Bytes)
if err != nil {
return nil, fmt.Errorf("parsing certificate at index %d: %w", i, err)
} </s> remove // go through all pem blocks, but take first valid pem block and drop the rest
</s> add parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
return nil, errors.Error("empty certificate")
}
return parsedCerts, nil
}
// validatePKey validates the private key and sets data in status. The returned
// error is also set in status.WarningValidation.
func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}()
var key *pem.Block
// Go through all pem blocks, but take first valid pem block and drop the
// rest. </s> remove // parameters are optional. On error, validateCertificates returns a partially
// set object with field WarningValidation containing error description.
func validateCertificates(certChain, pkey, serverName string) tlsConfigStatus {
var data tlsConfigStatus
// check only public certificate separately from the key
if certChain != "" {
if verifyCertChain(&data, certChain, serverName) != nil {
return data
</s> add // parameters are optional. status must not be nil. The returned error is also
// set in status.WarningValidation.
func validateCertificates(
status *tlsConfigStatus,
certChain []byte,
pkey []byte,
serverName string,
) (err error) {
defer func() {
// Capitalize the warning for the UI. Assume that warnings are all
// ASCII-only.
//
// TODO(a.garipov): Figure out a better way to do this. Perhaps a
// custom string or error type.
if w := status.WarningValidation; w != "" {
status.WarningValidation = strings.ToUpper(w[:1]) + w[1:]
}
}()
// Check only the public certificate separately from the key.
if len(certChain) > 0 {
err = validateCertChain(status, certChain, serverName)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
log.Debug("tls: got certificate chain: %d bytes", len(certChain)) | <mask>
<mask> func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
<mask> log.Tracef("TLS: got certificate: %d bytes", len(certChain))
<mask>
<mask> // now do a more extended validation
<mask> var certs []*pem.Block // PEM-encoded certificates
<mask>
<mask> pemblock := []byte(certChain)
<mask> for {
<mask> var decoded *pem.Block
<mask> decoded, pemblock = pem.Decode(pemblock)
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove pemblock := []byte(certChain)
</s> add var certs []*pem.Block
pemblock := certChain </s> remove func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
log.Tracef("TLS: got certificate: %d bytes", len(certChain))
</s> add // validateCertChain validates the certificate chain and sets data in status.
// The returned error is also set in status.WarningValidation.
func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove func validatePkey(data *tlsConfigStatus, pkey string) error {
// now do a more extended validation
var key *pem.Block // PEM-encoded certificates
</s> add // parsePEMCerts parses multiple PEM-encoded certificates.
func parsePEMCerts(certs []*pem.Block) (parsedCerts []*x509.Certificate, err error) {
for i, cert := range certs {
var parsed *x509.Certificate
parsed, err = x509.ParseCertificate(cert.Bytes)
if err != nil {
return nil, fmt.Errorf("parsing certificate at index %d: %w", i, err)
} </s> remove // go through all pem blocks, but take first valid pem block and drop the rest
</s> add parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
return nil, errors.Error("empty certificate")
}
return parsedCerts, nil
}
// validatePKey validates the private key and sets data in status. The returned
// error is also set in status.WarningValidation.
func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}()
var key *pem.Block
// Go through all pem blocks, but take first valid pem block and drop the
// rest. </s> remove // parameters are optional. On error, validateCertificates returns a partially
// set object with field WarningValidation containing error description.
func validateCertificates(certChain, pkey, serverName string) tlsConfigStatus {
var data tlsConfigStatus
// check only public certificate separately from the key
if certChain != "" {
if verifyCertChain(&data, certChain, serverName) != nil {
return data
</s> add // parameters are optional. status must not be nil. The returned error is also
// set in status.WarningValidation.
func validateCertificates(
status *tlsConfigStatus,
certChain []byte,
pkey []byte,
serverName string,
) (err error) {
defer func() {
// Capitalize the warning for the UI. Assume that warnings are all
// ASCII-only.
//
// TODO(a.garipov): Figure out a better way to do this. Perhaps a
// custom string or error type.
if w := status.WarningValidation; w != "" {
status.WarningValidation = strings.ToUpper(w[:1]) + w[1:]
}
}()
// Check only the public certificate separately from the key.
if len(certChain) > 0 {
err = validateCertChain(status, certChain, serverName)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
var certs []*pem.Block
pemblock := certChain | <mask>
<mask> // now do a more extended validation
<mask> var certs []*pem.Block // PEM-encoded certificates
<mask>
<mask> pemblock := []byte(certChain)
<mask> for {
<mask> var decoded *pem.Block
<mask> decoded, pemblock = pem.Decode(pemblock)
<mask> if decoded == nil {
<mask> break
</s> Pull request: 4925-refactor-tls-vol-2
Updates #4925.
Squashed commit of the following:
commit 4b221936ea6c2a244c404e95fa2a033571e07168
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Oct 14 19:03:42 2022 +0300
all: refactor tls </s> remove // now do a more extended validation
var certs []*pem.Block // PEM-encoded certificates
</s> add log.Debug("tls: got certificate chain: %d bytes", len(certChain)) </s> remove // go through all pem blocks, but take first valid pem block and drop the rest
</s> add parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
return nil, errors.Error("empty certificate")
}
return parsedCerts, nil
}
// validatePKey validates the private key and sets data in status. The returned
// error is also set in status.WarningValidation.
func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}()
var key *pem.Block
// Go through all pem blocks, but take first valid pem block and drop the
// rest. </s> remove func validatePkey(data *tlsConfigStatus, pkey string) error {
// now do a more extended validation
var key *pem.Block // PEM-encoded certificates
</s> add // parsePEMCerts parses multiple PEM-encoded certificates.
func parsePEMCerts(certs []*pem.Block) (parsedCerts []*x509.Certificate, err error) {
for i, cert := range certs {
var parsed *x509.Certificate
parsed, err = x509.ParseCertificate(cert.Bytes)
if err != nil {
return nil, fmt.Errorf("parsing certificate at index %d: %w", i, err)
} </s> remove func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
log.Tracef("TLS: got certificate: %d bytes", len(certChain))
</s> add // validateCertChain validates the certificate chain and sets data in status.
// The returned error is also set in status.WarningValidation.
func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) {
defer func() {
if err != nil {
status.WarningValidation = err.Error()
}
}() </s> remove var parsedCerts []*x509.Certificate
for _, cert := range certs {
parsed, err := x509.ParseCertificate(cert.Bytes)
if err != nil {
data.WarningValidation = fmt.Sprintf("Failed to parse certificate: %s", err)
return errors.Error(data.WarningValidation)
}
parsedCerts = append(parsedCerts, parsed)
}
if len(parsedCerts) == 0 {
data.WarningValidation = "You have specified an empty certificate"
return errors.Error(data.WarningValidation)
</s> add parsedCerts, err := parsePEMCerts(certs)
if err != nil {
return err | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/fee81b31eca6b1593aad6fe2c2780b0531998dec | internal/home/tls.go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.