mirror of
https://github.com/postgres/pgweb.git
synced 2025-07-25 16:02:27 +00:00
Use base64.urlsafe_b64encode() instead of manual specification of chars
This makes for better readability, and is exactly the same functionality... Pointed out by Jacob Champion
This commit is contained in:
@ -729,9 +729,9 @@ def communityauth(request, siteid):
|
|||||||
encryptor = AES.new(base64.b64decode(site.cryptkey), AES.MODE_SIV, nonce=nonce)
|
encryptor = AES.new(base64.b64decode(site.cryptkey), AES.MODE_SIV, nonce=nonce)
|
||||||
cipher, tag = encryptor.encrypt_and_digest(s.encode('ascii'))
|
cipher, tag = encryptor.encrypt_and_digest(s.encode('ascii'))
|
||||||
redirparams = {
|
redirparams = {
|
||||||
'd': base64.b64encode(cipher, b"-_").decode('ascii'),
|
'd': base64.urlsafe_b64encode(cipher),
|
||||||
'n': base64.b64encode(nonce, b"-_").decode('ascii'),
|
'n': base64.urlsafe_b64encode(nonce),
|
||||||
't': base64.b64encode(tag, b"-_").decode('ascii'),
|
't': base64.urlsafe_b64encode(tag),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
# v2 = plain AES
|
# v2 = plain AES
|
||||||
@ -741,8 +741,8 @@ def communityauth(request, siteid):
|
|||||||
encryptor = AES.new(base64.b64decode(site.cryptkey), AES.MODE_CBC, iv)
|
encryptor = AES.new(base64.b64decode(site.cryptkey), AES.MODE_CBC, iv)
|
||||||
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # Pad to even 16 bytes
|
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # Pad to even 16 bytes
|
||||||
redirparams = {
|
redirparams = {
|
||||||
'i': base64.b64encode(iv, b"-_").decode('ascii'),
|
'i': base64.urlsafe_b64encode(iv),
|
||||||
'd': base64.b64encode(cipher, b"-_").decode('ascii'),
|
'd': base64.urlsafe_b64encode(cipher),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate redirect
|
# Generate redirect
|
||||||
@ -794,9 +794,9 @@ def _encrypt_site_response(site, s, version):
|
|||||||
cipher, tag = encryptor.encrypt_and_digest(s.encode('ascii'))
|
cipher, tag = encryptor.encrypt_and_digest(s.encode('ascii'))
|
||||||
|
|
||||||
return "&".join((
|
return "&".join((
|
||||||
base64.b64encode(nonce, b'-_').decode('ascii'),
|
base64.urlsafe_b64encode(nonce).decode('ascii'),
|
||||||
base64.b64encode(cipher, b'-_').decode('ascii'),
|
base64.urlsafe_b64encode(cipher).decode('ascii'),
|
||||||
base64.b64encode(tag, b'-_').decode('ascii'),
|
base64.urlsafe_b64encode(tag).decode('ascii'),
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
# Encrypt it with the shared key (and IVs)
|
# Encrypt it with the shared key (and IVs)
|
||||||
@ -806,8 +806,8 @@ def _encrypt_site_response(site, s, version):
|
|||||||
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # Pad to even 16 bytes
|
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # Pad to even 16 bytes
|
||||||
|
|
||||||
return "&".join((
|
return "&".join((
|
||||||
base64.b64encode(iv, b'-_').decode('ascii'),
|
base64.urlsafe_b64encode(iv).decode('ascii'),
|
||||||
base64.b64encode(cipher, b'-_').decode('ascii'),
|
base64.urlsafe_b64encode(cipher).decode('ascii'),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ def login(request):
|
|||||||
|
|
||||||
return HttpResponseRedirect("%s?%s" % (settings.PGAUTH_REDIRECT, urlencode({
|
return HttpResponseRedirect("%s?%s" % (settings.PGAUTH_REDIRECT, urlencode({
|
||||||
'd': '$'.join((
|
'd': '$'.join((
|
||||||
base64.b64encode(nonce, b"-_").decode('utf8'),
|
base64.urlsafe_b64encode(nonce).decode('utf8'),
|
||||||
base64.b64encode(cipher, b"-_").decode('utf8'),
|
base64.urlsafe_b64encode(cipher).decode('utf8'),
|
||||||
base64.b64encode(tag, b"-_").decode('utf8'),
|
base64.urlsafe_b64encode(tag).decode('utf8'),
|
||||||
)),
|
)),
|
||||||
})))
|
})))
|
||||||
else:
|
else:
|
||||||
@ -119,11 +119,11 @@ def auth_receive(request):
|
|||||||
decryptor = AES.new(
|
decryptor = AES.new(
|
||||||
base64.b64decode(settings.PGAUTH_KEY),
|
base64.b64decode(settings.PGAUTH_KEY),
|
||||||
AES.MODE_SIV,
|
AES.MODE_SIV,
|
||||||
nonce=base64.b64decode(str(request.GET['n']), "-_"),
|
nonce=base64.urlsafe_b64decode(str(request.GET['n'])),
|
||||||
)
|
)
|
||||||
s = decryptor.decrypt_and_verify(
|
s = decryptor.decrypt_and_verify(
|
||||||
base64.b64decode(str(request.GET['d']), "-_"),
|
base64.urlsafe_b64decode(str(request.GET['d'])),
|
||||||
base64.b64decode(str(request.GET['t']), "-_"),
|
base64.urlsafe_b64decode(str(request.GET['t'])),
|
||||||
).rstrip(b' ').decode('utf8')
|
).rstrip(b' ').decode('utf8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
return HttpResponse("Badly encoded data found", 400)
|
return HttpResponse("Badly encoded data found", 400)
|
||||||
@ -215,11 +215,11 @@ We apologize for the inconvenience.
|
|||||||
decryptor = AES.new(
|
decryptor = AES.new(
|
||||||
SHA256.new(settings.SECRET_KEY.encode('ascii')).digest()[:32],
|
SHA256.new(settings.SECRET_KEY.encode('ascii')).digest()[:32],
|
||||||
AES.MODE_SIV,
|
AES.MODE_SIV,
|
||||||
nonce=base64.b64decode(nonces, b"-_"),
|
nonce=base64.urlsafe_b64decode(nonces),
|
||||||
)
|
)
|
||||||
s = decryptor.decrypt_and_verify(
|
s = decryptor.decrypt_and_verify(
|
||||||
base64.b64decode(datas, "-_"),
|
base64.urlsafe_b64decode(datas),
|
||||||
base64.b64decode(tags, "-_"),
|
base64.urlsafe_b64decode(tags),
|
||||||
).rstrip(b' ').decode('utf8')
|
).rstrip(b' ').decode('utf8')
|
||||||
try:
|
try:
|
||||||
rdata = parse_qs(s, strict_parsing=True)
|
rdata = parse_qs(s, strict_parsing=True)
|
||||||
@ -331,11 +331,11 @@ def user_search(searchterm=None, userid=None):
|
|||||||
decryptor = AES.new(
|
decryptor = AES.new(
|
||||||
base64.b64decode(settings.PGAUTH_KEY),
|
base64.b64decode(settings.PGAUTH_KEY),
|
||||||
AES.MODE_SIV,
|
AES.MODE_SIV,
|
||||||
nonce=base64.b64decode(nonces, "-_")
|
nonce=base64.urlsafe_b64decode(nonces)
|
||||||
)
|
)
|
||||||
s = decryptor.decrypt_and_verify(
|
s = decryptor.decrypt_and_verify(
|
||||||
base64.b64decode(datas, "-_"),
|
base64.urlsafe_b64decode(datas),
|
||||||
base64.b64decode(tags, "-_"),
|
base64.urlsafe_b64decode(tags),
|
||||||
).rstrip(b' ').decode('utf8')
|
).rstrip(b' ').decode('utf8')
|
||||||
|
|
||||||
j = json.loads(s)
|
j = json.loads(s)
|
||||||
|
@ -63,9 +63,9 @@ if __name__ == "__main__":
|
|||||||
cipher, tag = encryptor.encrypt_and_digest(s.encode('ascii'))
|
cipher, tag = encryptor.encrypt_and_digest(s.encode('ascii'))
|
||||||
|
|
||||||
redirparams = {
|
redirparams = {
|
||||||
'd': base64.b64encode(cipher, b"-_").decode('ascii'),
|
'd': base64.urlsafe_b64encode(cipher).decode('ascii'),
|
||||||
'n': base64.b64encode(nonce, b"-_").decode('ascii'),
|
'n': base64.urlsafe_b64encode(nonce).decode('ascii'),
|
||||||
't': base64.b64encode(tag, b"-_").decode('ascii'),
|
't': base64.urlsafe_b64encode(tag).decode('ascii'),
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Paste the following after the receiving url:")
|
print("Paste the following after the receiving url:")
|
||||||
|
Reference in New Issue
Block a user