diff --git a/backend/web.py b/backend/web.py new file mode 100644 index 0000000000000000000000000000000000000000..60b3c3cce11a587cb1a3b0b44158a0e7e161cdca --- /dev/null +++ b/backend/web.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import ssl +from rich.console import Console +from cryptography import x509 + +import tls_utils as tls_utils + +def web_noconn_expiry_days(web_domain: str) -> int | None: + try: + pem_cert = ssl.get_server_certificate((web_domain, 443), timeout=5) + cert = x509.load_pem_x509_certificate(pem_cert.encode()) + except Exception as e: + console = Console() + console.log("Could not grab server cert for", "[orange bold underline]"+web_domain, ":", e, style="orange") + return None + + not_after = cert.not_valid_after.timestamp() + return tls_utils.get_expiry_timestamps(not_after) \ No newline at end of file