Skip to content

Commit 3bf0c8c

Browse files
authored
Merge pull request #992 from CDLUC3/987_remove_LdapSha1PasswordHasher
remove LdapSha1PasswordHasher
2 parents 0c100ae + 764a749 commit 3bf0c8c

4 files changed

Lines changed: 0 additions & 53 deletions

File tree

ezidapp/models/user.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,6 @@ def authenticate(self, password):
157157

158158
logger.debug('Auth successful')
159159

160-
# Upgrade older LDAP password hashes.
161-
if self.password.split("$")[0] == "ldap_sha1":
162-
import ezidapp.admin
163-
164-
try:
165-
with django.db.transaction.atomic():
166-
self.setPassword(password)
167-
self.save()
168-
ezidapp.admin.scheduleUserChangePostCommitActions(self)
169-
except Exception:
170-
pass
171-
172160
return True
173161

174162
# See below.

impl/userauth.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -164,42 +164,3 @@ def authenticateRequest(request, storeSessionCookie=False):
164164
else:
165165
return None
166166

167-
168-
class LdapSha1PasswordHasher(django.contrib.auth.hashers.SHA1PasswordHasher):
169-
"""Password hasher for legacy LDAP-encoded passwords
170-
171-
File this
172-
under So Close, Yet So Far. LDAP uses salted SHA-1 hashing, and
173-
Django supports exactly that scheme. With some syntactic
174-
shuffling it would be possible for Django to work with
175-
LDAP-encoded passwords directly, except: LDAP uses binary salts,
176-
whereas Django requires salts to be text. Ergo, this custom
177-
hasher.
178-
"""
179-
algorithm = "ldap_sha1"
180-
181-
def encode(self, password, salt):
182-
assert password is not None
183-
assert len(salt) == 16
184-
binarySalt = "".join(chr(int(salt[i : i + 2], 16)) for i in range(0, 16, 2))
185-
hash = hashlib.sha1(
186-
django.utils.encoding.force_bytes(password) + binarySalt
187-
).hexdigest()
188-
return f"{self.algorithm}${salt}${hash}"
189-
190-
# TODO: Commented out for now, but as far as I can tell, this is unused.
191-
# def convertLegacyRepresentation(self, legacy):
192-
# # Converts a legacy LDAP-encoded password to Django syntax. In
193-
# # LDAP encoding, a 20-byte binary SHA-1 hash and an 8-byte binary
194-
# # salt are concatenated, Base64-encoded, and prepended with
195-
# # "{SSHA}".
196-
# assert legacy.startswith("{SSHA}")
197-
# d = base64.b64decode(legacy[6:])
198-
# assert len(d) == 28
199-
# hash = d[:20]
200-
# salt = d[20:]
201-
#
202-
# def hexify(s):
203-
# return "".join(f"{ord(c):02x}" for c in s)
204-
#
205-
# return f"{self.algorithm}${hexify(salt)}${hexify(hash)}"

settings/settings.py.j2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ MIDDLEWARE = (
568568

569569
PASSWORD_HASHERS = [
570570
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
571-
'impl.userauth.LdapSha1PasswordHasher',
572571
]
573572

574573
TEMPLATES = [

settings/tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@
554554

555555
PASSWORD_HASHERS = [
556556
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
557-
'impl.userauth.LdapSha1PasswordHasher',
558557
]
559558

560559
TEMPLATES = [

0 commit comments

Comments
 (0)