9 from zope.interface import implementer, provider
11 from letsencrypt import errors
12 from letsencrypt import interfaces
13 from letsencrypt.plugins import common
16 logger = logging.getLogger(__name__)
19 @implementer(interfaces.IInstaller)
20 @provider(interfaces.IPluginFactory)
21 class Installer(common.Plugin):
22 """Hitch installer."""
24 description = "Hitch Installer"
28 with open("/etc/hitch/hitch.conf") as config_file:
29 self.config = config_file.readlines()
32 return "Installer for Hitch TLS wrapper."
34 def get_all_names(self):
35 raise errors.PluginError("not implemented")
37 def deploy_cert(self, domain, cert_path, key_path,
38 chain_path=None, fullchain_path=None):
39 # Concatenate private key and certificate together into one file.
40 with open(key_path) as key_file:
43 # Add the full chain if we have it; else just the certificate.
44 if fullchain_path is not None:
45 with open(fullchain_path) as cert_file:
46 pem += cert_file.read()
48 with open(cert_path) as cert_file:
49 pem += cert_file.read()
51 # Add DH params if we have them (needed for PFS).
53 with open("/etc/hitch/dh-param.pem") as dh_param_file:
54 pem += dh_param_file.read()
58 # Actually write the full file.
59 filename = os.path.join(os.path.dirname(cert_path), "all.pem")
60 fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
61 with os.fdopen(fd, 'w') as pem_file:
64 # Now go check the config file to see if this file is already there.
67 for line_num in range(len(self.config)):
68 m = re.match("^\s*pem-file\s*=\s*\"([^\"]+)\"", self.config[line_num])
70 last_pem_line = line_num
71 if m.groups()[0] == filename:
74 # If it's not already there, add it after the last line.
76 if last_pem_line is None:
77 last_pem_line = len(self.config) - 1
78 config_line = "pem-file = \"%s\" # Added by Let's Encrypt installer.\n" % filename
79 self.config.insert(last_pem_line + 1, config_line)
81 pass # pragma: no cover
83 def enhance(self, domain, enhancement, options=None):
84 raise errors.PluginError("not implemented")
86 def supported_enhancements(self):
89 def get_all_certs_keys(self):
90 raise errors.PluginError("not implemented")
93 def save(self, title=None, temporary=False):
95 raise errors.PluginError("temporary is not implemented")
97 with open("/etc/hitch/hitch.conf", "w") as config_file:
98 config_file.writelines(self.config)
100 def rollback_checkpoints(self, rollback=1):
101 raise errors.PluginError("not implemented")
103 def recovery_routine(self):
104 raise errors.PluginError("not implemented")
106 def view_config_changes(self):
107 raise errors.PluginError("not implemented")
109 def config_test(self):
110 raise errors.PluginError("not implemented")
113 subprocess.call(["systemctl", "reload", "hitch.service"])