From 33da1d64f02831fddf78fbf040d7567ef8f6f234 Mon Sep 17 00:00:00 2001 From: Kota Date: Sat, 24 Jun 2023 07:41:48 +0900 Subject: [PATCH 1/3] fix ioutil.WriteFile --- cert.go | 14 +++++++------- truststore_darwin.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cert.go b/cert.go index 4ce36ccf..0bd9491f 100644 --- a/cert.go +++ b/cert.go @@ -113,19 +113,19 @@ func (m *mkcert) makeCert(hosts []string) { privPEM := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: privDER}) if certFile == keyFile { - err = ioutil.WriteFile(keyFile, append(certPEM, privPEM...), 0600) + err = os.WriteFile(keyFile, append(certPEM, privPEM...), 0600) fatalIfErr(err, "failed to save certificate and key") } else { - err = ioutil.WriteFile(certFile, certPEM, 0644) + err = os.WriteFile(certFile, certPEM, 0644) fatalIfErr(err, "failed to save certificate") - err = ioutil.WriteFile(keyFile, privPEM, 0600) + err = os.WriteFile(keyFile, privPEM, 0600) fatalIfErr(err, "failed to save certificate key") } } else { domainCert, _ := x509.ParseCertificate(cert) pfxData, err := pkcs12.Encode(rand.Reader, priv, domainCert, []*x509.Certificate{m.caCert}, "changeit") fatalIfErr(err, "failed to generate PKCS#12") - err = ioutil.WriteFile(p12File, pfxData, 0644) + err = os.WriteFile(p12File, pfxData, 0644) fatalIfErr(err, "failed to save PKCS#12") } @@ -267,7 +267,7 @@ func (m *mkcert) makeCertFromCSR() { } certFile, _, _ := m.fileNames(hosts) - err = ioutil.WriteFile(certFile, pem.EncodeToMemory( + err = os.WriteFile(certFile, pem.EncodeToMemory( &pem.Block{Type: "CERTIFICATE", Bytes: cert}), 0644) fatalIfErr(err, "failed to save certificate") @@ -352,11 +352,11 @@ func (m *mkcert) newCA() { privDER, err := x509.MarshalPKCS8PrivateKey(priv) fatalIfErr(err, "failed to encode CA key") - err = ioutil.WriteFile(filepath.Join(m.CAROOT, rootKeyName), pem.EncodeToMemory( + err = os.WriteFile(filepath.Join(m.CAROOT, rootKeyName), pem.EncodeToMemory( &pem.Block{Type: "PRIVATE KEY", Bytes: privDER}), 0400) fatalIfErr(err, "failed to save CA key") - err = ioutil.WriteFile(filepath.Join(m.CAROOT, rootName), pem.EncodeToMemory( + err = os.WriteFile(filepath.Join(m.CAROOT, rootName), pem.EncodeToMemory( &pem.Block{Type: "CERTIFICATE", Bytes: cert}), 0644) fatalIfErr(err, "failed to save CA certificate") diff --git a/truststore_darwin.go b/truststore_darwin.go index 83b8fac7..cd452952 100644 --- a/truststore_darwin.go +++ b/truststore_darwin.go @@ -92,7 +92,7 @@ func (m *mkcert) installPlatform() bool { plistData, err = plist.MarshalIndent(plistRoot, plist.XMLFormat, "\t") fatalIfErr(err, "failed to serialize trust settings") - err = ioutil.WriteFile(plistFile.Name(), plistData, 0600) + err = os.WriteFile(plistFile.Name(), plistData, 0600) fatalIfErr(err, "failed to write trust settings") cmd = commandWithSudo("security", "trust-settings-import", "-d", plistFile.Name()) From 6f14475428bccd88fd34a042c532b7bce1aa1f88 Mon Sep 17 00:00:00 2001 From: Kota Date: Sat, 24 Jun 2023 07:42:29 +0900 Subject: [PATCH 2/3] fix ioutil.ReadFile --- cert.go | 7 +++---- truststore_darwin.go | 2 +- truststore_linux.go | 2 +- truststore_windows.go | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cert.go b/cert.go index 0bd9491f..7e5a3c2e 100644 --- a/cert.go +++ b/cert.go @@ -15,7 +15,6 @@ import ( "crypto/x509/pkix" "encoding/asn1" "encoding/pem" - "io/ioutil" "log" "math/big" "net" @@ -211,7 +210,7 @@ func (m *mkcert) makeCertFromCSR() { log.Fatalln("ERROR: can't create new certificates because the CA key (rootCA-key.pem) is missing") } - csrPEMBytes, err := ioutil.ReadFile(m.csrPath) + csrPEMBytes, err := os.ReadFile(m.csrPath) fatalIfErr(err, "failed to read the CSR") csrPEM, _ := pem.Decode(csrPEMBytes) if csrPEM == nil { @@ -284,7 +283,7 @@ func (m *mkcert) loadCA() { m.newCA() } - certPEMBlock, err := ioutil.ReadFile(filepath.Join(m.CAROOT, rootName)) + certPEMBlock, err := os.ReadFile(filepath.Join(m.CAROOT, rootName)) fatalIfErr(err, "failed to read the CA certificate") certDERBlock, _ := pem.Decode(certPEMBlock) if certDERBlock == nil || certDERBlock.Type != "CERTIFICATE" { @@ -297,7 +296,7 @@ func (m *mkcert) loadCA() { return // keyless mode, where only -install works } - keyPEMBlock, err := ioutil.ReadFile(filepath.Join(m.CAROOT, rootKeyName)) + keyPEMBlock, err := os.ReadFile(filepath.Join(m.CAROOT, rootKeyName)) fatalIfErr(err, "failed to read the CA key") keyDERBlock, _ := pem.Decode(keyPEMBlock) if keyDERBlock == nil || keyDERBlock.Type != "PRIVATE KEY" { diff --git a/truststore_darwin.go b/truststore_darwin.go index cd452952..559ba96b 100644 --- a/truststore_darwin.go +++ b/truststore_darwin.go @@ -65,7 +65,7 @@ func (m *mkcert) installPlatform() bool { out, err = cmd.CombinedOutput() fatalIfCmdErr(err, "security trust-settings-export", out) - plistData, err := ioutil.ReadFile(plistFile.Name()) + plistData, err := os.ReadFile(plistFile.Name()) fatalIfErr(err, "failed to read trust settings") var plistRoot map[string]interface{} _, err = plist.Unmarshal(plistData, &plistRoot) diff --git a/truststore_linux.go b/truststore_linux.go index 2c4e5a37..43d139d0 100644 --- a/truststore_linux.go +++ b/truststore_linux.go @@ -59,7 +59,7 @@ func (m *mkcert) installPlatform() bool { return false } - cert, err := ioutil.ReadFile(filepath.Join(m.CAROOT, rootName)) + cert, err := os.ReadFile(filepath.Join(m.CAROOT, rootName)) fatalIfErr(err, "failed to read root certificate") cmd := commandWithSudo("tee", m.systemTrustFilename()) diff --git a/truststore_windows.go b/truststore_windows.go index a4c9fcb4..a6f41cb5 100644 --- a/truststore_windows.go +++ b/truststore_windows.go @@ -34,7 +34,7 @@ var ( func (m *mkcert) installPlatform() bool { // Load cert - cert, err := ioutil.ReadFile(filepath.Join(m.CAROOT, rootName)) + cert, err := os.ReadFile(filepath.Join(m.CAROOT, rootName)) fatalIfErr(err, "failed to read root certificate") // Decode PEM if certBlock, _ := pem.Decode(cert); certBlock == nil || certBlock.Type != "CERTIFICATE" { From dffe63ab017e84585b2e9350f4b7f84e79bdcc35 Mon Sep 17 00:00:00 2001 From: Kota Date: Sat, 24 Jun 2023 07:43:53 +0900 Subject: [PATCH 3/3] fix ioutil.TempFile --- truststore_darwin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/truststore_darwin.go b/truststore_darwin.go index 559ba96b..385911c4 100644 --- a/truststore_darwin.go +++ b/truststore_darwin.go @@ -7,7 +7,6 @@ package main import ( "bytes" "encoding/asn1" - "io/ioutil" "log" "os" "path/filepath" @@ -57,7 +56,7 @@ func (m *mkcert) installPlatform() bool { // Make trustSettings explicit, as older Go does not know the defaults. // https://github.com/golang/go/issues/24652 - plistFile, err := ioutil.TempFile("", "trust-settings") + plistFile, err := os.CreateTemp("", "trust-settings") fatalIfErr(err, "failed to create temp file") defer os.Remove(plistFile.Name())