fix: close key files

This commit is contained in:
guangwu 2024-04-22 14:55:33 +08:00 committed by GitHub
parent f7def87d0f
commit b6d74ec8a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -114,11 +114,13 @@ func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.Priva
if err != nil {
return nil, nil, fmt.Errorf("proxy: could not open cert file for writing: %w", err)
}
defer certOut.Close()
keyOut, err := os.OpenFile(caKeyFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return nil, nil, fmt.Errorf("proxy: could not open key file for writing: %w", err)
}
defer keyOut.Close()
// Write PEM blocks to CA certificate and key files.
if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: caCert.Raw}); err != nil {