Skip to content

Commit e475196

Browse files
Fix md5 hashing with FIPS mode (#6635)
### Description MD5 hashing is not allowed in FIPS enabled machines for security. A simple fix is to use the `usedforsecurity=False` flag in the `md5()` calls. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Matthew Vine <32849887+MattTheCuber@users.noreply.github.com> Signed-off-by: monai-bot <monai.miccai2019@gmail.com> Co-authored-by: monai-bot <monai.miccai2019@gmail.com>
1 parent 2cbed6c commit e475196

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
default_language_version:
2-
python: python3.8
2+
python: python3
33

44
ci:
55
autofix_prs: true

monai/data/utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import math
1818
import os
1919
import pickle
20+
import sys
2021
from collections import abc, defaultdict
2122
from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
2223
from copy import deepcopy
@@ -1370,7 +1371,13 @@ def json_hashing(item) -> bytes:
13701371
13711372
"""
13721373
# TODO: Find way to hash transforms content as part of the cache
1373-
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
1374+
cache_key = ""
1375+
if sys.version_info.minor < 9:
1376+
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
1377+
else:
1378+
cache_key = hashlib.md5(
1379+
json.dumps(item, sort_keys=True).encode("utf-8"), usedforsecurity=False # type: ignore
1380+
).hexdigest()
13741381
return f"{cache_key}".encode()
13751382

13761383

@@ -1385,7 +1392,13 @@ def pickle_hashing(item, protocol=pickle.HIGHEST_PROTOCOL) -> bytes:
13851392
Returns: the corresponding hash key
13861393
13871394
"""
1388-
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
1395+
cache_key = ""
1396+
if sys.version_info.minor < 9:
1397+
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
1398+
else:
1399+
cache_key = hashlib.md5(
1400+
pickle.dumps(sorted_dict(item), protocol=protocol), usedforsecurity=False # type: ignore
1401+
).hexdigest()
13891402
return f"{cache_key}".encode()
13901403

13911404

0 commit comments

Comments
 (0)