Create missing directories before writing certpair.

This commit is contained in:
Josh Rickmar 2014-01-17 12:17:51 -05:00
parent 80b16790bc
commit a309196ea2

View file

@ -37,6 +37,7 @@ import (
"net" "net"
"net/http" "net/http"
"os" "os"
"path/filepath"
"runtime" "runtime"
"sync" "sync"
"time" "time"
@ -169,6 +170,17 @@ func newServer(listenAddrs []string) (*server, error) {
func genCertPair(certFile, keyFile string) error { func genCertPair(certFile, keyFile string) error {
log.Infof("Generating TLS certificates...") log.Infof("Generating TLS certificates...")
// Create directories for cert and key files if they do not yet exist.
certDir, _ := filepath.Split(certFile)
keyDir, _ := filepath.Split(keyFile)
if err := os.MkdirAll(certDir, 0700); err != nil {
return err
}
if err := os.MkdirAll(keyDir, 0700); err != nil {
return err
}
// Generate cert pair.
org := "btcwallet autogenerated cert" org := "btcwallet autogenerated cert"
validUntil := time.Now().Add(10 * 365 * 24 * time.Hour) validUntil := time.Now().Add(10 * 365 * 24 * time.Hour)
cert, key, err := btcutil.NewTLSCertPair(org, validUntil, nil) cert, key, err := btcutil.NewTLSCertPair(org, validUntil, nil)