Skip to content

Commit

Permalink
fix(jwks): base64url encode exponent and modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudyard Richter authored and philloooo committed Feb 22, 2018
1 parent a929cb2 commit b65ad35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions fence/jwt/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
return default private key for the app
"""

import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
import flask
Expand Down Expand Up @@ -53,8 +54,8 @@ def public_key_to_jwk(self):
'use': 'sig',
'key_ops': 'verify',
'kid': self.kid,
'n': n,
'e': e,
'n': base64.urlsafe_b64encode(str(n)),
'e': base64.urlsafe_b64encode(str(e)),
}
return jwk

Expand Down
5 changes: 3 additions & 2 deletions tests/rfc7517/test_jwks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers
Expand Down Expand Up @@ -48,8 +49,8 @@ def test_response_values(app, client):
# Attempt to reproduce the public key from the values for the public
# modulus and exponent provided in the response, using cryptography
# primitives.
n = int(key['n'])
e = int(key['e'])
n = int(base64.b64decode(key['n']))
e = int(base64.b64decode(key['e']))
numbers = RSAPublicNumbers(e, n)
key = numbers.public_key(default_backend())
key_pem = key.public_bytes(
Expand Down

0 comments on commit b65ad35

Please sign in to comment.