Skip to content

Commit

Permalink
webui: Show warning when trying to use non-ASCII LUKS passphrase
Browse files Browse the repository at this point in the history
We show this warning in the GTK UI so we should show it in the
WebUI too.

Resolves: rhbz#2234518
Related: rhbz#2231339
  • Loading branch information
vojtechtrefny committed Sep 4, 2023
1 parent 55d5aa9 commit 06a6776
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ui/webui/src/components/storage/DiskEncryption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ const PasswordFormFields = ({
onConfirmChange,
passwordStrength,
ruleLength,
ruleConfirmMatches
ruleConfirmMatches,
ruleAscii
}) => {
const [passwordHidden, setPasswordHidden] = useState(true);
const [confirmHidden, setConfirmHidden] = useState(true);
Expand Down Expand Up @@ -154,6 +155,15 @@ const PasswordFormFields = ({
>
{_("Must be at least 8 characters")}
</HelperTextItem>
{ruleAscii &&
<HelperTextItem
id={idPrefix + "-password-rule-ascii"}
isDynamic
variant="warning"
component="li"
>
{_("The passphrase you have provided contains non-ASCII characters. You may not be able to switch between keyboard layouts when typing it.")}
</HelperTextItem>}
</HelperText>
</FormHelperText>
</FormGroup>
Expand Down Expand Up @@ -253,6 +263,10 @@ export const DiskEncryption = ({
return getRuleLength(password);
}, [password]);

const ruleAscii = useMemo(() => {
return password.length > 0 && !/^[\x20-\x7F]*$/.test(password);
}, [password]);

const encryptedDevicesCheckbox = content => (
<Checkbox
id={idPrefix + "-encrypt-devices"}
Expand All @@ -273,6 +287,7 @@ export const DiskEncryption = ({
passwordConfirmLabel={_("Confirm passphrase")}
ruleLength={ruleLength}
ruleConfirmMatches={ruleConfirmMatches}
ruleAscii={ruleAscii}
onChange={setPassword}
onConfirmChange={setConfirmPassword}
/>
Expand Down
12 changes: 12 additions & 0 deletions ui/webui/test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
s.check_pw_rule("match", "error")
s.check_pw_strength("weak")

# Non-ASCII password
s.set_password(8 * "š")
s.check_password(8 * "š")
s.check_pw_rule("8-chars", "success")
s.check_pw_rule("match", "error")
s.check_pw_rule("ascii", "warning")
s.check_pw_strength("weak")

# Valid ASCII password
s.set_password("abcdefgh")
s.check_password("abcdefgh")

# Set the password confirm
s.set_password_confirm("abcdefg")
s.check_pw_rule("match", "error")
Expand Down

0 comments on commit 06a6776

Please sign in to comment.