Repeater, room server, sensor: guests no longer cause a flash write per request

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-18 12:57:53 +01:00
1 parent 84f6fa03b2
commit de92ca9ba2
5 files changed
+26 -13

No files matched your search

+1 -2
View File
@@ -379,13 +379,12 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
MESH_DEBUG_PRINTLN("Possible login replay attack!");
return 0; // FATAL: client table is full -OR- replay attack
}
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
client->last_activity = getRTCClock()->getCurrentTime();
client->permissions &= ~0x03;
client->permissions |= perms;
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): admin only, so after the role
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
if (perms != PERM_ACL_GUEST) { // keep number of FS writes to a minimum
+1 -2
View File
@@ -372,8 +372,6 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
MESH_DEBUG_PRINTLN("possible replay attack!");
return;
}
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
client->extra.room.sync_since = sender_sync_since;
@@ -383,6 +381,7 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
client->last_activity = getRTCClock()->getCurrentTime();
client->permissions &= ~0x03;
client->permissions |= perm;
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): admin only, so after the role
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
+1 -2
View File
@@ -387,12 +387,11 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
MESH_DEBUG_PRINTLN("Possible login replay attack!");
return 0; // FATAL: client table is full -OR- replay attack
}
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
client->last_activity = getRTCClock()->getCurrentTime();
client->permissions |= PERM_ACL_ADMIN;
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): admin only, so after the role
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
+5
View File
@@ -160,6 +160,11 @@ void ClientACL::orphanTimestamp(const ClientInfo* c) {
}
void ClientACL::persistTimestamp(ClientInfo* c, uint32_t sender_timestamp, uint32_t now) {
// Admins only. A guest can only read, and anybody gets in as one when the
// guest password is empty (the default): its every request would be a flash
// write, and its floors would push the admins' out of the orphan list. Its
// floor stays in RAM, as upstream.
if (!c->isAdmin()) return;
if (sender_timestamp <= c->saved_timestamp) return; // retry, or nothing new
if (sender_timestamp > now + ACL_TS_MAX_AHEAD) return; // runaway sender clock
c->saved_timestamp = sender_timestamp;
@@ -109,17 +109,28 @@ TEST(AclReplayFloor, FloorsOutliveAclClear) {
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(3), 0), NOW - 50));
}
TEST(AclReplayFloor, EvictedClientKeepsItsFloor) {
TEST(AclReplayFloor, GuestTrafficWritesNothing) {
Node n;
ClientInfo* g = n.acl->putClient(idFor(4), 0);
g->last_activity = 1; // least active -> evicted first
ASSERT_TRUE(n.accept(g, NOW - 70));
for (int i = 0; i < MAX_CLIENTS; i++) {
g->permissions = PERM_ACL_GUEST; // anybody, with the default empty guest password
int writes = n.fs.writes;
for (uint32_t i = 0; i < 1000; i++) ASSERT_TRUE(n.accept(g, NOW - 1000 + i));
EXPECT_EQ(n.fs.writes, writes);
}
TEST(AclReplayFloor, GuestsDoNotPushOutAdminFloors) {
Node n;
ASSERT_TRUE(n.accept(n.admin(3), NOW - 50));
n.acl->save(&n.fs);
n.acl->clear(); // the admin's floor is an orphan now
for (int i = 0; i < 4 * MAX_CLIENTS; i++) { // a flood of fresh guest identities
ClientInfo* c = n.acl->putClient(idFor(100 + i), 0);
c->last_activity = 1000 + i;
c->permissions = PERM_ACL_GUEST;
c->last_activity = i;
n.accept(c, NOW - 10);
}
ASSERT_EQ(n.acl->getClient(idFor(4).pub_key, PUB_KEY_SIZE), nullptr);
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(4), 0), NOW - 70));
n.boot();
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(3), 0), NOW - 50));
}
TEST(AclReplayFloor, TornWriteFallsBackToTheOtherSlot) {