Skip to content
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

Fix verification of JWT using verify keys #511

Merged
merged 1 commit into from
Apr 6, 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on the [KeepAChangeLog] project.

### Fixed
- [#503] Fix error on UserInfo endpoint for removed clients
- [#508] JWT now uses verify keys for JWT verification

### Removed
- [#494] Methods and functions deprecated in previous releases have been removed
Expand All @@ -19,6 +20,7 @@ The format is based on the [KeepAChangeLog] project.
[#494]: https://github.com/OpenIDC/issues/494
[#496]: https://github.com/OpenIDC/pyoidc/issues/496
[#503]: https://github.com/OpenIDC/pyoidc/issues/503
[#508]: https://github.com/OpenIDC/pyoidc/issues/508

## 0.13.0 [2018-02-19]

Expand Down
3 changes: 1 addition & 2 deletions src/oic/utils/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def _verify(self, rj, token):
else:
owner = _msg['iss']

keys = self.keyjar.get_signing_key(jws.alg2keytype(rj.jwt.headers['alg']),
owner=owner)
keys = self.keyjar.get_verify_key(jws.alg2keytype(rj.jwt.headers['alg']), owner=owner)
return rj.verify_compact(token, keys)

def _decrypt(self, rj, token):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from oic.utils.jwt import JWT
from oic.utils.keyio import build_keyjar
from oic.utils.keyio import keybundle_from_local_file

__author__ = 'roland'

Expand Down Expand Up @@ -36,3 +37,20 @@ def test_jwt_pack_and_unpack():
info = srv.unpack(_jwt)

assert _eq(info.keys(), ['jti', 'iat', 'exp', 'iss', 'sub', 'kid'])


class TestJWT(object):
"""Tests for JWT."""

def test_unpack_verify_key(self):
srv = JWT(keyjar, iss=issuer)
_jwt = srv.pack(sub="sub")
# Remove the signing key from keyjar
keyjar.remove_key("", "RSA", "")
# And add it back as verify
kb = keybundle_from_local_file(os.path.join(BASE_PATH, "cert.key"), "RSA", ["ver"])
# keybundle_from_local_file doesn'assign kid, so assign manually
kb._keys[0].kid = kidd["sig"]["RSA"]
keyjar.add_kb("", kb)
info = srv.unpack(_jwt)
assert info["sub"] == "sub"