1 """Helper functions for the Cert Expiry platform."""
13 from .const
import TIMEOUT
27 """Get the certificate for the host and port combination."""
28 async
with asyncio.timeout(TIMEOUT):
29 transport, _ = await hass.loop.create_connection(
34 happy_eyeballs_delay=0.25,
38 return transport.get_extra_info(
"peercert")
47 ) -> datetime.datetime:
48 """Return the certificate's expiration timestamp."""
51 except socket.gaierror
as err:
52 raise ResolveFailed(f
"Cannot resolve hostname: {hostname}")
from err
53 except TimeoutError
as err:
55 f
"Connection timeout with server: {hostname}:{port}"
57 except ConnectionRefusedError
as err:
59 f
"Connection refused by server: {hostname}:{port}"
61 except ssl.CertificateError
as err:
63 except ssl.SSLError
as err:
66 ts_seconds = ssl.cert_time_to_seconds(cert[
"notAfter"])
67 return dt_util.utc_from_timestamp(ts_seconds)
datetime.datetime get_cert_expiry_timestamp(HomeAssistant hass, str hostname, int port)
dict[str, Any] async_get_cert(HomeAssistant hass, str host, int port)
ssl.SSLContext get_default_context()