Skip to content

Commit ddd1499

Browse files
jp-bennettthebenternCopilot
authored
More spoof remediation (#7612)
* More spoof remediation * Fix signed comparison error * Only fire self-bound messages into the routing module * Update src/mesh/MeshModule.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * String const --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e3dd816 commit ddd1499

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

src/mesh/MeshModule.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ meshtastic_MeshPacket *MeshModule::allocErrorResponse(meshtastic_Routing_Error e
8585
return r;
8686
}
8787

88-
void MeshModule::callModules(meshtastic_MeshPacket &mp, RxSource src)
88+
void MeshModule::callModules(meshtastic_MeshPacket &mp, RxSource src, const char *specificModule)
8989
{
90+
if (specificModule) {
91+
LOG_DEBUG("Calling specific module: %s", specificModule);
92+
}
9093
// LOG_DEBUG("In call modules");
9194
bool moduleFound = false;
9295

@@ -104,6 +107,11 @@ void MeshModule::callModules(meshtastic_MeshPacket &mp, RxSource src)
104107
for (auto i = modules->begin(); i != modules->end(); ++i) {
105108
auto &pi = **i;
106109

110+
// If specificModule is provided, only call that specific module
111+
if (specificModule && (!pi.name || strcmp(pi.name, specificModule) != 0)) {
112+
continue;
113+
}
114+
107115
pi.currentRequest = &mp;
108116

109117
/// We only call modules that are interested in the packet (and the message is destined to us or we are promiscious)

src/mesh/MeshModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MeshModule
7373

7474
/** For use only by MeshService
7575
*/
76-
static void callModules(meshtastic_MeshPacket &mp, RxSource src = RX_SRC_RADIO);
76+
static void callModules(meshtastic_MeshPacket &mp, RxSource src = RX_SRC_RADIO, const char *specificModule = nullptr);
7777

7878
static std::vector<MeshModule *> GetMeshModulesWithUIFrames(int startIndex);
7979
static void observeUIEvents(Observer<const UIFrameEvent *> *observer);

src/mesh/NodeDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ bool NodeDB::checkLowEntropyPublicKey(const meshtastic_Config_SecurityConfig_pub
18671867
uint8_t keyHash[32] = {0};
18681868
memcpy(keyHash, keyToTest.bytes, keyToTest.size);
18691869
crypto->hash(keyHash, 32);
1870-
for (int i = 0; i < sizeof(LOW_ENTROPY_HASHES) / sizeof(LOW_ENTROPY_HASHES[0]); i++) {
1870+
for (uint16_t i = 0; i < sizeof(LOW_ENTROPY_HASHES) / sizeof(LOW_ENTROPY_HASHES[0]); i++) {
18711871
if (memcmp(keyHash, LOW_ENTROPY_HASHES[i], sizeof(LOW_ENTROPY_HASHES[0])) == 0) {
18721872
return true;
18731873
}

src/mesh/Router.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
653653
}
654654

655655
// call modules here
656-
if (!skipHandle) {
656+
// If this could be a spoofed packet, don't let the modules see it.
657+
if (!skipHandle && p->from != nodeDB->getNodeNum()) {
657658
MeshModule::callModules(*p, src);
658659

659660
#if !MESHTASTIC_EXCLUDE_MQTT
@@ -667,6 +668,8 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
667668
!isFromUs(p) && mqtt)
668669
mqtt->onSend(*p_encrypted, *p, p->channel);
669670
#endif
671+
} else if (p->from == nodeDB->getNodeNum() && !skipHandle) {
672+
MeshModule::callModules(*p, src, ROUTING_MODULE);
670673
}
671674

672675
packetPool.release(p_encrypted); // Release the encrypted packet

src/modules/RoutingModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ uint8_t RoutingModule::getHopLimitForResponse(uint8_t hopStart, uint8_t hopLimit
7373
return Default::getConfiguredOrDefaultHopLimit(config.lora.hop_limit); // Use the default hop limit
7474
}
7575

76-
RoutingModule::RoutingModule() : ProtobufModule("routing", meshtastic_PortNum_ROUTING_APP, &meshtastic_Routing_msg)
76+
RoutingModule::RoutingModule() : ProtobufModule(ROUTING_MODULE, meshtastic_PortNum_ROUTING_APP, &meshtastic_Routing_msg)
7777
{
7878
isPromiscuous = true;
7979

src/modules/RoutingModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "Channels.h"
33
#include "ProtobufModule.h"
44

5+
static const char *ROUTING_MODULE = "routing";
6+
57
/**
68
* Routing module for router control messages
79
*/

0 commit comments

Comments
 (0)