Skip to content

Commit dc8e4fa

Browse files
committed
Update PEM of private key after regenerating
Otherwise, leads to mismatched key + cert in storage
1 parent dd8df32 commit dc8e4fa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

config.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,6 @@ func (cfg *Config) storageHasCertResourcesAnyIssuer(ctx context.Context, name st
715715
// and its assets in storage if successful. It DOES NOT update the in-memory
716716
// cache with the new certificate. The certificate will not be renewed if it
717717
// is not close to expiring unless force is true.
718-
//
719-
// Renewing a certificate is the same as obtaining a certificate, except that
720-
// the existing private key already in storage is reused.
721718
func (cfg *Config) RenewCertSync(ctx context.Context, name string, force bool) error {
722719
return cfg.renewCert(ctx, name, force, true)
723720
}
@@ -809,6 +806,14 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
809806
return err
810807
}
811808

809+
// if we generated a new key, make sure to replace its PEM encoding too!
810+
if !cfg.ReusePrivateKeys {
811+
certRes.PrivateKeyPEM, err = PEMEncodePrivateKey(privateKey)
812+
if err != nil {
813+
return err
814+
}
815+
}
816+
812817
csr, err := cfg.generateCSR(privateKey, []string{name})
813818
if err != nil {
814819
return err

0 commit comments

Comments
 (0)