Merge pull request #57 from xenolf/fix-san-renewal

Fix: renew dropping additional DNSNames
This commit is contained in:
xenolf 2015-12-18 18:09:58 +01:00
commit 37153517a9
2 changed files with 72 additions and 51 deletions

View file

@ -368,7 +368,24 @@ func (c *Client) RenewCertificate(cert CertificateResource, revokeOld bool, bund
return cert, nil return cert, nil
} }
newCerts, failures := c.ObtainCertificates([]string{cert.Domain}, bundle) var domains []string
newCerts := make([]CertificateResource, 1)
var failures map[string]error
// check for SAN certificate
if len(x509Cert.DNSNames) > 1 {
domains = append(domains, x509Cert.Subject.CommonName)
for _, sanDomain := range x509Cert.DNSNames {
if sanDomain == x509Cert.Subject.CommonName {
continue
}
domains = append(domains, sanDomain)
}
newCerts[0], failures = c.ObtainSANCertificate(domains, bundle)
} else {
domains = append(domains, x509Cert.Subject.CommonName)
newCerts, failures = c.ObtainCertificates(domains, bundle)
}
if len(failures) > 0 { if len(failures) > 0 {
return CertificateResource{}, failures[cert.Domain] return CertificateResource{}, failures[cert.Domain]
} }

View file

@ -173,7 +173,12 @@ func revoke(c *cli.Context) {
func renew(c *cli.Context) { func renew(c *cli.Context) {
conf, _, client := setup(c) conf, _, client := setup(c)
for _, domain := range c.GlobalStringSlice("domains") { if len(c.GlobalStringSlice("domains")) <= 0 {
logger().Fatal("Please specify at least one domain.")
}
domain := c.GlobalStringSlice("domains")[0]
// load the cert resource from files. // load the cert resource from files.
// We store the certificate, private key and metadata in different 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. // as web servers would not be able to work with a combined file.
@ -192,8 +197,8 @@ func renew(c *cli.Context) {
logger().Printf("Could not get Certification expiration for domain %s", domain) logger().Printf("Could not get Certification expiration for domain %s", domain)
} }
if int(expTime.Sub(time.Now()).Hours()/24.0) <= c.Int("days") { if int(expTime.Sub(time.Now()).Hours() / 24.0) <= c.Int("days") {
continue return
} }
} }
@ -222,5 +227,4 @@ func renew(c *cli.Context) {
} }
saveCertRes(newCert, conf) saveCertRes(newCert, conf)
}
} }