summaryrefslogtreecommitdiff
path: root/modules/caddytls/acmemanager.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-30 09:07:43 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-30 09:07:43 -0600
commitb249b45d109cdfef51b94cdeeb1ef7593e3b26ab (patch)
treead2798d7da52653fd477088c56300f288de89d6f /modules/caddytls/acmemanager.go
parentc12bf4054c37b88eb37f7c59631d55ae512bcd29 (diff)
tls: Change struct fields to pointers, add nil checks; rate.Burst update
Making them pointers makes for cleaner JSON when adapting configs, if the struct is empty now it will be omitted entirely. The x/time/rate package was updated to support changing the burst, so we've incorporated that here and removed a TODO.
Diffstat (limited to 'modules/caddytls/acmemanager.go')
-rw-r--r--modules/caddytls/acmemanager.go65
1 files changed, 37 insertions, 28 deletions
diff --git a/modules/caddytls/acmemanager.go b/modules/caddytls/acmemanager.go
index 9df2e26..dbc8fc9 100644
--- a/modules/caddytls/acmemanager.go
+++ b/modules/caddytls/acmemanager.go
@@ -40,16 +40,16 @@ func init() {
// after you have configured this struct
// to your liking.
type ACMEManagerMaker struct {
- CA string `json:"ca,omitempty"`
- Email string `json:"email,omitempty"`
- RenewAhead caddy.Duration `json:"renew_ahead,omitempty"`
- KeyType string `json:"key_type,omitempty"`
- ACMETimeout caddy.Duration `json:"acme_timeout,omitempty"`
- MustStaple bool `json:"must_staple,omitempty"`
- Challenges ChallengesConfig `json:"challenges,omitempty"`
- OnDemand bool `json:"on_demand,omitempty"`
- Storage json.RawMessage `json:"storage,omitempty"`
- TrustedRootsPEMFiles []string `json:"trusted_roots_pem_files,omitempty"`
+ CA string `json:"ca,omitempty"`
+ Email string `json:"email,omitempty"`
+ RenewAhead caddy.Duration `json:"renew_ahead,omitempty"`
+ KeyType string `json:"key_type,omitempty"`
+ ACMETimeout caddy.Duration `json:"acme_timeout,omitempty"`
+ MustStaple bool `json:"must_staple,omitempty"`
+ Challenges *ChallengesConfig `json:"challenges,omitempty"`
+ OnDemand bool `json:"on_demand,omitempty"`
+ Storage json.RawMessage `json:"storage,omitempty"`
+ TrustedRootsPEMFiles []string `json:"trusted_roots_pem_files,omitempty"`
storage certmagic.Storage
rootPool *x509.CertPool
@@ -72,7 +72,7 @@ func (m ACMEManagerMaker) NewManager(interactive bool) (certmagic.Manager, error
// Provision sets up m.
func (m *ACMEManagerMaker) Provision(ctx caddy.Context) error {
// DNS providers
- if m.Challenges.DNSRaw != nil {
+ if m.Challenges != nil && m.Challenges.DNSRaw != nil {
val, err := ctx.LoadModuleInline("provider", "tls.dns", m.Challenges.DNSRaw)
if err != nil {
return fmt.Errorf("loading DNS provider module: %s", err)
@@ -125,7 +125,7 @@ func (m *ACMEManagerMaker) makeCertMagicConfig(ctx caddy.Context) certmagic.Conf
if m.OnDemand {
var onDemand *OnDemandConfig
appVal, err := ctx.App("tls")
- if err == nil {
+ if err == nil && appVal.(*TLS).Automation != nil {
onDemand = appVal.(*TLS).Automation.OnDemand
}
@@ -153,24 +153,33 @@ func (m *ACMEManagerMaker) makeCertMagicConfig(ctx caddy.Context) certmagic.Conf
}
}
- return certmagic.Config{
- CA: m.CA,
- Email: m.Email,
- Agreed: true,
- DisableHTTPChallenge: m.Challenges.HTTP.Disabled,
- DisableTLSALPNChallenge: m.Challenges.TLSALPN.Disabled,
- RenewDurationBefore: time.Duration(m.RenewAhead),
- AltHTTPPort: m.Challenges.HTTP.AlternatePort,
- AltTLSALPNPort: m.Challenges.TLSALPN.AlternatePort,
- DNSProvider: m.Challenges.DNS,
- KeyType: supportedCertKeyTypes[m.KeyType],
- CertObtainTimeout: time.Duration(m.ACMETimeout),
- OnDemand: ond,
- MustStaple: m.MustStaple,
- Storage: storage,
- TrustedRoots: m.rootPool,
+ cfg := certmagic.Config{
+ CA: m.CA,
+ Email: m.Email,
+ Agreed: true,
+ RenewDurationBefore: time.Duration(m.RenewAhead),
+ KeyType: supportedCertKeyTypes[m.KeyType],
+ CertObtainTimeout: time.Duration(m.ACMETimeout),
+ OnDemand: ond,
+ MustStaple: m.MustStaple,
+ Storage: storage,
+ TrustedRoots: m.rootPool,
// TODO: listenHost
}
+
+ if m.Challenges != nil {
+ if m.Challenges.HTTP != nil {
+ cfg.DisableHTTPChallenge = m.Challenges.HTTP.Disabled
+ cfg.AltHTTPPort = m.Challenges.HTTP.AlternatePort
+ }
+ if m.Challenges.TLSALPN != nil {
+ cfg.DisableTLSALPNChallenge = m.Challenges.TLSALPN.Disabled
+ cfg.AltTLSALPNPort = m.Challenges.TLSALPN.AlternatePort
+ }
+ cfg.DNSProvider = m.Challenges.DNS
+ }
+
+ return cfg
}
// onDemandAskRequest makes a request to the ask URL