Repository navigation
Check the signature hash in the python-rsa RSAKey.verify - #429
Open
neeraj1235476 wants to merge 1 commit into
Open
neeraj1235476 wants to merge 1 commit into
neeraj1235476 wants to merge 1 commit into
Conversation
rsa.verify() reads the hash algorithm from the DigestInfo in the signature and returns its name, so an RS256 key accepted PKCS#1 v1.5 signatures over MD5, SHA-1 or SHA-512 made by the same key. Compare the returned name with the key's hash_alg.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With only the default dependencies installed (python-rsa backend), an RS256 allowlist accepts signatures made with other digests:
RSAKey.verifyinjose/backends/rsa_backend.pycallsrsa.verify(), which takes the hash algorithm from the DigestInfo inside the signature and returns its name. The key'shash_algwas never compared, so the headeralgand thealgorithmsallowlist did not bind the digest that was checked (RFC 7518 section 3.3 fixes RS256 to SHA-256). Any PKCS#1 v1.5 signature the key holder ever made over MD5 or SHA-1, in any protocol, verified as RS256. The cryptography backend already passes the hash explicitly, so this brings the pure-Python backend in line with it.The fix compares the returned hash name with
self.hash_alg. The new test signs with MD5, SHA-1 and SHA-512 and expects an RS256 key to reject each. It fails on master and passes with the change. The full suite andtox -e lintpass locally.test_incorrect_public_key_hmac_signingintest_EC.pyfails the same way on master.