-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webui: crypt user password by default before passing it to backend
NOTE: using the same method as the current Gtk GUI
- Loading branch information
Showing
4 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import crypt | ||
from random import SystemRandom as sr | ||
import sys | ||
|
||
# Using the function from pyanaconda/core/users.py | ||
|
||
def crypt_password(password): | ||
"""Crypt a password. | ||
Process a password with appropriate salted one-way algorithm. | ||
:param str password: password to be crypted | ||
:returns: crypted representation of the original password | ||
:rtype: str | ||
""" | ||
# yescrypt is not supported by Python's crypt module, | ||
# so we need to generate the setting ourselves | ||
b64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | ||
setting = "$y$j9T$" + "".join(sr().choice(b64) for _sc in range(24)) | ||
|
||
# and try to compute the password hash using our yescrypt setting | ||
try: | ||
cryptpw = crypt.crypt(password, setting) | ||
|
||
# Fallback to sha512crypt, if yescrypt is not supported | ||
except OSError: | ||
sys.stderr.write("yescrypt is not supported, falling back to sha512crypt\n") | ||
try: | ||
cryptpw = crypt.crypt(password, crypt.METHOD_SHA512) | ||
except OSError as exc: | ||
raise RuntimeError( | ||
"Unable to encrypt password: unsupported algorithm {}".format(crypt.METHOD_SHA512) | ||
) from exc | ||
|
||
return cryptpw | ||
|
||
|
||
try: | ||
print(crypt_password(sys.argv[1]), end="") | ||
except Exception as e: | ||
sys.stderr.write(str(e) + "\n") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters