Skip to content

Commit 8a1e536

Browse files
committed
Add "RSA PUBLIC KEY" to the forbidden key strings in HMAC. Prevents the use of PKCS1 keys, cited by this CVE as exposing a key-confusion attack. Also add a test case for it, doing the obvious thing. Closes #62
1 parent b54c12a commit 8a1e536

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

jose/jwk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(self, key, algorithm):
105105

106106
invalid_strings = [
107107
b'-----BEGIN PUBLIC KEY-----',
108+
b'-----BEGIN RSA PUBLIC KEY-----',
108109
b'-----BEGIN CERTIFICATE-----',
109110
b'ssh-rsa'
110111
]

tests/algorithms/test_HMAC.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def test_RSA_key(self):
1717
with pytest.raises(JOSEError):
1818
HMACKey(key, ALGORITHMS.HS256)
1919

20+
key = "-----BEGIN RSA PUBLIC KEY-----"
21+
with pytest.raises(JOSEError):
22+
HMACKey(key, ALGORITHMS.HS256)
23+
2024
key = "-----BEGIN CERTIFICATE-----"
2125
with pytest.raises(JOSEError):
2226
HMACKey(key, ALGORITHMS.HS256)

0 commit comments

Comments
 (0)