Updated pki regenerate dialog
This commit is contained in:
@@ -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>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -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,
|
properties: {
|
||||||
action: {
|
value: privateKey,
|
||||||
icon: privateKeyVisible ? EyeOff : Eye,
|
action: {
|
||||||
onClick: () => setPrivateKeyVisible(!privateKeyVisible),
|
icon: privateKeyVisible ? EyeOff : Eye,
|
||||||
|
onClick: () => setPrivateKeyVisible(!privateKeyVisible),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
type: "text",
|
||||||
type: "text",
|
name: "publicKey",
|
||||||
name: "publicKey",
|
label: "Public Key",
|
||||||
label: "Public Key",
|
description:
|
||||||
description:
|
"Sent out to other nodes on the mesh to allow them to compute a shared secret key",
|
||||||
"Sent out to other nodes on the mesh to allow them to compute a shared secret key",
|
disabledBy: [{ fieldName: "always" }],
|
||||||
disabledBy: [{ fieldName: "always" }],
|
properties: {
|
||||||
properties: {
|
value: publicKey,
|
||||||
value: publicKey,
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
},
|
{
|
||||||
{
|
label: "Admin Settings",
|
||||||
label: "Admin Settings",
|
description: "Settings for Admin",
|
||||||
description: "Settings for Admin",
|
fields: [
|
||||||
fields: [
|
{
|
||||||
{
|
type: "toggle",
|
||||||
type: "toggle",
|
name: "adminChannelEnabled",
|
||||||
name: "adminChannelEnabled",
|
label: "Allow Legacy Admin",
|
||||||
label: "Allow Legacy Admin",
|
description:
|
||||||
description:
|
"Allow incoming device control over the insecure legacy admin channel",
|
||||||
"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: "toggle",
|
||||||
},
|
name: "isManaged",
|
||||||
{
|
label: "Managed",
|
||||||
label: "Logging Settings",
|
description:
|
||||||
description: "Settings for Logging",
|
'If true, device is considered to be "managed" by a mesh administrator via admin messages',
|
||||||
fields: [
|
},
|
||||||
{
|
{
|
||||||
type: "toggle",
|
type: "text",
|
||||||
name: "bluetoothLoggingEnabled",
|
name: "adminKey",
|
||||||
label: "Allow Bluetooth Logging",
|
label: "Admin Key",
|
||||||
description: "Enables device (serial style logs) over Bluetooth",
|
description:
|
||||||
},
|
"The public key authorized to send admin messages to this node",
|
||||||
{
|
validationText: adminKeyValidationText,
|
||||||
type: "toggle",
|
inputChange: adminKeyInputChangeEvent,
|
||||||
name: "debugLogApiEnabled",
|
disabledBy: [{ fieldName: "adminChannelEnabled" }],
|
||||||
label: "Enable Debug Log API",
|
properties: {
|
||||||
description: "Output live debug logging over serial",
|
value: adminKey,
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
type: "toggle",
|
],
|
||||||
name: "serialEnabled",
|
},
|
||||||
label: "Serial Output Enabled",
|
{
|
||||||
description: "Serial Console over the Stream API",
|
label: "Logging Settings",
|
||||||
},
|
description: "Settings for Logging",
|
||||||
],
|
fields: [
|
||||||
},
|
{
|
||||||
]}
|
type: "toggle",
|
||||||
/>
|
name: "bluetoothLoggingEnabled",
|
||||||
|
label: "Allow Bluetooth Logging",
|
||||||
|
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()}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user