From: Sergey Matveev Date: Sat, 12 Aug 2023 12:10:36 +0000 (+0300) Subject: Lowercase domain names X-Git-Tag: v0.4.0^0 X-Git-Url: http://www.git.stargrave.org/?p=tofuproxy.git;a=commitdiff_plain;h=b11ace4832d2318235cdb1f836bb3677f6e52a20 Lowercase domain names --- diff --git a/tls/dial.go b/tls/dial.go index 2f1c8b6..172e3fc 100644 --- a/tls/dial.go +++ b/tls/dial.go @@ -33,6 +33,7 @@ var sessionCache = tls.NewLRUClientSessionCache(1024) func DialTLS(ctx context.Context, network, addr string) (net.Conn, error) { host, _, _ := SplitHostPort(addr) + host = toLowerCaseASCII(host) ccg := ClientCertificateGetter{host: host} cfg := tls.Config{ VerifyPeerCertificate: func( diff --git a/tls/tolower.go b/tls/tolower.go new file mode 100644 index 0000000..321441e --- /dev/null +++ b/tls/tolower.go @@ -0,0 +1,28 @@ +package tofuproxy + +import "unicode/utf8" + +// Copy-pasted from crypto/x509, as it is not public. +func toLowerCaseASCII(in string) string { + isAlreadyLowerCase := true + for _, c := range in { + if c == utf8.RuneError { + isAlreadyLowerCase = false + break + } + if 'A' <= c && c <= 'Z' { + isAlreadyLowerCase = false + break + } + } + if isAlreadyLowerCase { + return in + } + out := []byte(in) + for i, c := range out { + if 'A' <= c && c <= 'Z' { + out[i] += 'a' - 'A' + } + } + return string(out) +} diff --git a/version.go b/version.go index a36c72a..732fa04 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package tofuproxy -const Version = "0.3.0" +const Version = "0.4.0"