python3: encoding variations in hashers

This commit is contained in:
Paul Marillonnet 2020-02-06 16:55:24 +01:00
parent 7543da6dfb
commit 05af4ef140
1 changed files with 7 additions and 7 deletions

View File

@ -171,7 +171,7 @@ def olap_password_to_dj(password):
salt, password = (password[salt_offset:], password[:salt_offset]) if salt_offset else ('', password)
if hex_encode:
password = force_text(hexlify(password), encoding='ascii')
salt = force_text(hexlify(salt), encoding='ascii')
salt = force_text(hexlify(force_bytes(salt)), encoding='ascii')
return '%s$%s$%s' % (algo_name, salt, password)
else:
return make_password(password)
@ -231,9 +231,9 @@ class JoomlaPasswordHasher(CommonPasswordHasher):
def encode(self, password, salt):
assert password
assert '$' not in salt
hash = self.digest(force_bytes(password + salt)).hexdigest()
salt = force_text(hexlify(salt), encoding='ascii')
assert b'$' not in salt
hash = self.digest(force_bytes(password) + salt).hexdigest()
salt = force_text(hexlify(force_bytes(salt)), encoding='ascii')
return "%s$md5$%s$%s" % (self.algorithm, salt, hash)
def verify(self, password, encoded):
@ -257,7 +257,7 @@ class JoomlaPasswordHasher(CommonPasswordHasher):
h, salt = encoded.split(':', 1)
else:
h, salt = encoded, ''
salt = force_text(hexlify(salt), encoding='ascii')
salt = force_text(hexlify(force_bytes(salt)), encoding='ascii')
return '%s$md5$%s$%s' % (cls.algorithm, salt, h)
@classmethod
@ -268,7 +268,7 @@ class JoomlaPasswordHasher(CommonPasswordHasher):
if subalgo != 'md5':
raise NotImplementedError
if salt:
return '%s:%s' % (_hash, salt.decode('hex'))
return '%s:%s' % (_hash, force_text(unhexlify(force_bytes(salt))))
else:
return _hash
@ -292,7 +292,7 @@ class PloneSHA1PasswordHasher(hashers.SHA1PasswordHasher):
salt = force_bytes(salt)
hashed = base64.b64encode(hashlib.sha1(password + salt).digest() + salt)
return "%s$%s%s" % (self.algorithm, self._prefix, hashed)
return "%s$%s%s" % (self.algorithm, self._prefix, force_text(hashed))
def verify(self, password, encoded):
"""Verify the given password against the encoded string."""