*(home): fix TLS module initialization

Continue to work even when TLS cert-key pair is invalid

Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677
This commit is contained in:
Andrey Meshkov
2020-05-16 02:02:50 +03:00
parent 6adf48c938
commit 2fca419c7f
3 changed files with 24 additions and 10 deletions

View File

@@ -39,7 +39,14 @@ func tlsCreate(conf tlsConfigSettings) *TLSMod {
t.conf = conf
if t.conf.Enabled {
if !t.load() {
return nil
// Something is not valid - return an empty TLS config
return &TLSMod{conf: tlsConfigSettings{
Enabled: conf.Enabled,
ServerName: conf.ServerName,
PortHTTPS: conf.PortHTTPS,
PortDNSOverTLS: conf.PortDNSOverTLS,
AllowUnencryptedDOH: conf.AllowUnencryptedDOH,
}}
}
t.setCertFileTime()
}
@@ -55,7 +62,7 @@ func (t *TLSMod) load() bool {
// validate current TLS config and update warnings (it could have been loaded from file)
data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName)
if !data.ValidPair {
log.Error(data.WarningValidation)
log.Error("failed to validate certificate: %s", data.WarningValidation)
return false
}
t.status = data