Browse Source

cmd/stdiscosrv: Only generate keypair if it doesn't exist (fixes #5809) (#6419)

Kevin Bushiri 5 years ago
parent
commit
5975772ed8
1 changed files with 3 additions and 2 deletions
  1. 3 2
      cmd/stdiscosrv/main.go

+ 3 - 2
cmd/stdiscosrv/main.go

@@ -98,14 +98,15 @@ func main() {
 	}
 
 	cert, err := tls.LoadX509KeyPair(certFile, keyFile)
-	if err != nil {
+	if os.IsNotExist(err) {
 		log.Println("Failed to load keypair. Generating one, this might take a while...")
 		cert, err = tlsutil.NewCertificate(certFile, keyFile, "stdiscosrv", 20*365)
 		if err != nil {
 			log.Fatalln("Failed to generate X509 key pair:", err)
 		}
+	} else if err != nil {
+		log.Fatalln("Failed to load keypair:", err)
 	}
-
 	devID := protocol.NewDeviceID(cert.Certificate[0])
 	log.Println("Server device ID is", devID)