-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-95231: Disable md5 & crypt modules if FIPS is enabled #94742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Hi @vstinner, @erlend-aasland, @rhettinger |
Hi @gvanrossum @benjaminp @birkenfeld @freddrake, Please review this PR, need your inputs. |
Please abstain from pinging random developers. See https://www.python.org/dev/core-mentorship/ for getting help with your first contributions and in general https://devguide.python.org/ for documentation of our process. |
Hi, @sshedi; thanks for your interest in improving CPython! Please create an issue and explain why these changes are needed. Also, for the future, please follow Georg Brandl's advice: start with the devguide; it contains a lot of important information for new contributors. |
Thanks @erlend-aasland and @birkenfeld for your response. I have created an issue here #95231 I believe I have given sufficient info on the issue I'm facing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach with reading from /proc/sys/crypto/fips_enabled
and manually disabling MD5 and CRYPT is not portable. The proc interface is Linux specific. The system may block more or less algorithms depending on the local crypto policy.
I recommend that we should catch more errno values in _add_method
instead.
diff --git a/Lib/crypt.py b/Lib/crypt.py
index 46c3de8474b..92e70415e1a 100644
--- a/Lib/crypt.py
+++ b/Lib/crypt.py
@@ -100,6 +100,9 @@ def _add_method(name, *args, rounds=None):
# Not all libc libraries support all encryption methods.
if e.errno == errno.EINVAL:
return False
+ # unsupported or blocked by crypto policy
+ if e.errno in {errno.EPERM, errno.ENOSYS}:
+ return False
raise
if result and len(result) == method.total_size:
methods.append(method)
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Also, please add a NEWS entry using the https://devguide.python.org/getting-started/pull-request-lifecycle/ |
@tiran Valid point. But how other python modules are detecting kernel fips status? cpython/Lib/test/pythoninfo.py Line 840 in 310f948
Suggested code works but can we have something to know that we got EPERM because of fips? |
Your proposed solution is solving the wrong problem, or at least a too narrow part of a general problem. It is trying to detect FIPS mode and then hard-codes which algorithms it thinks are disabled in FIPS mode. FIPS is an evolving standard. For example FIPS 140-3 blocks some algorithms are are allowed in FIPS 140-2. There are also more crypto policy standards than FIPS. FIPS is only relevant for the US government. It is irrelevant for the rest of the world and non-government software inside the US. My solution is simpler and should fix your problem with less code. It is also not tight to FIPS and can handle other crypto policies that block algorithms. I don't know why libcrypt on your system raises a permission error. I recommend that your contact your vendor and make an inquiry. |
Thanks @tiran for the detailed explanation, I agree. I will make the suggested changes. |
The EPERM error is coming from libcrypt and glibc is doing it.
|
For the record; please do not force push PRs, as the GitHub UI do not play well with force-pushes. Please use @sshedi ☝🏻 |
Misc/NEWS.d/next/Library/2022-07-25-15-45-06.gh-issue-95231.i807-g.rst
Outdated
Show resolved
Hide resolved
Sorry @erlend-aasland , it has become a habit for me now. |
Misc/NEWS.d/next/Library/2022-07-25-15-45-06.gh-issue-95231.i807-g.rst
Outdated
Show resolved
Hide resolved
I have made the requested changes; please review again. @erlend-aasland - Sorry, I amended y changes addressing review comments so I have to force push to my branch. |
Thanks for making the requested changes! @tiran: please review the changes made to this pull request. |
Thanks for making the requested changes! @erlend-aasland, @tiran: please review the changes made to this pull request. |
Updating branch to retrigger Azure Pipelines CI. |
Thanks @sshedi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry @sshedi, I had trouble checking out the |
GH-95998 is a backport of this pull request to the 3.10 branch. |
…nGH-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]>
Thanks @sshedi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
…nGH-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]>
GH-95999 is a backport of this pull request to the 3.11 branch. |
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]>
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]>
Hi everyone, any chance of backport it to 3.9 too?? |
That's somehow a new feature, and 3.9 only accept security fixes: https://devguide.python.org/versions/ |
If kernel fips is enabled, we get permission error upon doing
import crypt
. So, if kernel fips is enabled, disable theunallowed 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.
Signed-off-by: Shreenidhi Shedi [email protected]
Automerge-Triggered-By: GH:tiran