From 14bcd465886dff65f7143cb82d1b5d9666a9ee14 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 6 May 2020 05:53:45 -0400 Subject: [PATCH] fix #982 --- irc/config.go | 2 +- irc/errors.go | 11 ++++++++++- oragono.go | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/irc/config.go b/irc/config.go index 5695214d..f3b54008 100644 --- a/irc/config.go +++ b/irc/config.go @@ -746,7 +746,7 @@ func (conf *Config) Operators(oc map[string]*OperClass) (map[string]*Oper, error func loadTlsConfig(config TLSListenConfig, webSocket bool) (tlsConfig *tls.Config, err error) { cert, err := tls.LoadX509KeyPair(config.Cert, config.Key) if err != nil { - return nil, ErrInvalidCertKeyPair + return nil, &CertKeyError{Err: err} } clientAuth := tls.RequestClientCert if webSocket { diff --git a/irc/errors.go b/irc/errors.go index fc11e320..20b208c8 100644 --- a/irc/errors.go +++ b/irc/errors.go @@ -7,6 +7,8 @@ package irc import ( "errors" + "fmt" + "github.com/oragono/oragono/irc/utils" ) @@ -78,10 +80,17 @@ var ( errInvalidCharacter = errors.New("Invalid character") ) +type CertKeyError struct { + Err error +} + +func (ck *CertKeyError) Error() string { + return fmt.Sprintf("Invalid TLS cert/key pair: %v", ck.Err) +} + // Config Errors var ( ErrDatastorePathMissing = errors.New("Datastore path missing") - ErrInvalidCertKeyPair = errors.New("tls cert+key: invalid pair") ErrLimitsAreInsane = errors.New("Limits aren't setup properly, check them and make them sane") ErrLineLengthsTooSmall = errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)") ErrLoggerExcludeEmpty = errors.New("Encountered logging type '-' with no type to exclude") diff --git a/oragono.go b/oragono.go index 6b2ee832..b8af50d7 100644 --- a/oragono.go +++ b/oragono.go @@ -145,8 +145,11 @@ Options: configfile := arguments["--conf"].(string) config, err := irc.LoadConfig(configfile) - if err != nil && !(err == irc.ErrInvalidCertKeyPair && arguments["mkcerts"].(bool)) { - log.Fatal("Config file did not load successfully: ", err.Error()) + if err != nil { + _, isCertError := err.(*irc.CertKeyError) + if !(isCertError && arguments["mkcerts"].(bool)) { + log.Fatal("Config file did not load successfully: ", err.Error()) + } } logman, err := logger.NewManager(config.Logging)