Uh oh!
There was an error while loading. Please reload this page.
gh-127298: Refactor test_hashlib for better usedforsecurity & openssl fips mode env support. - #127492
gh-127298: Refactor test_hashlib for better usedforsecurity & openssl fips mode env support.#127492gpshead wants to merge 8 commits into
Conversation
…environment support.
gpshead
commented
Dec 1, 2024
!buildbot FIPS |
bedevere-bot
commented
Dec 1, 2024
🤖 New build scheduled with the buildbot fleet by @gpshead for commit 59d9a85 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
gpshead
commented
Dec 1, 2024
!buildbot FIPS |
bedevere-bot
commented
Dec 1, 2024
🤖 New build scheduled with the buildbot fleet by @gpshead for commit bd46651 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
7a5ab6c to
bd46651Comparegpshead
commented
Dec 2, 2024
#127467 is follow-on work to this that combined gets the FIPS mode buildbots passing in main. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
stratakis
commented
Dec 3, 2024
Thanks for the PR! I'll have a look at it and I can also provide ssh access to the FIPS buildbots if that would make things easier to debug. |
vstinner
commented
Dec 5, 2024
I tested manually the change on RHEL8. 3 MD5 tests of test_hashlib are failing: |
vstinner
commented
Dec 5, 2024
I built Python with |
vstinner
commented
Dec 5, 2024
Suggested fix for file digest: diff --git a/Lib/hashlib.py b/Lib/hashlib.py
index 44656c33a..93d602571 100644
--- a/Lib/hashlib.py+++ b/Lib/hashlib.py@@ -192,7 +192,7 @@ def __hash_new(name, data=b'', **kwargs):
pass
-def file_digest(fileobj, digest, /, *, _bufsize=2**18):+def file_digest(fileobj, digest, /, *, usedforsecurity=True, _bufsize=2**18):
"""Hash the contents of a file-like object. Returns a digest object.
*fileobj* must be a file-like object opened for reading in binary mode.
@@ -206,9 +206,9 @@ def file_digest(fileobj, digest, /, *, _bufsize=2**18):
# On Linux we could use AF_ALG sockets and sendfile() to archive zero-copy
# hashing with hardware acceleration.
if isinstance(digest, str):
- digestobj = new(digest)+ digestobj = new(digest, usedforsecurity=usedforsecurity)
else:
- digestobj = digest()+ digestobj = digest(usedforsecurity=usedforsecurity)
if hasattr(fileobj, "getbuffer"):
# io.BytesIO object, use zero-copy buffer
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 1c1a0396c..a7cca0ba5 100644
--- a/Lib/test/test_hashlib.py+++ b/Lib/test/test_hashlib.py@@ -443,11 +443,13 @@ def check_file_digest(self, name, data, hexdigest):
for digest in digests:
buf = io.BytesIO(data)
buf.seek(0)
- self.assertEqual(- hashlib.file_digest(buf, digest).hexdigest(), hexdigest- )+ digestobj = hashlib.file_digest(buf, digest,+ usedforsecurity=False)+ self.assertEqual(digestobj.hexdigest(), hexdigest)+
with open(os_helper.TESTFN, "rb") as f:
- digestobj = hashlib.file_digest(f, digest)+ digestobj = hashlib.file_digest(f, digest,+ usedforsecurity=False)
self.assertEqual(digestobj.hexdigest(), hexdigest)
finally:
os.unlink(os_helper.TESTFN) |
xnox
commented
Dec 11, 2024
@gpshead the suggestion from @vstinner looks reasonable in #127492 (comment) will you push that to this pr? Or should that change be done separately, with a separate blurb entry? |
xnox
commented
Apr 28, 2025
@gpshead hi, my PRs had comments that you are taking over with these changes instead, but they now seem to have stalled. Are you still actively working on this and related PRs? |
Note that changing how we materialize a digest object should done carefully (see PEP-452). For buf=io.BytesIO(b"somedata")
mac1=hmac.HMAC(b"key", digestmod=hashlib.sha512)
digest=hashlib.file_digest(buf, lambda: mac1) |
xnox
commented
Sep 8, 2025
@gpshead Any updates on landing this? |
This PR is stale because it has been open for 30 days with no activity. |
gpshead
commented
Jun 29, 2026
I believe this PR is no longer relevant as is. |
Uh oh!
There was an error while loading. Please reload this page.