Skip to content

Commit 1710c15

Browse files
committed
Add support for public keys in OpenSSH (RFC 4253) format.
Cryptography previously lacked support for ECDSA keys in RFC 4253 format. Now that they have support for those keys, we should take advantage of it and support them in PyJWT. Implements jpadilla#243.
1 parent 299d196 commit 1710c15

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
[Unreleased][unreleased]
88
-------------------------------------------------------------------------
99
### Changed
10+
- Add support for ECDSA public keys in RFC 4253 (OpenSSH) format [#244][244]
1011
- Renamed commandline script `jwt` to `jwt-cli` to avoid issues with the script clobbering the `jwt` module in some circumstances.
1112
- Better error messages when using an algorithm that requires the cryptography package, but it isn't available [#230][230]
1213

@@ -129,3 +130,4 @@ rarely used. Users affected by this should upgrade to 3.3+.
129130
[182]: https://github.com/jpadilla/pyjwt/pull/182
130131
[183]: https://github.com/jpadilla/pyjwt/pull/183
131132
[213]: https://github.com/jpadilla/pyjwt/pull/214
133+
[244]: https://github.com/jpadilla/pyjwt/pull/244

jwt/algorithms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ def prepare_key(self, key):
356356
# a Signing Key or a Verifying Key, so we try
357357
# the Verifying Key first.
358358
try:
359-
key = load_pem_public_key(key, backend=default_backend())
359+
if key.startswith(b'ecdsa-sha2-'):
360+
key = load_ssh_public_key(key, backend=default_backend())
361+
else:
362+
key = load_pem_public_key(key, backend=default_backend())
360363
except ValueError:
361364
key = load_pem_private_key(key, password=None, backend=default_backend())
362365

0 commit comments

Comments
 (0)