Skip to content

Commit fb86f9d

Browse files
authored
Allow to verify with private key on ECAlgorithm, as well as on Ed25519Algorithm. (jpadilla#645)
* Add private key support for ECAlgorithm verify. * Update CHANGELOG.
1 parent bcd5728 commit fb86f9d

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Fixed
1818
- Remove padding from JWK test data. `#628 <https://github.com/jpadilla/pyjwt/pull/628>`__
1919
- Make `kty` mandatory in JWK to be compliant with RFC7517. `#624 <https://github.com/jpadilla/pyjwt/pull/624>`__
2020
- Allow JWK without `alg` to be compliant with RFC7517. `#624 <https://github.com/jpadilla/pyjwt/pull/624>`__
21+
- Allow to verify with private key on ECAlgorithm, as well as on Ed25519Algorithm. `#645 <https://github.com/jpadilla/pyjwt/pull/645>`__
2122

2223
Added
2324
~~~~~

jwt/algorithms.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ def verify(self, msg, key, sig):
427427
return False
428428

429429
try:
430+
if isinstance(key, EllipticCurvePrivateKey):
431+
key = key.public_key()
430432
key.verify(der_sig, msg, ec.ECDSA(self.hash_alg()))
431433
return True
432434
except InvalidSignature:

tests/test_algorithms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,13 @@ def test_ec_verify_should_return_true_for_test_vector(self):
658658
result = algo.verify(signing_input, key, signature)
659659
assert result
660660

661+
# private key can also be used.
662+
with open(key_path("jwk_ec_key_P-521.json")) as keyfile:
663+
private_key = algo.from_jwk(keyfile.read())
664+
665+
result = algo.verify(signing_input, private_key, signature)
666+
assert result
667+
661668

662669
@crypto_required
663670
class TestEd25519Algorithms:

0 commit comments

Comments
 (0)