mirror of
https://github.com/safing/portmaster
synced 2025-09-04 19:49:15 +00:00
Merge branch 'develop' of github.com:vlabo/portmaster into develop
This commit is contained in:
commit
4a7ab13bf5
1 changed files with 47 additions and 23 deletions
|
@ -2,8 +2,13 @@ package resolver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -40,7 +45,7 @@ func (pr *PlainResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
|
||||||
// create query
|
// create query
|
||||||
dnsQuery := new(dns.Msg)
|
dnsQuery := new(dns.Msg)
|
||||||
dnsQuery.SetQuestion(q.FQDN, uint16(q.QType))
|
dnsQuery.SetQuestion(q.FQDN, uint16(q.QType))
|
||||||
|
var reply *dns.Msg
|
||||||
// get timeout from context and config
|
// get timeout from context and config
|
||||||
var timeout time.Duration
|
var timeout time.Duration
|
||||||
if deadline, ok := ctx.Deadline(); !ok {
|
if deadline, ok := ctx.Deadline(); !ok {
|
||||||
|
@ -52,6 +57,24 @@ func (pr *PlainResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
|
||||||
timeout = defaultRequestTimeout
|
timeout = defaultRequestTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(pr.resolver.ServerAddress, "https:") {
|
||||||
|
buf, err := dnsQuery.Pack()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
b64dns := base64.RawStdEncoding.EncodeToString(buf)
|
||||||
|
url := fmt.Sprintf("%s/dns-query?dns=%s", pr.resolver.ServerAddress, b64dns)
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
reply := new(dns.Msg)
|
||||||
|
reply.Unpack(body)
|
||||||
|
} else {
|
||||||
// create client
|
// create client
|
||||||
dnsClient := &dns.Client{
|
dnsClient := &dns.Client{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
|
@ -79,6 +102,7 @@ func (pr *PlainResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
|
||||||
if pr.resolver.IsBlockedUpstream(reply) {
|
if pr.resolver.IsBlockedUpstream(reply) {
|
||||||
return nil, &BlockedUpstreamError{pr.resolver.Info.DescriptiveName()}
|
return nil, &BlockedUpstreamError{pr.resolver.Info.DescriptiveName()}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// hint network environment at successful connection
|
// hint network environment at successful connection
|
||||||
netenv.ReportSuccessfulConnection()
|
netenv.ReportSuccessfulConnection()
|
||||||
|
|
Loading…
Add table
Reference in a new issue