Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 13:15 UTC
httpcaddyfile: Set challenge ports when http_port or https_port are used
Matthew Holt committed
May 11, 2024 at 21:39 UTC
583c585c81ac4bcf94fb2046b695f64a83b41cf7
2 files changed
+27
-1
caddyconfig/httpcaddyfile/tlsapp.go
+19
-1
@@ -457,6 +457,7 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
457
globalACMEEAB := options["acme_eab"]
458
globalPreferredChains := options["preferred_chains"]
459
globalCertLifetime := options["cert_lifetime"]
460
+ globalHTTPPort, globalHTTPSPort := options["http_port"], options["https_port"]
461
462
if globalEmail != nil && acmeIssuer.Email == "" {
463
acmeIssuer.Email = globalEmail.(string)
@@ -480,7 +481,24 @@ func fillInGlobalACMEDefaults(issuer certmagic.Issuer, options map[string]any) e
481
if globalPreferredChains != nil && acmeIssuer.PreferredChains == nil {
482
acmeIssuer.PreferredChains = globalPreferredChains.(*caddytls.ChainPreference)
483
}
483
-
484
+ if globalHTTPPort != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.HTTP == nil || acmeIssuer.Challenges.HTTP.AlternatePort == 0) {
485
+ if acmeIssuer.Challenges == nil {
486
+ acmeIssuer.Challenges = new(caddytls.ChallengesConfig)
487
+ }
488
+ if acmeIssuer.Challenges.HTTP == nil {
489
+ acmeIssuer.Challenges.HTTP = new(caddytls.HTTPChallengeConfig)
490
+ }
491
+ acmeIssuer.Challenges.HTTP.AlternatePort = globalHTTPPort.(int)
492
+ }
493
+ if globalHTTPSPort != nil && (acmeIssuer.Challenges == nil || acmeIssuer.Challenges.TLSALPN == nil || acmeIssuer.Challenges.TLSALPN.AlternatePort == 0) {
494
+ if acmeIssuer.Challenges == nil {
495
+ acmeIssuer.Challenges = new(caddytls.ChallengesConfig)
496
+ }
497
+ if acmeIssuer.Challenges.TLSALPN == nil {
498
+ acmeIssuer.Challenges.TLSALPN = new(caddytls.TLSALPNChallengeConfig)
499
+ }
500
+ acmeIssuer.Challenges.TLSALPN.AlternatePort = globalHTTPSPort.(int)
501
+ }
502
if globalCertLifetime != nil && acmeIssuer.CertificateLifetime == 0 {
503
acmeIssuer.CertificateLifetime = globalCertLifetime.(caddy.Duration)
504
}
caddytest/integration/caddyfile_adapt/global_options_acme.caddyfiletest
+8
@@ -63,6 +63,14 @@
63
"issuers": [
64
{
65
"ca": "https://example.com",
66
+ "challenges": {
67
+ "http": {
68
+ "alternate_port": 8080
69
+ },
70
+ "tls-alpn": {
71
+ "alternate_port": 8443
72
+ }
73
+ },
74
"email": "test@example.com",
75
"external_account": {
76
"key_id": "4K2scIVbBpNd-78scadB2g",