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: with socket.create_connection((args.hostname, args.port)) as sock:
context = ssl.create_default_context() context = ssl.create_default_context()
with context.wrap_socket(sock, server_hostname=args.hostname) as ssock: try:
cert = ssock.getpeercert() with context.wrap_socket(sock, server_hostname=args.hostname) as ssock:
not_after = ssl.cert_time_to_seconds(cert["notAfter"]) cert = ssock.getpeercert()
delta = not_after - now not_after = ssl.cert_time_to_seconds(cert["notAfter"])
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta }) delta = not_after - now
except ssl.SSLCertVerificationError:
delta = 0
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta })
report = [ report = [
{ {