GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing github.com — gh-127298: Refactor test_hashlib for better usedforsecurity & openssl fips mode env support. by gpshead · Pull Request #127492 · python/cpython Conversation
|
|
!buildbot FIPS |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 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:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot FIPS |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 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:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
7a5ab6c to
bd46651
Compare
|
#127467 is follow-on work to this that combined gets the FIPS mode buildbots passing in main. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Nice Zombies <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I tested manually the change on RHEL8. 3 MD5 tests of test_hashlib are failing: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I built Python with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gpshead Any updates on landing this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I believe this PR is no longer relevant as is. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.