Skip to content

Commit d4807ac

Browse files
committed
Bytes to str conversion.
1 parent ae53c47 commit d4807ac

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/cryptojwt/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def unpack(self, token):
243243
part = split_token(token)
244244
self.b64part = part
245245
self.part = [b64d(p) for p in part]
246-
self.headers = json.loads(self.part[0].decode())
246+
#self.headers = json.loads(self.part[0].decode())
247+
self.headers = json.loads(as_unicode(self.part[0]))
247248
return self
248249

249250
def pack(self, parts=None, headers=None):

src/cryptojwt/exception.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ class UnSupported(JWKESTException):
7373

7474
class MissingValue(JWKESTException):
7575
pass
76+
77+
class VerificationError(JWKESTException):
78+
pass

src/cryptojwt/jwt.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import json
44
import uuid
55

6+
from cryptojwt import as_unicode
67
from cryptojwt import jwe
78
from cryptojwt import jws
89
from cryptojwt.exception import MissingValue
10+
from cryptojwt.exception import VerificationError
911
from cryptojwt.jwe import JWE
1012
from cryptojwt.jws import JWS
1113
from cryptojwt.jws import NoSuitableSigningKeys
@@ -62,7 +64,7 @@ def get_jwt_keys(jwt, keys, use):
6264

6365
# pick issuer keys
6466
if use == 'sig':
65-
payload = json.loads(jwt.part[1])
67+
payload = json.loads(as_unicode(jwt.part[1]))
6668
try:
6769
_keys = keys[payload['iss']]
6870
except KeyError: # No issuer, not kosher
@@ -79,6 +81,8 @@ def get_jwt_keys(jwt, keys, use):
7981

8082

8183
class JWT(object):
84+
msg_cls = None
85+
8286
def __init__(self, own_keys=None, iss='', rec_keys=None, lifetime=0,
8387
sign_alg='RS256', encrypt=False, enc_enc="A128CBC-HS256",
8488
enc_alg="RSA1_5"):
@@ -193,7 +197,7 @@ def _decrypt(self, rj, token):
193197
:param token: The encrypted JsonWebToken
194198
:return:
195199
"""
196-
keys = get_jwt_keys(rj.jwt, self.own_keys, 'enc')
200+
keys = get_jwt_keys(rj.jwt, self.my_keys(), 'enc')
197201
return rj.decrypt(token, keys=keys)
198202

199203
def unpack(self, token):
@@ -217,4 +221,10 @@ def unpack(self, token):
217221
else:
218222
raise Exception()
219223

220-
return info
224+
if self.msg_cls:
225+
_msg = self.msg_cls(**info)
226+
if not _msg.verify():
227+
raise VerificationError()
228+
return _msg
229+
else:
230+
return info

0 commit comments

Comments
 (0)