Skip to content

Commit

Permalink
Fix crash in exception handler
Browse files Browse the repository at this point in the history
Direct use of k['kid'] was causing the excpetion itself to
crash on keys that do not have a 'kid' with a keyError.

Always use the .get accessor to pull 'kid' so that None is
returned when not availble.

Fixes #209

Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed Jun 9, 2021
1 parent 38ecf42 commit 5f3c415
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jwcrypto/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,6 @@ def get_key(self, kid):
:param kid: the 'kid' key identifier.
"""
for jwk in self['keys']:
if jwk['kid'] == kid:
if jwk.get('kid') == kid:
return jwk
return None
2 changes: 1 addition & 1 deletion jwcrypto/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def deserialize(self, jwt, key=None):
self.deserializelog.append("Success")
break
except Exception as e: # pylint: disable=broad-except
keyid = k['kid']
keyid = k.get('kid')
if keyid is None:
keyid = k.thumbprint()
self.deserializelog.append('Key [%s] failed: [%s]' % (
Expand Down

0 comments on commit 5f3c415

Please sign in to comment.