Skip to content

Commit

Permalink
refactor!: remove md4 and related ENABLE_BLAKE2B_HASHING feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 committed Dec 24, 2024
1 parent 81f825f commit 0de7569
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 90 deletions.
24 changes: 1 addition & 23 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,7 @@ jobs:

- name: install system requirements
run: |
sudo apt-get update && sudo apt-get install libmysqlclient-dev libxmlsec1-dev lynx openssl
# This is needed until the ENABLE_BLAKE2B_HASHING can be removed and we
# can stop using MD4 by default.
- name: enable md4 hashing in libssl
run: |
cat <<EOF | sudo tee /etc/ssl/openssl.cnf
# Use this in order to automatically load providers.
openssl_conf = openssl_init
[openssl_init]
providers = provider_sect
[provider_sect]
default = default_sect
legacy = legacy_sect
[default_sect]
activate = 1
[legacy_sect]
activate = 1
EOF
sudo apt-get update && sudo apt-get install libmysqlclient-dev libxmlsec1-dev lynx
- name: Start MongoDB
uses: supercharge/[email protected]
Expand Down
3 changes: 0 additions & 3 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,6 @@
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/33911
'ENABLE_GRADING_METHOD_IN_PROBLEMS': False,

# See annotations in lms/envs/common.py for details.
'ENABLE_BLAKE2B_HASHING': False,

# .. toggle_name: FEATURES['BADGES_ENABLED']
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
Expand Down
6 changes: 1 addition & 5 deletions common/djangoapps/util/memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
import hashlib
from urllib.parse import quote_plus

from django.conf import settings
from django.utils.encoding import smart_str


def fasthash(string):
"""
Hashes `string` into a string representation of a 128-bit digest.
"""
if settings.FEATURES.get("ENABLE_BLAKE2B_HASHING", False):
hash_obj = hashlib.new("blake2b", digest_size=16)
else:
hash_obj = hashlib.new("md4")
hash_obj = hashlib.new("blake2b", digest_size=16)
hash_obj.update(string.encode('utf-8'))
return hash_obj.hexdigest()

Expand Down
48 changes: 1 addition & 47 deletions common/djangoapps/util/tests/test_memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
"""


from django.conf import settings
from django.core.cache import caches
from django.test import TestCase, override_settings
from django.test import TestCase

from common.djangoapps.util.memcache import safe_key

BLAKE2B_ENABLED_FEATURES = settings.FEATURES.copy()
BLAKE2B_ENABLED_FEATURES["ENABLE_BLAKE2B_HASHING"] = True


class MemcacheTest(TestCase):
"""
Expand Down Expand Up @@ -55,20 +51,6 @@ def test_safe_key_long(self):
# The key should now be valid
assert self._is_valid_key(key), f'Failed for key length {length}'

@override_settings(FEATURES=BLAKE2B_ENABLED_FEATURES)
def test_safe_key_long_with_blake2b_enabled(self):
# Choose lengths close to memcached's cutoff (250)
for length in [248, 249, 250, 251, 252]:

# Generate a key of that length
key = 'a' * length

# Make the key safe
key = safe_key(key, '', '')

# The key should now be valid
assert self._is_valid_key(key), f'Failed for key length {length}'

def test_long_key_prefix_version(self):

# Long key
Expand All @@ -83,34 +65,6 @@ def test_long_key_prefix_version(self):
key = safe_key('key', 'prefix', 'a' * 300)
assert self._is_valid_key(key)

@override_settings(FEATURES=BLAKE2B_ENABLED_FEATURES)
def test_long_key_prefix_version_with_blake2b_enabled(self):

# Long key
key = safe_key('a' * 300, 'prefix', 'version')
assert self._is_valid_key(key)

# Long prefix
key = safe_key('key', 'a' * 300, 'version')
assert self._is_valid_key(key)

# Long version
key = safe_key('key', 'prefix', 'a' * 300)
assert self._is_valid_key(key)

def test_safe_key_unicode(self):

for unicode_char in self.UNICODE_CHAR_CODES:

# Generate a key with that character
key = chr(unicode_char)

# Make the key safe
key = safe_key(key, '', '')

# The key should now be valid
assert self._is_valid_key(key), f'Failed for unicode character {unicode_char}'

def test_safe_key_prefix_unicode(self):

for unicode_char in self.UNICODE_CHAR_CODES:
Expand Down
12 changes: 0 additions & 12 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,18 +1059,6 @@
# .. toggle_creation_date: 2024-04-24
'ENABLE_COURSEWARE_SEARCH_VERIFIED_ENROLLMENT_REQUIRED': False,

# .. toggle_name: FEATURES['ENABLE_BLAKE2B_HASHING']
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
# .. toggle_description: Enables the memcache to use the blake2b hash algorithm instead of depreciated md4 for keys
# exceeding 250 characters
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-04-02
# .. toggle_target_removal_date: 2024-12-09
# .. toggle_warning: For consistency, keep the value in sync with the setting of the same name in the LMS and CMS.
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/34442
'ENABLE_BLAKE2B_HASHING': False,

# .. toggle_name: FEATURES['BADGES_ENABLED']
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
Expand Down

0 comments on commit 0de7569

Please sign in to comment.