Deprecation of crypt
The crypt
module is going to be removed from the standard library in python3.13.
We still use it for recovery codes. We should probably migrate recovery codes to PasswordHash
and a saner algorithm. However, we cannot break existing recovery codes.
Option 1: Switch to passlib
To quote Python's crypt deprecation notice:
The passlib package can replace all use cases of this module.
Technically this is not true. While the crypt
module calls the crypt function of the system libc, passlib contains pure-python implementations of the most common crypt methods. So there might be some libc-supported methods that passlib does not implement.
The project seems pretty dormant. Last commit was 3 years ago. Maybe it is simply "done".
Option 2: Manually call libc's crypt
>>> import ctypes
>>> crypt = ctypes.CDLL("libcrypt.so")
>>> crypt.restype = ctypes.c_char_p
>>> crypt(b'foobar', b'$6$EoC2R3kckYop9Zz0$QWdAmKAp5JaWThjPVThqmO1XvN.Gh7cEY9l51PQgEP0f9rL6luTMriif09x9TEJheq3KWc04W.ZsOCbnxRcvL.')
b'$6$EoC2R3kckYop9Zz0$QWdAmKAp5JaWThjPVThqmO1XvN.Gh7cEY9l51PQgEP0f9rL6luTMriif09x9TEJheq3KWc04W.ZsOCbnxRcvL.'
Not sure if library name "libcrypt.so" works in all cases.
Option 3: Implement most relevant methods ourselves
Find out which methods are the default/available on our target platform (Debian Buster and Bullseye). On our production system it is 6
, i.e. salted sha512 without any rounds. Then implement those methods. This approach has similar problems as using passlib.
Sadly we cannot convert crypt hashes to OpenLDAP-/NIS-style password hashes: E.g. crypt's 6
method hashes <password><salt><password>
instead of <password><salt>
.
Option 4: Switch algorithm and prompt users to generate new recovery codes
We will still not be able to drop crypt support anytime soon, but we might be able to do that at some point.
Not sure if potentially getting rid of this technical dept justifies the user impact.
I guess we will use some combination, like use crypt
python module if available, fall back to loading libcrypt
manually and gradually get rid of crypt hashes by prompting users to generate new recovery codes.