mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 02:54:34 +02:00
Attempt at cleaning {cert,chain}_path mess
This commit is contained in:
@@ -135,7 +135,7 @@ def install(args, config, plugins):
|
|||||||
return "Installer could not be determined"
|
return "Installer could not be determined"
|
||||||
acme, doms = _common_run(
|
acme, doms = _common_run(
|
||||||
args, config, acc, authenticator=None, installer=installer)
|
args, config, acc, authenticator=None, installer=installer)
|
||||||
assert args.cert_path is not None and args.chain_path is not None
|
assert args.cert_path is not None
|
||||||
acme.deploy_certificate(doms, acc.key, args.cert_path, args.chain_path)
|
acme.deploy_certificate(doms, acc.key, args.cert_path, args.chain_path)
|
||||||
acme.enhance_config(doms, args.redirect)
|
acme.enhance_config(doms, args.redirect)
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class Client(object):
|
|||||||
this CSR can be different than self.authkey
|
this CSR can be different than self.authkey
|
||||||
:type csr: :class:`CSR`
|
:type csr: :class:`CSR`
|
||||||
|
|
||||||
:returns: cert_file, chain_file (paths to respective files)
|
:returns: cert_path, chain_path (paths to respective files)
|
||||||
:rtype: `tuple` of `str`
|
:rtype: `tuple` of `str`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -136,13 +136,13 @@ class Client(object):
|
|||||||
authzr)
|
authzr)
|
||||||
|
|
||||||
# Save Certificate
|
# Save Certificate
|
||||||
cert_file, chain_file = self.save_certificate(
|
cert_path, chain_path = self.save_certificate(
|
||||||
certr, self.config.cert_path, self.config.chain_path)
|
certr, self.config.cert_path, self.config.chain_path)
|
||||||
|
|
||||||
revoker.Revoker.store_cert_key(
|
revoker.Revoker.store_cert_key(
|
||||||
cert_file, self.account.key.file, self.config)
|
cert_path, self.account.key.file, self.config)
|
||||||
|
|
||||||
return cert_file, chain_file
|
return cert_path, chain_path
|
||||||
|
|
||||||
def save_certificate(self, certr, cert_path, chain_path):
|
def save_certificate(self, certr, cert_path, chain_path):
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
@@ -154,7 +154,7 @@ class Client(object):
|
|||||||
:param str cert_path: Path to attempt to save the cert file
|
:param str cert_path: Path to attempt to save the cert file
|
||||||
:param str chain_path: Path to attempt to save the chain file
|
:param str chain_path: Path to attempt to save the chain file
|
||||||
|
|
||||||
:returns: cert_file, chain_file (absolute paths to the actual files)
|
:returns: cert_path, chain_path (absolute paths to the actual files)
|
||||||
:rtype: `tuple` of `str`
|
:rtype: `tuple` of `str`
|
||||||
|
|
||||||
:raises IOError: If unable to find room to write the cert files
|
:raises IOError: If unable to find room to write the cert files
|
||||||
@@ -191,7 +191,7 @@ class Client(object):
|
|||||||
|
|
||||||
return os.path.abspath(act_cert_path), cert_chain_abspath
|
return os.path.abspath(act_cert_path), cert_chain_abspath
|
||||||
|
|
||||||
def deploy_certificate(self, domains, privkey, cert_file, chain_file=None):
|
def deploy_certificate(self, domains, privkey, cert_path, chain_path=None):
|
||||||
"""Install certificate
|
"""Install certificate
|
||||||
|
|
||||||
:param list domains: list of domains to install the certificate
|
:param list domains: list of domains to install the certificate
|
||||||
@@ -199,8 +199,8 @@ class Client(object):
|
|||||||
:param privkey: private key for certificate
|
:param privkey: private key for certificate
|
||||||
:type privkey: :class:`letsencrypt.client.le_util.Key`
|
:type privkey: :class:`letsencrypt.client.le_util.Key`
|
||||||
|
|
||||||
:param str cert_file: certificate file path
|
:param str cert_path: certificate file path
|
||||||
:param str chain_file: chain file path
|
:param str chain_path: chain file path
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.installer is None:
|
if self.installer is None:
|
||||||
@@ -208,13 +208,12 @@ class Client(object):
|
|||||||
"the certificate")
|
"the certificate")
|
||||||
raise errors.LetsEncryptClientError("No installer available")
|
raise errors.LetsEncryptClientError("No installer available")
|
||||||
|
|
||||||
chain = None if chain_file is None else os.path.abspath(chain_file)
|
chain_path = None if chain_path is None else os.path.abspath(chain_path)
|
||||||
|
|
||||||
for dom in domains:
|
for dom in domains:
|
||||||
self.installer.deploy_cert(dom,
|
self.installer.deploy_cert(
|
||||||
os.path.abspath(cert_file),
|
dom, os.path.abspath(cert_path),
|
||||||
os.path.abspath(privkey.file),
|
os.path.abspath(privkey.file), chain_path)
|
||||||
chain)
|
|
||||||
|
|
||||||
self.installer.save("Deployed Let's Encrypt Certificate")
|
self.installer.save("Deployed Let's Encrypt Certificate")
|
||||||
# sites may have been enabled / final cleanup
|
# sites may have been enabled / final cleanup
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ class IConfig(zope.interface.Interface):
|
|||||||
|
|
||||||
le_vhost_ext = zope.interface.Attribute(
|
le_vhost_ext = zope.interface.Attribute(
|
||||||
"SSL vhost configuration extension.")
|
"SSL vhost configuration extension.")
|
||||||
cert_path = zope.interface.Attribute("Let's Encrypt certificate file.")
|
cert_path = zope.interface.Attribute("Let's Encrypt certificate file path.")
|
||||||
chain_path = zope.interface.Attribute("Let's Encrypt chain file.")
|
chain_path = zope.interface.Attribute("Let's Encrypt chain file path.")
|
||||||
|
|
||||||
|
|
||||||
class IInstaller(IPlugin):
|
class IInstaller(IPlugin):
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||||||
|
|
||||||
temp_install(self.conf('mod-ssl-conf'))
|
temp_install(self.conf('mod-ssl-conf'))
|
||||||
|
|
||||||
def deploy_cert(self, domain, cert, key, cert_chain=None):
|
def deploy_cert(self, domain, cert_path, key, chain_path=None):
|
||||||
"""Deploys certificate to specified virtual host.
|
"""Deploys certificate to specified virtual host.
|
||||||
|
|
||||||
Currently tries to find the last directives to deploy the cert in
|
Currently tries to find the last directives to deploy the cert in
|
||||||
@@ -163,25 +163,26 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||||||
This shouldn't happen within letsencrypt though
|
This shouldn't happen within letsencrypt though
|
||||||
|
|
||||||
:param str domain: domain to deploy certificate
|
:param str domain: domain to deploy certificate
|
||||||
:param str cert: certificate filename
|
:param str cert_path: certificate filename
|
||||||
:param str key: private key filename
|
:param str key: private key filename
|
||||||
:param str cert_chain: certificate chain filename
|
:param str chain_path: certificate chain filename
|
||||||
|
|
||||||
"""
|
"""
|
||||||
vhost = self.choose_vhost(domain)
|
vhost = self.choose_vhost(domain)
|
||||||
|
# TODO(jdkasten): vhost might be None
|
||||||
path = {}
|
path = {}
|
||||||
|
|
||||||
path["cert_file"] = self.parser.find_dir(parser.case_i(
|
path["cert_path"] = self.parser.find_dir(parser.case_i(
|
||||||
"SSLCertificateFile"), None, vhost.path)
|
"SSLCertificateFile"), None, vhost.path)
|
||||||
path["cert_key"] = self.parser.find_dir(parser.case_i(
|
path["cert_key"] = self.parser.find_dir(parser.case_i(
|
||||||
"SSLCertificateKeyFile"), None, vhost.path)
|
"SSLCertificateKeyFile"), None, vhost.path)
|
||||||
|
|
||||||
# Only include if a certificate chain is specified
|
# Only include if a certificate chain is specified
|
||||||
if cert_chain is not None:
|
if chain_path is not None:
|
||||||
path["cert_chain"] = self.parser.find_dir(
|
path["chain_path"] = self.parser.find_dir(
|
||||||
parser.case_i("SSLCertificateChainFile"), None, vhost.path)
|
parser.case_i("SSLCertificateChainFile"), None, vhost.path)
|
||||||
|
|
||||||
if len(path["cert_file"]) == 0 or len(path["cert_key"]) == 0:
|
if not path["cert_path"] or not path["cert_key"]:
|
||||||
# Throw some can't find all of the directives error"
|
# Throw some can't find all of the directives error"
|
||||||
logging.warn(
|
logging.warn(
|
||||||
"Cannot find a cert or key directive in %s", vhost.path)
|
"Cannot find a cert or key directive in %s", vhost.path)
|
||||||
@@ -191,22 +192,22 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||||||
|
|
||||||
logging.info("Deploying Certificate to VirtualHost %s", vhost.filep)
|
logging.info("Deploying Certificate to VirtualHost %s", vhost.filep)
|
||||||
|
|
||||||
self.aug.set(path["cert_file"][0], cert)
|
self.aug.set(path["cert_path"][0], cert_path)
|
||||||
self.aug.set(path["cert_key"][0], key)
|
self.aug.set(path["cert_key"][0], key)
|
||||||
if cert_chain is not None:
|
if chain_path is not None:
|
||||||
if len(path["cert_chain"]) == 0:
|
if not path["chain_path"]:
|
||||||
self.parser.add_dir(
|
self.parser.add_dir(
|
||||||
vhost.path, "SSLCertificateChainFile", cert_chain)
|
vhost.path, "SSLCertificateChainFile", chain_path)
|
||||||
else:
|
else:
|
||||||
self.aug.set(path["cert_chain"][0], cert_chain)
|
self.aug.set(path["chain_path"][0], chain_path)
|
||||||
|
|
||||||
self.save_notes += ("Changed vhost at %s with addresses of %s\n" %
|
self.save_notes += ("Changed vhost at %s with addresses of %s\n" %
|
||||||
(vhost.filep,
|
(vhost.filep,
|
||||||
", ".join(str(addr) for addr in vhost.addrs)))
|
", ".join(str(addr) for addr in vhost.addrs)))
|
||||||
self.save_notes += "\tSSLCertificateFile %s\n" % cert
|
self.save_notes += "\tSSLCertificateFile %s\n" % cert_path
|
||||||
self.save_notes += "\tSSLCertificateKeyFile %s\n" % key
|
self.save_notes += "\tSSLCertificateKeyFile %s\n" % key
|
||||||
if cert_chain:
|
if chain_path is not None:
|
||||||
self.save_notes += "\tSSLCertificateChainFile %s\n" % cert_chain
|
self.save_notes += "\tSSLCertificateChainFile %s\n" % chain_path
|
||||||
|
|
||||||
# Make sure vhost is enabled
|
# Make sure vhost is enabled
|
||||||
if not vhost.enabled:
|
if not vhost.enabled:
|
||||||
|
|||||||
Reference in New Issue
Block a user