Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions jose/backends/rsa_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def verify(self, msg, sig):
if not self.is_public():
warnings.warn("Attempting to verify a message with a private key. " "This is not recommended.")
try:
pyrsa.verify(msg, sig, self._prepared_key)
return True
return pyrsa.verify(msg, sig, self._prepared_key) == self.hash_alg
except pyrsa.pkcs1.VerificationError:
return False

Expand Down
8 changes: 8 additions & 0 deletions tests/algorithms/test_RSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def test_python_rsa_legacy_private_key_pkcs8_to_pkcs1_invalid(self):

excinfo.match("Invalid private key encoding")

@pytest.mark.parametrize("hash_method", ["MD5", "SHA-1", "SHA-512"])
def test_python_rsa_verify_rejects_other_hash(self, hash_method):
key = PurePythonRSAKey(private_key_4096_pkcs1, ALGORITHMS.RS256)
msg = b"test"
sig = rsa_backend.pyrsa.sign(msg, key._prepared_key, hash_method)

assert not key.public_key().verify(msg, sig)


@pytest.mark.cryptography
@pytest.mark.skipif(
Expand Down