-
Notifications
You must be signed in to change notification settings - Fork 292
feat: add packet authenticity policy setting #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
RCGV1
wants to merge
2
commits into
meshtastic:main
Choose a base branch
from
RCGV1:codex/packet-auth-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...eb/src/components/PageComponents/Settings/Security/PacketAuthenticityPolicyField.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { Protobuf } from "@meshtastic/sdk"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { useForm } from "react-hook-form"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { RawSecurity } from "@app/validation/config/security.ts"; | ||
| import { | ||
| PACKET_SIGNATURE_POLICY_OPTIONS, | ||
| PacketAuthenticityPolicyField, | ||
| } from "./PacketAuthenticityPolicyField.tsx"; | ||
|
|
||
| const Policy = Protobuf.Config.Config_SecurityConfig_PacketSignaturePolicy; | ||
|
|
||
| const Harness = ({ supported }: { supported: boolean }) => { | ||
| const { control } = useForm<RawSecurity>({ | ||
| defaultValues: { packetSignaturePolicy: Policy.BALANCED }, | ||
| }); | ||
|
|
||
| return ( | ||
| <PacketAuthenticityPolicyField | ||
| control={control} | ||
| supported={supported} | ||
| validateSelection={vi.fn().mockResolvedValue(true)} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| describe("PacketAuthenticityPolicyField", () => { | ||
| it("disables configuration and explains the unavailable capability", () => { | ||
| render(<Harness supported={false} />); | ||
|
|
||
| expect( | ||
| screen.getByRole("combobox", { name: "Protection level" }), | ||
| ).toBeDisabled(); | ||
| expect( | ||
| screen.getByText(/disconnected.*XEdDSA verification support/i), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("presents Compatible, Balanced, and Strict in explicit product order", async () => { | ||
| const user = userEvent.setup(); | ||
| render(<Harness supported />); | ||
|
|
||
| expect(Object.keys(PACKET_SIGNATURE_POLICY_OPTIONS)).toEqual([ | ||
| "COMPATIBLE", | ||
| "BALANCED", | ||
| "STRICT", | ||
| ]); | ||
|
|
||
| await user.click( | ||
| screen.getByRole("combobox", { name: "Protection level" }), | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getAllByRole("option").map((option) => option.textContent), | ||
| ).toEqual([ | ||
| "Compatible — Accept unsigned", | ||
| "Balanced — Prefer authenticated", | ||
| "Strict — Require authenticated", | ||
| ]); | ||
| }); | ||
|
|
||
| it("shows Balanced downgrade-protection copy by default", () => { | ||
| render(<Harness supported />); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| /unsigned, signable broadcasts from nodes known to sign/i, | ||
| ), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); |
73 changes: 73 additions & 0 deletions
73
apps/web/src/components/PageComponents/Settings/Security/PacketAuthenticityPolicyField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { SelectInput } from "@components/Form/FormSelect.tsx"; | ||
| import { FieldWrapper } from "@components/Form/FormWrapper.tsx"; | ||
| import { Protobuf } from "@meshtastic/sdk"; | ||
| import type { Control } from "react-hook-form"; | ||
| import { useWatch } from "react-hook-form"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import type { RawSecurity } from "@app/validation/config/security.ts"; | ||
| import { PACKET_SIGNATURE_POLICY_OPTIONS } from "./packetAuthenticityPolicy.ts"; | ||
|
|
||
| const Policy = Protobuf.Config.Config_SecurityConfig_PacketSignaturePolicy; | ||
|
|
||
| export { PACKET_SIGNATURE_POLICY_OPTIONS } from "./packetAuthenticityPolicy.ts"; | ||
|
|
||
| const POLICY_DESCRIPTION_KEYS: Record< | ||
| Protobuf.Config.Config_SecurityConfig_PacketSignaturePolicy, | ||
| string | ||
| > = { | ||
| [Policy.COMPATIBLE]: | ||
| "security.packetAuthenticity.options.compatible.description", | ||
| [Policy.BALANCED]: "security.packetAuthenticity.options.balanced.description", | ||
| [Policy.STRICT]: "security.packetAuthenticity.options.strict.description", | ||
| }; | ||
|
|
||
| interface PacketAuthenticityPolicyFieldProps { | ||
| control: Control<RawSecurity>; | ||
| supported: boolean; | ||
| validateSelection: (policyKey: string) => Promise<boolean>; | ||
| } | ||
|
|
||
| export const PacketAuthenticityPolicyField = ({ | ||
| control, | ||
| supported, | ||
| validateSelection, | ||
| }: PacketAuthenticityPolicyFieldProps) => { | ||
| const { t } = useTranslation("config"); | ||
| const selectedPolicy = useWatch({ | ||
| control, | ||
| name: "packetSignaturePolicy", | ||
| }); | ||
| const description = supported | ||
| ? t(POLICY_DESCRIPTION_KEYS[selectedPolicy] ?? POLICY_DESCRIPTION_KEYS[0]) | ||
| : t("security.packetAuthenticity.unavailable"); | ||
|
|
||
| return ( | ||
| <FieldWrapper | ||
| label={t("security.packetAuthenticity.protectionLevel")} | ||
| fieldName="packetSignaturePolicy" | ||
| description={description} | ||
| > | ||
| <SelectInput<RawSecurity> | ||
| control={control} | ||
| disabled={!supported} | ||
| field={{ | ||
| type: "select", | ||
| name: "packetSignaturePolicy", | ||
| label: t("security.packetAuthenticity.protectionLevel"), | ||
| validate: validateSelection, | ||
| properties: { | ||
| enumValue: PACKET_SIGNATURE_POLICY_OPTIONS, | ||
| optionLabels: { | ||
| COMPATIBLE: t( | ||
| "security.packetAuthenticity.options.compatible.label", | ||
| ), | ||
| BALANCED: t("security.packetAuthenticity.options.balanced.label"), | ||
| STRICT: t("security.packetAuthenticity.options.strict.label"), | ||
| }, | ||
| "aria-label": t("security.packetAuthenticity.protectionLevel"), | ||
| }, | ||
| }} | ||
| /> | ||
| </FieldWrapper> | ||
| ); | ||
| }; |
43 changes: 43 additions & 0 deletions
43
...b/src/components/PageComponents/Settings/Security/PacketAuthenticityStrictDialog.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { PacketAuthenticityStrictDialog } from "./PacketAuthenticityStrictDialog.tsx"; | ||
|
|
||
| describe("PacketAuthenticityStrictDialog", () => { | ||
| it("explains Strict authentication and visibility consequences", () => { | ||
| render( | ||
| <PacketAuthenticityStrictDialog | ||
| open | ||
| onOpenChange={vi.fn()} | ||
| onConfirm={vi.fn()} | ||
| onCancel={vi.fn()} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByText(/verified XEdDSA signature/i)).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText(/successful PKI authentication/i), | ||
| ).toBeInTheDocument(); | ||
| expect(screen.getByText(/older firmware/i)).toBeInTheDocument(); | ||
| expect(screen.getByText(/licensed\/ham nodes/i)).toBeInTheDocument(); | ||
| expect(screen.getByText(/oversized unsigned packets/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("exposes explicit confirm and cancel actions", () => { | ||
| const onConfirm = vi.fn(); | ||
| const onCancel = vi.fn(); | ||
| render( | ||
| <PacketAuthenticityStrictDialog | ||
| open | ||
| onOpenChange={vi.fn()} | ||
| onConfirm={onConfirm} | ||
| onCancel={onCancel} | ||
| />, | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByRole("button", { name: "Enable Strict" })); | ||
| fireEvent.click(screen.getByRole("button", { name: "Cancel" })); | ||
|
|
||
| expect(onConfirm).toHaveBeenCalledOnce(); | ||
| expect(onCancel).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); |
32 changes: 32 additions & 0 deletions
32
apps/web/src/components/PageComponents/Settings/Security/PacketAuthenticityStrictDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { DialogWrapper } from "@components/Dialog/DialogWrapper.tsx"; | ||
| import { useTranslation } from "react-i18next"; | ||
|
|
||
| interface PacketAuthenticityStrictDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| onConfirm: () => void; | ||
| onCancel: () => void; | ||
| } | ||
|
|
||
| export const PacketAuthenticityStrictDialog = ({ | ||
| open, | ||
| onOpenChange, | ||
| onConfirm, | ||
| onCancel, | ||
| }: PacketAuthenticityStrictDialogProps) => { | ||
| const { t } = useTranslation("dialog"); | ||
|
|
||
| return ( | ||
| <DialogWrapper | ||
| open={open} | ||
| onOpenChange={onOpenChange} | ||
| type="confirm" | ||
| title={t("packetAuthenticityStrict.title")} | ||
| description={t("packetAuthenticityStrict.description")} | ||
| confirmText={t("packetAuthenticityStrict.confirm")} | ||
| cancelText={t("button.cancel")} | ||
| onConfirm={onConfirm} | ||
| onCancel={onCancel} | ||
| /> | ||
| ); | ||
| }; |
61 changes: 61 additions & 0 deletions
61
apps/web/src/components/PageComponents/Settings/Security/Security.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { Protobuf } from "@meshtastic/sdk"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { RawSecurity } from "@app/validation/config/security.ts"; | ||
| import { | ||
| submitSecurityConfig, | ||
| toFormShape, | ||
| toSecurityPayload, | ||
| } from "./Security.tsx"; | ||
|
|
||
| const Policy = Protobuf.Config.Config_SecurityConfig_PacketSignaturePolicy; | ||
|
|
||
| const rawSecurity = ( | ||
| packetSignaturePolicy: RawSecurity["packetSignaturePolicy"], | ||
| ) => | ||
| ({ | ||
| isManaged: false, | ||
| adminChannelEnabled: false, | ||
| debugLogApiEnabled: false, | ||
| serialEnabled: true, | ||
| packetSignaturePolicy, | ||
| privateKey: "", | ||
| publicKey: "", | ||
| adminKey: ["", "", ""], | ||
| }) satisfies RawSecurity; | ||
|
|
||
| describe("Security packet authenticity persistence", () => { | ||
| it.each([Policy.COMPATIBLE, Policy.BALANCED, Policy.STRICT])( | ||
| "preserves policy %s when mapping firmware config into the form", | ||
| (packetSignaturePolicy) => { | ||
| const form = toFormShape({ | ||
| packetSignaturePolicy, | ||
| } as Protobuf.Config.Config_SecurityConfig); | ||
|
|
||
| expect(form.packetSignaturePolicy).toBe(packetSignaturePolicy); | ||
| }, | ||
| ); | ||
|
|
||
| it.each([Policy.COMPATIBLE, Policy.BALANCED, Policy.STRICT])( | ||
| "preserves policy %s when mapping the form to a security payload", | ||
| (packetSignaturePolicy) => { | ||
| expect( | ||
| toSecurityPayload(rawSecurity(packetSignaturePolicy)) | ||
| .packetSignaturePolicy, | ||
| ).toBe(packetSignaturePolicy); | ||
| }, | ||
| ); | ||
|
|
||
| it.each([Policy.COMPATIBLE, Policy.BALANCED, Policy.STRICT])( | ||
| "submits policy %s through the security radio section", | ||
| (packetSignaturePolicy) => { | ||
| const setRadioSection = vi.fn(); | ||
|
|
||
| submitSecurityConfig(setRadioSection, rawSecurity(packetSignaturePolicy)); | ||
|
|
||
| expect(setRadioSection).toHaveBeenCalledWith( | ||
| "security", | ||
| expect.objectContaining({ packetSignaturePolicy }), | ||
| ); | ||
| }, | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.