diff --git a/sockets.go b/sockets.go index ac95f64..dd84059 100644 --- a/sockets.go +++ b/sockets.go @@ -37,6 +37,7 @@ import ( "net" "net/http" "os" + "path/filepath" "runtime" "sync" "time" @@ -169,6 +170,17 @@ func newServer(listenAddrs []string) (*server, error) { func genCertPair(certFile, keyFile string) error { 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" validUntil := time.Now().Add(10 * 365 * 24 * time.Hour) cert, key, err := btcutil.NewTLSCertPair(org, validUntil, nil)