mirror of
https://github.com/caddyserver/caddy.git
synced 2025-04-25 06:14:04 +08:00
caddytls: Fix sni_regexp matcher
This commit is contained in:
parent
8d748bee71
commit
5b13c65a82
@ -15,6 +15,7 @@
|
||||
package caddytls
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
@ -224,13 +225,26 @@ func (MatchServerNameRE) CaddyModule() caddy.ModuleInfo {
|
||||
|
||||
// Match matches hello based on SNI using a regular expression.
|
||||
func (m MatchServerNameRE) Match(hello *tls.ClientHelloInfo) bool {
|
||||
repl := caddy.NewReplacer()
|
||||
var repl *caddy.Replacer
|
||||
// caddytls.TestServerNameMatcher calls this function without any context
|
||||
if ctx := hello.Context(); ctx != nil {
|
||||
// In some situations the existing context may have no replacer
|
||||
if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil {
|
||||
repl = replAny.(*caddy.Replacer)
|
||||
}
|
||||
} else if mayHaveContext, ok := hello.Conn.(interface{ GetContext() context.Context }); ok {
|
||||
// layer4.Connection implements GetContext() to pass its context here,
|
||||
// since hello.Context() returns nil
|
||||
if ctx = mayHaveContext.GetContext(); ctx != nil {
|
||||
// In some situations the existing context may have no replacer
|
||||
if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil {
|
||||
repl = replAny.(*caddy.Replacer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if repl == nil {
|
||||
repl = caddy.NewReplacer()
|
||||
}
|
||||
|
||||
return m.MatchRegexp.Match(hello.ServerName, repl)
|
||||
|
Loading…
x
Reference in New Issue
Block a user