Skip to content

Commit 3107dc8

Browse files
committed
issue2551191 - Module deprication PEP 594. crypt
Handle missing crypt module "better" by raising an exception rather than just silently failing to log in the user when a crypt encoded password can't be checked. Update tests and upgrading.txt too.
1 parent 04db5c5 commit 3107dc8

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

doc/upgrading.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,33 @@ can use the ``_generic.404.html`` template to create a
154154
the 400 template by appending ``@template=400`` to the url for the
155155
tracker.
156156

157+
Change passwords using crypt module (optional)
158+
----------------------------------------------
159+
160+
The crypt module is being removed from the standard library. Any
161+
stored password using crypt encoding will fail to verify once the
162+
crypt module is removed (expected in Python 3.13 see
163+
pep-0594). Automatic migration of passwords (if enabled in config.ini)
164+
re-encrypts old passwords using something other than crypt if a user
165+
logs in using the web interface.
166+
167+
You can find users with passwords still encrypted using crypt by
168+
running::
169+
170+
roundup-admin -i <tracker_home> table password,id,username
171+
172+
Look for lines starting with ``{CRYPT}``. You can reset the user's
173+
password using::
174+
175+
roundup-admin -i <tracker_home>
176+
roundup> set user16 password=somenewpassword
177+
178+
changing ``16`` to the id in the second column of the table output.
179+
The example uses interactive mode (indicated by the ``roundup>``
180+
prompt). This prevents the new password from showing up in the output
181+
of ps or shell history. The new password will be encrypted using the
182+
default encryption method (usually pbkdf2).
183+
157184
Migrating from 2.0.0 to 2.1.0
158185
=============================
159186

roundup/password.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ def encodePassword(plaintext, scheme, other=None, config=None):
201201
s = sha1(s2b(plaintext)).hexdigest() # nosec
202202
elif scheme == 'MD5':
203203
s = md5(s2b(plaintext)).hexdigest() # nosec
204-
elif scheme == 'crypt' and crypt is not None:
204+
elif scheme == 'crypt':
205+
if crypt is None:
206+
raise PasswordValueError(
207+
'Unsupported encryption scheme %r' % scheme)
205208
if other is not None:
206209
salt = other
207210
else:
@@ -355,6 +358,8 @@ def __str__(self):
355358
raise ValueError('Password not set')
356359
return '{%s}%s' % (self.scheme, self.password)
357360

361+
def test_missing_crypt():
362+
p = encodePassword('sekrit', 'crypt')
358363

359364
def test():
360365
# SHA
@@ -415,5 +420,6 @@ def test():
415420

416421
if __name__ == '__main__':
417422
test()
423+
test_missing_crypt()
418424

419425
# vim: set filetype=python sts=4 sw=4 et si :

test/test_security.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,15 @@ def testTransitiveSearchPermissions(self):
411411
self.assertEqual(has(uimu, 'issue', 'messages.recipients'), 1)
412412
self.assertEqual(has(uimu, 'issue', 'messages.recipients.username'), 1)
413413

414-
# roundup.password has its own built-in test, call it.
414+
# roundup.password has its own built-in tests, call them.
415415
def test_password(self):
416416
roundup.password.test()
417417

418+
# pretend import of crypt failed
419+
orig_crypt = roundup.password.crypt
420+
roundup.password.crypt = None
421+
with self.assertRaises(roundup.password.PasswordValueError) as ctx:
422+
roundup.password.test_missing_crypt()
423+
roundup.password.crypt = orig_crypt
424+
418425
# vim: set filetype=python sts=4 sw=4 et si :

0 commit comments

Comments
 (0)