@marcel91200 / caddy Mirror · read-only / commits / 66863aad
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: Add support for ZeroSSL; add Caddyfile support for issuers (#3633)

* caddytls: Add support for ZeroSSL; add Caddyfile support for issuers Configuring issuers explicitly in a Caddyfile is not easily compatible with existing ACME-specific parameters such as email or acme_ca which infer the kind of issuer it creates (this is complicated now because the ZeroSSL issuer wraps the ACME issuer)... oh well, we can revisit that later if we need to. New Caddyfile global option: { cert_issuer <name> ... } Or, alternatively, as a tls subdirective: tls { issuer <name> ... } For example, to use ZeroSSL with an API key: { cert_issuser zerossl API_KEY } For now, that still uses ZeroSSL's ACME endpoint; it fetches EAB credentials for you. You can also provide the EAB credentials directly just like any other ACME endpoint: { cert_issuer acme { eab KEY_ID MAC_KEY } } All these examples use the new global option (or tls subdirective). You can still use traditional/existing options with ZeroSSL, since it's just another ACME endpoint: { acme_ca https://acme.zerossl.com/v2/DV90 acme_eab KEY_ID MAC_KEY } That's all there is to it. You just can't mix-and-match acme_* options with cert_issuer, because it becomes confusing/ambiguous/complicated to merge the settings. * Fix broken test This test was asserting buggy behavior, oops - glad this branch both discovers and fixes the bug at the same time! * Fix broken test (post-merge) * Update modules/caddytls/acmeissuer.go Fix godoc comment Co-authored-by: Francis Lavoie <lavofr@gmail.com> * Add support for ZeroSSL's EAB-by-email endpoint Also transform the ACMEIssuer into ZeroSSLIssuer implicitly if set to the ZeroSSL endpoint without EAB (the ZeroSSLIssuer is needed to generate EAB if not already provided); this is now possible with either an API key or an email address. * go.mod: Use latest certmagic, acmez, and x/net * Wrap underlying logic rather than repeating it Oops, duh * Form-encode email info into request body for EAB endpoint Co-authored-by: Francis Lavoie <lavofr@gmail.com>

Matt Holt committed Aug 11, 2020 at 08:58 UTC 66863aad3beb480a26664c77b73eb2ff7fcab754
12 files changed +579 -96
caddyconfig/httpcaddyfile/builtins.go
+44 -8
@@ -29,6 +29,7 @@ import (
29 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
30 "github.com/caddyserver/caddy/v2/modules/caddyhttp"
31 "github.com/caddyserver/caddy/v2/modules/caddytls"
32 + "github.com/caddyserver/certmagic"
33 "github.com/mholt/acmez/acme"
34 "go.uber.org/zap/zapcore"
35 )
@@ -76,6 +77,7 @@ func parseBind(h Helper) ([]ConfigValue, error) {
77 // ca_root <pem_file>
78 // dns <provider_name>
79 // on_demand
80 +// issuer <module_name> ...
81 // }
82 //
83 func parseTLS(h Helper) ([]ConfigValue, error) {
@@ -85,6 +87,7 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
87 var certSelector caddytls.CustomCertSelectionPolicy
88 var acmeIssuer *caddytls.ACMEIssuer
89 var internalIssuer *caddytls.InternalIssuer
90 + var issuer certmagic.Issuer
91 var onDemand bool
92
93 for h.Next() {
@@ -276,6 +279,28 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
279 MACKey: arg[1],
280 }
281
282 + case "issuer":
283 + if !h.NextArg() {
284 + return nil, h.ArgErr()
285 + }
286 + modName := h.Val()
287 + mod, err := caddy.GetModule("tls.issuance." + modName)
288 + if err != nil {
289 + return nil, h.Errf("getting issuer module '%s': %v", modName, err)
290 + }
291 + unm, ok := mod.New().(caddyfile.Unmarshaler)
292 + if !ok {
293 + return nil, h.Errf("issuer module '%s' is not a Caddyfile unmarshaler", mod.ID)
294 + }
295 + err = unm.UnmarshalCaddyfile(h.NewFromNextSegment())
296 + if err != nil {
297 + return nil, err
298 + }
299 + issuer, ok = unm.(certmagic.Issuer)
300 + if !ok {
301 + return nil, h.Errf("module %s is not a certmagic.Issuer", mod.ID)
302 + }
303 +
304 case "dns":
305 if !h.NextArg() {
306 return nil, h.ArgErr()
@@ -350,7 +375,24 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
375 // the logic to support this would be complex
376 return nil, h.Err("cannot use both ACME and internal issuers in same server block")
377 }
353 - if acmeIssuer != nil {
378 + if issuer != nil && (acmeIssuer != nil || internalIssuer != nil) {
379 + // similarly, the logic to support this would be complex
380 + return nil, h.Err("when defining an issuer, all its config must be in its block, rather than from separate tls subdirectives")
381 + }
382 + switch {
383 + case issuer != nil:
384 + configVals = append(configVals, ConfigValue{
385 + Class: "tls.cert_issuer",
386 + Value: issuer,
387 + })
388 +
389 + case internalIssuer != nil:
390 + configVals = append(configVals, ConfigValue{
391 + Class: "tls.cert_issuer",
392 + Value: internalIssuer,
393 + })
394 +
395 + case acmeIssuer != nil:
396 // fill in global defaults, if configured
397 if email := h.Option("email"); email != nil && acmeIssuer.Email == "" {
398 acmeIssuer.Email = email.(string)
@@ -361,15 +403,9 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
403 if caPemFile := h.Option("acme_ca_root"); caPemFile != nil {
404 acmeIssuer.TrustedRootsPEMFiles = append(acmeIssuer.TrustedRootsPEMFiles, caPemFile.(string))
405 }
364 -
406 configVals = append(configVals, ConfigValue{
407 Class: "tls.cert_issuer",
367 - Value: acmeIssuer,
368 - })
369 - } else if internalIssuer != nil {
370 - configVals = append(configVals, ConfigValue{
371 - Class: "tls.cert_issuer",
372 - Value: internalIssuer,
408 + Value: disambiguateACMEIssuer(acmeIssuer),
409 })
410 }
411
caddyconfig/httpcaddyfile/options.go
+29
@@ -20,6 +20,7 @@ import (
20 "github.com/caddyserver/caddy/v2"
21 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
22 "github.com/caddyserver/caddy/v2/modules/caddytls"
23 + "github.com/caddyserver/certmagic"
24 "github.com/mholt/acmez/acme"
25 )
26
@@ -35,6 +36,7 @@ func init() {
36 RegisterGlobalOption("acme_ca_root", parseOptSingleString)
37 RegisterGlobalOption("acme_dns", parseOptSingleString)
38 RegisterGlobalOption("acme_eab", parseOptACMEEAB)
39 + RegisterGlobalOption("cert_issuer", parseOptCertIssuer)
40 RegisterGlobalOption("email", parseOptSingleString)
41 RegisterGlobalOption("admin", parseOptAdmin)
42 RegisterGlobalOption("on_demand_tls", parseOptOnDemand)
@@ -210,6 +212,33 @@ func parseOptACMEEAB(d *caddyfile.Dispenser) (interface{}, error) {
212 return eab, nil
213 }
214
215 +func parseOptCertIssuer(d *caddyfile.Dispenser) (interface{}, error) {
216 + if !d.Next() { // consume option name
217 + return nil, d.ArgErr()
218 + }
219 + if !d.Next() { // get issuer module name
220 + return nil, d.ArgErr()
221 + }
222 + modName := d.Val()
223 + mod, err := caddy.GetModule("tls.issuance." + modName)
224 + if err != nil {
225 + return nil, d.Errf("getting issuer module '%s': %v", modName, err)
226 + }
227 + unm, ok := mod.New().(caddyfile.Unmarshaler)
228 + if !ok {
229 + return nil, d.Errf("issuer module '%s' is not a Caddyfile unmarshaler", mod.ID)
230 + }
231 + err = unm.UnmarshalCaddyfile(d.NewFromNextSegment())
232 + if err != nil {
233 + return nil, err
234 + }
235 + iss, ok := unm.(certmagic.Issuer)
236 + if !ok {
237 + return nil, d.Errf("module %s is not a certmagic.Issuer", mod.ID)
238 + }
239 + return iss, nil
240 +}
241 +
242 func parseOptSingleString(d *caddyfile.Dispenser) (interface{}, error) {
243 d.Next() // consume parameter name
244 if !d.Next() {
caddyconfig/httpcaddyfile/tlsapp.go
+32 -8
@@ -21,6 +21,7 @@ import (
21 "reflect"
22 "sort"
23 "strconv"
24 + "strings"
25
26 "github.com/caddyserver/caddy/v2"
27 "github.com/caddyserver/caddy/v2/caddyconfig"
@@ -135,8 +136,11 @@ func (st ServerType) buildTLSApp(
136 // issuer, skip, since we intend to adjust only ACME issuers
137 var acmeIssuer *caddytls.ACMEIssuer
138 if ap.Issuer != nil {
138 - var ok bool
139 - if acmeIssuer, ok = ap.Issuer.(*caddytls.ACMEIssuer); !ok {
139 + // ensure we include any issuer that embeds/wraps an underlying ACME issuer
140 + type acmeCapable interface{ GetACMEIssuer() *caddytls.ACMEIssuer }
141 + if acmeWrapper, ok := ap.Issuer.(acmeCapable); ok {
142 + acmeIssuer = acmeWrapper.GetACMEIssuer()
143 + } else {
144 break
145 }
146 }
@@ -348,6 +352,8 @@ func (st ServerType) buildTLSApp(
352 // returned if there are no default/global options. However, if always is
353 // true, a non-nil value will always be returned (unless there is an error).
354 func newBaseAutomationPolicy(options map[string]interface{}, warnings []caddyconfig.Warning, always bool) (*caddytls.AutomationPolicy, error) {
355 + issuer, hasIssuer := options["cert_issuer"]
356 +
357 acmeCA, hasACMECA := options["acme_ca"]
358 acmeCARoot, hasACMECARoot := options["acme_ca_root"]
359 acmeDNS, hasACMEDNS := options["acme_dns"]
@@ -357,7 +363,7 @@ func newBaseAutomationPolicy(options map[string]interface{}, warnings []caddycon
363 localCerts, hasLocalCerts := options["local_certs"]
364 keyType, hasKeyType := options["key_type"]
365
360 - hasGlobalAutomationOpts := hasACMECA || hasACMECARoot || hasACMEDNS || hasACMEEAB || hasEmail || hasLocalCerts || hasKeyType
366 + hasGlobalAutomationOpts := hasIssuer || hasACMECA || hasACMECARoot || hasACMEDNS || hasACMEEAB || hasEmail || hasLocalCerts || hasKeyType
367
368 // if there are no global options related to automation policies
369 // set, then we can just return right away
@@ -369,8 +375,16 @@ func newBaseAutomationPolicy(options map[string]interface{}, warnings []caddycon
375 }
376
377 ap := new(caddytls.AutomationPolicy)
378 + if keyType != nil {
379 + ap.KeyType = keyType.(string)
380 + }
381
373 - if localCerts != nil {
382 + if hasIssuer {
383 + if hasACMECA || hasACMEDNS || hasACMEEAB || hasEmail || hasLocalCerts {
384 + return nil, fmt.Errorf("global options are ambiguous: cert_issuer is confusing when combined with acme_*, email, or local_certs options")
385 + }
386 + ap.Issuer = issuer.(certmagic.Issuer)
387 + } else if localCerts != nil {
388 // internal issuer enabled trumps any ACME configurations; useful in testing
389 ap.Issuer = new(caddytls.InternalIssuer) // we'll encode it later
390 } else {
@@ -402,15 +416,25 @@ func newBaseAutomationPolicy(options map[string]interface{}, warnings []caddycon
416 if acmeEAB != nil {
417 mgr.ExternalAccount = acmeEAB.(*acme.EAB)
418 }
405 - if keyType != nil {
406 - ap.KeyType = keyType.(string)
407 - }
408 - ap.Issuer = mgr // we'll encode it later
419 + ap.Issuer = disambiguateACMEIssuer(mgr) // we'll encode it later
420 }
421
422 return ap, nil
423 }
424
425 +// disambiguateACMEIssuer returns an issuer based on the properties of acmeIssuer.
426 +// If acmeIssuer implicitly configures a certain kind of ACMEIssuer (for example,
427 +// ZeroSSL), the proper wrapper over acmeIssuer will be returned instead.
428 +func disambiguateACMEIssuer(acmeIssuer *caddytls.ACMEIssuer) certmagic.Issuer {
429 + // as a special case, we integrate with ZeroSSL's ACME endpoint if it looks like an
430 + // implicit ZeroSSL configuration (this requires a wrapper type over ACMEIssuer
431 + // because of the EAB generation; if EAB is provided, we can use plain ACMEIssuer)
432 + if strings.Contains(acmeIssuer.CA, "acme.zerossl.com") && acmeIssuer.ExternalAccount == nil {
433 + return &caddytls.ZeroSSLIssuer{ACMEIssuer: acmeIssuer}
434 + }
435 + return acmeIssuer
436 +}
437 +
438 // consolidateAutomationPolicies combines automation policies that are the same,
439 // for a cleaner overall output.
440 func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls.AutomationPolicy {
caddytest/integration/caddyfile_adapt/global_options.txt
+2 -1
@@ -56,7 +56,8 @@
56 {
57 "issuer": {
58 "module": "internal"
59 - }
59 + },
60 + "key_type": "ed25519"
61 }
62 ],
63 "on_demand": {
caddytest/integration/caddyfile_adapt/global_options_admin.txt
+2 -1
@@ -64,7 +64,8 @@
64 {
65 "issuer": {
66 "module": "internal"
67 - }
67 + },
68 + "key_type": "ed25519"
69 }
70 ],
71 "on_demand": {
go.mod
+2 -2
@@ -6,7 +6,7 @@ require (
6 github.com/Masterminds/sprig/v3 v3.1.0
7 github.com/alecthomas/chroma v0.8.0
8 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a
9 - github.com/caddyserver/certmagic v0.11.3-0.20200808143826-2e100d6d0bcf
9 + github.com/caddyserver/certmagic v0.11.3-0.20200810220624-10a8b5c72339
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.5.1
@@ -14,7 +14,7 @@ require (
14 github.com/klauspost/compress v1.10.10
15 github.com/klauspost/cpuid v1.2.5
16 github.com/lucas-clemente/quic-go v0.17.3
17 - github.com/mholt/acmez v0.1.0
17 + github.com/mholt/acmez v0.1.1-0.20200810215816-dbe88fc6cf09
18 github.com/naoina/go-stringutil v0.1.0 // indirect
19 github.com/naoina/toml v0.1.1
20 github.com/smallstep/certificates v0.14.6
go.sum
+4 -4
@@ -86,8 +86,8 @@ github.com/bombsimon/wsl/v2 v2.0.0/go.mod h1:mf25kr/SqFEPhhcxW1+7pxzGlW+hIl/hYTK
86 github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
87 github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
88 github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
89 -github.com/caddyserver/certmagic v0.11.3-0.20200808143826-2e100d6d0bcf h1:Srcj7CdiavYImKMLDj8sSJKS3htwwwJB3bjPRTXh+P0=
90 -github.com/caddyserver/certmagic v0.11.3-0.20200808143826-2e100d6d0bcf/go.mod h1:z0loWzjr6Sr8rOG2pdsiwajDpAcck2wfF8E7hTV0qT4=
89 +github.com/caddyserver/certmagic v0.11.3-0.20200810220624-10a8b5c72339 h1:wTD+Y63XoBtiTJhe/Xn7WLrwKenmjkt2WxH3FP+Y0DM=
90 +github.com/caddyserver/certmagic v0.11.3-0.20200810220624-10a8b5c72339/go.mod h1:mqOzOvKa7UcC+TWbBLcP0ZLRut/xaaQBw0hRGWHBIkY=
91 github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
92 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
93 github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
@@ -384,8 +384,8 @@ github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
384 github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
385 github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
386 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
387 -github.com/mholt/acmez v0.1.0 h1:LL7WQVCjZvwbo3pjAUdsqEao5kI8nyHubAGtCzrTS5g=
388 -github.com/mholt/acmez v0.1.0/go.mod h1:rNLSzYu5VR6ggyarXDKDCNefo06cOkJn+VObTDJCk0U=
387 +github.com/mholt/acmez v0.1.1-0.20200810215816-dbe88fc6cf09 h1:J7NVJ46iBFeWsUc5aeVv8QNO2mLhI6rJKIbpAsH7d7g=
388 +github.com/mholt/acmez v0.1.1-0.20200810215816-dbe88fc6cf09/go.mod h1:8qnn8QA/Ewx8E3ZSsmscqsIjhhpxuy9vqdgbX2ceceM=
389 github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
390 github.com/miekg/dns v1.1.30 h1:Qww6FseFn8PRfw07jueqIXqodm0JKiiKuK0DeXSqfyo=
391 github.com/miekg/dns v1.1.30/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
modules/caddyhttp/autohttps.go
+11 -5
@@ -451,8 +451,8 @@ func (app *App) createAutomationPolicies(ctx caddy.Context, publicNames, interna
451 if ap.Issuer == nil {
452 ap.Issuer = new(caddytls.ACMEIssuer)
453 }
454 - if acmeIssuer, ok := ap.Issuer.(*caddytls.ACMEIssuer); ok {
455 - err := app.fillInACMEIssuer(acmeIssuer)
454 + if acmeIssuer, ok := ap.Issuer.(acmeCapable); ok {
455 + err := app.fillInACMEIssuer(acmeIssuer.GetACMEIssuer())
456 if err != nil {
457 return err
458 }
@@ -470,9 +470,13 @@ func (app *App) createAutomationPolicies(ctx caddy.Context, publicNames, interna
470 basePolicy = new(caddytls.AutomationPolicy)
471 }
472
473 - // if the basePolicy has an existing ACMEIssuer, let's
474 - // use it, otherwise we'll make one
475 - baseACMEIssuer, _ := basePolicy.Issuer.(*caddytls.ACMEIssuer)
473 + // if the basePolicy has an existing ACMEIssuer (particularly to
474 + // include any type that embeds/wraps an ACMEIssuer), let's use it,
475 + // otherwise we'll make one
476 + var baseACMEIssuer *caddytls.ACMEIssuer
477 + if acmeWrapper, ok := basePolicy.Issuer.(acmeCapable); ok {
478 + baseACMEIssuer = acmeWrapper.GetACMEIssuer()
479 + }
480 if baseACMEIssuer == nil {
481 // note that this happens if basePolicy.Issuer is nil
482 // OR if it is not nil but is not an ACMEIssuer
@@ -630,3 +634,5 @@ func (app *App) automaticHTTPSPhase2() error {
634 app.allCertDomains = nil // no longer needed; allow GC to deallocate
635 return nil
636 }
637 +
638 +type acmeCapable interface{ GetACMEIssuer() *caddytls.ACMEIssuer }
modules/caddytls/acmeissuer.go
+174 -47
@@ -20,9 +20,11 @@ import (
20 "fmt"
21 "io/ioutil"
22 "net/url"
23 + "strconv"
24 "time"
25
26 "github.com/caddyserver/caddy/v2"
27 + "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
28 "github.com/caddyserver/certmagic"
29 "github.com/mholt/acmez"
30 "github.com/mholt/acmez/acme"
@@ -85,13 +87,13 @@ func (ACMEIssuer) CaddyModule() caddy.ModuleInfo {
87 }
88 }
89
88 -// Provision sets up m.
89 -func (m *ACMEIssuer) Provision(ctx caddy.Context) error {
90 - m.logger = ctx.Logger(m)
90 +// Provision sets up iss.
91 +func (iss *ACMEIssuer) Provision(ctx caddy.Context) error {
92 + iss.logger = ctx.Logger(iss)
93
94 // DNS providers
93 - if m.Challenges != nil && m.Challenges.DNS != nil && m.Challenges.DNS.ProviderRaw != nil {
94 - val, err := ctx.LoadModule(m.Challenges.DNS, "ProviderRaw")
95 + if iss.Challenges != nil && iss.Challenges.DNS != nil && iss.Challenges.DNS.ProviderRaw != nil {
96 + val, err := ctx.LoadModule(iss.Challenges.DNS, "ProviderRaw")
97 if err != nil {
98 return fmt.Errorf("loading DNS provider module: %v", err)
99 }
@@ -104,32 +106,32 @@ func (m *ACMEIssuer) Provision(ctx caddy.Context) error {
106 // acmez.Solver type, so we use it directly. The user must set environment
107 // variables to configure it. Remove this shim once a sufficient number of
108 // DNS providers are implemented for the libdns APIs instead.
107 - m.Challenges.DNS.solver = deprecatedProvider
109 + iss.Challenges.DNS.solver = deprecatedProvider
110 } else {
109 - m.Challenges.DNS.solver = &certmagic.DNS01Solver{
111 + iss.Challenges.DNS.solver = &certmagic.DNS01Solver{
112 DNSProvider: val.(certmagic.ACMEDNSProvider),
111 - TTL: time.Duration(m.Challenges.DNS.TTL),
112 - PropagationTimeout: time.Duration(m.Challenges.DNS.PropagationTimeout),
113 + TTL: time.Duration(iss.Challenges.DNS.TTL),
114 + PropagationTimeout: time.Duration(iss.Challenges.DNS.PropagationTimeout),
115 }
116 }
117 }
118
119 // add any custom CAs to trust store
118 - if len(m.TrustedRootsPEMFiles) > 0 {
119 - m.rootPool = x509.NewCertPool()
120 - for _, pemFile := range m.TrustedRootsPEMFiles {
120 + if len(iss.TrustedRootsPEMFiles) > 0 {
121 + iss.rootPool = x509.NewCertPool()
122 + for _, pemFile := range iss.TrustedRootsPEMFiles {
123 pemData, err := ioutil.ReadFile(pemFile)
124 if err != nil {
125 return fmt.Errorf("loading trusted root CA's PEM file: %s: %v", pemFile, err)
126 }
125 - if !m.rootPool.AppendCertsFromPEM(pemData) {
127 + if !iss.rootPool.AppendCertsFromPEM(pemData) {
128 return fmt.Errorf("unable to add %s to trust pool: %v", pemFile, err)
129 }
130 }
131 }
132
133 var err error
132 - m.template, err = m.makeIssuerTemplate()
134 + iss.template, err = iss.makeIssuerTemplate()
135 if err != nil {
136 return err
137 }
@@ -137,30 +139,30 @@ func (m *ACMEIssuer) Provision(ctx caddy.Context) error {
139 return nil
140 }
141
140 -func (m *ACMEIssuer) makeIssuerTemplate() (certmagic.ACMEManager, error) {
142 +func (iss *ACMEIssuer) makeIssuerTemplate() (certmagic.ACMEManager, error) {
143 template := certmagic.ACMEManager{
142 - CA: m.CA,
143 - TestCA: m.TestCA,
144 - Email: m.Email,
145 - CertObtainTimeout: time.Duration(m.ACMETimeout),
146 - TrustedRoots: m.rootPool,
147 - ExternalAccount: m.ExternalAccount,
148 - Logger: m.logger,
144 + CA: iss.CA,
145 + TestCA: iss.TestCA,
146 + Email: iss.Email,
147 + CertObtainTimeout: time.Duration(iss.ACMETimeout),
148 + TrustedRoots: iss.rootPool,
149 + ExternalAccount: iss.ExternalAccount,
150 + Logger: iss.logger,
151 }
152
151 - if m.Challenges != nil {
152 - if m.Challenges.HTTP != nil {
153 - template.DisableHTTPChallenge = m.Challenges.HTTP.Disabled
154 - template.AltHTTPPort = m.Challenges.HTTP.AlternatePort
153 + if iss.Challenges != nil {
154 + if iss.Challenges.HTTP != nil {
155 + template.DisableHTTPChallenge = iss.Challenges.HTTP.Disabled
156 + template.AltHTTPPort = iss.Challenges.HTTP.AlternatePort
157 }
156 - if m.Challenges.TLSALPN != nil {
157 - template.DisableTLSALPNChallenge = m.Challenges.TLSALPN.Disabled
158 - template.AltTLSALPNPort = m.Challenges.TLSALPN.AlternatePort
158 + if iss.Challenges.TLSALPN != nil {
159 + template.DisableTLSALPNChallenge = iss.Challenges.TLSALPN.Disabled
160 + template.AltTLSALPNPort = iss.Challenges.TLSALPN.AlternatePort
161 }
160 - if m.Challenges.DNS != nil {
161 - template.DNS01Solver = m.Challenges.DNS.solver
162 + if iss.Challenges.DNS != nil {
163 + template.DNS01Solver = iss.Challenges.DNS.solver
164 }
163 - template.ListenHost = m.Challenges.BindHost
165 + template.ListenHost = iss.Challenges.BindHost
166 }
167
168 return template, nil
@@ -170,8 +172,8 @@ func (m *ACMEIssuer) makeIssuerTemplate() (certmagic.ACMEManager, error) {
172 // This is required because ACME needs values from the config in
173 // order to solve the challenges during issuance. This implements
174 // the ConfigSetter interface.
173 -func (m *ACMEIssuer) SetConfig(cfg *certmagic.Config) {
174 - m.magic = cfg
175 +func (iss *ACMEIssuer) SetConfig(cfg *certmagic.Config) {
176 + iss.magic = cfg
177 }
178
179 // TODO: I kind of hate how each call to these methods needs to
@@ -179,23 +181,147 @@ func (m *ACMEIssuer) SetConfig(cfg *certmagic.Config) {
181 // we find the right place to do that just once and then re-use?
182
183 // PreCheck implements the certmagic.PreChecker interface.
182 -func (m *ACMEIssuer) PreCheck(ctx context.Context, names []string, interactive bool) error {
183 - return certmagic.NewACMEManager(m.magic, m.template).PreCheck(ctx, names, interactive)
184 +func (iss *ACMEIssuer) PreCheck(ctx context.Context, names []string, interactive bool) error {
185 + return certmagic.NewACMEManager(iss.magic, iss.template).PreCheck(ctx, names, interactive)
186 }
187
188 // Issue obtains a certificate for the given csr.
187 -func (m *ACMEIssuer) Issue(ctx context.Context, csr *x509.CertificateRequest) (*certmagic.IssuedCertificate, error) {
188 - return certmagic.NewACMEManager(m.magic, m.template).Issue(ctx, csr)
189 +func (iss *ACMEIssuer) Issue(ctx context.Context, csr *x509.CertificateRequest) (*certmagic.IssuedCertificate, error) {
190 + return certmagic.NewACMEManager(iss.magic, iss.template).Issue(ctx, csr)
191 }
192
193 // IssuerKey returns the unique issuer key for the configured CA endpoint.
192 -func (m *ACMEIssuer) IssuerKey() string {
193 - return certmagic.NewACMEManager(m.magic, m.template).IssuerKey()
194 +func (iss *ACMEIssuer) IssuerKey() string {
195 + return certmagic.NewACMEManager(iss.magic, iss.template).IssuerKey()
196 }
197
198 // Revoke revokes the given certificate.
197 -func (m *ACMEIssuer) Revoke(ctx context.Context, cert certmagic.CertificateResource, reason int) error {
198 - return certmagic.NewACMEManager(m.magic, m.template).Revoke(ctx, cert, reason)
199 +func (iss *ACMEIssuer) Revoke(ctx context.Context, cert certmagic.CertificateResource, reason int) error {
200 + return certmagic.NewACMEManager(iss.magic, iss.template).Revoke(ctx, cert, reason)
201 +}
202 +
203 +// GetACMEIssuer returns iss. This is useful when other types embed ACMEIssuer, because
204 +// type-asserting them to *ACMEIssuer will fail, but type-asserting them to an interface
205 +// with only this method will succeed, and will still allow the embedded ACMEIssuer
206 +// to be accessed and manipulated.
207 +func (iss *ACMEIssuer) GetACMEIssuer() *ACMEIssuer { return iss }
208 +
209 +// UnmarshalCaddyfile deserializes Caddyfile tokens into iss.
210 +//
211 +// ... acme {
212 +// dir <directory_url>
213 +// test_dir <test_directory_url>
214 +// email <email>
215 +// timeout <duration>
216 +// disable_http_challenge
217 +// disable_tlsalpn_challenge
218 +// alt_http_port <port>
219 +// alt_tlsalpn_port <port>
220 +// eab <key_id> <mac_key>
221 +// trusted_roots <pem_files...>
222 +// }
223 +//
224 +func (iss *ACMEIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
225 + for d.Next() {
226 + for nesting := d.Nesting(); d.NextBlock(nesting); {
227 + switch d.Val() {
228 + case "dir":
229 + if !d.AllArgs(&iss.CA) {
230 + return d.ArgErr()
231 + }
232 +
233 + case "test_dir":
234 + if !d.AllArgs(&iss.TestCA) {
235 + return d.ArgErr()
236 + }
237 +
238 + case "email":
239 + if !d.AllArgs(&iss.Email) {
240 + return d.ArgErr()
241 + }
242 +
243 + case "timeout":
244 + var timeoutStr string
245 + if !d.AllArgs(&timeoutStr) {
246 + return d.ArgErr()
247 + }
248 + timeout, err := caddy.ParseDuration(timeoutStr)
249 + if err != nil {
250 + return d.Errf("invalid timeout duration %s: %v", timeoutStr, err)
251 + }
252 + iss.ACMETimeout = caddy.Duration(timeout)
253 +
254 + case "disable_http_challenge":
255 + if d.NextArg() {
256 + return d.ArgErr()
257 + }
258 + if iss.Challenges == nil {
259 + iss.Challenges = new(ChallengesConfig)
260 + }
261 + if iss.Challenges.HTTP == nil {
262 + iss.Challenges.HTTP = new(HTTPChallengeConfig)
263 + }
264 + iss.Challenges.HTTP.Disabled = true
265 +
266 + case "disable_tlsalpn_challenge":
267 + if d.NextArg() {
268 + return d.ArgErr()
269 + }
270 + if iss.Challenges == nil {
271 + iss.Challenges = new(ChallengesConfig)
272 + }
273 + if iss.Challenges.TLSALPN == nil {
274 + iss.Challenges.TLSALPN = new(TLSALPNChallengeConfig)
275 + }
276 + iss.Challenges.TLSALPN.Disabled = true
277 +
278 + case "alt_http_port":
279 + if !d.NextArg() {
280 + return d.ArgErr()
281 + }
282 + port, err := strconv.Atoi(d.Val())
283 + if err != nil {
284 + return d.Errf("invalid port %s: %v", d.Val(), err)
285 + }
286 + if iss.Challenges == nil {
287 + iss.Challenges = new(ChallengesConfig)
288 + }
289 + if iss.Challenges.HTTP == nil {
290 + iss.Challenges.HTTP = new(HTTPChallengeConfig)
291 + }
292 + iss.Challenges.HTTP.AlternatePort = port
293 +
294 + case "alt_tlsalpn_port":
295 + if !d.NextArg() {
296 + return d.ArgErr()
297 + }
298 + port, err := strconv.Atoi(d.Val())
299 + if err != nil {
300 + return d.Errf("invalid port %s: %v", d.Val(), err)
301 + }
302 + if iss.Challenges == nil {
303 + iss.Challenges = new(ChallengesConfig)
304 + }
305 + if iss.Challenges.TLSALPN == nil {
306 + iss.Challenges.TLSALPN = new(TLSALPNChallengeConfig)
307 + }
308 + iss.Challenges.TLSALPN.AlternatePort = port
309 +
310 + case "eab":
311 + iss.ExternalAccount = new(acme.EAB)
312 + if !d.AllArgs(&iss.ExternalAccount.KeyID, &iss.ExternalAccount.MACKey) {
313 + return d.ArgErr()
314 + }
315 +
316 + case "trusted_roots":
317 + iss.TrustedRootsPEMFiles = d.RemainingArgs()
318 +
319 + default:
320 + return d.Errf("unrecognized ACME issuer property: %s", d.Val())
321 + }
322 + }
323 + }
324 + return nil
325 }
326
327 // onDemandAskRequest makes a request to the ask URL
@@ -228,9 +354,10 @@ func onDemandAskRequest(ask string, name string) error {
354
355 // Interface guards
356 var (
231 - _ certmagic.PreChecker = (*ACMEIssuer)(nil)
232 - _ certmagic.Issuer = (*ACMEIssuer)(nil)
233 - _ certmagic.Revoker = (*ACMEIssuer)(nil)
234 - _ caddy.Provisioner = (*ACMEIssuer)(nil)
235 - _ ConfigSetter = (*ACMEIssuer)(nil)
357 + _ certmagic.PreChecker = (*ACMEIssuer)(nil)
358 + _ certmagic.Issuer = (*ACMEIssuer)(nil)
359 + _ certmagic.Revoker = (*ACMEIssuer)(nil)
360 + _ caddy.Provisioner = (*ACMEIssuer)(nil)
361 + _ ConfigSetter = (*ACMEIssuer)(nil)
362 + _ caddyfile.Unmarshaler = (*ACMEIssuer)(nil)
363 )
modules/caddytls/internalissuer.go
+39 -18
@@ -23,6 +23,7 @@ import (
23 "time"
24
25 "github.com/caddyserver/caddy/v2"
26 + "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
27 "github.com/caddyserver/caddy/v2/modules/caddypki"
28 "github.com/caddyserver/certmagic"
29 "github.com/smallstep/certificates/authority/provisioner"
@@ -63,25 +64,25 @@ func (InternalIssuer) CaddyModule() caddy.ModuleInfo {
64 }
65
66 // Provision sets up the issuer.
66 -func (li *InternalIssuer) Provision(ctx caddy.Context) error {
67 +func (iss *InternalIssuer) Provision(ctx caddy.Context) error {
68 // get a reference to the configured CA
69 appModule, err := ctx.App("pki")
70 if err != nil {
71 return err
72 }
73 pkiApp := appModule.(*caddypki.PKI)
73 - if li.CA == "" {
74 - li.CA = caddypki.DefaultCAID
74 + if iss.CA == "" {
75 + iss.CA = caddypki.DefaultCAID
76 }
76 - ca, ok := pkiApp.CAs[li.CA]
77 + ca, ok := pkiApp.CAs[iss.CA]
78 if !ok {
78 - return fmt.Errorf("no certificate authority configured with id: %s", li.CA)
79 + return fmt.Errorf("no certificate authority configured with id: %s", iss.CA)
80 }
80 - li.ca = ca
81 + iss.ca = ca
82
83 // set any other default values
83 - if li.Lifetime == 0 {
84 - li.Lifetime = caddy.Duration(defaultInternalCertLifetime)
84 + if iss.Lifetime == 0 {
85 + iss.Lifetime = caddy.Duration(defaultInternalCertLifetime)
86 }
87
88 return nil
@@ -89,38 +90,38 @@ func (li *InternalIssuer) Provision(ctx caddy.Context) error {
90
91 // IssuerKey returns the unique issuer key for the
92 // confgured CA endpoint.
92 -func (li InternalIssuer) IssuerKey() string {
93 - return li.ca.ID()
93 +func (iss InternalIssuer) IssuerKey() string {
94 + return iss.ca.ID()
95 }
96
97 // Issue issues a certificate to satisfy the CSR.
97 -func (li InternalIssuer) Issue(ctx context.Context, csr *x509.CertificateRequest) (*certmagic.IssuedCertificate, error) {
98 +func (iss InternalIssuer) Issue(ctx context.Context, csr *x509.CertificateRequest) (*certmagic.IssuedCertificate, error) {
99 // prepare the signing authority
100 authCfg := caddypki.AuthorityConfig{
100 - SignWithRoot: li.SignWithRoot,
101 + SignWithRoot: iss.SignWithRoot,
102 }
102 - auth, err := li.ca.NewAuthority(authCfg)
103 + auth, err := iss.ca.NewAuthority(authCfg)
104 if err != nil {
105 return nil, err
106 }
107
108 // get the cert (public key) that will be used for signing
109 var issuerCert *x509.Certificate
109 - if li.SignWithRoot {
110 - issuerCert = li.ca.RootCertificate()
110 + if iss.SignWithRoot {
111 + issuerCert = iss.ca.RootCertificate()
112 } else {
112 - issuerCert = li.ca.IntermediateCertificate()
113 + issuerCert = iss.ca.IntermediateCertificate()
114 }
115
116 // ensure issued certificate does not expire later than its issuer
116 - lifetime := time.Duration(li.Lifetime)
117 + lifetime := time.Duration(iss.Lifetime)
118 if time.Now().Add(lifetime).After(issuerCert.NotAfter) {
119 // TODO: log this
120 lifetime = issuerCert.NotAfter.Sub(time.Now())
121 }
122
123 certChain, err := auth.Sign(csr, provisioner.Options{},
123 - profileDefaultDuration(li.Lifetime),
124 + profileDefaultDuration(iss.Lifetime),
125 )
126 if err != nil {
127 return nil, err
@@ -139,6 +140,26 @@ func (li InternalIssuer) Issue(ctx context.Context, csr *x509.CertificateRequest
140 }, nil
141 }
142
143 +// UnmarshalCaddyfile deserializes Caddyfile tokens into iss.
144 +//
145 +// ... internal {
146 +// ca <name>
147 +// }
148 +//
149 +func (iss *InternalIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
150 + for d.Next() {
151 + for d.NextBlock(0) {
152 + switch d.Val() {
153 + case "ca":
154 + if !d.AllArgs(&iss.CA) {
155 + return d.ArgErr()
156 + }
157 + }
158 + }
159 + }
160 + return nil
161 +}
162 +
163 // profileDefaultDuration is a wrapper against x509util.WithOption to conform
164 // the SignOption interface.
165 //
modules/caddytls/tls.go
+4 -2
@@ -313,8 +313,10 @@ func (t *TLS) HandleHTTPChallenge(w http.ResponseWriter, r *http.Request) bool {
313 if ap.magic.Issuer == nil {
314 return false
315 }
316 - if am, ok := ap.magic.Issuer.(*ACMEIssuer); ok {
317 - return certmagic.NewACMEManager(am.magic, am.template).HandleHTTPChallenge(w, r)
316 + type acmeCapable interface{ GetACMEIssuer() *ACMEIssuer }
317 + if am, ok := ap.magic.Issuer.(acmeCapable); ok {
318 + iss := am.GetACMEIssuer()
319 + return certmagic.NewACMEManager(iss.magic, iss.template).HandleHTTPChallenge(w, r)
320 }
321 return false
322 }
modules/caddytls/zerosslissuer.go new
+236
@@ -0,0 +1,236 @@
1 +// Copyright 2015 Matthew Holt and The Caddy Authors
2 +//
3 +// Licensed under the Apache License, Version 2.0 (the "License");
4 +// you may not use this file except in compliance with the License.
5 +// You may obtain a copy of the License at
6 +//
7 +// http://www.apache.org/licenses/LICENSE-2.0
8 +//
9 +// Unless required by applicable law or agreed to in writing, software
10 +// distributed under the License is distributed on an "AS IS" BASIS,
11 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 +// See the License for the specific language governing permissions and
13 +// limitations under the License.
14 +
15 +package caddytls
16 +
17 +import (
18 + "context"
19 + "crypto/x509"
20 + "encoding/json"
21 + "fmt"
22 + "io"
23 + "net/http"
24 + "net/url"
25 + "strings"
26 + "sync"
27 +
28 + "github.com/caddyserver/caddy/v2"
29 + "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
30 + "github.com/caddyserver/certmagic"
31 + "github.com/mholt/acmez/acme"
32 + "go.uber.org/zap"
33 +)
34 +
35 +func init() {
36 + caddy.RegisterModule(new(ZeroSSLIssuer))
37 +}
38 +
39 +// ZeroSSLIssuer makes an ACME manager
40 +// for managing certificates using ACME.
41 +type ZeroSSLIssuer struct {
42 + *ACMEIssuer
43 +
44 + // The API key (or "access key") for using the ZeroSSL API.
45 + APIKey string `json:"api_key,omitempty"`
46 +
47 + mu sync.Mutex
48 + logger *zap.Logger
49 +}
50 +
51 +// CaddyModule returns the Caddy module information.
52 +func (*ZeroSSLIssuer) CaddyModule() caddy.ModuleInfo {
53 + return caddy.ModuleInfo{
54 + ID: "tls.issuance.zerossl",
55 + New: func() caddy.Module { return new(ZeroSSLIssuer) },
56 + }
57 +}
58 +
59 +// Provision sets up iss.
60 +func (iss *ZeroSSLIssuer) Provision(ctx caddy.Context) error {
61 + iss.logger = ctx.Logger(iss)
62 +
63 + if iss.ACMEIssuer == nil {
64 + iss.ACMEIssuer = new(ACMEIssuer)
65 + }
66 + err := iss.ACMEIssuer.Provision(ctx)
67 + if err != nil {
68 + return err
69 + }
70 +
71 + return nil
72 +}
73 +
74 +func (iss *ZeroSSLIssuer) newAccountCallback(ctx context.Context, am *certmagic.ACMEManager, _ acme.Account) error {
75 + if am.ExternalAccount != nil {
76 + return nil
77 + }
78 + var err error
79 + am.ExternalAccount, err = iss.generateEABCredentials(ctx)
80 + return err
81 +}
82 +
83 +func (iss *ZeroSSLIssuer) generateEABCredentials(ctx context.Context) (*acme.EAB, error) {
84 + var endpoint string
85 + var body io.Reader
86 +
87 + // there are two ways to generate EAB credentials: authenticated with
88 + // their API key, or unauthenticated with their email address
89 + switch {
90 + case iss.APIKey != "":
91 + apiKey := caddy.NewReplacer().ReplaceAll(iss.APIKey, "")
92 + if apiKey == "" {
93 + return nil, fmt.Errorf("missing API key: '%v'", iss.APIKey)
94 + }
95 + qs := url.Values{"access_key": []string{apiKey}}
96 + endpoint = fmt.Sprintf("%s/eab-credentials?%s", zerosslAPIBase, qs.Encode())
97 +
98 + case iss.Email != "":
99 + email := caddy.NewReplacer().ReplaceAll(iss.Email, "")
100 + if email == "" {
101 + return nil, fmt.Errorf("missing email: '%v'", iss.Email)
102 + }
103 + endpoint = zerosslAPIBase + "/eab-credentials-email"
104 + form := url.Values{"email": []string{email}}
105 + body = strings.NewReader(form.Encode())
106 +
107 + default:
108 + return nil, fmt.Errorf("must configure either an API key or email address to use ZeroSSL without explicit EAB")
109 + }
110 +
111 + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, body)
112 + if err != nil {
113 + return nil, fmt.Errorf("forming request: %v", err)
114 + }
115 + if body != nil {
116 + req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
117 + }
118 + req.Header.Set("User-Agent", certmagic.UserAgent)
119 +
120 + resp, err := http.DefaultClient.Do(req)
121 + if err != nil {
122 + return nil, fmt.Errorf("performing EAB credentials request: %v", err)
123 + }
124 + defer resp.Body.Close()
125 +
126 + var result struct {
127 + Success bool `json:"success"`
128 + Error struct {
129 + Code int `json:"code"`
130 + Type string `json:"type"`
131 + } `json:"error"`
132 + EABKID string `json:"eab_kid"`
133 + EABHMACKey string `json:"eab_hmac_key"`
134 + }
135 + err = json.NewDecoder(resp.Body).Decode(&result)
136 + if err != nil {
137 + return nil, fmt.Errorf("decoding API response: %v", err)
138 + }
139 + if result.Error.Code != 0 {
140 + return nil, fmt.Errorf("failed getting EAB credentials: HTTP %d: %s (code %d)",
141 + resp.StatusCode, result.Error.Type, result.Error.Code)
142 + }
143 + if resp.StatusCode != http.StatusOK {
144 + return nil, fmt.Errorf("failed getting EAB credentials: HTTP %d", resp.StatusCode)
145 + }
146 +
147 + iss.logger.Info("generated EAB credentials", zap.String("key_id", result.EABKID))
148 +
149 + return &acme.EAB{
150 + KeyID: result.EABKID,
151 + MACKey: result.EABHMACKey,
152 + }, nil
153 +}
154 +
155 +// initialize modifies the template for the underlying ACMEManager
156 +// values by setting the CA endpoint to the ZeroSSL directory and
157 +// setting the NewAccountFunc callback to one which allows us to
158 +// generate EAB credentials only if a new account is being made.
159 +// Since it modifies the stored template, its effect should only
160 +// be needed once, but it is fine to call it repeatedly.
161 +func (iss *ZeroSSLIssuer) initialize() {
162 + iss.mu.Lock()
163 + defer iss.mu.Unlock()
164 + if iss.template.CA == "" {
165 + iss.template.CA = zerosslACMEDirectory
166 + }
167 + if iss.template.NewAccountFunc == nil {
168 + iss.template.NewAccountFunc = iss.newAccountCallback
169 + }
170 +}
171 +
172 +// PreCheck implements the certmagic.PreChecker interface.
173 +func (iss *ZeroSSLIssuer) PreCheck(ctx context.Context, names []string, interactive bool) error {
174 + iss.initialize()
175 + return iss.ACMEIssuer.PreCheck(ctx, names, interactive)
176 +}
177 +
178 +// Issue obtains a certificate for the given csr.
179 +func (iss *ZeroSSLIssuer) Issue(ctx context.Context, csr *x509.CertificateRequest) (*certmagic.IssuedCertificate, error) {
180 + iss.initialize()
181 + return iss.ACMEIssuer.Issue(ctx, csr)
182 +}
183 +
184 +// IssuerKey returns the unique issuer key for the configured CA endpoint.
185 +func (iss *ZeroSSLIssuer) IssuerKey() string {
186 + iss.initialize()
187 + return iss.ACMEIssuer.IssuerKey()
188 +}
189 +
190 +// Revoke revokes the given certificate.
191 +func (iss *ZeroSSLIssuer) Revoke(ctx context.Context, cert certmagic.CertificateResource, reason int) error {
192 + iss.initialize()
193 + return iss.ACMEIssuer.Revoke(ctx, cert, reason)
194 +}
195 +
196 +// UnmarshalCaddyfile deserializes Caddyfile tokens into iss.
197 +//
198 +// ... zerossl <api_key> {
199 +// ...
200 +// }
201 +//
202 +// Any of the subdirectives for the ACME issuer can be used in the block.
203 +func (iss *ZeroSSLIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
204 + for d.Next() {
205 + if !d.AllArgs(&iss.APIKey) {
206 + return d.ArgErr()
207 + }
208 +
209 + if iss.ACMEIssuer == nil {
210 + iss.ACMEIssuer = new(ACMEIssuer)
211 + }
212 + err := iss.ACMEIssuer.UnmarshalCaddyfile(d.NewFromNextSegment())
213 + if err != nil {
214 + return err
215 + }
216 + }
217 + return nil
218 +}
219 +
220 +const (
221 + zerosslACMEDirectory = "https://acme.zerossl.com/v2/DV90"
222 + zerosslAPIBase = "https://api.zerossl.com/acme"
223 +)
224 +
225 +// Interface guards
226 +var (
227 + _ certmagic.PreChecker = (*ZeroSSLIssuer)(nil)
228 + _ certmagic.Issuer = (*ZeroSSLIssuer)(nil)
229 + _ certmagic.Revoker = (*ZeroSSLIssuer)(nil)
230 + _ caddy.Provisioner = (*ZeroSSLIssuer)(nil)
231 + _ ConfigSetter = (*ZeroSSLIssuer)(nil)
232 +
233 + // a type which properly embeds an ACMEIssuer should implement
234 + // this interface so it can be treated as an ACMEIssuer
235 + _ interface{ GetACMEIssuer() *ACMEIssuer } = (*ZeroSSLIssuer)(nil)
236 +)