From d62f57eab343d7a47a45ea9068a415ccd6a2942c Mon Sep 17 00:00:00 2001 From: kevgliss Date: Thu, 20 Aug 2015 15:49:08 -0700 Subject: [PATCH] Fixing an issue with futures, unicode and b64 not being able to handle the unicode values --- lemur/auth/service.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lemur/auth/service.py b/lemur/auth/service.py index ba19c509..352b905d 100644 --- a/lemur/auth/service.py +++ b/lemur/auth/service.py @@ -8,11 +8,12 @@ .. moduleauthor:: Kevin Glisson """ +from __future__ import unicode_literals +from builtins import bytes import jwt import json import base64 import binascii -from builtins import str from functools import wraps from datetime import datetime, timedelta @@ -34,19 +35,16 @@ from lemur.auth.permissions import CertificateCreatorNeed, \ def base64url_decode(data): - if isinstance(data, str): - data = str(data) - rem = len(data) % 4 if rem > 0: - data += b'=' * (4 - rem) + data += '=' * (4 - rem) - return base64.urlsafe_b64decode(data) + return base64.urlsafe_b64decode(bytes(data.encode('latin-1'))) def base64url_encode(data): - return base64.urlsafe_b64encode(data).replace(b'=', b'') + return base64.urlsafe_b64encode(data).replace('=', '') def get_rsa_public_key(n, e): @@ -141,9 +139,11 @@ def fetch_token_header(token): try: return json.loads(base64url_decode(header_segment)) - except TypeError: + except TypeError as e: + current_app.logger.exception(e) raise jwt.DecodeError('Invalid header padding') - except binascii.Error: + except binascii.Error as e: + current_app.logger.exception(e) raise jwt.DecodeError('Invalid header padding')