Skip to content

Commit

Permalink
remove more hostname functions
Browse files Browse the repository at this point in the history
  • Loading branch information
phbnf committed Feb 25, 2025
1 parent be9db26 commit f0c8bd0
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions internal/x509util/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"fmt"
"strings"
"time"
"unicode/utf8"
)

type InvalidReason int
Expand Down Expand Up @@ -417,62 +416,3 @@ func buildChains(c *x509.Certificate, currentChain []*x509.Certificate, sigCheck

return
}

func matchHostnames(pattern, host string) bool {
pattern = toLowerCaseASCII(pattern)
host = toLowerCaseASCII(strings.TrimSuffix(host, "."))

if len(pattern) == 0 || len(host) == 0 {
return false
}

patternParts := strings.Split(pattern, ".")
hostParts := strings.Split(host, ".")

if len(patternParts) != len(hostParts) {
return false
}

for i, patternPart := range patternParts {
if i == 0 && patternPart == "*" {
continue
}
if patternPart != hostParts[i] {
return false
}
}

return true
}

// toLowerCaseASCII returns a lower-case version of in. See RFC 6125 6.4.1. We use
// an explicitly ASCII function to avoid any sharp corners resulting from
// performing Unicode operations on DNS labels.
func toLowerCaseASCII(in string) string {
// If the string is already lower-case then there's nothing to do.
isAlreadyLowerCase := true
for _, c := range in {
if c == utf8.RuneError {
// If we get a UTF-8 error then there might be
// upper-case ASCII bytes in the invalid sequence.
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)
}

0 comments on commit f0c8bd0

Please sign in to comment.