@marcel91200 / caddy Mirror · read-only / commits / c87f82f0
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

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

Matthew Holt committed Mar 26, 2020 at 14:01 UTC c87f82f0ce58ec714b3e13fbe69c322a0d612c67
4 files changed +12 -26
go.mod
+3 -3
@@ -5,10 +5,10 @@ go 1.14
5 require (
6 github.com/Masterminds/sprig/v3 v3.0.2
7 github.com/alecthomas/chroma v0.7.2-0.20200305040604-4f3623dce67a
8 - github.com/caddyserver/certmagic v0.10.4
8 + github.com/caddyserver/certmagic v0.10.5
9 github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
10 github.com/go-acme/lego/v3 v3.5.0
11 - github.com/google/cel-go v0.4.0
11 + github.com/google/cel-go v0.4.1
12 github.com/jsternberg/zap-logfmt v1.2.0
13 github.com/klauspost/compress v1.10.3
14 github.com/klauspost/cpuid v1.2.3
@@ -21,7 +21,7 @@ require (
21 github.com/smallstep/cli v0.14.0-rc.3
22 github.com/smallstep/truststore v0.9.4
23 github.com/vulcand/oxy v1.1.0
24 - github.com/yuin/goldmark v1.1.25
24 + github.com/yuin/goldmark v1.1.26
25 github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
26 go.uber.org/zap v1.14.1
27 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
go.sum
+6 -6
@@ -120,8 +120,8 @@ github.com/bombsimon/wsl/v2 v2.0.0/go.mod h1:mf25kr/SqFEPhhcxW1+7pxzGlW+hIl/hYTK
120 github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
121 github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
122 github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
123 -github.com/caddyserver/certmagic v0.10.4 h1:3jRzfMnOVsmGo2XYZ7mkksgoB14my1CTmqc1Apx7qsg=
124 -github.com/caddyserver/certmagic v0.10.4/go.mod h1:Y8jcUBctgk/IhpAzlHKfimZNyXCkfGgRTC0orl8gROQ=
123 +github.com/caddyserver/certmagic v0.10.5 h1:Dg4ipO1y23rWvFmiiRqhtUTh5Hy7PmfoFvPfDpnE8Z8=
124 +github.com/caddyserver/certmagic v0.10.5/go.mod h1:Y8jcUBctgk/IhpAzlHKfimZNyXCkfGgRTC0orl8gROQ=
125 github.com/cenkalti/backoff/v4 v4.0.0 h1:6VeaLF9aI+MAUQ95106HwWzYZgJJpZ4stumjj6RFYAU=
126 github.com/cenkalti/backoff/v4 v4.0.0/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
127 github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -298,8 +298,8 @@ github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039/go.mod h1:qOQCunE
298 github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ=
299 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
300 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
301 -github.com/google/cel-go v0.4.0 h1:9i5p9ms/kph/Lau3qL7DtnF49g3+/iBoi3KrMdnPTOU=
302 -github.com/google/cel-go v0.4.0/go.mod h1:F0UncVAXNlNjl/4C8hqGdoV6APmuFpetoMJSLIQLBPU=
301 +github.com/google/cel-go v0.4.1 h1:2kqc5arTucvtLJzXVUbmiUh7n2xjizwZijPrpEsagAE=
302 +github.com/google/cel-go v0.4.1/go.mod h1:F0UncVAXNlNjl/4C8hqGdoV6APmuFpetoMJSLIQLBPU=
303 github.com/google/cel-spec v0.3.0/go.mod h1:MjQm800JAGhOZXI7vatnVpmIaFTR6L8FHcKk+piiKpI=
304 github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg=
305 github.com/google/certificate-transparency-go v1.1.0/go.mod h1:i+Q7XY+ArBveOUT36jiHGfuSK1fHICIg6sUkRxPAbCs=
@@ -758,8 +758,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ
758 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
759 github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
760 github.com/yuin/goldmark v1.1.22/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
761 -github.com/yuin/goldmark v1.1.25 h1:isv+Q6HQAmmL2Ofcmg8QauBmDPlUUnSoNhEcC940Rds=
762 -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
761 +github.com/yuin/goldmark v1.1.26 h1:81MfIApzizD8JqKIjnWy2Vxj7GgmQUrJlh/jYWH8yGk=
762 +github.com/yuin/goldmark v1.1.26/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
763 github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691 h1:VWSxtAiQNh3zgHJpdpkpVYjTPqRE3P6UZCOPa1nRDio=
764 github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691/go.mod h1:YLF3kDffRfUH/bTxOxHhV6lxwIB3Vfj91rEwNMS9MXo=
765 go.etcd.io/bbolt v1.3.2 h1:Z/90sZLPOeCy2PwprqkFa25PdkusRzaj9P8zm/KNyvk=
modules/caddytls/matchers.go
+2 -16
@@ -16,9 +16,9 @@ package caddytls
16
17 import (
18 "crypto/tls"
19 - "strings"
19
20 "github.com/caddyserver/caddy/v2"
21 + "github.com/caddyserver/certmagic"
22 )
23
24 func init() {
@@ -41,23 +41,9 @@ func (MatchServerName) CaddyModule() caddy.ModuleInfo {
41 // Match matches hello based on SNI.
42 func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
43 for _, name := range m {
44 - if hello.ServerName == name {
44 + if certmagic.MatchWildcard(hello.ServerName, name) {
45 return true
46 }
47 -
48 - // check for wildcard match on this name, but only
49 - // bother if there is even a wildcard character
50 - if !strings.Contains(name, "*") {
51 - continue
52 - }
53 - labels := strings.Split(hello.ServerName, ".")
54 - for i := range labels {
55 - labels[i] = "*"
56 - candidate := strings.Join(labels, ".")
57 - if candidate == name {
58 - return true
59 - }
60 - }
47 }
48 return false
49 }
modules/caddytls/tls.go
+1 -1
@@ -329,7 +329,7 @@ func (t *TLS) getAutomationPolicyForName(name string) *AutomationPolicy {
329 return ap // no host filter is an automatic match
330 }
331 for _, h := range ap.Subjects {
332 - if h == name {
332 + if certmagic.MatchWildcard(name, h) {
333 return ap
334 }
335 }