7 from zope.interface import implementer, provider
9 from certbot import errors
10 from certbot import interfaces
11 from certbot.plugins import common
14 logger = logging.getLogger(__name__)
17 @implementer(interfaces.IInstaller)
18 @provider(interfaces.IPluginFactory)
19 class Installer(common.Plugin):
20 """Hitch installer."""
22 description = "Hitch Installer"
26 with open("/etc/hitch/hitch.conf") as config_file:
27 self.config = config_file.readlines()
30 return "Installer for Hitch TLS wrapper."
32 def get_all_names(self):
33 raise errors.PluginError("not implemented")
36 def add_parser_arguments(cls, add):
39 def deploy_cert(self, domain, cert_path, key_path,
40 chain_path=None, fullchain_path=None):
41 # Concatenate private key and certificate together into one file.
42 with open(key_path) as key_file:
45 # Add the full chain if we have it; else just the certificate.
46 if fullchain_path is not None:
47 with open(fullchain_path) as cert_file:
48 pem += cert_file.read()
50 with open(cert_path) as cert_file:
51 pem += cert_file.read()
53 # Add DH params if we have them (needed for PFS).
55 with open("/etc/hitch/dh-param.pem") as dh_param_file:
56 pem += dh_param_file.read()
60 # Actually write the full file.
61 filename = os.path.join(os.path.dirname(cert_path), "all.pem")
62 fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
63 with os.fdopen(fd, 'w') as pem_file:
66 # Now go check the config file to see if this file is already there.
69 for line_num in range(len(self.config)):
70 m = re.match("^\s*pem-file\s*=\s*\"([^\"]+)\"", self.config[line_num])
72 last_pem_line = line_num
73 if m.groups()[0] == filename:
76 # If it's not already there, add it after the last line.
78 if last_pem_line is None:
79 last_pem_line = len(self.config) - 1
80 config_line = "pem-file = \"%s\" # Added by Let's Encrypt installer.\n" % filename
81 self.config.insert(last_pem_line + 1, config_line)
83 pass # pragma: no cover
85 def enhance(self, domain, enhancement, options=None):
86 raise errors.PluginError("not implemented")
88 def supported_enhancements(self):
91 def get_all_certs_keys(self):
92 raise errors.PluginError("not implemented")
95 def save(self, title=None, temporary=False):
97 raise errors.PluginError("temporary is not implemented")
99 with open("/etc/hitch/hitch.conf", "w") as config_file:
100 config_file.writelines(self.config)
102 def rollback_checkpoints(self, rollback=1):
103 raise errors.PluginError("not implemented")
105 def recovery_routine(self):
106 raise errors.PluginError("not implemented")
108 def view_config_changes(self):
109 raise errors.PluginError("not implemented")
111 def config_test(self):
112 raise errors.PluginError("not implemented")
115 subprocess.call(["systemctl", "reload", "hitch.service"])