* Enable cert_expiry config entries * add black * lint fixes * Rerun black * Black on json files is a bad idea * Work on comments * Forgot the lint * More comment work * Correctly set defaults * More comments * Add codeowner * Fix black * More comments implemented * Removed the catch * Add helper.py from cert_expiry to .coveragerc
15 lines
474 B
Python
15 lines
474 B
Python
"""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:
|
|
cert = ssock.getpeercert()
|
|
return cert
|