Skip to content

Commit

Permalink
Replace MD5 with SHA1
Browse files Browse the repository at this point in the history
  • Loading branch information
frapell committed Jul 21, 2021
1 parent 692b1d1 commit 5fd47fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion news/25.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Work in a FIPS enabled environment [frapell] (#25)
Work in a FIPS enabled environment by using SHA1 instead of MD5 for computing the cache key [frapell] (#25)
17 changes: 3 additions & 14 deletions plone/memoize/ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""A cache decorator that uses RAMCache by default.
"""

from functools import partial
from hashlib import sha1
from plone.memoize import volatile
from plone.memoize.interfaces import ICacheChooser
from zope import component
Expand All @@ -18,17 +18,6 @@
except ImportError:
import cPickle as pickle # Python 2

try:
from hashlib import md5 as md5_original
except ImportError:
from md5 import new as md5_original

try:
hashed = md5_original(b'test')
md5 = md5_original
except ValueError:
md5 = partial(md5_original, usedforsecurity=False)


global_cache = ram.RAMCache()
global_cache.update(maxAge=86400)
Expand All @@ -53,7 +42,7 @@ def __init__(self, client, globalkey=""):
def _make_key(self, source):
if issubclass(type(source), six.text_type):
source = source.encode("utf-8")
return md5(source).hexdigest()
return sha1(source).hexdigest()

def __getitem__(self, key):
cached_value = self.client.get(self.globalkey + self._make_key(key))
Expand All @@ -75,7 +64,7 @@ def __init__(self, ramcache, globalkey=""):
def _make_key(self, source):
if issubclass(type(source), six.text_type):
source = source.encode("utf-8")
return md5(source).digest()
return sha1(source).digest()

def __getitem__(self, key):
value = self.ramcache.query(
Expand Down

0 comments on commit 5fd47fc

Please sign in to comment.