feat(#887): contact remote-CLI permission toggle (flag 0x10)

F3/E3.1. Upstream 1.18 gates remote CLI (TXT type 3) on contact flag
0x10 (isRemoteCLIAllowed): the receiving radio checks it, so setting it
on a contact grants that contact permission to run CLI on this radio.

Adds the constant, Contact.remoteCliAllowed, a remoteCli param to
setContactFlags (same set/clear pattern as the telemetry flags, reading
a fresh device snapshot first), and an opt-in SwitchListTile in the
shared contact settings dialog (default off). Written with the existing
add/update-contact frame; the flags byte already rides it.

Tests: the 0x10 bit on the write-path frame (set/clear/coexist) and the
getter. Full suite green (1424); Gemini 2.5-pro review: no defects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
epic/870-console-gating
diffwireauto 1 month ago committed by Strycher
parent 2984ece46c
commit 8017ce4baf

@ -5375,6 +5375,7 @@ class MeshCoreConnector extends ChangeNotifier {
bool? teleBase,
bool? teleLoc,
bool? teleEnv,
bool? remoteCli,
}) async {
if (!isConnected) return;
final latestContact =
@ -5399,6 +5400,11 @@ class MeshCoreConnector extends ChangeNotifier {
? (updatedFlags | contactFlagTeleEnv)
: (updatedFlags & ~contactFlagTeleEnv))
: updatedFlags;
updatedFlags = remoteCli != null
? (remoteCli
? (updatedFlags | contactFlagRemoteCliAllowed)
: (updatedFlags & ~contactFlagRemoteCliAllowed))
: updatedFlags;
await sendFrame(
buildUpdateContactPathFrame(

@ -1021,6 +1021,11 @@ const int contactFlagFavorite = 0x01;
const int contactFlagTeleBase = 0x02; // 'base' permission includes battery
const int contactFlagTeleLoc = 0x04;
const int contactFlagTeleEnv = 0x08; //access environment sensors
// 0x10 (isRemoteCLIAllowed): this contact may run remote CLI (TXT type 3)
// commands on our radio. The receiving side checks it, so setting it here grants
// the contact permission to command THIS device. [verified: BaseChatMesh.cpp /
// MyMesh.cpp companion at companion-v1.18.0; INVESTIGATION.md section A]
const int contactFlagRemoteCliAllowed = 0x10;
const int contactPathLenOffset = 35;
const int contactPathOffset = 36;
const int contactNameOffset = 100;

@ -793,6 +793,8 @@
"contact_teleLocSubtitle": "Allow sharing location data",
"contact_teleEnv": "Telemetry Environment",
"contact_teleEnvSubtitle": "Allow sharing environment sensor data",
"contact_remoteCli": "Remote CLI",
"contact_remoteCliSubtitle": "Let this contact run CLI commands on your radio",
"channels_title": "Channels",
"channels_noChannelsConfigured": "No channels configured",
"channels_addPublicChannel": "Add Public Channel",

@ -2746,6 +2746,18 @@ abstract class AppLocalizations {
/// **'Allow sharing environment sensor data'**
String get contact_teleEnvSubtitle;
/// No description provided for @contact_remoteCli.
///
/// In en, this message translates to:
/// **'Remote CLI'**
String get contact_remoteCli;
/// No description provided for @contact_remoteCliSubtitle.
///
/// In en, this message translates to:
/// **'Let this contact run CLI commands on your radio'**
String get contact_remoteCliSubtitle;
/// No description provided for @channels_title.
///
/// In en, this message translates to:

@ -1536,6 +1536,13 @@ class AppLocalizationsBg extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Позволи споделяне на данни от средносферните датчици';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Канали';

@ -1530,6 +1530,13 @@ class AppLocalizationsDe extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Teilen von Umgebungsensordaten zulassen';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Kanäle';

@ -1512,6 +1512,13 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get contact_teleEnvSubtitle => 'Allow sharing environment sensor data';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Channels';

@ -1531,6 +1531,13 @@ class AppLocalizationsEs extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Permitir el intercambio de datos de sensores de entorno';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Canales';

@ -1536,6 +1536,13 @@ class AppLocalizationsFr extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Autoriser le partage des données des capteurs d\'environnement';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Canaux';

@ -1537,6 +1537,13 @@ class AppLocalizationsHu extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Engedje meg az érzékelő adatok megosztását';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Csatornák';

@ -1532,6 +1532,13 @@ class AppLocalizationsIt extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Consenti la condivisione dei dati del sensore ambientale';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Canali';

@ -1480,6 +1480,13 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get contact_teleEnvSubtitle => '環境センサーのデータを共有することを許可する';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'チャンネル';

@ -1475,6 +1475,13 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get contact_teleEnvSubtitle => '환경 센서 데이터를 공유하도록 허용';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => '채널';

@ -1523,6 +1523,13 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get contact_teleEnvSubtitle => 'Delen van omgevingsensordata toestaan';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Kanaal';

@ -1542,6 +1542,13 @@ class AppLocalizationsPl extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Zezwalaj na udostępnianie danych czujników środowiskowych';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Kanały';

@ -1532,6 +1532,13 @@ class AppLocalizationsPt extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Permitir compartilhamento de dados do sensor de ambiente';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Canais';

@ -1533,6 +1533,13 @@ class AppLocalizationsRu extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Разрешить обмен данными датчиков окружающей среды';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Каналы';

@ -1523,6 +1523,13 @@ class AppLocalizationsSk extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Povoliť zdieľanie údajov senzorov prostredia';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Kanály';

@ -1520,6 +1520,13 @@ class AppLocalizationsSl extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Dovoli deljenje podatkov okoljskih senzorjev';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Kanali';

@ -1514,6 +1514,13 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get contact_teleEnvSubtitle => 'Tillåt delning av miljösensordata';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Kanaler';

@ -1528,6 +1528,13 @@ class AppLocalizationsUk extends AppLocalizations {
String get contact_teleEnvSubtitle =>
'Дозволити спільний доступ до даних датчиків середовища';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => 'Канали';

@ -1461,6 +1461,13 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get contact_teleEnvSubtitle => '允许共享环境传感器数据';
@override
String get contact_remoteCli => 'Remote CLI';
@override
String get contact_remoteCliSubtitle =>
'Let this contact run CLI commands on your radio';
@override
String get channels_title => '频道';

@ -531,4 +531,7 @@ class Contact {
bool get teleBaseEnabled => (flags & contactFlagTeleBase) != 0;
bool get teleLocEnabled => (flags & contactFlagTeleLoc) != 0;
bool get teleEnvEnabled => (flags & contactFlagTeleEnv) != 0;
/// This contact may run remote CLI (TXT type 3) commands on our radio (#887).
bool get remoteCliAllowed => (flags & contactFlagRemoteCliAllowed) != 0;
}

@ -23,6 +23,7 @@ void showContactSettingsDialog(BuildContext context, Contact contact) {
bool teleBaseEnabled = contact.teleBaseEnabled;
bool teleLocEnabled = contact.teleLocEnabled;
bool teleEnvEnabled = contact.teleEnvEnabled;
bool remoteCliEnabled = contact.remoteCliAllowed;
showDialog(
context: context,
builder: (context) => StatefulBuilder(
@ -115,6 +116,16 @@ void showContactSettingsDialog(BuildContext context, Contact contact) {
setDialogState(() => teleEnvEnabled = value);
},
),
const Divider(height: 8),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(context.l10n.contact_remoteCli),
subtitle: Text(context.l10n.contact_remoteCliSubtitle),
value: remoteCliEnabled,
onChanged: (value) {
setDialogState(() => remoteCliEnabled = value);
},
),
],
),
),
@ -126,6 +137,7 @@ void showContactSettingsDialog(BuildContext context, Contact contact) {
teleBase: teleBaseEnabled,
teleLoc: teleLocEnabled,
teleEnv: teleEnvEnabled,
remoteCli: remoteCliEnabled,
);
Navigator.pop(context);
},

@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/models/contact.dart';
void main() {
// Frame layout per the doc comment on buildUpdateContactPathFrame:
@ -220,4 +221,63 @@ void main() {
expect(frame[pathLenOffset], 0xFF);
});
});
group('remote-CLI permission flag on the write path (#887)', () {
// 1 cmd + 32 pubKey + 1 type = 34.
const int flagsOffset = 34;
test('the 0x10 bit rides the flags byte when set', () {
final frame = buildUpdateContactPathFrame(
pubKey,
path,
path.length,
flags: contactFlagRemoteCliAllowed,
);
expect(
frame[flagsOffset] & contactFlagRemoteCliAllowed,
contactFlagRemoteCliAllowed,
);
});
test('remote-CLI coexists with telemetry flags in the one byte', () {
final frame = buildUpdateContactPathFrame(
pubKey,
path,
path.length,
flags: contactFlagRemoteCliAllowed | contactFlagTeleBase,
);
expect(frame[flagsOffset] & contactFlagRemoteCliAllowed, isNonZero);
expect(frame[flagsOffset] & contactFlagTeleBase, isNonZero);
});
test('a frame without the permission carries a clear 0x10 bit', () {
final frame = buildUpdateContactPathFrame(
pubKey,
path,
path.length,
flags: contactFlagTeleBase,
);
expect(frame[flagsOffset] & contactFlagRemoteCliAllowed, 0);
});
test('Contact.remoteCliAllowed reflects the 0x10 bit', () {
Contact withFlags(int flags) => Contact(
publicKey: Uint8List(32),
name: 'X',
type: 1,
pathLength: 0,
path: Uint8List(0),
lastSeen: DateTime.now(),
flags: flags,
);
expect(withFlags(contactFlagRemoteCliAllowed).remoteCliAllowed, isTrue);
expect(withFlags(contactFlagTeleBase).remoteCliAllowed, isFalse);
expect(
withFlags(
contactFlagRemoteCliAllowed | contactFlagFavorite,
).remoteCliAllowed,
isTrue,
);
});
});
}

Loading…
Cancel
Save

Powered by TurnKey Linux.