Ensure server certs are stored in tmp directory

This commit is contained in:
Tobie Morgan Hitchcock 2017-11-16 19:49:32 +00:00
parent 4320804779
commit 010d0ffe4b

View file

@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"path"
"regexp" "regexp"
"strings" "strings"
@ -209,23 +210,25 @@ func setup() {
if strings.HasPrefix(opts.Cert.Crt, "-----") { if strings.HasPrefix(opts.Cert.Crt, "-----") {
var err error var err error
var doc *os.File var doc *os.File
if doc, err = os.Create("cert.crt"); err != nil { var out string = path.Join(os.TempDir(), "surreal.crt")
log.Fatal("Can not decode PEM encoded certificate into cert.crt") if doc, err = os.Create(out); err != nil {
log.Fatalf("Can not decode PEM encoded certificate into %s", out)
} }
doc.Write([]byte(opts.Cert.Crt)) doc.Write([]byte(opts.Cert.Crt))
doc.Close() doc.Close()
opts.Cert.Crt = "cert.crt" opts.Cert.Crt = out
} }
if strings.HasPrefix(opts.Cert.Key, "-----") { if strings.HasPrefix(opts.Cert.Key, "-----") {
var err error var err error
var doc *os.File var doc *os.File
if doc, err = os.Create("cert.key"); err != nil { var out string = path.Join(os.TempDir(), "surreal.key")
log.Fatal("Can not decode PEM encoded private key into cert.key") if doc, err = os.Create(out); err != nil {
log.Fatalf("Can not decode PEM encoded private key into %s: %s", out)
} }
doc.Write([]byte(opts.Cert.Key)) doc.Write([]byte(opts.Cert.Key))
doc.Close() doc.Close()
opts.Cert.Key = "cert.key" opts.Cert.Key = out
} }
// -------------------------------------------------- // --------------------------------------------------