From edad84b1d0f60115a7153b8d10f8a4671439a851 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sat, 19 Jan 2019 20:03:33 +0100 Subject: [PATCH] Fix base64 encodings --- pgweb/account/views.py | 8 ++++---- tools/communityauth/generate_cryptkey.py | 2 +- tools/communityauth/test_auth.py | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pgweb/account/views.py b/pgweb/account/views.py index e61f3743..9a67afa4 100644 --- a/pgweb/account/views.py +++ b/pgweb/account/views.py @@ -551,8 +551,8 @@ def communityauth(request, siteid): # Generate redirect return HttpResponseRedirect("%s?i=%s&d=%s" % ( site.redirecturl, - base64.b64encode(iv, "-_"), - base64.b64encode(cipher, "-_"), + base64.b64encode(iv, b"-_").decode('ascii'), + base64.b64encode(cipher, b"-_").decode('ascii'), )) @@ -597,8 +597,8 @@ def _encrypt_site_response(site, s): # Base64-encode the response, just to be consistent return "%s&%s" % ( - base64.b64encode(iv, '-_'), - base64.b64encode(cipher, '-_'), + base64.b64encode(iv, b'-_').decode('ascii'), + base64.b64encode(cipher, b'-_').decode('ascii'), ) diff --git a/tools/communityauth/generate_cryptkey.py b/tools/communityauth/generate_cryptkey.py index 6e84e3b4..aaf17e04 100755 --- a/tools/communityauth/generate_cryptkey.py +++ b/tools/communityauth/generate_cryptkey.py @@ -16,4 +16,4 @@ if __name__ == "__main__": r = Random.new() key = r.read(32) - print base64.b64encode(key) + print(base64.b64encode(key)) diff --git a/tools/communityauth/test_auth.py b/tools/communityauth/test_auth.py index 4417c1de..a1d9747e 100755 --- a/tools/communityauth/test_auth.py +++ b/tools/communityauth/test_auth.py @@ -54,15 +54,15 @@ if __name__ == "__main__": # the first block more random.. # Since this is a fake authentication, put it 5 minutes into the future to # give more time to copy/paste it. - s = "t=%s&%s" % (int(time.time() + 300), urllib.urlencode(info)) + s = "t=%s&%s" % (int(time.time() + 300), urllib.parse.urlencode(info)) r = Random.new() iv = r.read(16) encryptor = AES.new(base64.b64decode(options.key), AES.MODE_CBC, iv) cipher = encryptor.encrypt(s + ' ' * (16 - (len(s) % 16))) - print "Paste the following after the receiving url:" - print "?i=%s&d=%s" % ( - base64.b64encode(iv, "-_"), - base64.b64encode(cipher, "-_"), - ) + print("Paste the following after the receiving url:") + print("?i=%s&d=%s" % ( + base64.b64encode(iv, b"-_").decode('ascii'), + base64.b64encode(cipher, b"-_").decode('ascii'), + ))