From 70b68108c7517c10e4b707b85be71a9942b04231 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Tue, 10 Oct 2023 10:28:56 +0200 Subject: [PATCH] Treat ConnectionRefusedError like SSLCertVerificationError --- clients/record_tlscert | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clients/record_tlscert b/clients/record_tlscert index cb80d18..3f1c7c8 100755 --- a/clients/record_tlscert +++ b/clients/record_tlscert @@ -16,17 +16,17 @@ args = ap.parse_args() now = time.time() report0 = [] -with socket.create_connection((args.hostname, args.port)) as sock: - context = ssl.create_default_context() - try: +try: + 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 - except ssl.SSLCertVerificationError as e: - print("got error %s; setting delta to 0", e) - delta = 0 - report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta }) +except (ssl.SSLCertVerificationError, ConnectionRefusedError) as e: + print("got error %s; setting delta to 0" % e) + delta = 0 +report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta }) report = [ {