Get or generate a certificate for the specified domain
(self, domain: str)
| 94 | self.ca_cert = x509.load_pem_x509_certificate(f.read(), default_backend()) |
| 95 | |
| 96 | def get_domain_cert(self, domain: str) -> Tuple[Any, Any]: |
| 97 | """Get or generate a certificate for the specified domain""" |
| 98 | cert_path = self.cert_dir / f"{domain}.crt" |
| 99 | key_path = self.cert_dir / f"{domain}.key" |
| 100 | |
| 101 | if cert_path.exists() and key_path.exists(): |
| 102 | # Load existing certificate and key |
| 103 | with open(key_path, "rb") as f: |
| 104 | private_key = serialization.load_pem_private_key( |
| 105 | f.read(), password=None, backend=default_backend() |
| 106 | ) |
| 107 | |
| 108 | with open(cert_path, "rb") as f: |
| 109 | cert = x509.load_pem_x509_certificate(f.read(), default_backend()) |
| 110 | |
| 111 | return private_key, cert |
| 112 | |
| 113 | # Generate new certificate |
| 114 | return self._generate_domain_cert(domain) |
| 115 | |
| 116 | def _generate_domain_cert(self, domain: str) -> Tuple[Any, Any]: |
| 117 | """Generate a certificate for the specified domain signed by the CA""" |