mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-21 23:39:43 +00:00
Default shortlived only when both ACME endpoints are Let's Encrypt.
This commit is contained in:
parent
646bffc0e2
commit
01beb67ce8
2 changed files with 32 additions and 21 deletions
|
|
@ -47,20 +47,27 @@ const (
|
|||
letsEncryptShortlivedProfile = "shortlived"
|
||||
)
|
||||
|
||||
// letsEncryptProfile returns the profile sent to the CA.
|
||||
// Let's Encrypt defaults to the shortlived profile. An explicit
|
||||
// profile, including "classic", is left alone. Other CAs do not
|
||||
// get a profile unless one was configured.
|
||||
func letsEncryptProfile(ca, profile string) string {
|
||||
func letsEncryptDirectory(ca string) bool {
|
||||
switch ca {
|
||||
case "", letsEncryptProductionDirectory, letsEncryptStagingDirectory:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// letsEncryptProfile returns the profile sent to both the CA and TestCA.
|
||||
// CertMagic uses one profile for both endpoints, so the shortlived default
|
||||
// applies only when each endpoint is Let's Encrypt. An explicit profile,
|
||||
// including "classic", is left alone. A custom CA or TestCA gets no default.
|
||||
func letsEncryptProfile(ca, testCA, profile string) string {
|
||||
if profile != "" {
|
||||
return profile
|
||||
}
|
||||
switch ca {
|
||||
case "", letsEncryptProductionDirectory, letsEncryptStagingDirectory:
|
||||
if letsEncryptDirectory(ca) && letsEncryptDirectory(testCA) {
|
||||
return letsEncryptShortlivedProfile
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ACMEIssuer manages certificates using the ACME protocol (RFC 8555).
|
||||
|
|
@ -86,11 +93,12 @@ type ACMEIssuer struct {
|
|||
// orders. Must be a profile name offered by the ACME server,
|
||||
// which are listed at its directory endpoint.
|
||||
//
|
||||
// When this is empty and the CA is Let's Encrypt (the default
|
||||
// directory, or either of Let's Encrypt's public directories),
|
||||
// Caddy asks for the "shortlived" profile. Set this to "classic"
|
||||
// to keep Let's Encrypt's long-lived profile. Other CAs are
|
||||
// unchanged when this is empty.
|
||||
// When this is empty and both the CA and the test CA are Let's
|
||||
// Encrypt (the default directories, or either public directory),
|
||||
// Caddy asks for the "shortlived" profile. The same profile is
|
||||
// sent to both endpoints, so a custom test CA does not get that
|
||||
// default. Set this to "classic" to keep Let's Encrypt's
|
||||
// long-lived profile.
|
||||
//
|
||||
// EXPERIMENTAL: Subject to change.
|
||||
// See https://datatracker.ietf.org/doc/draft-aaron-acme-profiles/
|
||||
|
|
@ -284,7 +292,7 @@ func (iss *ACMEIssuer) makeIssuerTemplate(ctx caddy.Context) (certmagic.ACMEIssu
|
|||
CA: iss.CA,
|
||||
TestCA: iss.TestCA,
|
||||
Email: iss.Email,
|
||||
Profile: letsEncryptProfile(iss.CA, iss.Profile),
|
||||
Profile: letsEncryptProfile(iss.CA, iss.TestCA, iss.Profile),
|
||||
AccountKeyPEM: iss.AccountKey,
|
||||
CertObtainTimeout: time.Duration(iss.ACMETimeout),
|
||||
TrustedRoots: iss.rootPool,
|
||||
|
|
|
|||
|
|
@ -7,21 +7,24 @@ import (
|
|||
)
|
||||
|
||||
func TestLetsEncryptProfileDefault(t *testing.T) {
|
||||
if got := letsEncryptProfile("", ""); got != letsEncryptShortlivedProfile {
|
||||
t.Fatalf("default Let's Encrypt CA: got %q, want %q", got, letsEncryptShortlivedProfile)
|
||||
if got := letsEncryptProfile("", "", ""); got != letsEncryptShortlivedProfile {
|
||||
t.Fatalf("default Let's Encrypt endpoints: got %q, want %q", got, letsEncryptShortlivedProfile)
|
||||
}
|
||||
if got := letsEncryptProfile(letsEncryptProductionDirectory, ""); got != letsEncryptShortlivedProfile {
|
||||
if got := letsEncryptProfile(letsEncryptProductionDirectory, "", ""); got != letsEncryptShortlivedProfile {
|
||||
t.Fatalf("production directory: got %q, want %q", got, letsEncryptShortlivedProfile)
|
||||
}
|
||||
if got := letsEncryptProfile(letsEncryptStagingDirectory, ""); got != letsEncryptShortlivedProfile {
|
||||
if got := letsEncryptProfile(letsEncryptStagingDirectory, letsEncryptStagingDirectory, ""); got != letsEncryptShortlivedProfile {
|
||||
t.Fatalf("staging directory: got %q, want %q", got, letsEncryptShortlivedProfile)
|
||||
}
|
||||
if got := letsEncryptProfile("", "classic"); got != "classic" {
|
||||
if got := letsEncryptProfile("", "", "classic"); got != "classic" {
|
||||
t.Fatalf("long-lived opt-out: got %q, want classic", got)
|
||||
}
|
||||
if got := letsEncryptProfile("https://acme.example.com/directory", ""); got != "" {
|
||||
if got := letsEncryptProfile("https://acme.example.com/directory", "", ""); got != "" {
|
||||
t.Fatalf("other CA: got %q, want empty", got)
|
||||
}
|
||||
if got := letsEncryptProfile("", "https://acme.example.com/directory", ""); got != "" {
|
||||
t.Fatalf("custom TestCA: got %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestACMEIssuerExpandPlaceholders(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue