Print SSLCertVerificationError if we get one

This also adds an option --verbose, but it doesn't actually do anything.
The error is alway reported.
This commit is contained in:
Peter J. Holzer 2022-12-21 10:03:13 +01:00
parent b10b62e77d
commit 2f400fccee
1 changed files with 3 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import time
import requests import requests
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
ap.add_argument("--verbose", action="store_true")
ap.add_argument("hostname") ap.add_argument("hostname")
ap.add_argument("port", type=int, default=443, nargs="?") ap.add_argument("port", type=int, default=443, nargs="?")
args = ap.parse_args() args = ap.parse_args()
@ -28,7 +29,8 @@ with socket.create_connection((args.hostname, args.port)) as sock:
cert = ssock.getpeercert() cert = ssock.getpeercert()
not_after = ssl.cert_time_to_seconds(cert["notAfter"]) not_after = ssl.cert_time_to_seconds(cert["notAfter"])
delta = not_after - now delta = not_after - now
except ssl.SSLCertVerificationError: except ssl.SSLCertVerificationError as e:
print("got error %s; setting delta to 0", e)
delta = 0 delta = 0
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta }) report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta })