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: Configurable OCSP stapling; global option (closes #3714)
Allows user to disable OCSP stapling (including support in the Caddyfile via the ocsp_stapling global option) or overriding responder URLs. Useful in environments where responders are not reachable due to firewalls.
Matthew Holt committed
Jan 7, 2021 at 15:52 UTC
09432ba64d3931206181c895c845116db8d7e877
5 files changed
+46
-7
caddyconfig/httpcaddyfile/options.go
+15
@@ -43,6 +43,7 @@ func init() {
43
RegisterGlobalOption("key_type", parseOptSingleString)
44
RegisterGlobalOption("auto_https", parseOptAutoHTTPS)
45
RegisterGlobalOption("servers", parseServerOptions)
46
+ RegisterGlobalOption("ocsp_stapling", parseOCSPStaplingOptions)
47
}
48
49
func parseOptTrue(d *caddyfile.Dispenser, _ interface{}) (interface{}, error) { return true, nil }
@@ -370,3 +371,17 @@ func parseOptAutoHTTPS(d *caddyfile.Dispenser, _ interface{}) (interface{}, erro
371
func parseServerOptions(d *caddyfile.Dispenser, _ interface{}) (interface{}, error) {
372
return unmarshalCaddyfileServerOptions(d)
373
}
374
+
375
+func parseOCSPStaplingOptions(d *caddyfile.Dispenser, _ interface{}) (interface{}, error) {
376
+ d.Next() // consume option name
377
+ var val string
378
+ if !d.AllArgs(&val) {
379
+ return nil, d.ArgErr()
380
+ }
381
+ if val != "off" {
382
+ return nil, d.Errf("invalid argument '%s'", val)
383
+ }
384
+ return certmagic.OCSPConfig{
385
+ DisableStapling: val == "off",
386
+ }, nil
387
+}
caddyconfig/httpcaddyfile/tlsapp.go
+8
-1
@@ -417,8 +417,9 @@ func newBaseAutomationPolicy(options map[string]interface{}, warnings []caddycon
417
issuers, hasIssuers := options["cert_issuer"]
418
_, hasLocalCerts := options["local_certs"]
419
keyType, hasKeyType := options["key_type"]
420
+ ocspStapling, hasOCSPStapling := options["ocsp_stapling"]
421
421
- hasGlobalAutomationOpts := hasIssuers || hasLocalCerts || hasKeyType
422
+ hasGlobalAutomationOpts := hasIssuers || hasLocalCerts || hasKeyType || hasOCSPStapling
423
424
// if there are no global options related to automation policies
425
// set, then we can just return right away
@@ -444,6 +445,12 @@ func newBaseAutomationPolicy(options map[string]interface{}, warnings []caddycon
445
ap.Issuers = []certmagic.Issuer{new(caddytls.InternalIssuer)}
446
}
447
448
+ if hasOCSPStapling {
449
+ ocspConfig := ocspStapling.(certmagic.OCSPConfig)
450
+ ap.DisableOCSPStapling = ocspConfig.DisableStapling
451
+ ap.OCSPOverrides = ocspConfig.ResponderOverrides
452
+ }
453
+
454
return ap, nil
455
}
456
go.mod
+1
-1
@@ -6,7 +6,7 @@ require (
6
github.com/Masterminds/sprig/v3 v3.1.0
7
github.com/alecthomas/chroma v0.8.2
8
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a
9
- github.com/caddyserver/certmagic v0.12.1-0.20210104224249-7891c830824b
9
+ github.com/caddyserver/certmagic v0.12.1-0.20210107224522-725b69d53d57
10
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
11
github.com/go-chi/chi v4.1.2+incompatible
12
github.com/google/cel-go v0.6.0
go.sum
+2
-2
@@ -99,8 +99,8 @@ github.com/bombsimon/wsl/v2 v2.0.0/go.mod h1:mf25kr/SqFEPhhcxW1+7pxzGlW+hIl/hYTK
99
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
100
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
101
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
102
-github.com/caddyserver/certmagic v0.12.1-0.20210104224249-7891c830824b h1:3sAfeMhRiv0CVLWvM+bTSVkZIf1KupsMjglpaOCAQjE=
103
-github.com/caddyserver/certmagic v0.12.1-0.20210104224249-7891c830824b/go.mod h1:yHMCSjG2eOFdI/Jx0+CCzr2DLw+UQu42KbaOVBx7LwA=
102
+github.com/caddyserver/certmagic v0.12.1-0.20210107224522-725b69d53d57 h1:eslWGgoQlVAzOGMUfK3ncoHnONjCUVOPTGRD9JG3gAY=
103
+github.com/caddyserver/certmagic v0.12.1-0.20210107224522-725b69d53d57/go.mod h1:yHMCSjG2eOFdI/Jx0+CCzr2DLw+UQu42KbaOVBx7LwA=
104
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
105
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
106
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
modules/caddytls/automation.go
+20
-3
@@ -107,6 +107,19 @@ type AutomationPolicy struct {
107
// load.
108
OnDemand bool `json:"on_demand,omitempty"`
109
110
+ // Disables OCSP stapling. Disabling OCSP stapling puts clients at
111
+ // greater risk, reduces their privacy, and usually lowers client
112
+ // performance. It is NOT recommended to disable this unless you
113
+ // are able to justify the costs.
114
+ // EXPERIMENTAL. Subject to change.
115
+ DisableOCSPStapling bool `json:"disable_ocsp_stapling,omitempty"`
116
+
117
+ // Overrides the URLs of OCSP responders embedded in certificates.
118
+ // Each key is a OCSP server URL to override, and its value is the
119
+ // replacement. An empty value will disable querying of that server.
120
+ // EXPERIMENTAL. Subject to change.
121
+ OCSPOverrides map[string]string `json:"ocsp_overrides,omitempty"`
122
+
123
// Issuers stores the decoded issuer parameters. This is only
124
// used to populate an underlying certmagic.Config's Issuers
125
// field; it is not referenced thereafter.
@@ -205,9 +218,13 @@ func (ap *AutomationPolicy) Provision(tlsApp *TLS) error {
218
RenewalWindowRatio: ap.RenewalWindowRatio,
219
KeySource: keySource,
220
OnDemand: ond,
208
- Storage: storage,
209
- Issuers: issuers,
210
- Logger: tlsApp.logger,
221
+ OCSP: certmagic.OCSPConfig{
222
+ DisableStapling: ap.DisableOCSPStapling,
223
+ ResponderOverrides: ap.OCSPOverrides,
224
+ },
225
+ Storage: storage,
226
+ Issuers: issuers,
227
+ Logger: tlsApp.logger,
228
}
229
ap.magic = certmagic.New(tlsApp.certCache, template)
230