Skip to content

Commit

Permalink
fix ca key save issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Aug 2, 2023
1 parent 972efab commit 7841bbb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/certs/mitm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ func GetMitMConfig() *mitm.Config {

func SaveCAToFile(filename string) error {
buffer := &bytes.Buffer{}
_ = pem.Encode(buffer, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
err := pem.Encode(buffer, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
if err != nil {
return err
}
return os.WriteFile(filename, buffer.Bytes(), 0600)
}

func SaveKeyToFile(filename string) error {
buffer := &bytes.Buffer{}
err := pem.Encode(buffer, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(pkey)})
if err != nil {
return err
}
return os.WriteFile(filename, buffer.Bytes(), 0600)
}

Expand All @@ -58,14 +70,9 @@ func generateCertificate(certFile, keyFile string) error {
if err = SaveCAToFile(certFile); err != nil {
gologger.Fatal().Msgf("failed to save certFile to disk got %v", err)
}
kf, err := os.OpenFile(keyFile, os.O_WRONLY, 0600)
if err != nil {
gologger.Fatal().Msgf("failed to load open %v while saving private key got %v", keyFile, err)
}
if err := pem.Encode(kf, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(pkey)}); err != nil {
if err := SaveKeyToFile(keyFile); err != nil {
gologger.Fatal().Msgf("failed to write private key to file got %v", err)
}
_ = kf.Close()
return nil
}

Expand Down

0 comments on commit 7841bbb

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy