Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedJul 11, 2022 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
bedevere-bot commentedJul 11, 2022
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
sshedi commentedJul 11, 2022
Hi@vstinner,@erlend-aasland,@rhettinger |
sshedi commentedJul 25, 2022
Hi@gvanrossum@benjaminp@birkenfeld@freddrake, Please review this PR, need your inputs. |
birkenfeld commentedJul 25, 2022
Please abstain from pinging random developers. Seehttps://www.python.org/dev/core-mentorship/ for getting help with your first contributions and in generalhttps://devguide.python.org/ for documentation of our process. |
erlend-aasland commentedJul 25, 2022
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. |
sshedi commentedJul 25, 2022
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. |
tiran left a comment
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.pyindex 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)bedevere-bot commentedJul 25, 2022
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 |
erlend-aasland commentedJul 25, 2022
Also, please add a NEWS entry using the https://devguide.python.org/getting-started/pull-request-lifecycle/ |
sshedi commentedJul 25, 2022
@tiran Valid point. But how other python modules are detecting kernel fips status? cpython/Lib/test/pythoninfo.py Line 840 in310f948
Suggested code works but can we have something to know that we got EPERM because of fips? |
tiran commentedJul 25, 2022
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. |
sshedi commentedJul 25, 2022
Thanks@tiran for the detailed explanation, I agree. I will make the suggested changes. |
sshedi commentedJul 25, 2022
The EPERM error is coming from libcrypt and glibc is doing it. |
erlend-aasland commentedJul 25, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
sshedi commentedJul 25, 2022
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
sshedi commentedJul 26, 2022
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. |
bedevere-bot commentedJul 26, 2022
Thanks for making the requested changes! @tiran: please review the changes made to this pull request. |
bedevere-bot commentedAug 15, 2022
Thanks for making the requested changes! @erlend-aasland,@tiran: please review the changes made to this pull request. |
erlend-aasland commentedAug 15, 2022
Updating branch to retrigger Azure Pipelines CI. |
miss-islington commentedAug 15, 2022
Thanks@sshedi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
miss-islington commentedAug 15, 2022
Sorry@sshedi, I had trouble checking out the |
bedevere-bot commentedAug 15, 2022
GH-95998 is a backport of this pull request to the3.10 branch. |
…nGH-94742)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 linuxType "help", "copyright", "credits" or "license" for more information.>>> import cryptTraceback (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 permittedSigned-off-by: Shreenidhi Shedi <sshedi@vmware.com>(cherry picked from commit2fa03b1)Co-authored-by: Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com>
miss-islington commentedAug 15, 2022
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 theunallowed hashing methods.Python 3.9.1 (default, May 10 2022, 11:36:26)[GCC 10.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import cryptTraceback (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 permittedSigned-off-by: Shreenidhi Shedi <sshedi@vmware.com>(cherry picked from commit2fa03b1)Co-authored-by: Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com>
bedevere-bot commentedAug 15, 2022
GH-95999 is a backport of this pull request to the3.11 branch. |
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 linuxType "help", "copyright", "credits" or "license" for more information.>>> import cryptTraceback (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 permittedSigned-off-by: Shreenidhi Shedi <sshedi@vmware.com>(cherry picked from commit2fa03b1)Co-authored-by: Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com>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 linuxType "help", "copyright", "credits" or "license" for more information.>>> import cryptTraceback (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 permittedSigned-off-by: Shreenidhi Shedi <sshedi@vmware.com>(cherry picked from commit2fa03b1)Co-authored-by: Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com>mixmind commentedMay 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi everyone, any chance of backport it to 3.9 too?? |
vstinner commentedMay 3, 2024
That's somehow a new feature, and 3.9 only accept security fixes:https://devguide.python.org/versions/ |
Uh oh!
There was an error while loading.Please reload this page.
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 Shedisshedi@vmware.com
Automerge-Triggered-By: GH:tiran