From 2b49e7f3935812c59842919ba640c53af4568858 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Fri, 4 Feb 2022 17:49:06 +0300 Subject: [PATCH 1/2] fix generate signature --- jws/__init__.py | 2 +- jws/utils.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/jws/__init__.py b/jws/__init__.py index 178905a..e6cafd4 100644 --- a/jws/__init__.py +++ b/jws/__init__.py @@ -53,4 +53,4 @@ def verify(head, payload, encoded_signature, key=None, is_json=False): def _signing_input(head, payload, is_json=False): enc = utils.to_base64 if is_json else utils.encode head_input, payload_input = map(enc, [head, payload]) - return "%s.%s" % (head_input, payload_input) + return b'%s.%s' % (head_input, payload_input) diff --git a/jws/utils.py b/jws/utils.py index 091adf4..2e0d11b 100644 --- a/jws/utils.py +++ b/jws/utils.py @@ -21,9 +21,10 @@ def base64url_decode(input): input += b'=' * (4 - (len(input) % 4)) return base64.urlsafe_b64decode(input) def base64url_encode(input): - return base64.urlsafe_b64encode(to_bytes_2and3(input)).replace(b'=', b'') + return base64.urlsafe_b64encode(to_bytes_2and3(input)).rstrip(b'=') -def to_json(a): return json.dumps(a) +def to_json(a): + return json.dumps(a, separators=(',', ':')) def from_json(a): return json.loads(a) def to_base64(a): return base64url_encode(a) def from_base64(a): return base64url_decode(a) From 5123781058b647ed7fa0762f50823d76cab69831 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Fri, 4 Feb 2022 18:23:26 +0300 Subject: [PATCH 2/2] fix verify function --- jws/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jws/utils.py b/jws/utils.py index 2e0d11b..6005fc9 100644 --- a/jws/utils.py +++ b/jws/utils.py @@ -47,5 +47,5 @@ def constant_time_compare(val1, val2): return False result = 0 for x, y in zip(val1, val2): - result |= ord(x) ^ ord(y) + result |= x ^ y return result == 0