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:
1 parent
84f6fa03b2
commit
de92ca9ba2
5 files changed
+26
-13
No files matched your search
@@ -379,13 +379,12 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
|
|||||||
MESH_DEBUG_PRINTLN("Possible login replay attack!");
|
MESH_DEBUG_PRINTLN("Possible login replay attack!");
|
||||||
return 0; // FATAL: client table is full -OR- 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!");
|
MESH_DEBUG_PRINTLN("Login success!");
|
||||||
client->last_timestamp = sender_timestamp;
|
client->last_timestamp = sender_timestamp;
|
||||||
client->last_activity = getRTCClock()->getCurrentTime();
|
client->last_activity = getRTCClock()->getCurrentTime();
|
||||||
client->permissions &= ~0x03;
|
client->permissions &= ~0x03;
|
||||||
client->permissions |= perms;
|
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);
|
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
|
||||||
|
|
||||||
if (perms != PERM_ACL_GUEST) { // keep number of FS writes to a minimum
|
if (perms != PERM_ACL_GUEST) { // keep number of FS writes to a minimum
|
||||||
|
|||||||
@@ -372,8 +372,6 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
|||||||
MESH_DEBUG_PRINTLN("possible replay attack!");
|
MESH_DEBUG_PRINTLN("possible replay attack!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
|
|
||||||
|
|
||||||
MESH_DEBUG_PRINTLN("Login success!");
|
MESH_DEBUG_PRINTLN("Login success!");
|
||||||
client->last_timestamp = sender_timestamp;
|
client->last_timestamp = sender_timestamp;
|
||||||
client->extra.room.sync_since = sender_sync_since;
|
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->last_activity = getRTCClock()->getCurrentTime();
|
||||||
client->permissions &= ~0x03;
|
client->permissions &= ~0x03;
|
||||||
client->permissions |= perm;
|
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);
|
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
|
||||||
|
|
||||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||||
|
|||||||
@@ -387,12 +387,11 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
|
|||||||
MESH_DEBUG_PRINTLN("Possible login replay attack!");
|
MESH_DEBUG_PRINTLN("Possible login replay attack!");
|
||||||
return 0; // FATAL: client table is full -OR- 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!");
|
MESH_DEBUG_PRINTLN("Login success!");
|
||||||
client->last_timestamp = sender_timestamp;
|
client->last_timestamp = sender_timestamp;
|
||||||
client->last_activity = getRTCClock()->getCurrentTime();
|
client->last_activity = getRTCClock()->getCurrentTime();
|
||||||
client->permissions |= PERM_ACL_ADMIN;
|
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);
|
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
|
||||||
|
|
||||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||||
|
|||||||
@@ -160,6 +160,11 @@ void ClientACL::orphanTimestamp(const ClientInfo* c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClientACL::persistTimestamp(ClientInfo* c, uint32_t sender_timestamp, uint32_t now) {
|
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 <= c->saved_timestamp) return; // retry, or nothing new
|
||||||
if (sender_timestamp > now + ACL_TS_MAX_AHEAD) return; // runaway sender clock
|
if (sender_timestamp > now + ACL_TS_MAX_AHEAD) return; // runaway sender clock
|
||||||
c->saved_timestamp = sender_timestamp;
|
c->saved_timestamp = sender_timestamp;
|
||||||
|
|||||||
@@ -109,17 +109,28 @@ TEST(AclReplayFloor, FloorsOutliveAclClear) {
|
|||||||
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(3), 0), NOW - 50));
|
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(3), 0), NOW - 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AclReplayFloor, EvictedClientKeepsItsFloor) {
|
TEST(AclReplayFloor, GuestTrafficWritesNothing) {
|
||||||
Node n;
|
Node n;
|
||||||
ClientInfo* g = n.acl->putClient(idFor(4), 0);
|
ClientInfo* g = n.acl->putClient(idFor(4), 0);
|
||||||
g->last_activity = 1; // least active -> evicted first
|
g->permissions = PERM_ACL_GUEST; // anybody, with the default empty guest password
|
||||||
ASSERT_TRUE(n.accept(g, NOW - 70));
|
int writes = n.fs.writes;
|
||||||
for (int i = 0; i < MAX_CLIENTS; i++) {
|
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);
|
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);
|
n.boot();
|
||||||
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(4), 0), NOW - 70));
|
EXPECT_FALSE(n.accept(n.acl->putClient(idFor(3), 0), NOW - 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AclReplayFloor, TornWriteFallsBackToTheOtherSlot) {
|
TEST(AclReplayFloor, TornWriteFallsBackToTheOtherSlot) {
|
||||||
|
|||||||
Reference in new issue
Block a user