/* * Copyright (C) 2023 Red Hat, Inc. * SPDX-License-Identifier: LGPL-2.1-or-later */ import cockpit from "cockpit"; import React, { useContext } from "react"; import { Alert } from "@patternfly/react-core/dist/esm/components/Alert/index.js"; import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox/index.js"; import { Content, ContentVariants } from "@patternfly/react-core/dist/esm/components/Content/index.js"; import { EmptyState, EmptyStateFooter } from "@patternfly/react-core/dist/esm/components/EmptyState/index.js"; import { Form, FormGroup, FormSection } from "@patternfly/react-core/dist/esm/components/Form/index.js"; import { Spinner } from "@patternfly/react-core/dist/esm/components/Spinner/index.js"; import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput/index.js"; import { Title } from "@patternfly/react-core/dist/esm/components/Title/index.js"; import { setLuksEncryptionDataAction } from "../../../actions/storage-actions.js"; import { LanguageContext, PageContext, RuntimeContext, StorageContext } from "../../../contexts/Common.jsx"; import { PasswordFormFields, ruleLength } from "../../Password.jsx"; import "./DiskEncryption.scss"; const _ = cockpit.gettext; const idPrefix = "disk-encryption"; const ruleAscii = { check: (policy, password) => password.length > 0 && /^[\x20-\x7F]*$/.test(password), id: "ascii", isError: false, text: () => _("The passphrase you have provided contains non-ASCII characters. You may not be able to switch between keyboard layouts when typing it."), }; const CheckDisksSpinner = ( {_("Checking storage configuration")}} id={idPrefix + "-next-spinner"}> {_("This may take a moment")} ); export const DiskEncryption = ({ dispatch }) => { const { setIsFormValid } = useContext(PageContext) ?? {}; const { luks } = useContext(StorageContext); const luksPolicy = useContext(RuntimeContext).passwordPolicies.luks; const { plannedVconsole } = useContext(LanguageContext); if (luks.passphrase === undefined) { return CheckDisksSpinner; } const encryptedDevicesCheckbox = content => ( { dispatch(setLuksEncryptionDataAction({ encrypted: isEncrypted })); }} body={content} /> ); const encryptionContent = ( <> dispatch(setLuksEncryptionDataAction({ passphrase: value }))} passwordLabel={_("Passphrase")} confirmPassword={luks.confirmPassphrase} setConfirmPassword={(value) => dispatch(setLuksEncryptionDataAction({ confirmPassphrase: value }))} confirmPasswordLabel={_("Confirm passphrase")} rules={[ruleLength, ruleAscii]} setIsValid={setIsFormValid} /> ); return (
{ e.preventDefault(); return false }}> {_("Encryption")}} > {_("Secure your data using disk-based encryption. Only applies to new partitions")} {encryptedDevicesCheckbox(luks.encrypted ? encryptionContent : null)}
); };