[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:
parent
2a129ef949
commit
ea0ea9c527
1 changed files with 15 additions and 3 deletions
|
@ -66,12 +66,17 @@ for arg in sys.argv[1:]:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
host = arg
|
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:
|
if filename:
|
||||||
cert = X509.load_cert(host)
|
cert = X509.load_cert(host)
|
||||||
elif port != 25:
|
elif not starttls:
|
||||||
conn = SSL.Connection(SSL.Context())
|
conn = SSL.Connection(SSL.Context())
|
||||||
try:
|
try:
|
||||||
conn.connect((host, port))
|
conn.connect((host, port))
|
||||||
|
@ -81,12 +86,19 @@ elif port != 25:
|
||||||
|
|
||||||
cert = conn.get_peer_cert()
|
cert = conn.get_peer_cert()
|
||||||
conn.close()
|
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()
|
expire_date = cert.get_not_after().get_datetime()
|
||||||
subject = cert.get_subject.as_text()
|
subject = cert.get_subject().as_text()
|
||||||
try:
|
try:
|
||||||
altname = "(alt: %s)" % cert.get_ext('subjectAltName').get_value()
|
altname = "(alt: %s)" % cert.get_ext('subjectAltName').get_value()
|
||||||
except LookupError:
|
except LookupError:
|
||||||
altname = ""
|
altname = ""
|
||||||
|
# Avec starttls, on fait totalement autre chose (et on n'utilise pas la variable
|
||||||
|
# cert d'au dessus)
|
||||||
else:
|
else:
|
||||||
smtp = socket.socket()
|
smtp = socket.socket()
|
||||||
smtp.connect((host, port))
|
smtp.connect((host, port))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue