Skip to content

Conversation

@dubsector
Copy link

Imported Protobuf in RangeTest.tsx to inspect channel PSK data.

Pulled channels and activeNode from useDevice() to evaluate the primary channel state.

Added logic to detect public/unsecured channels based on PSK length (0 or 1 bytes).

Disabled the entire UI via isDisabled={isPrimaryChannelPublic}.

Forced enabled = false inside both defaultValues and live values to fully prevent enabling Range Test, even via state manipulation.

Ensures all platforms (Android, iOS, Web) consistently prevent Range Test usage on public channels.

Description

Related Issues

Changes Made

Testing Done

Screenshots (if applicable)

Checklist

  • Code follows project style guidelines
  • Documentation has been updated or added
  • Tests have been added or updated
  • All i18n translation labels have been added (read
    CONTRIBUTING_I18N_DEVELOPER_GUIDE.md for more details)

Imported Protobuf in RangeTest.tsx to inspect channel PSK data.

Pulled channels and activeNode from useDevice() to evaluate the primary channel state.

Added logic to detect public/unsecured channels based on PSK length (0 or 1 bytes).

Disabled the entire <DynamicForm> UI via isDisabled={isPrimaryChannelPublic}.

Forced enabled = false inside both defaultValues and live values to fully prevent enabling Range Test, even via state manipulation.

Ensures all platforms (Android, iOS, Web) consistently prevent Range Test usage on public channels.
@vercel
Copy link

vercel bot commented Nov 25, 2025

@dubsector is attempting to deploy a commit to the Meshtastic Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Nov 25, 2025

CLA assistant check
All committers have signed the CLA.

@dubsector
Copy link
Author

Apologies in advance this is really my first pull request of this caliber.

const hexLen = pskBytes instanceof Uint8Array ? pskBytes.length : 0;
// Treat very short/absent keys as effectively "public"/unencrypted.
return hexLen === 0 || hexLen === 1;
})();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, wanted to understand why an IIFE was used here though, maybe I'm missing something about how this is designed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how does this channel custom channels 0-9?

Copy link
Author

@dubsector dubsector Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only treat Range Test as blocked when channel 0 is effectively “public” (no PSK or a 1-byte PSK). Additional custom channels (1–9) are untouched by this check, and Range Test isn’t gated on them here.

I originally used an IIFE here to keep the logic self-contained and allow early returns without needing a mutable variable. I did pull requests for web, android, and apple, so i was trying to keep the code consistent.

Could switch this to a local helper function. Let me know and I can update it.

const isChannelPublic = (channel?: Protobuf.Channel.Channel): boolean => {
  if (!channel) return false;

  const pskBytes = channel.settings?.psk;
  const hexLen = pskBytes instanceof Uint8Array ? pskBytes.length : 0;

  // Treat very short/absent keys as effectively "public"/unencrypted.
  return hexLen === 0 || hexLen === 1;
};

const primaryChannel = channels.get(0 as Protobuf.Types.ChannelNumber);
const isPrimaryChannelPublic = isChannelPublic(primaryChannel);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yeah I dont think we use IIFE's anywhere else in the web code base. So lets switch to an arrow function wrapped with "useCallback" to make sure its reference is stable during rendering.

Copy link
Collaborator

@danditomaso danditomaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one comment to respond to and we can get this approved.

…nction

Removed the inline IIFE used for computing isPrimaryChannelPublic

Added a small useCallback helper (isChannelPublic) for reference stability during rendering

Behavior remains identical: primary channel is treated as “public” when PSK length is 0–1 bytes

No other logic or form behavior changed
Copy link
Author

@dubsector dubsector left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I have updated it.

@danditomaso
Copy link
Collaborator

Looks good, thanks for contributing!

@danditomaso
Copy link
Collaborator

It looks like a couple of lint errors are preventing this from being merged. Our lint rules prevent inline block statements, so once that is fixed we can get this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants