Skip to content

Commit

Permalink
webui: crypt user password by default before passing it to backend
Browse files Browse the repository at this point in the history
NOTE: using the same method as the current Gtk GUI
  • Loading branch information
rvykydal committed Nov 14, 2023
1 parent bed2e8b commit 49e91c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions ui/webui/src/components/AnacondaWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { getDefaultScenario } from "./storage/InstallationScenario.jsx";
import { MountPointMapping, getPageProps as getMountPointMappingProps } from "./storage/MountPointMapping.jsx";
import { DiskEncryption, getStorageEncryptionState, getPageProps as getDiskEncryptionProps } from "./storage/DiskEncryption.jsx";
import { InstallationLanguage, getPageProps as getInstallationLanguageProps } from "./localization/InstallationLanguage.jsx";
import { Accounts, getPageProps as getAccountsProps, getAccountsState, accountsToDbusUsers } from "./users/Accounts.jsx";
import { Accounts, getPageProps as getAccountsProps, getAccountsState, accountsToDbusUsers, cryptUserPassword } from "./users/Accounts.jsx";
import { InstallationProgress } from "./installation/InstallationProgress.jsx";
import { ReviewConfiguration, ReviewConfigurationConfirmModal, getPageProps as getReviewConfigurationProps } from "./review/ReviewConfiguration.jsx";
import { exitGui } from "../helpers/exit.js";
Expand Down Expand Up @@ -362,8 +362,12 @@ const Footer = ({
},
});
} else if (activeStep.id === "accounts") {
setUsers(accountsToDbusUsers(accounts));
onNext();
cryptUserPassword(accounts.password)
.then(cryptedPassword => {
const users = accountsToDbusUsers({ ...accounts, password: cryptedPassword });
setUsers(users);
onNext();
}, onCritFail({ context: N_("Password ecryption failed.") }));
} else {
onNext();
}
Expand Down
8 changes: 7 additions & 1 deletion ui/webui/src/components/users/Accounts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ export function getAccountsState (
};
}

export const cryptUserPassword = async (password) => {
const pythonScript = `from random import SystemRandom as sr; import crypt; print(crypt.crypt("${password}", "$y$j9T$" + "".join(sr().choice("./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") for _sc in range(24))))`;
const crypted = await cockpit.spawn(["python3", "-c", pythonScript]);
return crypted;
};

export const accountsToDbusUsers = (accounts) => {
return [{
name: cockpit.variant("s", accounts.userAccount || ""),
gecos: cockpit.variant("s", accounts.fullName || ""),
password: cockpit.variant("s", accounts.password || ""),
"is-crypted": cockpit.variant("b", false),
"is-crypted": cockpit.variant("b", true),
groups: cockpit.variant("as", ["wheel"]),
}];
};
Expand Down
3 changes: 1 addition & 2 deletions ui/webui/test/check-users
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class TestUsers(anacondalib.VirtInstallMachineCase):

users = u.dbus_get_users()
self.assertIn('"groups" as 1 "wheel"', users)
self.assertIn('"is-crypted" b false', users)
self.assertIn('"password" s "password"', users)
self.assertIn('"is-crypted" b true', users)

if __name__ == '__main__':
test_main()

0 comments on commit 49e91c8

Please sign in to comment.