mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-20 21:51:42 +00:00
cmd/derper: provide support for forcing autocert renewals
Change-Id: I127a803144ec5ca989823610f1bbd21dc5cfadba Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
1af26222b6
commit
b1cf0a04d6
@ -10,8 +10,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/acme/autocert"
|
"golang.org/x/crypto/acme/autocert"
|
||||||
)
|
)
|
||||||
@ -39,6 +42,24 @@ func certProviderByCertMode(mode, dir, hostname string) (certProvider, error) {
|
|||||||
if hostname == "derp.tailscale.com" {
|
if hostname == "derp.tailscale.com" {
|
||||||
certManager.HostPolicy = prodAutocertHostPolicy
|
certManager.HostPolicy = prodAutocertHostPolicy
|
||||||
certManager.Email = "security@tailscale.com"
|
certManager.Email = "security@tailscale.com"
|
||||||
|
if v, err := os.ReadFile("/home/derp/forcerenew.secret"); err == nil {
|
||||||
|
proto := strings.TrimSpace(string(v))
|
||||||
|
am2 := *certManager
|
||||||
|
am2.RenewBefore = 89 * 24 * time.Hour
|
||||||
|
defGetCertificate := certManager.TLSConfig().GetCertificate
|
||||||
|
tlsConf2 := am2.TLSConfig()
|
||||||
|
getCertificate := func(hi *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||||
|
for _, p := range hi.SupportedProtos {
|
||||||
|
if p == proto {
|
||||||
|
return tlsConf2.GetCertificate(hi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defGetCertificate(hi)
|
||||||
|
}
|
||||||
|
altConf := certManager.TLSConfig()
|
||||||
|
altConf.GetCertificate = getCertificate
|
||||||
|
return altConfig{certManager, altConf}, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return certManager, nil
|
return certManager, nil
|
||||||
case "manual":
|
case "manual":
|
||||||
@ -48,6 +69,14 @@ func certProviderByCertMode(mode, dir, hostname string) (certProvider, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// altConfig is a certProvider wrapper that returns an explicit tls.Config.
|
||||||
|
type altConfig struct {
|
||||||
|
certProvider
|
||||||
|
tlsConfig *tls.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac altConfig) TLSConfig() *tls.Config { return ac.tlsConfig }
|
||||||
|
|
||||||
type manualCertManager struct {
|
type manualCertManager struct {
|
||||||
cert *tls.Certificate
|
cert *tls.Certificate
|
||||||
hostname string
|
hostname string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user