Companion: the private key and the BLE PIN are again refused over USB, UART and WiFi -- only paired BLE gets them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-19 17:09:12 +01:00
1 parent cac3249e41
commit 769139999d
5 files changed
+173 -10

No files matched your search

+32 -2
View File
@@ -26,6 +26,7 @@ private:
bool _enabled = false;
RegisteredInterface _interfaces[MAX_INTERFACES] = {};
int _last_rx = -1; // CUSTOM (TeTeHacko): slot of the most recent frame's transport
public:
bool addInterface(InterfaceType type, BaseSerialInterface* iface) {
@@ -57,6 +58,7 @@ public:
for(int i = 0; i < MAX_INTERFACES; i++){
if(_interfaces[i].instance == iface){
_interfaces[i] = {};
if (_last_rx == i) _last_rx = -1;
return true;
}
}
@@ -184,11 +186,13 @@ public:
}
// try to read a frame from any enabled interface
for(auto iface : _interfaces){
for(int i = 0; i < MAX_INTERFACES; i++){
auto& iface = _interfaces[i];
if(iface.instance && iface.instance->isEnabled()){
size_t frameSize = iface.instance->checkRecvFrame(dest);
if(frameSize > 0){
return frameSize;
_last_rx = i;
return frameSize;
}
}
}
@@ -197,4 +201,30 @@ public:
return 0;
}
// CUSTOM (TeTeHacko): only a frame that came over (MITM-paired) Bluetooth is
// authenticated. USB, a hardware UART, WiFi and Ethernet carry no pairing, so
// the companion's key-export / PIN gates (89eb71ab) refuse them. Without this
// override the base class answered `true` for everything: the gates written
// for SerialDualInterface went dead when the v1.17 merge replaced it with
// this class, and USB could export the key and read or set the BLE PIN.
// A build with no Bluetooth (USB-only companion) has nothing to pair over, so
// its one transport stays trusted, as BaseSerialInterface defines it.
bool isConnectionSecure() const override {
bool has_ble = false;
for (const auto& iface : _interfaces) {
if (iface.instance && iface.type == InterfaceType::Bluetooth) has_ble = true;
}
if (!has_ble) return true;
if (_last_rx < 0) return false;
const auto& iface = _interfaces[_last_rx];
return iface.instance && iface.type == InterfaceType::Bluetooth && iface.instance->isConnectionSecure();
}
size_t writeReplyFrame(const uint8_t src[], size_t len) override {
if (!_enabled || len == 0 || _last_rx < 0) return 0;
auto* iface = _interfaces[_last_rx].instance;
if (!iface || !iface->isEnabled()) return 0;
return iface->writeFrame(src, len);
}
};