Fix base64 encodings
authorMagnus Hagander <magnus@hagander.net>
Sat, 19 Jan 2019 19:03:33 +0000 (20:03 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sat, 26 Jan 2019 15:19:26 +0000 (16:19 +0100)
pgweb/account/views.py
tools/communityauth/generate_cryptkey.py
tools/communityauth/test_auth.py

index e61f37431dbadf1e5e373e6900faac3192b20cc4..9a67afa415c201f572acdd7e06a1b2d88b7370be 100644 (file)
@@ -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'),
     )
 
 
index 6e84e3b46dc7602ac4d8ead8c733868d49e4f878..aaf17e0425be9de7e48a5a03ca22e085c84bde4f 100755 (executable)
@@ -16,4 +16,4 @@ if __name__ == "__main__":
 
     r = Random.new()
     key = r.read(32)
-    print base64.b64encode(key)
+    print(base64.b64encode(key))
index 4417c1defe6744ef449dd5d36d64b44b122e5128..a1d9747ecc2f4e7a87d54728328390cb80b510eb 100755 (executable)
@@ -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'),
+    ))