mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 01:32:40 +00:00
Clear out user.id except for sending to phone (#8202)
* Null out user.id except for sending to phone * Fix * Update src/modules/NodeInfoModule.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Copilot garbage * This is unnecessary, because we don't stored user.id on userlite * Don't need this * Fix warning * Just alter the protobuf * Alter protobuf doesn't do anything with the altered data, so let's re-encode it * Check inputbroker before access --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1601,6 +1601,7 @@ void loop()
|
|||||||
|
|
||||||
service->loop();
|
service->loop();
|
||||||
#if !MESHTASTIC_EXCLUDE_INPUTBROKER && defined(HAS_FREE_RTOS)
|
#if !MESHTASTIC_EXCLUDE_INPUTBROKER && defined(HAS_FREE_RTOS)
|
||||||
|
if (inputBroker)
|
||||||
inputBroker->processInputEventQueue();
|
inputBroker->processInputEventQueue();
|
||||||
#endif
|
#endif
|
||||||
#if defined(LGFX_SDL)
|
#if defined(LGFX_SDL)
|
||||||
|
|||||||
@@ -56,10 +56,6 @@
|
|||||||
#include <WiFiOTA.h>
|
#include <WiFiOTA.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// stringify
|
|
||||||
#define xstr(s) str(s)
|
|
||||||
#define str(s) #s
|
|
||||||
|
|
||||||
NodeDB *nodeDB = nullptr;
|
NodeDB *nodeDB = nullptr;
|
||||||
|
|
||||||
// we have plenty of ram so statically alloc this tempbuf (for now)
|
// we have plenty of ram so statically alloc this tempbuf (for now)
|
||||||
@@ -260,6 +256,8 @@ NodeDB::NodeDB()
|
|||||||
owner.role = config.device.role;
|
owner.role = config.device.role;
|
||||||
// Ensure macaddr is set to our macaddr as it will be copied in our info below
|
// Ensure macaddr is set to our macaddr as it will be copied in our info below
|
||||||
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
|
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
|
||||||
|
// Ensure owner.id is always derived from the node number
|
||||||
|
snprintf(owner.id, sizeof(owner.id), "!%08x", getNodeNum());
|
||||||
|
|
||||||
if (!config.has_security) {
|
if (!config.has_security) {
|
||||||
config.has_security = true;
|
config.has_security = true;
|
||||||
@@ -1695,6 +1693,9 @@ bool NodeDB::updateUser(uint32_t nodeId, meshtastic_User &p, uint8_t channelInde
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Always ensure user.id is derived from nodeId, regardless of what was received
|
||||||
|
snprintf(p.id, sizeof(p.id), "!%08x", nodeId);
|
||||||
|
|
||||||
// Both of info->user and p start as filled with zero so I think this is okay
|
// Both of info->user and p start as filled with zero so I think this is okay
|
||||||
auto lite = TypeConversions::ConvertToUserLite(p);
|
auto lite = TypeConversions::ConvertToUserLite(p);
|
||||||
bool changed = memcmp(&info->user, &lite, sizeof(info->user)) || (info->channel != channelIndex);
|
bool changed = memcmp(&info->user, &lite, sizeof(info->user)) || (info->channel != channelIndex);
|
||||||
|
|||||||
@@ -554,10 +554,8 @@ void AdminModule::handleSetOwner(const meshtastic_User &o)
|
|||||||
changed |= strcmp(owner.short_name, o.short_name);
|
changed |= strcmp(owner.short_name, o.short_name);
|
||||||
strncpy(owner.short_name, o.short_name, sizeof(owner.short_name));
|
strncpy(owner.short_name, o.short_name, sizeof(owner.short_name));
|
||||||
}
|
}
|
||||||
if (*o.id) {
|
snprintf(owner.id, sizeof(owner.id), "!%08x", nodeDB->getNodeNum());
|
||||||
changed |= strcmp(owner.id, o.id);
|
|
||||||
strncpy(owner.id, o.id, sizeof(owner.id));
|
|
||||||
}
|
|
||||||
if (owner.is_licensed != o.is_licensed) {
|
if (owner.is_licensed != o.is_licensed) {
|
||||||
changed = 1;
|
changed = 1;
|
||||||
owner.is_licensed = o.is_licensed;
|
owner.is_licensed = o.is_licensed;
|
||||||
|
|||||||
@@ -30,14 +30,32 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
|||||||
|
|
||||||
bool wasBroadcast = isBroadcast(mp.to);
|
bool wasBroadcast = isBroadcast(mp.to);
|
||||||
|
|
||||||
|
// LOG_DEBUG("did encode");
|
||||||
// if user has changed while packet was not for us, inform phone
|
// if user has changed while packet was not for us, inform phone
|
||||||
if (hasChanged && !wasBroadcast && !isToUs(&mp))
|
if (hasChanged && !wasBroadcast && !isToUs(&mp)) {
|
||||||
service->sendToPhone(packetPool.allocCopy(mp));
|
auto packetCopy = packetPool.allocCopy(mp); // Keep a copy of the packet for later analysis
|
||||||
|
|
||||||
|
// Re-encode the user protobuf, as we have stripped out the user.id
|
||||||
|
packetCopy->decoded.payload.size = pb_encode_to_bytes(
|
||||||
|
packetCopy->decoded.payload.bytes, sizeof(packetCopy->decoded.payload.bytes), &meshtastic_User_msg, &p);
|
||||||
|
|
||||||
|
service->sendToPhone(packetCopy);
|
||||||
|
}
|
||||||
|
|
||||||
// LOG_DEBUG("did handleReceived");
|
// LOG_DEBUG("did handleReceived");
|
||||||
return false; // Let others look at this message also if they want
|
return false; // Let others look at this message also if they want
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeInfoModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic_User *p)
|
||||||
|
{
|
||||||
|
// Coerce user.id to be derived from the node number
|
||||||
|
snprintf(p->id, sizeof(p->id), "!%08x", getFrom(&mp));
|
||||||
|
|
||||||
|
// Re-encode the altered protobuf back into the packet
|
||||||
|
mp.decoded.payload.size =
|
||||||
|
pb_encode_to_bytes(mp.decoded.payload.bytes, sizeof(mp.decoded.payload.bytes), &meshtastic_User_msg, p);
|
||||||
|
}
|
||||||
|
|
||||||
void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t channel, bool _shorterTimeout)
|
void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t channel, bool _shorterTimeout)
|
||||||
{
|
{
|
||||||
// cancel any not yet sent (now stale) position packets
|
// cancel any not yet sent (now stale) position packets
|
||||||
@@ -95,6 +113,8 @@ meshtastic_MeshPacket *NodeInfoModule::allocReply()
|
|||||||
u.public_key.size = 0;
|
u.public_key.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the user.id field since it should be derived from node number on the receiving end
|
||||||
|
u.id[0] = '\0';
|
||||||
LOG_INFO("Send owner %s/%s/%s", u.id, u.long_name, u.short_name);
|
LOG_INFO("Send owner %s/%s/%s", u.id, u.long_name, u.short_name);
|
||||||
lastSentToMesh = millis();
|
lastSentToMesh = millis();
|
||||||
return allocDataProtobuf(u);
|
return allocDataProtobuf(u);
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ class NodeInfoModule : public ProtobufModule<meshtastic_User>, private concurren
|
|||||||
*/
|
*/
|
||||||
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_User *p) override;
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_User *p) override;
|
||||||
|
|
||||||
|
/** Called to alter received User protobuf */
|
||||||
|
virtual void alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic_User *p) override;
|
||||||
|
|
||||||
/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
|
/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
|
||||||
* so that subclasses can (optionally) send a response back to the original sender. */
|
* so that subclasses can (optionally) send a response back to the original sender. */
|
||||||
virtual meshtastic_MeshPacket *allocReply() override;
|
virtual meshtastic_MeshPacket *allocReply() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user