WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4401ff5

Browse files
authored
Fix hashlib.md5 call for FIPS-enabled builds (#3228)
FIPS errors with the following message: ``` File "/usr/lib/python3.11/site-packages/pdm/cli/commands/run.py", line 167, in _get_script_env venv_name = hashlib.md5(os.path.realpath(script_file).encode("utf-8")).hexdigest() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _hashlib.UnsupportedDigestmodError: [digital envelope routines] unsupported ``` Since the hash isn't use for cryptographic use we indicate that md5 can be safely used
1 parent ceb387b commit 4401ff5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/pdm/cli/commands/run.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ def _get_script_env(self, script_file: str) -> BaseEnvironment:
164164
tool_config = metadata.pop("tool", {})
165165
script_project = self.project.core.create_project()
166166
script_project.pyproject.set_data({"project": metadata, "tool": tool_config})
167-
venv_name = hashlib.md5(os.path.realpath(script_file).encode("utf-8")).hexdigest()
167+
md5_kwargs = {}
168+
# for python >= 3.9, indicate that md5 is not used in a security context
169+
if sys.version_info >= (3, 9):
170+
md5_kwargs = {"usedforsecurity": False}
171+
venv_name = hashlib.md5(os.path.realpath(script_file).encode("utf-8"), **md5_kwargs).hexdigest()
168172
venv_backend = BACKENDS[script_project.config["venv.backend"]](script_project, None)
169173
venv = venv_backend.get_location(None, venv_name)
170174
if venv.exists() and not self.recreate_env:

0 commit comments

Comments
 (0)