Skip to content

Commit

Permalink
Support JWK Set
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmc committed Jul 15, 2016
1 parent 048377d commit f5216cf
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions jose/jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ def _load(jwt):
return (header, payload, signing_input, signature)


def _sig_matches_keys(keys, signing_input, signature, alg):
for key in keys:
key = jwk.construct(key, alg)
if key.verify(signing_input, signature):
return True
return False


def _verify_signature(signing_input, header, signature, key='', algorithms=None):

alg = header.get('alg')
Expand All @@ -214,12 +222,14 @@ def _verify_signature(signing_input, header, signature, key='', algorithms=None)
if algorithms is not None and alg not in algorithms:
raise JWSError('The specified alg value is not allowed')

try:
key = jwk.construct(key, alg)
if 'keys' in key: # JWK Set per RFC 7517
keys = key['keys']
else:
keys = [key]

if not key.verify(signing_input, signature):
try:
if not _sig_matches_keys(keys, signing_input, signature, alg):
raise JWSSignatureError()

except JWSSignatureError:
raise JWSError('Signature verification failed.')
except JWSError:
Expand Down

0 comments on commit f5216cf

Please sign in to comment.