Browse Source

Updated pki regenerate dialog

pull/277/head
Tilen Komel 2 years ago
parent
commit
9d4aa05316
  1. 39
      src/components/Dialog/PkiRegenerateDialog.tsx
  2. 251
      src/components/PageComponents/Config/Security.tsx

39
src/components/Dialog/PkiRegenerateDialog.tsx

@ -0,0 +1,39 @@
import { Button } from "@components/UI/Button.js";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@components/UI/Dialog.js";
export interface PkiRegenerateDialogProps {
open: boolean;
onOpenChange: () => void;
onSubmit: () => void;
}
export const PkiRegenerateDialog = ({
open,
onOpenChange,
onSubmit,
}: PkiRegenerateDialogProps): JSX.Element => {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Regenerate Key pair?</DialogTitle>
<DialogDescription>
Are you sure you want to regenerate key pair?
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="destructive" onClick={() => onSubmit()}>
Regenerate
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};

251
src/components/PageComponents/Config/Security.tsx

@ -1,3 +1,4 @@
import { PkiRegenerateDialog } from "@app/components/Dialog/PkiRegenerateDialog";
import { DynamicForm } from "@app/components/Form/DynamicForm.js"; import { DynamicForm } from "@app/components/Form/DynamicForm.js";
import { import {
getX25519PrivateKey, getX25519PrivateKey,
@ -30,6 +31,7 @@ export const Security = (): JSX.Element => {
); );
const [adminKeyValidationText, setAdminKeyValidationText] = const [adminKeyValidationText, setAdminKeyValidationText] =
useState<string>(); useState<string>();
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
const onSubmit = (data: SecurityValidation) => { const onSubmit = (data: SecurityValidation) => {
if (privateKeyValidationText || adminKeyValidationText) return; if (privateKeyValidationText || adminKeyValidationText) return;
@ -69,11 +71,10 @@ export const Security = (): JSX.Element => {
}; };
const privateKeyClickEvent = () => { const privateKeyClickEvent = () => {
const generate = confirm( setDialogOpen(true);
"Are you sure you want to generate a new key pair?", };
);
if (!generate) return;
const pkiRegenerate = () => {
const privateKey = getX25519PrivateKey(); const privateKey = getX25519PrivateKey();
const publicKey = getX25519PublicKey(privateKey); const publicKey = getX25519PublicKey(privateKey);
@ -84,6 +85,8 @@ export const Security = (): JSX.Element => {
privateKeyBitCount, privateKeyBitCount,
setPrivateKeyValidationText, setPrivateKeyValidationText,
); );
setDialogOpen(false);
}; };
const privateKeyInputChangeEvent = ( const privateKeyInputChangeEvent = (
@ -114,126 +117,134 @@ export const Security = (): JSX.Element => {
}; };
return ( return (
<DynamicForm<SecurityValidation> <>
onSubmit={onSubmit} <DynamicForm<SecurityValidation>
submitType="onSubmit" onSubmit={onSubmit}
hasSubmitButton={true} submitType="onSubmit"
defaultValues={{ hasSubmitButton={true}
...config.security, defaultValues={{
...{ ...config.security,
adminKey: adminKey, ...{
privateKey: privateKey, adminKey: adminKey,
publicKey: publicKey, privateKey: privateKey,
adminChannelEnabled: config.security?.adminChannelEnabled ?? false, publicKey: publicKey,
isManaged: config.security?.isManaged ?? false, adminChannelEnabled: config.security?.adminChannelEnabled ?? false,
bluetoothLoggingEnabled: isManaged: config.security?.isManaged ?? false,
config.security?.bluetoothLoggingEnabled ?? false, bluetoothLoggingEnabled:
debugLogApiEnabled: config.security?.debugLogApiEnabled ?? false, config.security?.bluetoothLoggingEnabled ?? false,
serialEnabled: config.security?.serialEnabled ?? false, debugLogApiEnabled: config.security?.debugLogApiEnabled ?? false,
}, serialEnabled: config.security?.serialEnabled ?? false,
}} },
fieldGroups={[ }}
{ fieldGroups={[
label: "Security Settings", {
description: "Settings for the Security configuration", label: "Security Settings",
fields: [ description: "Settings for the Security configuration",
{ fields: [
type: "passwordGenerator", {
name: "privateKey", type: "passwordGenerator",
label: "Private Key", name: "privateKey",
description: "Used to create a shared key with a remote device", label: "Private Key",
bits: [{ text: "256 bit", value: "32", key: "bit256" }], description: "Used to create a shared key with a remote device",
validationText: privateKeyValidationText, bits: [{ text: "256 bit", value: "32", key: "bit256" }],
devicePSKBitCount: privateKeyBitCount, validationText: privateKeyValidationText,
inputChange: privateKeyInputChangeEvent, devicePSKBitCount: privateKeyBitCount,
selectChange: privateKeySelectChangeEvent, inputChange: privateKeyInputChangeEvent,
hide: !privateKeyVisible, selectChange: privateKeySelectChangeEvent,
buttonClick: privateKeyClickEvent, hide: !privateKeyVisible,
disabledBy: [ buttonClick: privateKeyClickEvent,
{ disabledBy: [
fieldName: "adminChannelEnabled", {
invert: true, fieldName: "adminChannelEnabled",
invert: true,
},
],
properties: {
value: privateKey,
action: {
icon: privateKeyVisible ? EyeOff : Eye,
onClick: () => setPrivateKeyVisible(!privateKeyVisible),
},
}, },
], },
properties: { {
value: privateKey, type: "text",
action: { name: "publicKey",
icon: privateKeyVisible ? EyeOff : Eye, label: "Public Key",
onClick: () => setPrivateKeyVisible(!privateKeyVisible), description:
"Sent out to other nodes on the mesh to allow them to compute a shared secret key",
disabledBy: [{ fieldName: "always" }],
properties: {
value: publicKey,
}, },
}, },
}, ],
{ },
type: "text", {
name: "publicKey", label: "Admin Settings",
label: "Public Key", description: "Settings for Admin",
description: fields: [
"Sent out to other nodes on the mesh to allow them to compute a shared secret key", {
disabledBy: [{ fieldName: "always" }], type: "toggle",
properties: { name: "adminChannelEnabled",
value: publicKey, label: "Allow Legacy Admin",
description:
"Allow incoming device control over the insecure legacy admin channel",
}, },
}, {
], type: "toggle",
}, name: "isManaged",
{ label: "Managed",
label: "Admin Settings", description:
description: "Settings for Admin", 'If true, device is considered to be "managed" by a mesh administrator via admin messages',
fields: [
{
type: "toggle",
name: "adminChannelEnabled",
label: "Allow Legacy Admin",
description:
"Allow incoming device control over the insecure legacy admin channel",
},
{
type: "toggle",
name: "isManaged",
label: "Managed",
description:
'If true, device is considered to be "managed" by a mesh administrator via admin messages',
},
{
type: "text",
name: "adminKey",
label: "Admin Key",
description:
"The public key authorized to send admin messages to this node",
validationText: adminKeyValidationText,
inputChange: adminKeyInputChangeEvent,
disabledBy: [{ fieldName: "adminChannelEnabled" }],
properties: {
value: adminKey,
}, },
}, {
], type: "text",
}, name: "adminKey",
{ label: "Admin Key",
label: "Logging Settings", description:
description: "Settings for Logging", "The public key authorized to send admin messages to this node",
fields: [ validationText: adminKeyValidationText,
{ inputChange: adminKeyInputChangeEvent,
type: "toggle", disabledBy: [{ fieldName: "adminChannelEnabled" }],
name: "bluetoothLoggingEnabled", properties: {
label: "Allow Bluetooth Logging", value: adminKey,
description: "Enables device (serial style logs) over Bluetooth", },
}, },
{ ],
type: "toggle", },
name: "debugLogApiEnabled", {
label: "Enable Debug Log API", label: "Logging Settings",
description: "Output live debug logging over serial", description: "Settings for Logging",
}, fields: [
{ {
type: "toggle", type: "toggle",
name: "serialEnabled", name: "bluetoothLoggingEnabled",
label: "Serial Output Enabled", label: "Allow Bluetooth Logging",
description: "Serial Console over the Stream API", description:
}, "Enables device (serial style logs) over Bluetooth",
], },
}, {
]} type: "toggle",
/> name: "debugLogApiEnabled",
label: "Enable Debug Log API",
description: "Output live debug logging over serial",
},
{
type: "toggle",
name: "serialEnabled",
label: "Serial Output Enabled",
description: "Serial Console over the Stream API",
},
],
},
]}
/>
<PkiRegenerateDialog
open={dialogOpen}
onOpenChange={() => setDialogOpen(false)}
onSubmit={() => pkiRegenerate()}
/>
</>
); );
}; };

Loading…
Cancel
Save