Skip to content

Commit 6c0761b

Browse files
authored
Merge pull request #8 from janste63/master
Fix alg matching in pick_key
2 parents 32542a0 + d33b200 commit 6c0761b

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/cryptojwt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from binascii import unhexlify
1818

19-
__version__ = '0.3.0'
19+
__version__ = '0.3.1'
2020

2121
logger = logging.getLogger(__name__)
2222

src/cryptojwt/jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def pick_key(keys, use, alg='', key_type='', kid=''):
4343
continue
4444

4545
if key.kty == key_type:
46-
if key.alg == '' or key.alg == alg:
46+
if key.alg == '' or alg == '' or key.alg == alg:
4747
if key.kid == '' or kid == '' or key.kid == kid:
4848
res.append(key)
4949
return res

tests/test_5_jwt.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,30 @@ def test_jwt_pack_encrypt_no_sign():
9595
info = bob.unpack(_jwt)
9696

9797
assert set(info.keys()) == {'iat', 'iss', 'sub', 'aud'}
98+
99+
100+
def test_jwt_pack_and_unpack_with_alg():
101+
alice = JWT(own_keys=ALICE_KEYS, iss=ALICE)
102+
payload = {'sub': 'sub'}
103+
_jwt = alice.pack(payload=payload)
104+
105+
from cryptojwt.jwk import KEYS
106+
alice_jwks = {
107+
"keys":
108+
[{
109+
"kty": "RSA",
110+
"alg": "RS256",
111+
"use": "sig",
112+
"kid": "1",
113+
"n": ALICE_PUB_KEYS[0].n,
114+
"e": ALICE_PUB_KEYS[0].e
115+
}]
116+
}
117+
alg_keys = KEYS()
118+
alg_keys.load_dict(alice_jwks)
119+
120+
bob = JWT(rec_keys={ALICE: alg_keys})
121+
info = bob.unpack(_jwt)
122+
123+
assert set(info.keys()) == {'iat', 'iss', 'sub', 'kid', 'aud'}
124+

0 commit comments

Comments
 (0)