Commit 6649daa4 authored by ilv's avatar ilv
Browse files

Changed sha1 to sha256 (dunno why I used sha1...)

parent d41eb8d4
......@@ -45,8 +45,8 @@ def get_bundle_info(file):
else:
raise ValueError("Bundle invalid format %s" % file)
def get_file_sha1(file):
"""Get the sha1 of a file.
def get_file_sha256(file):
"""Get the sha256 of a file.
Desc.
......@@ -54,7 +54,7 @@ def get_file_sha1(file):
# as seen on the internet
BLOCKSIZE = 65536
hasher = hashlib.sha1()
hasher = hashlib.sha256()
with open(file, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
......@@ -143,12 +143,12 @@ if __name__ == '__main__':
abs_file = os.path.abspath(os.path.join(upload_dir, file))
abs_asc = os.path.abspath(os.path.join(upload_dir, asc))
sha1_file = get_file_sha1(abs_file)
sha_file = get_file_sha256(abs_file)
# build links
link_file = client.share(file)
link_asc = client.share(asc)
link = link_file[u'url'] + ' ' + link_asc[u'url'] + ' ' + sha1_file
link = link_file[u'url'] + ' ' + link_asc[u'url'] + ' ' + sha_file
# add links
operating_system, locale = get_bundle_info(file)
......
......@@ -133,18 +133,18 @@ class SMTP(object):
logger.propagate = False
self.logger.debug("New smtp object created")
def _get_sha1(self, string):
"""Get sha1 of a string.
def _get_sha256(self, string):
"""Get sha256 of a string.
Used whenever we want to do things with addresses (log, blacklist,
etc.)
Params: The string to be sha1'ed.
Params: The string to be hashed.
Returns: sha1 of string.
Returns: sha256 of string.
"""
return str(hashlib.sha1(string).hexdigest())
return str(hashlib.sha256(string).hexdigest())
def _log_request(self, addr, raw_msg):
"""Log a request.
......@@ -163,9 +163,9 @@ class SMTP(object):
# to do: obtain content of msg, not the entire email
content = raw_msg
# We store the sha1 of the original address in order to know when
# We store the sha256 of the original address in order to know when
# specific addresses are doing weird requests
log_addr = self._get_sha1(addr)
log_addr = self._get_sha256(addr)
filename = str(time.time()) + '.log'
path = self.logdir_emails + filename
abs_path = os.path.abspath(path)
......@@ -191,7 +191,7 @@ class SMTP(object):
Params: addr - the address we want to check.
"""
anon_addr = self._get_sha1(addr)
anon_addr = self._get_sha256(addr)
self.logger.debug("Checking if address %s is blacklisted" %
anon_addr)
......@@ -242,7 +242,7 @@ class SMTP(object):
m = re.search(r'<([^>]*)>', addr)
if m is None:
raise AddressError("Couldn't extract normalized address "
"from %s" % self_get_sha1(addr))
"from %s" % self_get_sha256(addr))
addr = m.group(1)
return addr
......@@ -542,7 +542,7 @@ class SMTP(object):
if norm_from_addr:
try:
self._check_blacklist(self._get_sha1(norm_from_addr))
self._check_blacklist(self._get_sha256(norm_from_addr))
except BlacklistError as e:
# This shouldn't stop us from receiving other requests
self.logger.warning(str(e))
......
......@@ -169,18 +169,18 @@ class XMPP(object):
xmpp.connect()
xmpp.process(block=True)
def _get_sha1(self, string):
"""Get sha1 of a string.
def _get_sha256(self, string):
"""Get sha256 of a string.
Used whenever we want to do things with accounts (log, blacklist,
etc.)
Params: The string to be sha1'ed.
Params: The string to be hashed.
Returns: sha1 of string.
Returns: sha256 of string.
"""
return str(hashlib.sha1(string).hexdigest())
return str(hashlib.sha256(string).hexdigest())
def _check_blacklist(self, account):
"""Check if an account is blacklisted.
......@@ -192,7 +192,7 @@ class XMPP(object):
Params: account - the account we want to check.
"""
anon_account = self._get_sha1(account)
anon_account = self._get_sha256(account)
self.logger.debug("Checking if address %s is blacklisted" %
anon_account)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment