]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - tls/dane.go
Unify copyright comment format
[tofuproxy.git] / tls / dane.go
index ba6e7d059422718af4c74e934df409940c9afc43..55ae326ef6e1d04f5d90060bce0ddeabac5323d2 100644 (file)
@@ -1,20 +1,18 @@
-/*
-tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
-             manager, WARC/geminispace browser
-Copyright (C) 2021-2022 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+//              manager, WARC/geminispace browser
+// Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package tofuproxy
 
@@ -25,7 +23,6 @@ import (
        "encoding/hex"
        "fmt"
        "log"
-       "strings"
 
        "github.com/miekg/dns"
 )
@@ -36,12 +33,13 @@ func DANE(addr string, cert *x509.Certificate) (bool, bool) {
        if DNSSrv == "" {
                return false, false
        }
-       host := addr
-       port := "443"
-       cols := strings.Split(addr, ":")
-       if len(cols) > 1 {
-               host = cols[0]
-               port = cols[1]
+       host, port, err := SplitHostPort(addr)
+       if err != nil {
+               log.Printf("can not split host+port: %s: %+v\n", addr, err)
+               return false, false
+       }
+       if port == "" {
+               port = "443"
        }
        m := new(dns.Msg)
        m.SetQuestion(dns.Fqdn(fmt.Sprintf("_%s._tcp.%s", port, host)), dns.TypeTLSA)