Skip to content

Commit 3fa97b8

Browse files
gh-95231: Disable md5 & crypt modules if FIPS is enabled (GH-94742)
If kernel fips is enabled, we get permission error upon doing `import crypt`. So, if kernel fips is enabled, disable the unallowed hashing methods. Python 3.9.1 (default, May 10 2022, 11:36:26) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import crypt Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.9/crypt.py", line 117, in <module> _add_method('MD5', '1', 8, 34) File "/usr/lib/python3.9/crypt.py", line 94, in _add_method result = crypt('', salt) File "/usr/lib/python3.9/crypt.py", line 82, in crypt return _crypt.crypt(word, salt) PermissionError: [Errno 1] Operation not permitted Signed-off-by: Shreenidhi Shedi <[email protected]> (cherry picked from commit 2fa03b1) Co-authored-by: Shreenidhi Shedi <[email protected]>
1 parent 3ce1d00 commit 3fa97b8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/crypt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _add_method(name, *args, rounds=None):
9898
result = crypt('', salt)
9999
except OSError as e:
100100
# Not all libc libraries support all encryption methods.
101-
if e.errno == errno.EINVAL:
101+
if e.errno in {errno.EINVAL, errno.EPERM, errno.ENOSYS}:
102102
return False
103103
raise
104104
if result and len(result) == method.total_size:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fail gracefully if :data:`~errno.EPERM` or :data:`~errno.ENOSYS` is raised when loading
2+
:mod:`crypt` methods. This may happen when trying to load ``MD5`` on a Linux kernel
3+
with :abbr:`FIPS (Federal Information Processing Standard)` enabled.

0 commit comments

Comments
 (0)