Browse Source

Print the right hosts when a CSR doesn't have SANs

Close #344
Fixes #318
Filippo Valsorda 2 years ago
parent
commit
e4df8ab302
1 changed files with 6 additions and 4 deletions
  1. 6 4
      cert.go

+ 6 - 4
cert.go

@@ -253,14 +253,16 @@ func (m *mkcert) makeCertFromCSR() {
 
 	cert, err := x509.CreateCertificate(rand.Reader, tpl, m.caCert, csr.PublicKey, m.caKey)
 	fatalIfErr(err, "failed to generate certificate")
+	c, err := x509.ParseCertificate(cert)
+	fatalIfErr(err, "failed to parse generated certificate")
 
 	var hosts []string
-	hosts = append(hosts, csr.DNSNames...)
-	hosts = append(hosts, csr.EmailAddresses...)
-	for _, ip := range csr.IPAddresses {
+	hosts = append(hosts, c.DNSNames...)
+	hosts = append(hosts, c.EmailAddresses...)
+	for _, ip := range c.IPAddresses {
 		hosts = append(hosts, ip.String())
 	}
-	for _, uri := range csr.URIs {
+	for _, uri := range c.URIs {
 		hosts = append(hosts, uri.String())
 	}
 	certFile, _, _ := m.fileNames(hosts)