mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 07:43:17 +00:00
caddytls: Support multiple issuers (#3862)
* caddytls: Support multiple issuers Defaults are Let's Encrypt and ZeroSSL. There are probably bugs. * Commit updated integration tests, d'oh * Update go.mod
This commit is contained in:
parent
7a3d9d81fe
commit
13781e67ab
13 changed files with 310 additions and 237 deletions
|
@ -137,7 +137,7 @@ func (t *TLS) Provision(ctx caddy.Context) error {
|
|||
continue
|
||||
}
|
||||
t.Automation.defaultInternalAutomationPolicy = &AutomationPolicy{
|
||||
IssuerRaw: json.RawMessage(`{"module":"internal"}`),
|
||||
IssuersRaw: []json.RawMessage{json.RawMessage(`{"module":"internal"}`)},
|
||||
}
|
||||
err = t.Automation.defaultInternalAutomationPolicy.Provision(t)
|
||||
if err != nil {
|
||||
|
@ -303,20 +303,22 @@ func (t *TLS) Manage(names []string) error {
|
|||
|
||||
// HandleHTTPChallenge ensures that the HTTP challenge is handled for the
|
||||
// certificate named by r.Host, if it is an HTTP challenge request. It
|
||||
// requires that the automation policy for r.Host has an issue of type
|
||||
// *certmagic.ACMEManager.
|
||||
// requires that the automation policy for r.Host has an issuer of type
|
||||
// *certmagic.ACMEManager, or one that is ACME-enabled (GetACMEIssuer()).
|
||||
func (t *TLS) HandleHTTPChallenge(w http.ResponseWriter, r *http.Request) bool {
|
||||
if !certmagic.LooksLikeHTTPChallenge(r) {
|
||||
return false
|
||||
}
|
||||
// try all the issuers until we find the one that initiated the challenge
|
||||
ap := t.getAutomationPolicyForName(r.Host)
|
||||
if ap.magic.Issuer == nil {
|
||||
return false
|
||||
}
|
||||
type acmeCapable interface{ GetACMEIssuer() *ACMEIssuer }
|
||||
if am, ok := ap.magic.Issuer.(acmeCapable); ok {
|
||||
iss := am.GetACMEIssuer()
|
||||
return certmagic.NewACMEManager(iss.magic, iss.template).HandleHTTPChallenge(w, r)
|
||||
for _, iss := range ap.magic.Issuers {
|
||||
if am, ok := iss.(acmeCapable); ok {
|
||||
iss := am.GetACMEIssuer()
|
||||
if certmagic.NewACMEManager(iss.magic, iss.template).HandleHTTPChallenge(w, r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue