Skip to content

Commit 1c8c60e

Browse files
authored
apply md5 fips patch (#295)
1 parent 4df7513 commit 1c8c60e

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ ignore/
8282

8383
# pyenv
8484
.python-version
85+
report.xml

src/gdc_client/download/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import hashlib
21
from io import BytesIO
32
import logging
43
import os
@@ -158,7 +157,7 @@ def _md5_members(self, members):
158157
member_uuid = m.split("/")[0]
159158
log.debug(f"Validating checksum for {member_uuid}...")
160159

161-
md5sum = hashlib.md5()
160+
md5sum = utils.md5()
162161
filename = os.path.join(self.base_directory, m)
163162
with open(filename, "rb") as f:
164163
md5sum.update(f.read())

src/gdc_client/parcel/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from gdc_client.parcel import const
1010
from gdc_client.parcel import utils
1111
from gdc_client.parcel.download_stream import DownloadStream
12-
from gdc_client.parcel.portability import colored
1312
from gdc_client.parcel.portability import Process
1413
from gdc_client.parcel.segment import SegmentProducer
1514

src/gdc_client/parcel/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# ***************************************************************************************
88

99
from contextlib import contextmanager
10-
from functools import partial
1110
import hashlib
1211
import logging
1312
import mmap
@@ -26,6 +25,7 @@
2625

2726
from gdc_client.exceptions import MD5ValidationError
2827
from gdc_client.parcel.download_stream import DownloadStream
28+
from gdc_client.parcel import utils
2929

3030
# Logging
3131
log = logging.getLogger("utils")
@@ -180,13 +180,13 @@ def calculate_segments(start, stop, block):
180180

181181

182182
def md5sum(block):
183-
m = hashlib.md5()
183+
m = utils.md5()
184184
m.update(block)
185185
return m.hexdigest()
186186

187187

188188
def md5sum_whole_file(fname):
189-
hash_md5 = hashlib.md5()
189+
hash_md5 = utils.md5()
190190

191191
with open(fname, "rb") as f:
192192
for chunk in iter(lambda: f.read(4096), b""):
@@ -233,3 +233,8 @@ def mmap_open(path):
233233

234234
def STRIP(comment):
235235
return " ".join(comment.split())
236+
237+
238+
def md5():
239+
md5_kwargs = {} if sys.version_info < (3, 9) else {"usedforsecurity": False}
240+
return hashlib.md5(**md5_kwargs)

src/gdc_client/utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
try:
2-
# Python3
3-
from urllib.parse import urlencode
4-
except ImportError:
5-
# Python2
6-
from urllib import urlencode
1+
from urllib.parse import urlencode
72

83

94
def build_url(path, *params, **kwparams):

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import hashlib
21
from io import BytesIO
32
from multiprocessing import Process
43
import tarfile
@@ -9,16 +8,17 @@
98
from moto import mock_aws
109
import pytest
1110

11+
from gdc_client.parcel import utils
1212
from gdc_client.parcel.const import HTTP_CHUNK_SIZE
1313

1414

1515
def md5(iterable: Iterable):
16-
md5 = hashlib.md5()
16+
md5_fn = utils.md5()
1717

1818
for chunk in iterable:
19-
md5.update(chunk.encode("utf-8"))
19+
md5_fn.update(chunk.encode("utf-8"))
2020

21-
return md5.hexdigest()
21+
return md5_fn.hexdigest()
2222

2323

2424
def make_tarfile(

tests/test_download_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from gdc_client.parcel.const import HTTP_CHUNK_SIZE, SAVE_INTERVAL
1212
from gdc_client.parcel.download_stream import DownloadStream
1313

14-
from conftest import make_tarfile, md5, uuids
14+
from conftest import make_tarfile, uuids
1515
from gdc_client.download.client import GDCHTTPDownloadClient, fix_url
1616
from gdc_client.download.parser import download
1717
from gdc_client.query.index import GDCIndexClient

0 commit comments

Comments
 (0)