Skip to content

Commit b3513ec

Browse files
authored
[gcloud] use a different checksum method to fix downloading in FIPS mode (#1473)
Python 3.10 and later versions rely on OpenSSL 1.1.1 or newer, which includes FIPS-compliance checks. MD5 is not an approved algorithm in FIPS mode, so attempting to instantiate self.blob.download_to_file(self._file) will fail when the system is running in FIPS mode. The change configures the `download_to_file` function to use an alternative algorithm provided by gcloud storage SDK - 'crc32c' - for checksum calculation. Configurable checksumming is available in the google-storage lib since v1.31.0, but pinning to >=1.32 for the retry import. Co-authored-by: markesha <>
1 parent fda4e23 commit b3513ec

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dropbox = [
5555
"dropbox>=7.2.1",
5656
]
5757
google = [
58-
"google-cloud-storage>=1.27",
58+
"google-cloud-storage>=1.32",
5959
]
6060
libcloud = [
6161
"apache-libcloud",

storages/backends/gcloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _get_file(self):
6262
)
6363
if "r" in self._mode:
6464
self._is_dirty = False
65-
self.blob.download_to_file(self._file)
65+
self.blob.download_to_file(self._file, checksum="crc32c")
6666
self._file.seek(0)
6767
if self._storage.gzip and self.blob.content_encoding == "gzip":
6868
self._file = self._decompress_file(mode=self._mode, file=self._file)

tests/test_gcloud.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_open_read(self):
4242
self.filename, chunk_size=None
4343
)
4444

45-
f.blob.download_to_file = lambda tmpfile: tmpfile.write(data)
45+
f.blob.download_to_file = lambda tmpfile, **kwargs: tmpfile.write(data)
4646
self.assertEqual(f.read(), data)
4747

4848
def test_open_read_num_bytes(self):
@@ -55,7 +55,7 @@ def test_open_read_num_bytes(self):
5555
self.filename, chunk_size=None
5656
)
5757

58-
f.blob.download_to_file = lambda tmpfile: tmpfile.write(data)
58+
f.blob.download_to_file = lambda tmpfile, **kwargs: tmpfile.write(data)
5959
self.assertEqual(f.read(num_bytes), data[0:num_bytes])
6060

6161
def test_open_read_nonexistent(self):

0 commit comments

Comments
 (0)