8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Merge branch 'quick_fix_login' into 'dev'

fix: 🚑 Replace decodestring by decodebytes

See merge request re2o/re2o!606
This commit is contained in:
chirac 2021-02-15 21:25:48 +00:00
commit d8d172fe97

View file

@ -32,7 +32,7 @@ import binascii
import crypt import crypt
import hashlib import hashlib
import os import os
from base64 import b64decode, b64encode, decodestring, encodestring from base64 import b64decode, b64encode, decodebytes, encodebytes
from collections import OrderedDict from collections import OrderedDict
from hmac import compare_digest as constant_time_compare from hmac import compare_digest as constant_time_compare
@ -56,7 +56,7 @@ def makeSecret(password):
salt = os.urandom(4) salt = os.urandom(4)
h = hashlib.sha1(password.encode()) h = hashlib.sha1(password.encode())
h.update(salt) h.update(salt)
return ALGO_NAME + "$" + encodestring(h.digest() + salt).decode()[:-1] return ALGO_NAME + "$" + encodebytes(h.digest() + salt).decode()[:-1]
def hashNT(password): def hashNT(password):
@ -84,7 +84,7 @@ def checkPassword(challenge_password, password):
boolean: True if challenge_password and password match boolean: True if challenge_password and password match
""" """
challenge_bytes = decodestring(challenge_password[ALGO_LEN:].encode()) challenge_bytes = decodebytes(challenge_password[ALGO_LEN:].encode())
digest = challenge_bytes[:DIGEST_LEN] digest = challenge_bytes[:DIGEST_LEN]
salt = challenge_bytes[DIGEST_LEN:] salt = challenge_bytes[DIGEST_LEN:]
hr = hashlib.sha1(password.encode()) hr = hashlib.sha1(password.encode())
@ -158,7 +158,7 @@ class CryptPasswordHasher(hashers.BasePasswordHasher):
""" """
assert encoded.startswith(self.algorithm) assert encoded.startswith(self.algorithm)
hash_str = encoded[7:] hash_str = encoded[7:]
hash_str = binascii.hexlify(decodestring(hash_str.encode())).decode() hash_str = binascii.hexlify(decodebytes(hash_str.encode())).decode()
return OrderedDict( return OrderedDict(
[ [
("algorithm", self.algorithm), ("algorithm", self.algorithm),
@ -207,7 +207,7 @@ class MD5PasswordHasher(hashers.BasePasswordHasher):
""" """
assert encoded.startswith(self.algorithm) assert encoded.startswith(self.algorithm)
hash_str = encoded[7:] hash_str = encoded[7:]
hash_str = binascii.hexlify(decodestring(hash_str.encode())).decode() hash_str = binascii.hexlify(decodebytes(hash_str.encode())).decode()
return OrderedDict( return OrderedDict(
[ [
("algorithm", self.algorithm), ("algorithm", self.algorithm),
@ -255,7 +255,7 @@ class SSHAPasswordHasher(hashers.BasePasswordHasher):
""" """
assert encoded.startswith(self.algorithm) assert encoded.startswith(self.algorithm)
hash_str = encoded[ALGO_LEN:] hash_str = encoded[ALGO_LEN:]
hash_str = binascii.hexlify(decodestring(hash_str.encode())).decode() hash_str = binascii.hexlify(decodebytes(hash_str.encode())).decode()
return OrderedDict( return OrderedDict(
[ [
("algorithm", self.algorithm), ("algorithm", self.algorithm),