Skip to content

Fix alg matching in pick_key #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cryptojwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from binascii import unhexlify

__version__ = '0.3.0'
__version__ = '0.3.1'

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/cryptojwt/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def pick_key(keys, use, alg='', key_type='', kid=''):
continue

if key.kty == key_type:
if key.alg == '' or key.alg == alg:
if key.alg == '' or alg == '' or key.alg == alg:
if key.kid == '' or kid == '' or key.kid == kid:
res.append(key)
return res
Expand Down
27 changes: 27 additions & 0 deletions tests/test_5_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,30 @@ def test_jwt_pack_encrypt_no_sign():
info = bob.unpack(_jwt)

assert set(info.keys()) == {'iat', 'iss', 'sub', 'aud'}


def test_jwt_pack_and_unpack_with_alg():
alice = JWT(own_keys=ALICE_KEYS, iss=ALICE)
payload = {'sub': 'sub'}
_jwt = alice.pack(payload=payload)

from cryptojwt.jwk import KEYS
alice_jwks = {
"keys":
[{
"kty": "RSA",
"alg": "RS256",
"use": "sig",
"kid": "1",
"n": ALICE_PUB_KEYS[0].n,
"e": ALICE_PUB_KEYS[0].e
}]
}
alg_keys = KEYS()
alg_keys.load_dict(alice_jwks)

bob = JWT(rec_keys={ALICE: alg_keys})
info = bob.unpack(_jwt)

assert set(info.keys()) == {'iat', 'iss', 'sub', 'kid', 'aud'}