From b7249f449ae5c630ec31a6194e79f8e2046afd0a Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Thu, 19 Nov 2026 17:21:29 +0100 Subject: [PATCH] Repeater, room server, sensor, companion: build flag LOCKED_NODE for a node that keeps its secrets from whoever holds it Co-Authored-By: Claude Opus 5.5 --- docs/tth-commands.md | 1 + examples/companion_radio/MyMesh.cpp | 15 +++++++++++++++ src/helpers/CommonCLI.cpp | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/docs/tth-commands.md b/docs/tth-commands.md index 1538dbc0..f26a3b5b 100644 --- a/docs/tth-commands.md +++ b/docs/tth-commands.md @@ -189,6 +189,7 @@ The ones that change what a node does; set in `platformio.ini` / | `FW_OTA` | `-ota` images | admin-pushed firmware update | | `PATH_HASH_MODE_DEFAULT` | `1` (2 B per hop) | path hash width for a node without prefs | | `ACL_TS_MAX_AHEAD` | `86400` (s) | a client timestamp further ahead of the node's clock is not stored as the replay floor | +| `LOCKED_NODE` | unset | a node that keeps its secrets from whoever holds it: `get prv.key`, `get guest.password` and `get bridge.secret` answer `Error: locked build` to everyone (USB and BLE console, an admin over the mesh); a companion serves only paired BLE (USB, UART and WiFi get the device info and nothing else) and its rescue CLI refuses `set pin`. Only half of it: [locked-bootloader.md](locked-bootloader.md) | | `LOGIN_FAIL_MAX`, `LOGIN_FAIL_SECS` | `4`, `180` (s) | after that many wrong passwords in the window no password is checked until it ends (an admin already in the ACL always gets in) | Prefs saved on the node override the build defaults: a reflash keeps what a diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 460455d8..89696029 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1070,6 +1070,16 @@ void MyMesh::startInterface(BaseSerialInterface &serial) { } void MyMesh::handleCmdFrame(size_t len) { +#ifdef LOCKED_NODE + // CUSTOM (TeTeHacko): a locked companion serves only paired BLE. USB, a UART + // and WiFi/TCP get the device info (so an app sees what it talks to) and + // nothing else: no contacts, channels, messages or settings for whoever holds + // the board or sits on the LAN. docs/locked-bootloader.md, point 4. + if (!_serial->isConnectionSecure() && cmd_frame[0] != CMD_DEVICE_QUERY) { + writeDisabledFrame(); + return; + } +#endif if (cmd_frame[0] == CMD_DEVICE_QUERY && len >= 2) { // sent when app establishes connection app_target_ver = cmd_frame[1]; // which version of protocol does app understand @@ -2492,6 +2502,11 @@ void MyMesh::checkCLIRescueCmd() { cli_command[len - 1] = 0; // replace newline with C string null terminator reply_buf[0] = 0; +#ifdef LOCKED_NODE + if (memcmp(cli_command, "set pin ", 8) == 0) { // CUSTOM (TeTeHacko): a known PIN = pair and read it all + Serial.println(" Error: locked build"); + } else +#endif if (handleCommand(cli_command, 0, reply_buf)) { // command was handled, print reply output Serial.print(" "); Serial.print(reply_buf); Serial.println(); diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 0fc110a0..5fed38ad 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -927,6 +927,16 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* reply) { const char* config = &command[4]; +#ifdef LOCKED_NODE + // CUSTOM (TeTeHacko): a locked node gives its secrets to nobody -- not to the + // USB console (no login: whoever holds the board), not to the BLE console, not + // to an admin over the mesh. docs/locked-bootloader.md, point 4. + if (memcmp(config, "prv.key", 7) == 0 || memcmp(config, "guest.password", 14) == 0 || + memcmp(config, "bridge.secret", 13) == 0) { + strcpy(reply, "Error: locked build"); + return; + } +#endif if (memcmp(config, "allow.read.only", 15) == 0) { sprintf(reply, "> %s", _prefs->allow_read_only ? "on" : "off"); } else if (memcmp(config, "flood.advert.interval", 21) == 0) {