2019-08-28 17:35:09 +00:00
|
|
|
"""Helper functions for the Cert Expiry platform."""
|
|
|
|
import socket
|
|
|
|
import ssl
|
|
|
|
|
|
|
|
from .const import TIMEOUT
|
|
|
|
|
|
|
|
|
|
|
|
def get_cert(host, port):
|
|
|
|
"""Get the ssl certificate for the host and port combination."""
|
|
|
|
ctx = ssl.create_default_context()
|
|
|
|
address = (host, port)
|
|
|
|
with socket.create_connection(address, timeout=TIMEOUT) as sock:
|
|
|
|
with ctx.wrap_socket(sock, server_hostname=address[0]) as ssock:
|
2019-10-07 15:17:39 +00:00
|
|
|
# pylint disable: https://github.com/PyCQA/pylint/issues/3166
|
|
|
|
cert = ssock.getpeercert() # pylint: disable=no-member
|
2019-08-28 17:35:09 +00:00
|
|
|
return cert
|