2019-03-11 16:56:48 +00:00
|
|
|
package cmd
|
2018-12-06 21:50:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto"
|
|
|
|
"crypto/x509"
|
2023-05-27 15:05:22 +00:00
|
|
|
"errors"
|
2022-06-15 07:08:24 +00:00
|
|
|
"math/rand"
|
2022-06-17 09:15:20 +00:00
|
|
|
"os"
|
2018-12-06 21:50:17 +00:00
|
|
|
"time"
|
|
|
|
|
2023-05-27 15:05:22 +00:00
|
|
|
"github.com/go-acme/lego/v4/acme/api"
|
2020-09-02 01:20:01 +00:00
|
|
|
"github.com/go-acme/lego/v4/certcrypto"
|
|
|
|
"github.com/go-acme/lego/v4/certificate"
|
|
|
|
"github.com/go-acme/lego/v4/lego"
|
|
|
|
"github.com/go-acme/lego/v4/log"
|
2022-06-17 09:15:20 +00:00
|
|
|
"github.com/mattn/go-isatty"
|
2022-02-13 11:28:51 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-12-06 21:50:17 +00:00
|
|
|
)
|
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
// Flag names.
|
|
|
|
const (
|
|
|
|
flgDays = "days"
|
|
|
|
flgARIEnable = "ari-enable"
|
|
|
|
flgARIWaitToRenewDuration = "ari-wait-to-renew-duration"
|
|
|
|
flgReuseKey = "reuse-key"
|
|
|
|
flgRenewHook = "renew-hook"
|
|
|
|
flgNoRandomSleep = "no-random-sleep"
|
|
|
|
)
|
|
|
|
|
2020-04-11 12:57:06 +00:00
|
|
|
const (
|
2024-04-17 13:09:06 +00:00
|
|
|
renewEnvAccountEmail = "LEGO_ACCOUNT_EMAIL"
|
|
|
|
renewEnvCertDomain = "LEGO_CERT_DOMAIN"
|
|
|
|
renewEnvCertPath = "LEGO_CERT_PATH"
|
|
|
|
renewEnvCertKeyPath = "LEGO_CERT_KEY_PATH"
|
|
|
|
renewEnvIssuerCertKeyPath = "LEGO_ISSUER_CERT_PATH"
|
|
|
|
renewEnvCertPEMPath = "LEGO_CERT_PEM_PATH"
|
|
|
|
renewEnvCertPFXPath = "LEGO_CERT_PFX_PATH"
|
2020-04-11 12:57:06 +00:00
|
|
|
)
|
|
|
|
|
2022-02-13 11:28:51 +00:00
|
|
|
func createRenew() *cli.Command {
|
|
|
|
return &cli.Command{
|
2018-12-06 21:50:17 +00:00
|
|
|
Name: "renew",
|
|
|
|
Usage: "Renew a certificate",
|
|
|
|
Action: renew,
|
|
|
|
Before: func(ctx *cli.Context) error {
|
|
|
|
// we require either domains or csr, but not both
|
2024-09-20 17:47:50 +00:00
|
|
|
hasDomains := len(ctx.StringSlice(flgDomains)) > 0
|
|
|
|
hasCsr := ctx.String(flgCSR) != ""
|
2018-12-06 21:50:17 +00:00
|
|
|
if hasDomains && hasCsr {
|
2024-09-20 17:47:50 +00:00
|
|
|
log.Fatal("Please specify either --%s/-d or --%s/-c, but not both", flgDomains, flgCSR)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
if !hasDomains && !hasCsr {
|
2024-09-20 17:47:50 +00:00
|
|
|
log.Fatal("Please specify --%s/-d (or --%s/-c if you already have a CSR)", flgDomains, flgCSR)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Flags: []cli.Flag{
|
2022-02-13 11:28:51 +00:00
|
|
|
&cli.IntFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgDays,
|
2019-02-08 01:43:05 +00:00
|
|
|
Value: 30,
|
2018-12-06 21:50:17 +00:00
|
|
|
Usage: "The number of days left on a certificate to renew it.",
|
|
|
|
},
|
2023-05-27 15:05:22 +00:00
|
|
|
&cli.BoolFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgARIEnable,
|
2023-05-27 15:05:22 +00:00
|
|
|
Usage: "Use the renewalInfo endpoint (draft-ietf-acme-ari) to check if a certificate should be renewed.",
|
|
|
|
},
|
|
|
|
&cli.DurationFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgARIWaitToRenewDuration,
|
2023-05-27 15:05:22 +00:00
|
|
|
Usage: "The maximum duration you're willing to sleep for a renewal time returned by the renewalInfo endpoint.",
|
|
|
|
},
|
2022-02-13 11:28:51 +00:00
|
|
|
&cli.BoolFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgReuseKey,
|
2018-12-06 21:50:17 +00:00
|
|
|
Usage: "Used to indicate you want to reuse your current private key for the new certificate.",
|
|
|
|
},
|
2022-02-13 11:28:51 +00:00
|
|
|
&cli.BoolFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgNoBundle,
|
2018-12-06 21:50:17 +00:00
|
|
|
Usage: "Do not create a certificate bundle by adding the issuers certificate to the new certificate.",
|
|
|
|
},
|
2022-02-13 11:28:51 +00:00
|
|
|
&cli.BoolFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgMustStaple,
|
2023-01-08 13:53:15 +00:00
|
|
|
Usage: "Include the OCSP must staple TLS extension in the CSR and generated certificate." +
|
|
|
|
" Only works if the CSR is generated by lego.",
|
2018-12-06 21:50:17 +00:00
|
|
|
},
|
2023-05-28 14:45:48 +00:00
|
|
|
&cli.TimestampFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgNotBefore,
|
2023-05-28 14:45:48 +00:00
|
|
|
Usage: "Set the notBefore field in the certificate (RFC3339 format)",
|
|
|
|
Layout: time.RFC3339,
|
|
|
|
},
|
|
|
|
&cli.TimestampFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgNotAfter,
|
2023-05-28 14:45:48 +00:00
|
|
|
Usage: "Set the notAfter field in the certificate (RFC3339 format)",
|
|
|
|
Layout: time.RFC3339,
|
2019-04-02 16:38:23 +00:00
|
|
|
},
|
2022-02-13 11:28:51 +00:00
|
|
|
&cli.StringFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgPreferredChain,
|
2023-01-08 13:53:15 +00:00
|
|
|
Usage: "If the CA offers multiple certificate chains, prefer the chain with an issuer matching this Subject Common Name." +
|
|
|
|
" If no match, the default offered chain will be used.",
|
2020-09-02 00:22:53 +00:00
|
|
|
},
|
2022-02-13 11:28:51 +00:00
|
|
|
&cli.StringFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgAlwaysDeactivateAuthorizations,
|
2021-09-08 21:14:21 +00:00
|
|
|
Usage: "Force the authorizations to be relinquished even if the certificate request was successful.",
|
|
|
|
},
|
2023-05-28 14:45:48 +00:00
|
|
|
&cli.StringFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgRenewHook,
|
2023-05-28 14:45:48 +00:00
|
|
|
Usage: "Define a hook. The hook is executed only when the certificates are effectively renewed.",
|
|
|
|
},
|
2022-06-15 07:08:24 +00:00
|
|
|
&cli.BoolFlag{
|
2024-09-20 17:47:50 +00:00
|
|
|
Name: flgNoRandomSleep,
|
2023-01-08 13:53:15 +00:00
|
|
|
Usage: "Do not add a random sleep before the renewal." +
|
|
|
|
" We do not recommend using this flag if you are doing your renewals in an automated way.",
|
2022-06-15 07:08:24 +00:00
|
|
|
},
|
2018-12-06 21:50:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func renew(ctx *cli.Context) error {
|
|
|
|
account, client := setup(ctx, NewAccountsStorage(ctx))
|
2019-03-11 15:54:35 +00:00
|
|
|
setupChallenges(ctx, client)
|
2018-12-06 21:50:17 +00:00
|
|
|
|
|
|
|
if account.Registration == nil {
|
|
|
|
log.Fatalf("Account %s is not registered. Use 'run' to register a new account.\n", account.Email)
|
|
|
|
}
|
|
|
|
|
|
|
|
certsStorage := NewCertificatesStorage(ctx)
|
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
bundle := !ctx.Bool(flgNoBundle)
|
2018-12-06 21:50:17 +00:00
|
|
|
|
2020-04-11 12:57:06 +00:00
|
|
|
meta := map[string]string{renewEnvAccountEmail: account.Email}
|
|
|
|
|
2018-12-06 21:50:17 +00:00
|
|
|
// CSR
|
2024-09-20 17:47:50 +00:00
|
|
|
if ctx.IsSet(flgCSR) {
|
2020-04-11 12:57:06 +00:00
|
|
|
return renewForCSR(ctx, client, certsStorage, bundle, meta)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Domains
|
2020-04-11 12:57:06 +00:00
|
|
|
return renewForDomains(ctx, client, certsStorage, bundle, meta)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 12:57:06 +00:00
|
|
|
func renewForDomains(ctx *cli.Context, client *lego.Client, certsStorage *CertificatesStorage, bundle bool, meta map[string]string) error {
|
2024-09-20 17:47:50 +00:00
|
|
|
domains := ctx.StringSlice(flgDomains)
|
2018-12-06 21:50:17 +00:00
|
|
|
domain := domains[0]
|
|
|
|
|
|
|
|
// load the cert resource from files.
|
|
|
|
// We store the certificate, private key and metadata in different files
|
|
|
|
// as web servers would not be able to work with a combined file.
|
2024-09-20 17:47:50 +00:00
|
|
|
certificates, err := certsStorage.ReadCertificate(domain, certExt)
|
2018-12-06 21:50:17 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error while loading the certificate for domain %s\n\t%v", domain, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cert := certificates[0]
|
|
|
|
|
2023-05-27 15:05:22 +00:00
|
|
|
var ariRenewalTime *time.Time
|
2024-09-20 17:47:50 +00:00
|
|
|
if ctx.Bool(flgARIEnable) {
|
2024-01-24 21:02:50 +00:00
|
|
|
ariRenewalTime = getARIRenewalTime(ctx, cert, domain, client)
|
2023-05-27 15:05:22 +00:00
|
|
|
if ariRenewalTime != nil {
|
|
|
|
now := time.Now().UTC()
|
|
|
|
// Figure out if we need to sleep before renewing.
|
|
|
|
if ariRenewalTime.After(now) {
|
|
|
|
log.Infof("[%s] Sleeping %s until renewal time %s", domain, ariRenewalTime.Sub(now), ariRenewalTime)
|
|
|
|
time.Sleep(ariRenewalTime.Sub(now))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
if ariRenewalTime == nil && !needRenewal(cert, domain, ctx.Int(flgDays)) {
|
2018-12-06 21:50:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is just meant to be informal for the user.
|
|
|
|
timeLeft := cert.NotAfter.Sub(time.Now().UTC())
|
|
|
|
log.Infof("[%s] acme: Trying renewal with %d hours remaining", domain, int(timeLeft.Hours()))
|
|
|
|
|
|
|
|
certDomains := certcrypto.ExtractDomains(cert)
|
|
|
|
|
|
|
|
var privateKey crypto.PrivateKey
|
2024-09-20 17:47:50 +00:00
|
|
|
if ctx.Bool(flgReuseKey) {
|
|
|
|
keyBytes, errR := certsStorage.ReadFile(domain, keyExt)
|
2018-12-06 21:50:17 +00:00
|
|
|
if errR != nil {
|
|
|
|
log.Fatalf("Error while loading the private key for domain %s\n\t%v", domain, errR)
|
|
|
|
}
|
|
|
|
|
|
|
|
privateKey, errR = certcrypto.ParsePEMPrivateKey(keyBytes)
|
|
|
|
if errR != nil {
|
|
|
|
return errR
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-17 09:15:20 +00:00
|
|
|
// https://github.com/go-acme/lego/issues/1656
|
|
|
|
// https://github.com/certbot/certbot/blob/284023a1b7672be2bd4018dd7623b3b92197d4b0/certbot/certbot/_internal/renewal.py#L435-L440
|
2024-09-20 17:47:50 +00:00
|
|
|
if !isatty.IsTerminal(os.Stdout.Fd()) && !ctx.Bool(flgNoRandomSleep) {
|
2022-06-15 07:08:24 +00:00
|
|
|
// https://github.com/certbot/certbot/blob/284023a1b7672be2bd4018dd7623b3b92197d4b0/certbot/certbot/_internal/renewal.py#L472
|
|
|
|
const jitter = 8 * time.Minute
|
|
|
|
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
sleepTime := time.Duration(rnd.Int63n(int64(jitter)))
|
|
|
|
|
|
|
|
log.Infof("renewal: random delay of %s", sleepTime)
|
|
|
|
time.Sleep(sleepTime)
|
|
|
|
}
|
|
|
|
|
2018-12-06 21:50:17 +00:00
|
|
|
request := certificate.ObtainRequest{
|
2021-09-08 21:14:21 +00:00
|
|
|
Domains: merge(certDomains, domains),
|
|
|
|
PrivateKey: privateKey,
|
2024-09-20 17:47:50 +00:00
|
|
|
MustStaple: ctx.Bool(flgMustStaple),
|
|
|
|
NotBefore: getTime(ctx, flgNotBefore),
|
|
|
|
NotAfter: getTime(ctx, flgNotAfter),
|
2023-05-28 14:45:48 +00:00
|
|
|
Bundle: bundle,
|
2024-09-20 17:47:50 +00:00
|
|
|
PreferredChain: ctx.String(flgPreferredChain),
|
|
|
|
AlwaysDeactivateAuthorizations: ctx.Bool(flgAlwaysDeactivateAuthorizations),
|
2024-03-10 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
if ctx.Bool(flgARIEnable) {
|
2024-03-10 23:04:53 +00:00
|
|
|
request.ReplacesCertID, err = certificate.MakeARICertID(cert)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error while construction the ARI CertID for domain %s\n\t%v", domain, err)
|
|
|
|
}
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
2023-05-28 14:45:48 +00:00
|
|
|
|
2018-12-06 21:50:17 +00:00
|
|
|
certRes, err := client.Certificate.Obtain(request)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
certsStorage.SaveResource(certRes)
|
|
|
|
|
2024-04-17 13:09:06 +00:00
|
|
|
addPathToMetadata(meta, domain, certRes, certsStorage)
|
2020-04-11 12:57:06 +00:00
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
return launchHook(ctx.String(flgRenewHook), meta)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 12:57:06 +00:00
|
|
|
func renewForCSR(ctx *cli.Context, client *lego.Client, certsStorage *CertificatesStorage, bundle bool, meta map[string]string) error {
|
2024-09-20 17:47:50 +00:00
|
|
|
csr, err := readCSRFile(ctx.String(flgCSR))
|
2018-12-06 21:50:17 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2024-01-26 23:16:47 +00:00
|
|
|
domain, err := certcrypto.GetCSRMainDomain(csr)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error: %v", err)
|
|
|
|
}
|
2018-12-06 21:50:17 +00:00
|
|
|
|
|
|
|
// load the cert resource from files.
|
|
|
|
// We store the certificate, private key and metadata in different files
|
|
|
|
// as web servers would not be able to work with a combined file.
|
2024-09-20 17:47:50 +00:00
|
|
|
certificates, err := certsStorage.ReadCertificate(domain, certExt)
|
2018-12-06 21:50:17 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error while loading the certificate for domain %s\n\t%v", domain, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cert := certificates[0]
|
|
|
|
|
2023-05-27 15:05:22 +00:00
|
|
|
var ariRenewalTime *time.Time
|
2024-09-20 17:47:50 +00:00
|
|
|
if ctx.Bool(flgARIEnable) {
|
2024-01-24 21:02:50 +00:00
|
|
|
ariRenewalTime = getARIRenewalTime(ctx, cert, domain, client)
|
2023-05-27 15:05:22 +00:00
|
|
|
if ariRenewalTime != nil {
|
|
|
|
now := time.Now().UTC()
|
|
|
|
// Figure out if we need to sleep before renewing.
|
|
|
|
if ariRenewalTime.After(now) {
|
|
|
|
log.Infof("[%s] Sleeping %s until renewal time %s", domain, ariRenewalTime.Sub(now), ariRenewalTime)
|
|
|
|
time.Sleep(ariRenewalTime.Sub(now))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
if ariRenewalTime == nil && !needRenewal(cert, domain, ctx.Int(flgDays)) {
|
2018-12-06 21:50:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is just meant to be informal for the user.
|
|
|
|
timeLeft := cert.NotAfter.Sub(time.Now().UTC())
|
|
|
|
log.Infof("[%s] acme: Trying renewal with %d hours remaining", domain, int(timeLeft.Hours()))
|
|
|
|
|
2023-05-28 14:45:48 +00:00
|
|
|
request := certificate.ObtainForCSRRequest{
|
2021-09-08 21:14:21 +00:00
|
|
|
CSR: csr,
|
2024-09-20 17:47:50 +00:00
|
|
|
NotBefore: getTime(ctx, flgNotBefore),
|
|
|
|
NotAfter: getTime(ctx, flgNotAfter),
|
2021-09-08 21:14:21 +00:00
|
|
|
Bundle: bundle,
|
2024-09-20 17:47:50 +00:00
|
|
|
PreferredChain: ctx.String(flgPreferredChain),
|
|
|
|
AlwaysDeactivateAuthorizations: ctx.Bool(flgAlwaysDeactivateAuthorizations),
|
2024-03-10 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
if ctx.Bool(flgARIEnable) {
|
2024-03-10 23:04:53 +00:00
|
|
|
request.ReplacesCertID, err = certificate.MakeARICertID(cert)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error while construction the ARI CertID for domain %s\n\t%v", domain, err)
|
|
|
|
}
|
2023-05-28 14:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
certRes, err := client.Certificate.ObtainForCSR(request)
|
2018-12-06 21:50:17 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
certsStorage.SaveResource(certRes)
|
|
|
|
|
2024-04-17 13:09:06 +00:00
|
|
|
addPathToMetadata(meta, domain, certRes, certsStorage)
|
2024-04-16 21:10:59 +00:00
|
|
|
|
2024-09-20 17:47:50 +00:00
|
|
|
return launchHook(ctx.String(flgRenewHook), meta)
|
2018-12-06 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func needRenewal(x509Cert *x509.Certificate, domain string, days int) bool {
|
|
|
|
if x509Cert.IsCA {
|
|
|
|
log.Fatalf("[%s] Certificate bundle starts with a CA certificate", domain)
|
|
|
|
}
|
|
|
|
|
|
|
|
if days >= 0 {
|
2019-03-11 16:08:48 +00:00
|
|
|
notAfter := int(time.Until(x509Cert.NotAfter).Hours() / 24.0)
|
|
|
|
if notAfter > days {
|
|
|
|
log.Printf("[%s] The certificate expires in %d days, the number of days defined to perform the renewal is %d: no renewal.",
|
|
|
|
domain, notAfter, days)
|
2018-12-06 21:50:17 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-05-27 15:05:22 +00:00
|
|
|
// getARIRenewalTime checks if the certificate needs to be renewed using the renewalInfo endpoint.
|
2024-01-24 21:02:50 +00:00
|
|
|
func getARIRenewalTime(ctx *cli.Context, cert *x509.Certificate, domain string, client *lego.Client) *time.Time {
|
2023-05-27 15:05:22 +00:00
|
|
|
if cert.IsCA {
|
|
|
|
log.Fatalf("[%s] Certificate bundle starts with a CA certificate", domain)
|
|
|
|
}
|
|
|
|
|
2024-01-24 21:02:50 +00:00
|
|
|
renewalInfo, err := client.Certificate.GetRenewalInfo(certificate.RenewalInfoRequest{Cert: cert})
|
2023-05-27 15:05:22 +00:00
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, api.ErrNoARI) {
|
|
|
|
// The server does not advertise a renewal info endpoint.
|
2024-01-24 21:02:50 +00:00
|
|
|
log.Warnf("[%s] acme: %v", domain, err)
|
2023-05-27 15:05:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2024-01-24 21:02:50 +00:00
|
|
|
log.Warnf("[%s] acme: calling renewal info endpoint: %v", domain, err)
|
2023-05-27 15:05:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UTC()
|
2024-09-20 17:47:50 +00:00
|
|
|
renewalTime := renewalInfo.ShouldRenewAt(now, ctx.Duration(flgARIWaitToRenewDuration))
|
2023-05-27 15:05:22 +00:00
|
|
|
if renewalTime == nil {
|
|
|
|
log.Infof("[%s] acme: renewalInfo endpoint indicates that renewal is not needed", domain)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
log.Infof("[%s] acme: renewalInfo endpoint indicates that renewal is needed", domain)
|
|
|
|
|
|
|
|
if renewalInfo.ExplanationURL != "" {
|
|
|
|
log.Infof("[%s] acme: renewalInfo endpoint provided an explanation: %s", domain, renewalInfo.ExplanationURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
return renewalTime
|
|
|
|
}
|
|
|
|
|
2024-04-17 13:09:06 +00:00
|
|
|
func addPathToMetadata(meta map[string]string, domain string, certRes *certificate.Resource, certsStorage *CertificatesStorage) {
|
|
|
|
meta[renewEnvCertDomain] = domain
|
|
|
|
meta[renewEnvCertPath] = certsStorage.GetFileName(domain, certExt)
|
|
|
|
meta[renewEnvCertKeyPath] = certsStorage.GetFileName(domain, keyExt)
|
|
|
|
|
|
|
|
if certRes.IssuerCertificate != nil {
|
|
|
|
meta[renewEnvIssuerCertKeyPath] = certsStorage.GetFileName(domain, issuerExt)
|
|
|
|
}
|
|
|
|
|
|
|
|
if certsStorage.pem {
|
|
|
|
meta[renewEnvCertPEMPath] = certsStorage.GetFileName(domain, pemExt)
|
|
|
|
}
|
|
|
|
|
|
|
|
if certsStorage.pfx {
|
|
|
|
meta[renewEnvCertPFXPath] = certsStorage.GetFileName(domain, pfxExt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 23:48:18 +00:00
|
|
|
func merge(prevDomains, nextDomains []string) []string {
|
2018-12-06 21:50:17 +00:00
|
|
|
for _, next := range nextDomains {
|
|
|
|
var found bool
|
|
|
|
for _, prev := range prevDomains {
|
|
|
|
if prev == next {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
prevDomains = append(prevDomains, next)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return prevDomains
|
|
|
|
}
|