From ea0ea9c5274e550e27deb76aa482b12d6959f780 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Sun, 4 Aug 2013 14:11:13 +0200 Subject: [PATCH] =?UTF-8?q?[check=5Fcert]=20repare=20bugs=20du=20commit=20?= =?UTF-8?q?pr=C3=A9c=C3=A9dent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le commit introduisait starttls mait pétait tout le reste ... Rajouts de commentaires pour espérer qu'on ne casse plus ce script... --- utils/check_cert.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/utils/check_cert.py b/utils/check_cert.py index 842fde7d..bfadf3d4 100755 --- a/utils/check_cert.py +++ b/utils/check_cert.py @@ -66,12 +66,17 @@ for arg in sys.argv[1:]: except ValueError: host = arg +# Va-t-on faire du starttls ? +# pour l'instant, uniquement pour smtp, mais on peut imaginer étendre à +# l'avenir à d'autre protocole (xmpp en aurait bien besoin par exemple) +starttls = (port == 25) + # -# Getting cert ! +# Getting cert ! (sauf starttls) # if filename: cert = X509.load_cert(host) -elif port != 25: +elif not starttls: conn = SSL.Connection(SSL.Context()) try: conn.connect((host, port)) @@ -81,12 +86,19 @@ elif port != 25: cert = conn.get_peer_cert() conn.close() +# +# Getting subject, altname et expire_date +# +# Sans starttls, pour les fichiers simples comme pour les connexions +if not starttls: expire_date = cert.get_not_after().get_datetime() - subject = cert.get_subject.as_text() + subject = cert.get_subject().as_text() try: altname = "(alt: %s)" % cert.get_ext('subjectAltName').get_value() except LookupError: altname = "" +# Avec starttls, on fait totalement autre chose (et on n'utilise pas la variable +# cert d'au dessus) else: smtp = socket.socket() smtp.connect((host, port))