[check_cert] repare bugs du commit précédent

Le commit introduisait starttls mait pétait tout le reste ...
Rajouts de commentaires pour espérer qu'on ne casse plus ce script...
This commit is contained in:
Daniel STAN 2013-08-04 14:11:13 +02:00
parent 2a129ef949
commit ea0ea9c527

View file

@ -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))