Report errors as "just expired"

This commit is contained in:
Peter J. Holzer 2022-11-20 18:46:39 +01:00
parent 81fa412202
commit e23f3f8726
1 changed files with 8 additions and 5 deletions

View File

@ -23,11 +23,14 @@ report0 = []
with socket.create_connection((args.hostname, args.port)) as sock:
context = ssl.create_default_context()
with context.wrap_socket(sock, server_hostname=args.hostname) as ssock:
cert = ssock.getpeercert()
not_after = ssl.cert_time_to_seconds(cert["notAfter"])
delta = not_after - now
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta })
try:
with context.wrap_socket(sock, server_hostname=args.hostname) as ssock:
cert = ssock.getpeercert()
not_after = ssl.cert_time_to_seconds(cert["notAfter"])
delta = not_after - now
except ssl.SSLCertVerificationError:
delta = 0
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta })
report = [
{