mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 15:53:17 +00:00
caddytls: Match automation policies by wildcard subjects too
https://caddy.community/t/wildcard-snis-not-being-matched/7271/24?u=matt Also use new CertMagic function for matching wildcard names
This commit is contained in:
parent
5c55e5d53f
commit
c87f82f0ce
4 changed files with 12 additions and 26 deletions
|
@ -16,9 +16,9 @@ package caddytls
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"strings"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/certmagic"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -41,23 +41,9 @@ func (MatchServerName) CaddyModule() caddy.ModuleInfo {
|
|||
// Match matches hello based on SNI.
|
||||
func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
|
||||
for _, name := range m {
|
||||
if hello.ServerName == name {
|
||||
if certmagic.MatchWildcard(hello.ServerName, name) {
|
||||
return true
|
||||
}
|
||||
|
||||
// check for wildcard match on this name, but only
|
||||
// bother if there is even a wildcard character
|
||||
if !strings.Contains(name, "*") {
|
||||
continue
|
||||
}
|
||||
labels := strings.Split(hello.ServerName, ".")
|
||||
for i := range labels {
|
||||
labels[i] = "*"
|
||||
candidate := strings.Join(labels, ".")
|
||||
if candidate == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue