cmd/stdiscosrv: Generate keys if missing on startup (fixes #3511)

This commit is contained in:
Audrius Butkevicius 2016-08-23 08:41:49 +02:00 committed by Jakob Borg
parent db6f68d031
commit 81f683a61c

View File

@ -14,6 +14,7 @@ import (
"time" "time"
"github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/tlsutil"
"github.com/thejerf/suture" "github.com/thejerf/suture"
) )
@ -86,7 +87,11 @@ func main() {
if !useHTTP { if !useHTTP {
cert, err = tls.LoadX509KeyPair(certFile, keyFile) cert, err = tls.LoadX509KeyPair(certFile, keyFile)
if err != nil { if err != nil {
log.Fatalln("Failed to load X509 key pair:", err) log.Println("Failed to load keypair. Generating one, this might take a while...")
cert, err = tlsutil.NewCertificate(certFile, keyFile, "stdiscosrv", 3072)
if err != nil {
log.Fatalln("Failed to generate X509 key pair:", err)
}
} }
devID := protocol.NewDeviceID(cert.Certificate[0]) devID := protocol.NewDeviceID(cert.Certificate[0])