From f44b5607b87a37c4927e8c0488d1f4ea3d2a9795 Mon Sep 17 00:00:00 2001 From: Anthony Bourguignon Date: Wed, 22 Feb 2023 12:30:45 +0100 Subject: [PATCH] add SSHA password hasher --- modoboa/core/password_hashers/__init__.py | 2 +- modoboa/core/password_hashers/advanced.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modoboa/core/password_hashers/__init__.py b/modoboa/core/password_hashers/__init__.py index b94bccae7..bcbf86b3f 100644 --- a/modoboa/core/password_hashers/__init__.py +++ b/modoboa/core/password_hashers/__init__.py @@ -7,7 +7,7 @@ from django.utils.encoding import smart_text from modoboa.core.password_hashers.advanced import ( # NOQA:F401 BLFCRYPTHasher, MD5CRYPTHasher, SHA256CRYPTHasher, SHA512CRYPTHasher, - ARGON2IDHasher + ARGON2IDHasher, SSHAHasher ) from modoboa.core.password_hashers.base import ( # NOQA:F401 CRYPTHasher, MD5Hasher, PLAINHasher, SHA256Hasher diff --git a/modoboa/core/password_hashers/advanced.py b/modoboa/core/password_hashers/advanced.py index 75edbf4d8..0a3dba774 100644 --- a/modoboa/core/password_hashers/advanced.py +++ b/modoboa/core/password_hashers/advanced.py @@ -113,6 +113,25 @@ class SHA512CRYPTHasher(PasswordHasher): return sha512_crypt.verify(clearvalue, hashed_value) +class SSHAHasher(PasswordHasher): + """ + Salted SHA1 password hasher. + """ + _weak = True + + @property + def scheme(self): + return "{SSHA}" + + def _encrypt(self, clearvalue, salt=None): + # We have to remove the {SSHA} at the beginning of the string + return ldap_salted_sha1.hash(clearvalue)[6:] + + def verify(self, clearvalue, hashed_value): + # We have to add the scheme for the hashed_value to be validated + return ldap_salted_sha1.verify(clearvalue, f'{{SSHA}}{hashed_value}') + + if argon2_hasher is not None: class ARGON2IDHasher(PasswordHasher): """