From e4df8ab30233b38b25931fdd1ec038c9031dae2f Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Mon, 25 Apr 2022 20:05:46 +0200 Subject: [PATCH] Print the right hosts when a CSR doesn't have SANs Close #344 Fixes #318 --- cert.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cert.go b/cert.go index 56750aa..eb72660 100644 --- a/cert.go +++ b/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)