Skip to content

Commit

Permalink
Throw if key is an PKCS1 PEM-encoded public key
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Jun 22, 2017
1 parent e4c67b1 commit 37926ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions jwt/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def prepare_key(self, key):
invalid_strings = [
b'-----BEGIN PUBLIC KEY-----',
b'-----BEGIN CERTIFICATE-----',
b'-----BEGIN RSA PUBLIC KEY-----',
b'ssh-rsa'
]

Expand Down
5 changes: 5 additions & 0 deletions tests/keys/testkey_pkcs1.pub.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN RSA PUBLIC KEY-----
MIGHAoGBAOV/0Vl/5VdHcYpnILYzBGWo5JQVzo9wBkbxzjAStcAnTwvv1ZJTMXs6
fjz91f9hiMM4Z/5qNTE/EHlDWxVdj1pyRaQulZPUs0r9qJ02ogRRGLG3jjrzzbzF
yj/pdNBwym0UJYC/Jmn/kMLwGiWI2nfa9vM5SovqZiAy2FD7eOtVAgED
-----END RSA PUBLIC KEY-----
7 changes: 7 additions & 0 deletions tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def test_hmac_should_throw_exception_if_key_is_x509_cert(self):
with open(key_path('testkey2_rsa.pub.pem'), 'r') as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_should_throw_exception_if_key_is_pkcs1_pem_public(self):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

with pytest.raises(InvalidKeyError):
with open(key_path('testkey_pkcs1.pub.pem'), 'r') as keyfile:
algo.prepare_key(keyfile.read())

def test_hmac_jwk_should_parse_and_verify(self):
algo = HMACAlgorithm(HMACAlgorithm.SHA256)

Expand Down

0 comments on commit 37926ea

Please sign in to comment.