Create missing directories before writing certpair.
This commit is contained in:
parent
80b16790bc
commit
a309196ea2
1 changed files with 12 additions and 0 deletions
12
sockets.go
12
sockets.go
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue