Match matches hello based on SNI using a regular expression.
(hello *tls.ClientHelloInfo)
| 277 | |
| 278 | // Match matches hello based on SNI using a regular expression. |
| 279 | func (m MatchServerNameRE) Match(hello *tls.ClientHelloInfo) bool { |
| 280 | // Note: caddytls.TestServerNameMatcher calls this function without any context |
| 281 | ctx := hello.Context() |
| 282 | if ctx == nil { |
| 283 | // layer4.Connection implements GetContext() to pass its context here, |
| 284 | // since hello.Context() returns nil |
| 285 | if mayHaveContext, ok := hello.Conn.(interface{ GetContext() context.Context }); ok { |
| 286 | ctx = mayHaveContext.GetContext() |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | var repl *caddy.Replacer |
| 291 | if ctx != nil { |
| 292 | // In some situations the existing context may have no replacer |
| 293 | if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil { |
| 294 | repl = replAny.(*caddy.Replacer) |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if repl == nil { |
| 299 | repl = caddy.NewReplacer() |
| 300 | } |
| 301 | |
| 302 | return m.MatchRegexp.Match(hello.ServerName, repl) |
| 303 | } |
| 304 | |
| 305 | // MatchRemoteIP matches based on the remote IP of the |
| 306 | // connection. Specific IPs or CIDR ranges can be specified. |