Catch base64 decode error on b64decode to raise our custom exception BadHash

This commit is contained in:
Valentin Samir 2016-07-31 12:27:14 +02:00
parent fbc977c6bd
commit 4721eb4f81

View file

@ -561,7 +561,10 @@ class LdapHashUserPassword(object):
elif scheme == b'{CRYPT}':
return b'$'.join(hashed_passord.split(b'$', 3)[:-1])[len(scheme):]
else:
try:
hashed_passord = base64.b64decode(hashed_passord[len(scheme):])
except TypeError as error:
raise cls.BadHash("Bad base64: %s" % error)
if len(hashed_passord) < cls._schemes_to_len[scheme]:
raise cls.BadHash("Hash too short for the scheme %s" % scheme)
return hashed_passord[cls._schemes_to_len[scheme]:]