diff options
-rw-r--r-- | cmd/acme/file.go | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/cmd/acme/file.go b/cmd/acme/file.go index f29345c..ae2ade8 100644 --- a/cmd/acme/file.go +++ b/cmd/acme/file.go @@ -26,29 +26,32 @@ func NewFile(fname string, mode os.FileMode) (io.WriteCloser, error) { return os.OpenFile(fname, flags, mode) } -func (d domain) Save(cert tls.Certificate) error { - if err := os.MkdirAll(path.Dir(d.KeyFile), 0700); err != nil { +func saveKey(fname string, key crypto.PrivateKey) error { + if err := os.MkdirAll(path.Dir(fname), 0700); err != nil { return err } - fd, err := NewFile(d.KeyFile, 0600) + fd, err := NewFile(fname, 0600) if err != nil { return err } defer fd.Close() - err = acme.SaveKey(fd, cert.PrivateKey) + err = acme.SaveKey(fd, key) if err != nil { return err } + return nil +} - if err := os.MkdirAll(path.Dir(d.CrtFile), 0755); err != nil { +func saveCrt(fname string, certs [][]byte) error { + if err := os.MkdirAll(path.Dir(fname), 0755); err != nil { return err } - fd, err = NewFile(d.CrtFile, 0644) + fd, err := NewFile(fname, 0644) if err != nil { return err } defer fd.Close() - for _, crt := range cert.Certificate { + for _, crt := range certs { if err := acme.SaveCert(fd, crt); err != nil { return err } @@ -56,6 +59,16 @@ func (d domain) Save(cert tls.Certificate) error { return nil } +func (d domain) Save(cert tls.Certificate) error { + if err := saveKey(d.KeyFile, cert.PrivateKey); err != nil { + return err + } + if err := saveCrt(d.CrtFile, cert.Certificate); err != nil { + return err + } + return nil +} + func (d domain) Load() (tls.Certificate, error) { crt, err := tls.LoadX509KeyPair(d.CrtFile, d.KeyFile) if err != nil { |