Some punycode bug fixing

This commit is contained in:
Klaus-Uwe Mitterer 2016-07-20 19:14:45 +02:00
parent c958d290d2
commit 27efb21c42

View file

@ -1,4 +1,4 @@
import datetime, encodings, os, setuptools, socketserver, ssltools, sys, syslog, threading import datetime, encodings.idna, os, setuptools, socketserver, ssltools, sys, syslog, threading
SYSLOG = 0 SYSLOG = 0
STDOUT = 1 STDOUT = 1
@ -35,7 +35,7 @@ def logger(message, prio=syslog.LOG_INFO, sink=logging):
def listIncluded(host, section): def listIncluded(host, section):
for i in setuptools.getListSetting("SSL" if section == 0 else "Ports", "hosts"): for i in setuptools.getListSetting("SSL" if section == 0 else "Ports", "hosts"):
if i[0].lower() == host.lower(): if encodings.idna.ToASCII(i[0].lower()).decode("UTF-8") == encodings.idna.ToASCII(host.lower()).decode("UTF-8"):
return True return True
return False return False
@ -61,7 +61,7 @@ class TCPHandler(socketserver.StreamRequestHandler):
return "UA: Not currently implemented." return "UA: Not currently implemented."
elif command in ("ssl", "tls"): elif command in ("ssl", "tls"):
try: try:
host = encodings.idna.ToASCII(str(content[1])) host = encodings.idna.ToASCII(str(content[1])).decode("UTF-8")
try: try:
port = int(content[2]) port = int(content[2])
except IndexError: except IndexError:
@ -81,7 +81,8 @@ class TCPHandler(socketserver.StreamRequestHandler):
return "AL: %s certificate has expired on: %s" % (content[1], expiry) return "AL: %s certificate has expired on: %s" % (content[1], expiry)
else: else:
return "NM: %s is not being monitored!" % content[1] return "NM: %s is not being monitored!" % content[1]
except: except Exception as e:
print(e)
return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], int(content[2])) return "ER: Could not verify SSL certificate on %s:%i. Is the server down?" % (content[1], int(content[2]))
elif command == "port": elif command == "port":
return "UA: Not currently implemented." return "UA: Not currently implemented."