From 27efb21c425eb965c750de9cdc762084df762a88 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 20 Jul 2016 19:14:45 +0200 Subject: [PATCH] Some punycode bug fixing --- servertools/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/servertools/__init__.py b/servertools/__init__.py index 880b25d..f21bd9c 100644 --- a/servertools/__init__.py +++ b/servertools/__init__.py @@ -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 STDOUT = 1 @@ -35,7 +35,7 @@ def logger(message, prio=syslog.LOG_INFO, sink=logging): def listIncluded(host, section): 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 False @@ -61,7 +61,7 @@ class TCPHandler(socketserver.StreamRequestHandler): return "UA: Not currently implemented." elif command in ("ssl", "tls"): try: - host = encodings.idna.ToASCII(str(content[1])) + host = encodings.idna.ToASCII(str(content[1])).decode("UTF-8") try: port = int(content[2]) except IndexError: @@ -81,7 +81,8 @@ class TCPHandler(socketserver.StreamRequestHandler): return "AL: %s certificate has expired on: %s" % (content[1], expiry) else: 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])) elif command == "port": return "UA: Not currently implemented."