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/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)
|
||||
|
|
Loading…
Reference in a new issue