* sec patch

This commit is contained in:
Scott Powell committed 2026-11-29 16:06:00 +11:00
1 parent 8603065de7
commit c2036b9502
11 files changed
+124 -9

No files matched your search

+9 -2
View File
@@ -1,6 +1,7 @@
#include "SensorMesh.h"
#include <helpers/RoutingPolicy.h>
#include <helpers/sensors/LPPDataHelpers.h>
#include <helpers/UTF8Helpers.h>
/* ------------------------------ Config -------------------------------- */
@@ -430,12 +431,12 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
client->last_activity = getRTCClock()->getCurrentTime();
client->permissions |= PERM_ACL_ADMIN;
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
}
client->last_activity = getRTCClock()->getCurrentTime();
if (is_flood) {
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
@@ -684,7 +685,12 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
memcpy(&sender_timestamp, data, 4); // timestamp (by sender's RTC clock - which could be wrong)
uint8_t flags = (data[4] >> 2); // message attempt number, and other flags
if (sender_timestamp > from->last_timestamp) { // prevent replay attacks
if (!mesh::isValidUtf8TextAndPadding(&data[5], len - 5)) {
MESH_DEBUG_PRINTLN("onPeerDataRecv: invalid text payload! (id prefix: %02X:%02X)", from->id.pub_key[0], from->id.pub_key[1]);
_err_flags |= ERR_EVENT_DIAG1; // report in next Get Stats
} else if (_reply_echo.matches(data, 5 + strnlen((const char *)&data[5], len - 5))) {
MESH_DEBUG_PRINTLN("onPeerDataRecv: text is our own CLI reply");
} else if (sender_timestamp > from->last_timestamp) { // prevent replay attacks
if (flags == TXT_TYPE_PLAIN) {
bool handled = handleIncomingMsg(*from, sender_timestamp, &data[5], flags, len - 5);
if (handled) { // if msg was handled then send an ack
@@ -722,6 +728,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
}
memcpy(temp, &timestamp, 4); // mostly an extra blob to help make packet_hash unique
temp[4] = (TXT_TYPE_CLI_DATA << 2);
_reply_echo.note(temp, 5 + text_len);
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, from->id, secret, temp, 5 + text_len);
if (reply) {
+2
View File
@@ -22,6 +22,7 @@
#include <helpers/CommonCLI.h>
#include <helpers/StatsFormatHelper.h>
#include <helpers/ClientACL.h>
#include <helpers/ReplyEchoGuard.h>
#include <helpers/RegionMap.h>
#include <RTClib.h>
#include <target.h>
@@ -142,6 +143,7 @@ private:
unsigned long next_local_advert, next_flood_advert;
NodePrefs _prefs;
ClientACL acl;
ReplyEchoGuard _reply_echo;
CommonCLI _cli;
uint8_t reply_data[MAX_PACKET_PAYLOAD];
unsigned long dirty_contacts_expiry;