Match matches hello based on SNI.
(hello *tls.ClientHelloInfo)
| 57 | |
| 58 | // Match matches hello based on SNI. |
| 59 | func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool { |
| 60 | var repl *caddy.Replacer |
| 61 | // caddytls.TestServerNameMatcher calls this function without any context |
| 62 | if ctx := hello.Context(); ctx != nil { |
| 63 | // In some situations the existing context may have no replacer |
| 64 | if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil { |
| 65 | repl = replAny.(*caddy.Replacer) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if repl == nil { |
| 70 | repl = caddy.NewReplacer() |
| 71 | } |
| 72 | |
| 73 | serverName := asciiServerNameForMatch(hello.ServerName) |
| 74 | for _, name := range m { |
| 75 | rs := asciiServerNameForMatch(repl.ReplaceAll(name, "")) |
| 76 | if certmagic.MatchWildcard(serverName, rs) { |
| 77 | return true |
| 78 | } |
| 79 | } |
| 80 | return false |
| 81 | } |
| 82 | |
| 83 | func asciiServerNameForMatch(name string) string { |
| 84 | if name == "" { |
nothing calls this directly
no test coverage detected