commit 61f315535165e37ac49f9a415d961b65540d8c20 Author: Christian Fromme kaner@strace.org Date: Tue Aug 23 21:19:00 2011 +0200
Clean up logs a bit (remove logging of sensitive data) --- lib/gettor/blacklist.py | 4 +--- lib/gettor/filters.py | 1 - lib/gettor/requests.py | 1 + lib/gettor/responses.py | 21 ++++++++++++--------- lib/gettor/utils.py | 4 ++++ 5 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/lib/gettor/blacklist.py b/lib/gettor/blacklist.py index cbf2c47..83cf188 100644 --- a/lib/gettor/blacklist.py +++ b/lib/gettor/blacklist.py @@ -2,7 +2,6 @@ # Christian Fromme kaner@strace.org # This is Free Software. See LICENSE for license information.
-import hashlib import os import re import glob @@ -109,5 +108,4 @@ class BWList: """Return hash for a given emailaddress """ emailonly = gettor.utils.stripEmail(address) - return str(hashlib.sha1(emailonly).hexdigest()) - + return gettor.utils.getHash(emailonly) diff --git a/lib/gettor/filters.py b/lib/gettor/filters.py index 4deacb0..f2f0534 100644 --- a/lib/gettor/filters.py +++ b/lib/gettor/filters.py @@ -32,7 +32,6 @@ def checkAddressHack(userAddress): XXX: This should merge somehow with the GetTor blacklisting mechanism at some point """ - logging.debug("Checking user address %s.." % userAddress) if re.compile(".*@.*torproject.org.*").match(userAddress): return False
diff --git a/lib/gettor/requests.py b/lib/gettor/requests.py index 9cadef5..5b9bb3b 100644 --- a/lib/gettor/requests.py +++ b/lib/gettor/requests.py @@ -22,6 +22,7 @@ class requestMail: self.config = config self.request = {} self.request['user'] = self.parsedMessage["Return-Path"] + self.request['hashed_user'] = gettor.utils.getHash(self.request['user']) self.request['ouraddr'] = self.getRealTo(self.parsedMessage["to"]) self.request['locale'] = self.getLocaleInTo(self.request['ouraddr']) self.request['package'] = None diff --git a/lib/gettor/responses.py b/lib/gettor/responses.py index 47bb7d3..b0dd643 100644 --- a/lib/gettor/responses.py +++ b/lib/gettor/responses.py @@ -5,6 +5,7 @@ import os import re import sys +import copy import smtplib import gettext import logging @@ -112,8 +113,10 @@ class Response: self.config = config self.reqInfo = reqInfo
- # Dump info - logging.info(str(self.reqInfo)) + # Delete sensitive data before dumping info + reqInfoClean = copy.deepcopy(self.reqInfo) + del reqInfoClean['user'] + logging.info(str(reqInfoClean))
# Initialize locale subsystem self.t = i18n.getLang(self.reqInfo['locale'], config) @@ -165,7 +168,7 @@ class Response: self.bList.createSublist(fname) if self.bList.lookupListEntry(self.reqInfo['user'], fname): logging.info("User %s is blacklisted for %s" \ - % (self.reqInfo['user'], fname)) + % (self.reqInfo['hashed_user'], fname)) return True else: self.bList.createListEntry(self.reqInfo['user'], fname) @@ -185,7 +188,7 @@ class Response: if self.isBlacklistedForMessageType("sendPackage"): # Don't send anything return False - logging.info("Sending out %s to %s." % (pack, to)) + logging.info("Sending out %s." % (pack)) f = os.path.join(self.config.BASEDIR, "packages", pack + ".z") txt = getPackageMsg(self.t) msg = self.makeMsg(txt, to, fileName=f) @@ -205,7 +208,7 @@ class Response: pack = self.reqInfo['package'] fwd = self.reqInfo['forward'] to = self.reqInfo['user'] - logging.info("Sending out %s to %s." % (pack, fwd)) + logging.info("Sending out %s." % (pack)) f = os.path.join(self.config.BASEDIR, "packages", pack + ".z") text = getPackageMsg(self.t) msg = self.makeMsg(text, fwd, fileName=f) @@ -282,7 +285,7 @@ class Response: if self.isBlacklistedForMessageType("sendDelayAlert"): # Don't send anything return False - logging.info("Sending delay alert to %s" % self.reqInfo['user']) + logging.info("Sending delay alert to %s" % self.reqInfo['hashed_user']) return self.sendTextEmail(getDelayAlertMsg(self.t))
def sendHelp(self): @@ -292,7 +295,7 @@ class Response: if self.isBlacklistedForMessageType("sendHelp"): # Don't send anything return False - logging.info("Sending out help message to %s" % self.reqInfo['user']) + logging.info("Sending out help message to %s" % self.reqInfo['hashed_user']) return self.sendTextEmail(getPackageHelpMsg(self.t))
def sendPackageHelp(self): @@ -302,7 +305,7 @@ class Response: if self.isBlacklistedForMessageType("sendPackageHelp"): # Don't send anything return False - logging.info("Sending package help to %s" % self.reqInfo['user']) + logging.info("Sending package help to %s" % self.reqInfo['hashed_user']) return self.sendTextEmail(i18n.MULTILANGHELP)
def sendTextEmail(self, text): @@ -313,7 +316,7 @@ class Response: status = self.sendEmail(self.reqInfo['user'], message) except: logging.error("Could not send message to user %s" \ - % self.reqInfo['user']) + % self.reqInfo['hashed_user']) status = False
logging.debug("Send status: %s" % status) diff --git a/lib/gettor/utils.py b/lib/gettor/utils.py index 0a51760..f29ddf6 100644 --- a/lib/gettor/utils.py +++ b/lib/gettor/utils.py @@ -285,3 +285,7 @@ def stripHTMLTags(string): """ return re.sub(r'<[^>]*?>', '', string)
+def getHash(string): + """Return hash of given string + """ + return str(hashlib.sha1(string).hexdigest())
tor-commits@lists.torproject.org