update SSL logic to accomodate pregenerated certificates

The @ecobytes instance showed a misbehaviour concerning TLS certificates which had been set in instance.cfg.
Ultimately 89cdc314ea9ad93d7951d1800e525f85ec47eaac#diff-c226f84131b50059e044a64c41fe782c added a logic which would not account for preconfigured TLS certificates anymore.
This commit introduces a small change to revive usage of third-party certificates without overwriting their configuration options.
This commit is contained in:
almereyda
2016-07-06 17:39:44 +01:00
parent 6c7c1fd806
commit d2aa7200ee

View File

@@ -11,16 +11,19 @@ class CertificateBackend(object):
def __init__(self, config): def __init__(self, config):
"""Set path to certificates.""" """Set path to certificates."""
self.config = config self.config = config
for base_dir in ["/etc/pki/tls", "/etc/ssl"]: if not config.has_option("general", "tls_key_file"):
if os.path.exists(base_dir): for base_dir in ["/etc/pki/tls", "/etc/ssl"]:
self.config.set( if os.path.exists(base_dir):
"general", "tls_key_file", self.config.set(
"{}/private/%(hostname)s.key".format(base_dir)) "general", "tls_key_file",
self.config.set( "{}/private/%(hostname)s.key".format(base_dir))
"general", "tls_cert_file", self.config.set(
"{}/certs/%(hostname)s.cert".format(base_dir)) "general", "tls_cert_file",
return "{}/certs/%(hostname)s.cert".format(base_dir))
raise RuntimeError("Cannot find a directory to store certificate") return
raise RuntimeError("Cannot find a directory to store certificate")
else:
return
class SelfSignedCertificate(CertificateBackend): class SelfSignedCertificate(CertificateBackend):