Skip to content

Commit eb2dc85

Browse files
committed
Added ACMECAURL option to support custom ACME provider
Closes #18306 Signed-off-by: Cristian Le <[email protected]>
1 parent 6c7084c commit eb2dc85

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cmd/web_letsencrypt.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package cmd
66

77
import (
8+
"crypto/x509"
9+
"encoding/pem"
10+
"io/ioutil"
811
"net/http"
912
"strconv"
1013
"strings"
@@ -34,7 +37,26 @@ func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler)
3437

3538
magic := certmagic.NewDefault()
3639
magic.Storage = &certmagic.FileStorage{Path: directory}
40+
// Try to use private CA root if provided, otherwise defaults to system's trust
41+
var CertPool *x509.CertPool = nil
42+
if setting.ACMECARoot != "" {
43+
r, err := ioutil.ReadFile(setting.ACMECARoot)
44+
if err != nil {
45+
log.Warn("Failed to read CARoot certificate, using default CA trust: %v", err)
46+
} else {
47+
block, _ := pem.Decode(r)
48+
CARoot, err := x509.ParseCertificate(block.Bytes)
49+
if err != nil {
50+
log.Warn("Failed to parse CARoot certificate, using default CA trust: %v", err)
51+
} else {
52+
CertPool = x509.NewCertPool()
53+
CertPool.AddCert(CARoot)
54+
}
55+
}
56+
}
3757
myACME := certmagic.NewACMEManager(magic, certmagic.ACMEManager{
58+
CA: setting.ACMECAURL,
59+
TrustedRoots: CertPool,
3860
Email: email,
3961
Agreed: setting.LetsEncryptTOS,
4062
DisableHTTPChallenge: !enableHTTPChallenge,

modules/setting/setting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ var (
113113
LetsEncryptTOS bool
114114
LetsEncryptDirectory string
115115
LetsEncryptEmail string
116+
ACMECAURL string
117+
ACMECARoot string
116118
SSLMinimumVersion string
117119
SSLMaximumVersion string
118120
SSLCurvePreferences []string
@@ -654,6 +656,8 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
654656
}
655657
}
656658
EnableLetsEncrypt = sec.Key("ENABLE_LETSENCRYPT").MustBool(false)
659+
ACMECAURL = sec.Key("ACME_CAURL").MustString("")
660+
ACMECARoot = sec.Key("ACME_CARoot").MustString("")
657661
LetsEncryptTOS = sec.Key("LETSENCRYPT_ACCEPTTOS").MustBool(false)
658662
if !LetsEncryptTOS && EnableLetsEncrypt {
659663
log.Warn("Failed to enable Let's Encrypt due to Let's Encrypt TOS not being accepted")

0 commit comments

Comments
 (0)