Skip to content

Commit

Permalink
Update PEM of private key after regenerating
Browse files Browse the repository at this point in the history
Otherwise, leads to mismatched key + cert in storage
  • Loading branch information
mholt committed Jun 21, 2023
1 parent dd8df32 commit dc8e4fa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,6 @@ func (cfg *Config) storageHasCertResourcesAnyIssuer(ctx context.Context, name st
// and its assets in storage if successful. It DOES NOT update the in-memory
// cache with the new certificate. The certificate will not be renewed if it
// is not close to expiring unless force is true.
//
// Renewing a certificate is the same as obtaining a certificate, except that
// the existing private key already in storage is reused.
func (cfg *Config) RenewCertSync(ctx context.Context, name string, force bool) error {
return cfg.renewCert(ctx, name, force, true)
}
Expand Down Expand Up @@ -809,6 +806,14 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
return err
}

// if we generated a new key, make sure to replace its PEM encoding too!
if !cfg.ReusePrivateKeys {
certRes.PrivateKeyPEM, err = PEMEncodePrivateKey(privateKey)
if err != nil {
return err
}
}

csr, err := cfg.generateCSR(privateKey, []string{name})
if err != nil {
return err
Expand Down

0 comments on commit dc8e4fa

Please sign in to comment.