From ce5e0c803153c47f8cafe2d549e7a97d1d948c29 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 9 Jan 2018 18:37:37 +0100 Subject: [PATCH] Try to retrieve the certificates using UDP before TCP --- dnscrypt-proxy/certs.go | 4 ++-- dnscrypt-proxy/serversInfo.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dnscrypt-proxy/certs.go b/dnscrypt-proxy/certs.go index 2a78681d..16ef8c6b 100644 --- a/dnscrypt-proxy/certs.go +++ b/dnscrypt-proxy/certs.go @@ -20,7 +20,7 @@ type CertInfo struct { CryptoConstruction CryptoConstruction } -func FetchCurrentCert(proxy *Proxy, pk ed25519.PublicKey, serverAddress string, providerName string) (CertInfo, error) { +func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAddress string, providerName string) (CertInfo, error) { if len(pk) != ed25519.PublicKeySize { return CertInfo{}, errors.New("Invalid public key length") } @@ -29,7 +29,7 @@ func FetchCurrentCert(proxy *Proxy, pk ed25519.PublicKey, serverAddress string, } query := new(dns.Msg) query.SetQuestion(providerName, dns.TypeTXT) - client := dns.Client{Net: "tcp", UDPSize: 1252} + client := dns.Client{Net: proto, UDPSize: uint16(MaxDNSUDPPacketSize)} in, _, err := client.Exchange(query, serverAddress) if err != nil { log.Fatal(err) diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index 66700e3f..b3089ba7 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -89,9 +89,12 @@ func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp if err != nil || len(serverPk) != ed25519.PublicKeySize { log.Fatal("Invalid public key") } - certInfo, err := FetchCurrentCert(proxy, serverPk, stamp.serverAddrStr, stamp.providerName) + certInfo, err := FetchCurrentCert(proxy, "udp", serverPk, stamp.serverAddrStr, stamp.providerName) if err != nil { - return ServerInfo{}, err + certInfo, err = FetchCurrentCert(proxy, "tcp", serverPk, stamp.serverAddrStr, stamp.providerName) + if err != nil { + return ServerInfo{}, err + } } remoteUDPAddr, err := net.ResolveUDPAddr("udp", stamp.serverAddrStr) if err != nil {