* 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

+10 -3
View File
@@ -1,6 +1,7 @@
#include "MyMesh.h"
#include <algorithm>
#include <helpers/sensors/LPPDataHelpers.h>
#include <helpers/UTF8Helpers.h>
/* ------------------------------ Config -------------------------------- */
@@ -131,7 +132,6 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
client->last_activity = getRTCClock()->getCurrentTime();
client->permissions &= ~0x03;
client->permissions |= perms;
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
@@ -140,6 +140,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
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
@@ -794,11 +795,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
uint32_t timestamp;
memcpy(&timestamp, data, 4);
if (timestamp > client->last_timestamp) { // prevent replay attacks
if (timestamp > client->last_req_timestamp) { // prevent replay attacks
int reply_len = handleRequest(client, timestamp, &data[4], len - 4);
if (reply_len == 0) return; // invalid command
client->last_timestamp = timestamp;
client->last_req_timestamp = timestamp;
client->last_activity = getRTCClock()->getCurrentTime();
if (packet->isRouteFlood()) {
@@ -827,6 +828,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND)) {
MESH_DEBUG_PRINTLN("onPeerDataRecv: unsupported text type received: flags=%02x", (uint32_t)flags);
} else if (!mesh::isValidUtf8TextAndPadding(&data[5], len - 5)) {
MESH_DEBUG_PRINTLN("onPeerDataRecv: invalid text payload! (id prefix: %02X:%02X)", client->id.pub_key[0], client->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 >= client->last_timestamp) { // prevent replay attacks
bool is_retry = (sender_timestamp == client->last_timestamp);
client->last_timestamp = sender_timestamp;
@@ -869,6 +875,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
}
memcpy(temp, &timestamp, 4); // mostly an extra blob to help make packet_hash unique
temp[4] = (TXT_TYPE_CLI_DATA << 2); // NOTE: legacy was: TXT_TYPE_PLAIN
_reply_echo.note(temp, 5 + text_len);
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
if (reply) {