Skip to content

Commit 93814a9

Browse files
committed
feat: Indicate that md5 is used as a CRC
MD5 in storage helpers is used as a CRC function for non-cryptographically secure purposes. Ensure that md5 is initiated with `usedforsecurity=False` to ensure that Python in FIPS mode can fetch MD5 implementation for such non cryptographically secure purpose. This is no effective change on non-FIPS mode Python installations. This improves compatibility with most FIPS mode Python installations.
1 parent dc3756d commit 93814a9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

google/cloud/storage/_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import datetime
2222
from hashlib import md5
2323
import os
24+
import sys
2425
from urllib.parse import urlsplit
2526
from urllib.parse import urlunsplit
2627
from uuid import uuid4
@@ -536,7 +537,10 @@ def _base64_md5hash(buffer_object):
536537
:rtype: str
537538
:returns: A base64 encoded digest of the MD5 hash.
538539
"""
539-
hash_obj = md5()
540+
if sys.version_info >= (3, 9):
541+
hash_obj = md5(usedforsecurity=False)
542+
else:
543+
hash_obj = md5()
540544
_write_buffer_to_hash(buffer_object, hash_obj)
541545
digest_bytes = hash_obj.digest()
542546
return base64.b64encode(digest_bytes)

tests/unit/test__helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def __init__(self, digest_val):
735735
self.hash_obj = _MD5Hash(digest_val)
736736
self._called = []
737737

738-
def __call__(self, data=None):
738+
def __call__(self, data=None, usedforsecurity=True):
739739
self._called.append(data)
740740
return self.hash_obj
741741

0 commit comments

Comments
 (0)