fix(companion): gate private-key export and factory-reset on WiFi builds#2527
Open
swaits wants to merge 1 commit into
Open
fix(companion): gate private-key export and factory-reset on WiFi builds#2527swaits wants to merge 1 commit into
swaits wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
On
companion_radiobuilds compiled withWIFI_SSID, the host frame-protocol surface is exposed over plain TCP port 5000 with no authentication. Anyone on the same WiFi network can issue any of the ~60CMD_*codes, includingCMD_EXPORT_PRIVATE_KEY(cmd 23),CMD_IMPORT_PRIVATE_KEY(cmd 24), andCMD_FACTORY_RESET(cmd 51). This change disables those three commands by default onWIFI_SSIDbuilds and gates them behind a new opt-in build flagALLOW_UNAUTHENTICATED_TCP_PRIVATE_KEY. Serial and BLE builds are unchanged (serial is local-only; BLE uses PIN-bonded characteristics).Background
The TCP frame protocol lives in
src/helpers/esp32/SerialWifiInterface.cpp.checkRecvFrame()accepts a TCPaccept(), reads a 3-byte header + body, and dispatches the body toMyMesh::handleCmdFrame(). There is no handshake / PIN / nonce / challenge at the framework or application layer.The most damaging unauth capabilities:
CMD_EXPORT_PRIVATE_KEY(examples/companion_radio/MyMesh.cpp) — writes the 64-byte Ed25519 private key to the TCP socket.CMD_IMPORT_PRIVATE_KEY(examples/companion_radio/MyMesh.cpp) — overwrites the device identity with attacker-supplied keypair.CMD_FACTORY_RESET(examples/companion_radio/MyMesh.cpp) — formats the FS and reboots.The base
platformio.inienablesENABLE_PRIVATE_KEY_EXPORT=1andENABLE_PRIVATE_KEY_IMPORT=1by default with a comment "NOTE: comment these out for more secure firmware", but in practice every shipped variant has them on, and the flags aren't aware that WiFi changes the trust model.PoC against an unpatched build:
Change
examples/companion_radio/MyMesh.cpponly — three command handlers gain a compile-time guard:#if ENABLE_PRIVATE_KEY_EXPORT && (!defined(WIFI_SSID) || defined(ALLOW_UNAUTHENTICATED_TCP_PRIVATE_KEY))(and the same for the IMPORT path and FACTORY_RESET, which gets a new
#if/#else writeDisabledFrame();#endifblock).When the guard fails, the handler responds with the existing
RESP_CODE_DISABLEDframe, matching the pre-existing "command disabled at build time" pattern.Why this is the minimal fix
The proper long-term fix is an out-of-band PIN handshake on the TCP socket — re-using the BLE PIN mechanism — so that no command works until the client authenticates. That requires host-app changes and a new wire-protocol message; it's a larger coordinated release.
This patch is the minimum-viable defense: remove the three most-dangerous capabilities from the unauthenticated TCP surface, leave the rest. Even after this lands, an attacker on the LAN can still observe traffic and issue benign commands; the PIN handshake remains worth doing. We don't change
platformio.inidefaults — the existingENABLE_PRIVATE_KEY_*flags continue to mean what they meant, just composed with the WiFi gate.Risk / compatibility
RESP_CODE_DISABLED, which is already in the protocol and is what they see when the feature is built-out.-D ALLOW_UNAUTHENTICATED_TCP_PRIVATE_KEY=1at build time. The flag name is intentionally accusatory.References