Add key generation
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
import { DynamicForm } from "@app/components/Form/DynamicForm.js";
|
import { DynamicForm } from "@app/components/Form/DynamicForm.js";
|
||||||
|
import {
|
||||||
|
getX25519PrivateKey,
|
||||||
|
getX25519PublicKey,
|
||||||
|
} from "@app/core/utils/x25519";
|
||||||
import type { SecurityValidation } from "@app/validation/config/security.js";
|
import type { SecurityValidation } from "@app/validation/config/security.js";
|
||||||
import { useDevice } from "@core/stores/deviceStore.js";
|
import { useDevice } from "@core/stores/deviceStore.js";
|
||||||
import { Protobuf } from "@meshtastic/js";
|
import { Protobuf } from "@meshtastic/js";
|
||||||
@@ -50,22 +54,25 @@ export const Security = (): JSX.Element => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const clickEvent = (
|
const privateKeyClickEvent = () => {
|
||||||
setKey: (value: React.SetStateAction<string>) => void,
|
const privateKey = getX25519PrivateKey();
|
||||||
bitCount: number,
|
const publicKey = getX25519PublicKey(privateKey);
|
||||||
setValidationText: (
|
|
||||||
value: React.SetStateAction<string | undefined>,
|
setPrivateKey(fromByteArray(privateKey));
|
||||||
) => void,
|
setPublicKey(fromByteArray(publicKey));
|
||||||
) => {
|
setPrivateKeyValidationText(undefined);
|
||||||
setKey(
|
};
|
||||||
|
|
||||||
|
const adminKeyClickEvent = () => {
|
||||||
|
setAdminKey(
|
||||||
btoa(
|
btoa(
|
||||||
cryptoRandomString({
|
cryptoRandomString({
|
||||||
length: bitCount ?? 0,
|
length: adminKeyBitCount ?? 0,
|
||||||
type: "alphanumeric",
|
type: "alphanumeric",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
setValidationText(undefined);
|
setAdminKeyValidationText(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
const validatePass = (
|
const validatePass = (
|
||||||
@@ -129,17 +136,13 @@ export const Security = (): JSX.Element => {
|
|||||||
name: "privateKey",
|
name: "privateKey",
|
||||||
label: "Private Key",
|
label: "Private Key",
|
||||||
description: "Used to create a shared key with a remote device",
|
description: "Used to create a shared key with a remote device",
|
||||||
|
bits: [{ text: "128 bit", value: "16", key: "bit128" }],
|
||||||
validationText: privateKeyValidationText,
|
validationText: privateKeyValidationText,
|
||||||
devicePSKBitCount: privateKeyBitCount,
|
devicePSKBitCount: privateKeyBitCount,
|
||||||
inputChange: privateKeyInputChangeEvent,
|
inputChange: privateKeyInputChangeEvent,
|
||||||
selectChange: privateKeySelectChangeEvent,
|
selectChange: privateKeySelectChangeEvent,
|
||||||
hide: !privateKeyVisible,
|
hide: !privateKeyVisible,
|
||||||
buttonClick: () =>
|
buttonClick: privateKeyClickEvent,
|
||||||
clickEvent(
|
|
||||||
setPrivateKey,
|
|
||||||
privateKeyBitCount,
|
|
||||||
setPrivateKeyValidationText,
|
|
||||||
),
|
|
||||||
disabledBy: [
|
disabledBy: [
|
||||||
{
|
{
|
||||||
fieldName: "adminChannelEnabled",
|
fieldName: "adminChannelEnabled",
|
||||||
@@ -161,6 +164,9 @@ export const Security = (): JSX.Element => {
|
|||||||
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: {
|
||||||
|
value: publicKey,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -193,12 +199,7 @@ export const Security = (): JSX.Element => {
|
|||||||
inputChange: adminKeyInputChangeEvent,
|
inputChange: adminKeyInputChangeEvent,
|
||||||
selectChange: adminKeySelectChangeEvent,
|
selectChange: adminKeySelectChangeEvent,
|
||||||
hide: !adminKeyVisible,
|
hide: !adminKeyVisible,
|
||||||
buttonClick: () =>
|
buttonClick: adminKeyClickEvent,
|
||||||
clickEvent(
|
|
||||||
setAdminKey,
|
|
||||||
adminKeyBitCount,
|
|
||||||
setAdminKeyValidationText,
|
|
||||||
),
|
|
||||||
disabledBy: [{ fieldName: "adminChannelEnabled" }],
|
disabledBy: [{ fieldName: "adminChannelEnabled" }],
|
||||||
properties: {
|
properties: {
|
||||||
value: adminKey,
|
value: adminKey,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { x25519 } from "@noble/curves/ed25519";
|
||||||
|
|
||||||
|
export function getX25519PrivateKey(): Uint8Array {
|
||||||
|
return x25519.utils.randomPrivateKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getX25519PublicKey(privateKey: Uint8Array): Uint8Array {
|
||||||
|
return x25519.getPublicKey(privateKey);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user