-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
hashlib: OpenSSL hash detection should obey security policy #84872
Comments
The hashlib module prefers hash implementations from OpenSSL. In case OpenSSL is not available or OpenSSL does not provide a hash algorithm, hashlib falls back to builtin implementations for MD5, SHA1, SHA2 family, SHA3/SHAKE family, and Blake2. The __get_openssl_constructor [1] function checks OpenSSL by retrieving the constructor and calling it. The calls fails if OpenSSL doesn't implement the EVP digest. It also fails when the EVP digest is available but blocked by a security policy. In this case it falls back to the builtin implementation. If the builtin implementation has been removed by the package builder or --with-builtin-hashlib-hashes, then Python considers the hash algorithm as broken. I propose to change the detection code so that Python uses OpenSSL implementation although it's blocked by the current system policy. Current behavior: $ rpm -qa openssl
openssl-1.1.1g-1.fc32.x86_64
$ /configure -C --with-builtin-hashlib-hashes=blake2
$ make -j4
$ ./python
>>> import hashlib
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/root/cpython/Lib/hashlib.py", line 131, in __get_openssl_constructor
f()
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/cpython/Lib/hashlib.py", line 251, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/root/cpython/Lib/hashlib.py", line 135, in __get_openssl_constructor
return __get_builtin_constructor(name)
File "/root/cpython/Lib/hashlib.py", line 118, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
>>> hashlib.md5()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'hashlib' has no attribute 'md5' Proposed behavior: $ ./python
>>> import hashlib
>>> hashlib.md5()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
>>> hashlib.md5(usedforsecurity=False)
<md5 _hashlib.HASH object @ 0x7fb9d44b9b30> Related issue: bpo-9216 added the new hash constructor argument "usedforsecurity". [1] Lines 121 to 135 in 97fe9cf
|
Is there anything more that needs to be done for this issue? |
No, nothing left to do. Thanks for the ping! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: