Only accept PKI messages for MQTT downlink if we know transmitter and receiver (#4498)

This commit is contained in:
GUVWAF 2024-08-18 19:15:50 +02:00 committed by GitHub
parent 7a65c8838d
commit a85df199a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -164,10 +164,14 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
// PKI messages get accepted even if we can't decrypt
if (router && p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag &&
strcmp(e.channel_id, "PKI") == 0)
router->enqueueReceivedMessage(p);
// ignore messages if we don't have the channel key
else if (router && perhapsDecode(p))
strcmp(e.channel_id, "PKI") == 0) {
meshtastic_NodeInfoLite *tx = nodeDB->getMeshNode(getFrom(p));
meshtastic_NodeInfoLite *rx = nodeDB->getMeshNode(p->to);
// Only accept PKI messages if we have both the sender and receiver in our nodeDB, as then it's likely
// they discovered each other via a channel we have downlink enabled for
if (tx && tx->has_user && rx && rx->has_user)
router->enqueueReceivedMessage(p);
} else if (router && perhapsDecode(p)) // ignore messages if we don't have the channel key
router->enqueueReceivedMessage(p);
else
packetPool.release(p);