|
14 | 14 |
|
15 | 15 | import logging
|
16 | 16 | import os
|
17 |
| -from datetime import datetime |
18 | 17 | from typing import List, Optional, Pattern
|
19 | 18 |
|
20 | 19 | from OpenSSL import SSL, crypto
|
@@ -133,55 +132,6 @@ def read_config(self, config: dict, config_dir_path: str, **kwargs):
|
133 | 132 | self.tls_certificate: Optional[crypto.X509] = None
|
134 | 133 | self.tls_private_key: Optional[crypto.PKey] = None
|
135 | 134 |
|
136 |
| - def is_disk_cert_valid(self, allow_self_signed=True): |
137 |
| - """ |
138 |
| - Is the certificate we have on disk valid, and if so, for how long? |
139 |
| -
|
140 |
| - Args: |
141 |
| - allow_self_signed (bool): Should we allow the certificate we |
142 |
| - read to be self signed? |
143 |
| -
|
144 |
| - Returns: |
145 |
| - int: Days remaining of certificate validity. |
146 |
| - None: No certificate exists. |
147 |
| - """ |
148 |
| - if not os.path.exists(self.tls_certificate_file): |
149 |
| - return None |
150 |
| - |
151 |
| - try: |
152 |
| - with open(self.tls_certificate_file, "rb") as f: |
153 |
| - cert_pem = f.read() |
154 |
| - except Exception as e: |
155 |
| - raise ConfigError( |
156 |
| - "Failed to read existing certificate file %s: %s" |
157 |
| - % (self.tls_certificate_file, e) |
158 |
| - ) |
159 |
| - |
160 |
| - try: |
161 |
| - tls_certificate = crypto.load_certificate(crypto.FILETYPE_PEM, cert_pem) |
162 |
| - except Exception as e: |
163 |
| - raise ConfigError( |
164 |
| - "Failed to parse existing certificate file %s: %s" |
165 |
| - % (self.tls_certificate_file, e) |
166 |
| - ) |
167 |
| - |
168 |
| - if not allow_self_signed: |
169 |
| - if tls_certificate.get_subject() == tls_certificate.get_issuer(): |
170 |
| - raise ValueError( |
171 |
| - "TLS Certificate is self signed, and this is not permitted" |
172 |
| - ) |
173 |
| - |
174 |
| - # YYYYMMDDhhmmssZ -- in UTC |
175 |
| - expiry_data = tls_certificate.get_notAfter() |
176 |
| - if expiry_data is None: |
177 |
| - raise ValueError( |
178 |
| - "TLS Certificate has no expiry date, and this is not permitted" |
179 |
| - ) |
180 |
| - expires_on = datetime.strptime(expiry_data.decode("ascii"), "%Y%m%d%H%M%SZ") |
181 |
| - now = datetime.utcnow() |
182 |
| - days_remaining = (expires_on - now).days |
183 |
| - return days_remaining |
184 |
| - |
185 | 135 | def read_certificate_from_disk(self):
|
186 | 136 | """
|
187 | 137 | Read the certificates and private key from disk.
|
|
0 commit comments