From 04b25eb6bf31f4af46bae7186e5c78a49ec81249 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 11 Sep 2019 20:15:34 -0400 Subject: [PATCH] fix #622 --- oragono.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/oragono.go b/oragono.go index b0e434ef..dcf0f43e 100644 --- a/oragono.go +++ b/oragono.go @@ -39,6 +39,13 @@ func getPassword() string { return strings.TrimSpace(text) } +func fileDoesNotExist(file string) bool { + if _, err := os.Stat(file); os.IsNotExist(err) { + return true + } + return false +} + // implements the `oragono mkcerts` command func doMkcerts(configFile string, quiet bool) { config, err := irc.LoadRawConfig(configFile) @@ -59,7 +66,7 @@ func doMkcerts(configFile string, quiet bool) { if existingKey == conf.TLS.Key { continue } else { - log.Fatal("Conflicting TLS key files for", conf.TLS.Cert) + log.Fatal("Conflicting TLS key files for ", conf.TLS.Cert) } } if !quiet { @@ -67,6 +74,9 @@ func doMkcerts(configFile string, quiet bool) { } host := config.Server.Name cert, key := conf.TLS.Cert, conf.TLS.Key + if !(fileDoesNotExist(cert) && fileDoesNotExist(key)) { + log.Fatalf("Preexisting TLS cert and/or key files: %s %s", cert, key) + } err := mkcerts.CreateCert("Oragono", host, cert, key) if err == nil { if !quiet {