2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// Copyright 2015 Matthew Holt and The Caddy Authors 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Licensed under the Apache License, Version 2.0 (the "License"); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// you may not use this file except in compliance with the License. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// You may obtain a copy of the License at 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								//     http://www.apache.org/licenses/LICENSE-2.0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Unless required by applicable law or agreed to in writing, software 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// distributed under the License is distributed on an "AS IS" BASIS, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// See the License for the specific language governing permissions and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// limitations under the License. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								package  caddytls 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  ( 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-07 18:40:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"crypto/tls" 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									"encoding/json" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-23 22:28:11 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"net" 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 16:30:56 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"slices" 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-20 12:06:00 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									"github.com/caddyserver/certmagic" 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-19 12:17:02 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"github.com/mholt/acmez/v3" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-23 22:28:11 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"go.uber.org/zap" 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-13 19:16:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"go.uber.org/zap/zapcore" 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-14 23:41:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									"github.com/caddyserver/caddy/v2" 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 15:18:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// AutomationConfig governs the automated management of TLS certificates. 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								type  AutomationConfig  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-24 18:31:01 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// The list of automation policies. The first policy matching 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// a certificate or subject name will be applied. 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									Policies  [ ] * AutomationPolicy  ` json:"policies,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// On-Demand TLS defers certificate operations to the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// moment they are needed, e.g. during a TLS handshake. 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Useful when you don't know all the hostnames at 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// config-time, or when you are not in control of the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// domain names you are managing certificates for. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// In 2015, Caddy became the first web server to 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// implement this experimental technology. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-24 18:31:01 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Note that this field does not enable on-demand TLS; 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// it only configures it for when it is used. To enable 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// it, create an automation policy with `on_demand`. 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									OnDemand  * OnDemandConfig  ` json:"on_demand,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Caddy staples OCSP (and caches the response) for all 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// qualifying certificates by default. This setting 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// changes how often it scans responses for freshness, 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-05 11:14:39 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// and updates them if they are getting stale. Default: 1h 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									OCSPCheckInterval  caddy . Duration  ` json:"ocsp_interval,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Every so often, Caddy will scan all loaded, managed 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// certificates for expiration. This setting changes how 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// frequently the scan for expiring certificates is 
							 
						 
					
						
							
								
									
										
										
										
											2020-06-05 11:14:39 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// performed. Default: 10m 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									RenewCheckInterval  caddy . Duration  ` json:"renew_interval,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-12 15:41:22 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// How often to scan storage units for old or expired 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// assets and remove them. These scans exert lots of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// reads (and list operations) on the storage module, so 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// choose a longer interval for large deployments. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Default: 24h 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Storage will always be cleaned when the process first 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// starts. Then, a new cleaning will be started this 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// duration after the previous cleaning started if the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// previous cleaning finished in less than half the time 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// of this interval (otherwise next start will be skipped). 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									StorageCleanInterval  caddy . Duration  ` json:"storage_clean_interval,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												httpcaddyfile, caddytls: Multiple edge case fixes; add tests
- Create two default automation policies; if the TLS app is used in
  isolation with the 'automate' certificate loader, it will now use
  an internal issuer for internal-only names, and an ACME issuer for
  all other names by default.
- If the HTTP Caddyfile adds an 'automate' loader, it now also adds an
  automation policy for any names in that loader that do not qualify
  for public certificates so that they will be issued internally. (It
  might be nice if this wasn't necessary, but the alternative is to
  either make auto-HTTPS logic way more complex by scanning the names in
  the 'automate' loader, or to have an automation policy without an
  issuer switch between default issuer based on the name being issued
  a certificate - I think I like the latter option better, right now we
  do something kind of like that but at a level above each individual
  automation policies, we do that switch only when no automation
  policies match, rather than when a policy without an issuer does
  match.)
- Set the default LoggerName rather than a LoggerNames with an empty
  host value, which is now taken literally rather than as a catch-all.
- hostsFromKeys, the function that gets a list of hosts from server
  block keys, no longer returns an empty string in its resulting slice,
  ever.
											 
										 
										
											2020-04-08 14:46:44 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									defaultPublicAutomationPolicy    * AutomationPolicy 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-09 13:09:48 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									defaultInternalAutomationPolicy  * AutomationPolicy  // only initialized if necessary 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// AutomationPolicy designates the policy for automating the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// management (obtaining, renewal, and revocation) of managed 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// TLS certificates. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// An AutomationPolicy value is not valid until it has been 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// provisioned; use the `AddAutomationPolicy()` method on the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// TLS app to properly provision a new policy. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								type  AutomationPolicy  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Which subjects (hostnames or IP addresses) this policy applies to. 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-04 22:15:50 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// This list is a filter, not a command. In other words, it is used 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// only to filter whether this policy should apply to a subject that 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// needs a certificate; it does NOT command the TLS app to manage a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// certificate for that subject. To have Caddy automate a certificate 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// or specific subjects, use the "automate" certificate loader module 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// of the TLS app. 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 17:16:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									SubjectsRaw  [ ] string  ` json:"subjects,omitempty" ` 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// The modules that may issue certificates. Default: internal if all 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-10 16:08:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// subjects do not qualify for public certificates; otherwise acme and 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// zerossl. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									IssuersRaw  [ ] json . RawMessage  ` json:"issuers,omitempty" caddy:"namespace=tls.issuance inline_key=module" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Modules that can get a custom certificate to use for any 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// given TLS handshake at handshake-time. Custom certificates 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// can be useful if another entity is managing certificates 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 10:47:30 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// and Caddy need only get it and serve it. Specifying a Manager 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// enables on-demand TLS, i.e. it has the side-effect of setting 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// the on_demand parameter to `true`. 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 10:47:30 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// TODO: This is an EXPERIMENTAL feature. Subject to change or removal. 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ManagersRaw  [ ] json . RawMessage  ` json:"get_certificate,omitempty" caddy:"namespace=tls.get_certificate inline_key=via" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									// If true, certificates will be requested with MustStaple. Not all 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// CAs support this, and there are potentially serious consequences 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// of enabling this feature without proper threat modeling. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									MustStaple  bool  ` json:"must_staple,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// How long before a certificate's expiration to try renewing it, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// as a function of its total lifetime. As a general and conservative 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// rule, it is a good idea to renew a certificate when it has about 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// 1/3 of its total lifetime remaining. This utilizes the majority 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// of the certificate's lifetime while still saving time to 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// troubleshoot problems. However, for extremely short-lived certs, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// you may wish to increase the ratio to ~1/2. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									RenewalWindowRatio  float64  ` json:"renewal_window_ratio,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// The type of key to generate for certificates. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Supported values: `ed25519`, `p256`, `p384`, `rsa2048`, `rsa4096`. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									KeyType  string  ` json:"key_type,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Optionally configure a separate storage module associated with this 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// manager, instead of using Caddy's global/default-configured storage. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									StorageRaw  json . RawMessage  ` json:"storage,omitempty" caddy:"namespace=caddy.storage inline_key=module" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// If true, certificates will be managed "on demand"; that is, during 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// TLS handshakes or when needed, as opposed to at startup or config 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// load. This enables On-Demand TLS for this policy. 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									OnDemand  bool  ` json:"on_demand,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-10 04:30:31 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// If true, private keys already existing in storage 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// will be reused. Otherwise, a new key will be 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// created for every new certificate to mitigate 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// pinning and reduce the scope of key compromise. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// TEMPORARY: Key pinning is against industry best practices. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// This property will likely be removed in the future. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Do not rely on it forever; watch the release notes. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ReusePrivateKeys  bool  ` json:"reuse_private_keys,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-07 15:52:58 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Disables OCSP stapling. Disabling OCSP stapling puts clients at 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// greater risk, reduces their privacy, and usually lowers client 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// performance. It is NOT recommended to disable this unless you 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// are able to justify the costs. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// EXPERIMENTAL. Subject to change. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									DisableOCSPStapling  bool  ` json:"disable_ocsp_stapling,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Overrides the URLs of OCSP responders embedded in certificates. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Each key is a OCSP server URL to override, and its value is the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// replacement. An empty value will disable querying of that server. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// EXPERIMENTAL. Subject to change. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									OCSPOverrides  map [ string ] string  ` json:"ocsp_overrides,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Issuers and Managers store the decoded issuer and manager modules; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// they are only used to populate an underlying certmagic.Config's 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// fields during provisioning so that the modules can survive a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// re-provisioning. 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-25 11:28:54 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									Issuers   [ ] certmagic . Issuer   ` json:"-" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Managers  [ ] certmagic . Manager  ` json:"-" ` 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 17:16:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									subjects  [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									magic     * certmagic . Config 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									storage   certmagic . Storage 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-20 08:48:59 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Whether this policy had explicit managers configured directly on it. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									hadExplicitManagers  bool 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-20 20:25:46 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Provision sets up ap and builds its underlying CertMagic config. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								func  ( ap  * AutomationPolicy )  Provision ( tlsApp  * TLS )  error  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 17:16:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// replace placeholders in subjects to allow environment variables 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									repl  :=  caddy . NewReplacer ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									subjects  :=  make ( [ ] string ,  len ( ap . SubjectsRaw ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  i ,  sub  :=  range  ap . SubjectsRaw  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										subjects [ i ]  =  repl . ReplaceAll ( sub ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ap . subjects  =  subjects 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									// policy-specific storage implementation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ap . StorageRaw  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										val ,  err  :=  tlsApp . ctx . LoadModule ( ap ,  "StorageRaw" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  fmt . Errorf ( "loading TLS storage module: %v" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										cmStorage ,  err  :=  val . ( caddy . StorageConverter ) . CertMagicStorage ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  fmt . Errorf ( "creating TLS storage configuration: %v" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ap . storage  =  cmStorage 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// we don't store loaded modules directly in the certmagic config since 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// policy provisioning may happen more than once (during auto-HTTPS) and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// loading a module clears its config bytes; thus, load the module and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// store them on the policy before putting it on the config 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// load and provision any cert manager modules 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ap . ManagersRaw  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-20 08:48:59 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ap . hadExplicitManagers  =  true 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										vals ,  err  :=  tlsApp . ctx . LoadModule ( ap ,  "ManagersRaw" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  fmt . Errorf ( "loading external certificate manager modules: %v" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 16:39:09 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										for  _ ,  getCertVal  :=  range  vals . ( [ ] any )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-25 11:28:54 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ap . Managers  =  append ( ap . Managers ,  getCertVal . ( certmagic . Manager ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-17 15:40:34 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// load and provision any explicitly-configured issuer modules 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ap . IssuersRaw  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										val ,  err  :=  tlsApp . ctx . LoadModule ( ap ,  "IssuersRaw" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  fmt . Errorf ( "loading TLS automation management module: %s" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-17 21:00:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 16:39:09 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										for  _ ,  issVal  :=  range  val . ( [ ] any )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ap . Issuers  =  append ( ap . Issuers ,  issVal . ( certmagic . Issuer ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-17 21:00:45 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									issuers  :=  ap . Issuers 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  len ( issuers )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  err  error 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-02 16:17:26 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										issuers ,  err  =  DefaultIssuersProvisioned ( tlsApp . ctx ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  err 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-26 06:16:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									keyType  :=  ap . KeyType 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  keyType  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  err  error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										keyType ,  err  =  caddy . NewReplacer ( ) . ReplaceOrErr ( ap . KeyType ,  true ,  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  fmt . Errorf ( "invalid key type %s: %s" ,  ap . KeyType ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  _ ,  ok  :=  supportedCertKeyTypes [ keyType ] ;  ! ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  fmt . Errorf ( "unrecognized key type: %s" ,  keyType ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									keySource  :=  certmagic . StandardKeyGenerator { 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-26 06:16:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										KeyType :  supportedCertKeyTypes [ keyType ] , 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									storage  :=  ap . storage 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  storage  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										storage  =  tlsApp . ctx . Storage ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// on-demand TLS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									var  ond  * certmagic . OnDemandConfig 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 10:47:30 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ap . OnDemand  ||  len ( ap . Managers )  >  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// permission module is now required after a number of negligence cases that allowed abuse; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// but it may still be optional for explicit subjects (bounded, non-wildcard), for the 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// internal issuer since it doesn't cause public PKI pressure on ACME servers; subtly, it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// is useful to allow on-demand TLS to be enabled so Managers can be used, but to still 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// prevent issuance from Issuers (when Managers don't provide a certificate) if there's no 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// permission module configured 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										noProtections  :=  ap . isWildcardOrDefault ( )  &&  ! ap . onlyInternalIssuer ( )  &&  ( tlsApp . Automation  ==  nil  ||  tlsApp . Automation . OnDemand  ==  nil  ||  tlsApp . Automation . OnDemand . permission  ==  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-20 08:48:59 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										failClosed  :=  noProtections  &&  ! ap . hadExplicitManagers  // don't allow on-demand issuance (other than implicit managers) if no managers have been explicitly configured 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  noProtections  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-20 08:48:59 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ! ap . hadExplicitManagers  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// no managers, no explicitly-configured permission module, this is a config error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  fmt . Errorf ( "on-demand TLS cannot be enabled without a permission module to prevent abuse; please refer to documentation for details" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											// allow on-demand to be enabled but only for the purpose of the Managers; issuance won't be allowed from Issuers 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											tlsApp . logger . Warn ( "on-demand TLS can only get certificates from the configured external manager(s) because no ask endpoint / permission module is specified" ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ond  =  & certmagic . OnDemandConfig { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-07 18:40:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											DecisionFunc :  func ( ctx  context . Context ,  name  string )  error  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  failClosed  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													return  fmt . Errorf ( "no permission module configured; certificates not allowed except from external Managers" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 10:47:30 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  tlsApp . Automation  ==  nil  ||  tlsApp . Automation . OnDemand  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// logging the remote IP can be useful for servers that want to count 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// attempts from clients to detect patterns of abuse -- it should NOT be 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// used solely for decision making, however 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var  remoteIP  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  hello ,  ok  :=  ctx . Value ( certmagic . ClientHelloInfoCtxKey ) . ( * tls . ClientHelloInfo ) ;  ok  &&  hello  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  remote  :=  hello . Conn . RemoteAddr ( ) ;  remote  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														remoteIP ,  _ ,  _  =  net . SplitHostPort ( remote . String ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-13 19:16:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  c  :=  tlsApp . logger . Check ( zapcore . DebugLevel ,  "asking for permission for on-demand certificate" ) ;  c  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													c . Write ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														zap . String ( "remote_ip" ,  remoteIP ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														zap . String ( "domain" ,  name ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// ask the permission module if this cert is allowed 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  err  :=  tlsApp . Automation . OnDemand . permission . CertificateAllowed ( ctx ,  name ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													// distinguish true errors from denials, because it's important to elevate actual errors 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													if  errors . Is ( err ,  ErrPermissionDenied )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-13 19:16:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  c  :=  tlsApp . logger . Check ( zapcore . DebugLevel ,  "on-demand certificate issuance denied" ) ;  c  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															c . Write ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																zap . String ( "domain" ,  name ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																zap . Error ( err ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-13 19:16:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  c  :=  tlsApp . logger . Check ( zapcore . ErrorLevel ,  "failed to get permission for on-demand certificate" ) ;  c  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															c . Write ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																zap . String ( "domain" ,  name ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																zap . Error ( err ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 16:11:29 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 10:47:30 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											Managers :  ap . Managers , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									template  :=  certmagic . Config { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										MustStaple :          ap . MustStaple , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										RenewalWindowRatio :  ap . RenewalWindowRatio , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										KeySource :           keySource , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-31 17:01:30 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										OnEvent :             tlsApp . onEvent , 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										OnDemand :            ond , 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-10 04:30:31 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ReusePrivateKeys :    ap . ReusePrivateKeys , 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-07 15:52:58 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										OCSP :  certmagic . OCSPConfig { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											DisableStapling :     ap . DisableOCSPStapling , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ResponderOverrides :  ap . OCSPOverrides , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-15 10:47:30 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										Storage :  storage , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										Issuers :  issuers , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										Logger :   tlsApp . logger , 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-11 13:10:58 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									certCacheMu . RLock ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ap . magic  =  certmagic . New ( certCache ,  template ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									certCacheMu . RUnlock ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// sometimes issuers may need the parent certmagic.Config in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// order to function properly (for example, ACMEIssuer needs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// access to the correct storage and cache so it can solve 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// ACME challenges -- it's an annoying, inelegant circular 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// dependency that I don't know how to resolve nicely!) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  _ ,  issuer  :=  range  ap . magic . Issuers  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  annoying ,  ok  :=  issuer . ( ConfigSetter ) ;  ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											annoying . SetConfig ( ap . magic ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 17:16:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Subjects returns the list of subjects with all placeholders replaced. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								func  ( ap  * AutomationPolicy )  Subjects ( )  [ ] string  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  ap . subjects 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// AllInternalSubjects returns true if all the subjects on this policy are internal. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								func  ( ap  * AutomationPolicy )  AllInternalSubjects ( )  bool  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-25 16:30:56 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  ! slices . ContainsFunc ( ap . subjects ,  func ( s  string )  bool  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ! certmagic . SubjectIsInternal ( s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 10:29:27 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								func  ( ap  * AutomationPolicy )  onlyInternalIssuer ( )  bool  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  len ( ap . Issuers )  !=  1  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									_ ,  ok  :=  ap . Issuers [ 0 ] . ( * InternalIssuer ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  ok 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-20 12:06:00 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// isWildcardOrDefault determines if the subjects include any wildcard domains, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// or is the "default" policy (i.e. no subjects) which is unbounded. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								func  ( ap  * AutomationPolicy )  isWildcardOrDefault ( )  bool  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									isWildcardOrDefault  :=  false 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 17:16:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  len ( ap . subjects )  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-20 12:06:00 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										isWildcardOrDefault  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-27 17:16:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  _ ,  sub  :=  range  ap . subjects  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-20 12:06:00 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  strings . HasPrefix ( sub ,  "*" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											isWildcardOrDefault  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  isWildcardOrDefault 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-02 16:17:26 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// DefaultIssuers returns empty Issuers (not provisioned) to be used as defaults. 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// This function is experimental and has no compatibility promises. 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								func  DefaultIssuers ( userEmail  string )  [ ] certmagic . Issuer  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									issuers  :=  [ ] certmagic . Issuer { new ( ACMEIssuer ) } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  strings . TrimSpace ( userEmail )  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										issuers  =  append ( issuers ,  & ACMEIssuer { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											CA :     certmagic . ZeroSSLProductionCA , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											Email :  userEmail , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  issuers 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-02 16:17:26 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// DefaultIssuersProvisioned returns empty but provisioned default Issuers from 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// DefaultIssuers(). This function is experimental and has no compatibility promises. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								func  DefaultIssuersProvisioned ( ctx  caddy . Context )  ( [ ] certmagic . Issuer ,  error )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									issuers  :=  DefaultIssuers ( "" ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-02 16:17:26 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  i ,  iss  :=  range  issuers  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  prov ,  ok  :=  iss . ( caddy . Provisioner ) ;  ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											err  :=  prov . Provision ( ctx ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  nil ,  fmt . Errorf ( "provisioning default issuer %d: %T: %v" ,  i ,  iss ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-02 16:17:26 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  issuers ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-16 11:05:55 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// ChallengesConfig configures the ACME challenges. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								type  ChallengesConfig  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// HTTP configures the ACME HTTP challenge. This 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// challenge is enabled and used automatically 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// and by default. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									HTTP  * HTTPChallengeConfig  ` json:"http,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// TLSALPN configures the ACME TLS-ALPN challenge. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// This challenge is enabled and used automatically 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// and by default. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									TLSALPN  * TLSALPNChallengeConfig  ` json:"tls-alpn,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Configures the ACME DNS challenge. Because this 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// challenge typically requires credentials for 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// interfacing with a DNS provider, this challenge is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// not enabled by default. This is the only challenge 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// type which does not require a direct connection 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// to Caddy from an external server. 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 15:18:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// NOTE: DNS providers are currently being upgraded, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// and this API is subject to change, but should be 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// stabilized soon. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									DNS  * DNSChallengeConfig  ` json:"dns,omitempty" ` 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-04-06 11:22:06 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Optionally customize the host to which a listener 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// is bound if required for solving a challenge. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									BindHost  string  ` json:"bind_host,omitempty" ` 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// HTTPChallengeConfig configures the ACME HTTP challenge. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								type  HTTPChallengeConfig  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// If true, the HTTP challenge will be disabled. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Disabled  bool  ` json:"disabled,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// An alternate port on which to service this 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// challenge. Note that the HTTP challenge port is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// hard-coded into the spec and cannot be changed, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// so you would have to forward packets from the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// standard HTTP challenge port to this one. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AlternatePort  int  ` json:"alternate_port,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// TLSALPNChallengeConfig configures the ACME TLS-ALPN challenge. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								type  TLSALPNChallengeConfig  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// If true, the TLS-ALPN challenge will be disabled. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Disabled  bool  ` json:"disabled,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// An alternate port on which to service this 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// challenge. Note that the TLS-ALPN challenge port 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// is hard-coded into the spec and cannot be changed, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// so you would have to forward packets from the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// standard TLS-ALPN challenge port to this one. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AlternatePort  int  ` json:"alternate_port,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// DNSChallengeConfig configures the ACME DNS challenge. 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 15:18:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// NOTE: This API is still experimental and is subject to change. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								type  DNSChallengeConfig  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// The DNS provider module to use which will manage 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// the DNS records relevant to the ACME challenge. 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 21:31:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Required. 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-02 16:28:10 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ProviderRaw  json . RawMessage  ` json:"provider,omitempty" caddy:"namespace=dns.providers inline_key=name" ` 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// The TTL of the TXT record used for the DNS challenge. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									TTL  caddy . Duration  ` json:"ttl,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 18:09:11 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// How long to wait before starting propagation checks. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Default: 0 (no wait). 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									PropagationDelay  caddy . Duration  ` json:"propagation_delay,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Maximum time to wait for temporary DNS record to appear. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Set to -1 to disable propagation checks. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Default: 2 minutes. 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 15:18:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									PropagationTimeout  caddy . Duration  ` json:"propagation_timeout,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-21 20:30:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Custom DNS resolvers to prefer over system/built-in defaults. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Often necessary to configure when using split-horizon DNS. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Resolvers  [ ] string  ` json:"resolvers,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-09 03:03:43 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Override the domain to use for the DNS challenge. This 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// is to delegate the challenge to a different domain, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// e.g. one that updates faster or one with a provider API. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									OverrideDomain  string  ` json:"override_domain,omitempty" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-30 15:18:14 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									solver  acmez . Solver 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-30 16:15:20 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-15 21:22:26 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// ConfigSetter is implemented by certmagic.Issuers that 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// need access to a parent certmagic.Config as part of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// their provisioning phase. For example, the ACMEIssuer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// requires a config so it can access storage and the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// cache to solve ACME challenges. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								type  ConfigSetter  interface  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									SetConfig ( cfg  * certmagic . Config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}