mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Automatically detect if ipv4/ipv6 is used for cert_expiry (#18916)
* Automatically detect if ipv4/ipv6 is used for cert_expiry Fixes #18818 Python sockets use ipv4 per default. If the domain which should be checked only has an ipv6 record, socket creation errors out with `[Errno -2] Name or service not known` This fix tries to guess the protocol family and creates the socket with the correct family type * Fix line length violation
This commit is contained in:
parent
5bf6951311
commit
7edd241059
@ -85,8 +85,10 @@ class SSLCertificate(Entity):
|
||||
"""Fetch the certificate information."""
|
||||
try:
|
||||
ctx = ssl.create_default_context()
|
||||
host_info = socket.getaddrinfo(self.server_name, self.server_port)
|
||||
family = host_info[0][0]
|
||||
sock = ctx.wrap_socket(
|
||||
socket.socket(), server_hostname=self.server_name)
|
||||
socket.socket(family=family), server_hostname=self.server_name)
|
||||
sock.settimeout(TIMEOUT)
|
||||
sock.connect((self.server_name, self.server_port))
|
||||
except socket.gaierror:
|
||||
|
Loading…
x
Reference in New Issue
Block a user