Track shared-password logins in RAM, tighten eviction and passwords

Mark guest and read-only logins with a RAM-only flag instead of an ACL
permission bit, so saved permission bytes keep their meaning. Inserts
evict unsaved entries before saved ones. Sensors refuse GPS movement
deltas from shared-password subscribers and give promoted admins the
default alert flags. The admin, guest and read-only passwords must all
differ, and set ro.password with no value clears it.
This commit is contained in:
agessaman committed 2026-12-02 08:14:05 -08:00
1 parent c9322f5759
commit 3513ddfc01
7 files changed
+45 -27

No files matched your search

+17 -6
View File
@@ -111,6 +111,13 @@ static uint8_t copyTelemWithoutGPS(uint8_t* dest, const uint8_t* buf, uint8_t si
return n;
}
static bool hasGPSDelta(const uint8_t* deltas, uint8_t len) {
for (uint8_t i = 0; i + 2 < len; i += 2 + LPPData::getDataSize(deltas[i + 1])) {
if (deltas[i + 1] == LPP_GPS) return true;
}
return false;
}
static float findTelemValue(const uint8_t* buf, uint8_t size, uint8_t channel, uint8_t type, float def_value) {
uint8_t i = 0;
@@ -208,7 +215,7 @@ uint8_t SensorMesh::handleRequest(ClientInfo* from, uint32_t sender_timestamp, u
// query other sensors -- target specific
if ((perms & PERM_ACL_ROLE_MASK) == PERM_ACL_GUEST) {
perm_mask = 0x00; // just base telemetry allowed
} else if (!from->isAdmin() && (from->permissions & PERM_ACL_TRANSIENT)) {
} else if (from->shared_login) {
perm_mask &= ~TELEM_PERM_LOCATION; // shared read-only password, no location
}
sensors.querySensors(perm_mask, telemetry);
@@ -283,7 +290,8 @@ uint8_t SensorMesh::handleRequest(ClientInfo* from, uint32_t sender_timestamp, u
r = region_map.getDefaultRegion();
}
uint8_t reply_len;
if (r && min_deltas_len >= 3 && min_deltas_len <= sizeof(from->extra.sensor.min_deltas)) {
if (r && min_deltas_len >= 3 && min_deltas_len <= sizeof(from->extra.sensor.min_deltas)
&& !(from->shared_login && hasGPSDelta(&payload[8], min_deltas_len))) { // no movement alerts without location access
from->extra.sensor.scope_region_id = r->id;
from->extra.sensor.expiry_timestamp = getRTCClock()->getCurrentTime() + timeout_secs;
from->extra.sensor.min_deltas_len = min_deltas_len;
@@ -439,7 +447,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
if (strcmp((char *) data, _prefs.password) == 0) { // check for valid admin password
perms = PERM_ACL_ADMIN;
} else if (_prefs.ro_password[0] && strcmp((char *) data, _prefs.ro_password) == 0) { // check read-only password
perms = PERM_ACL_READ_ONLY | PERM_ACL_TRANSIENT;
perms = PERM_ACL_READ_ONLY;
} else if (_prefs.guest_password[0] && strcmp((char *) data, _prefs.guest_password) == 0) { // check guest password (blank = disabled)
perms = PERM_ACL_GUEST;
} else {
@@ -459,12 +467,15 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
bool saved = client->permissions != 0 && !client->shared_login;
if (!shared_pw) {
client->permissions &= ~PERM_ACL_TRANSIENT;
if (!saved) client->permissions |= PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO; // same defaults as a new admin
client->permissions |= PERM_ACL_ADMIN;
client->shared_login = false;
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
} else if (client->permissions == 0 || (client->permissions & PERM_ACL_TRANSIENT)) { // shared passwords don't change saved entries
} else if (!saved) { // shared passwords don't change saved entries
client->permissions = perms;
client->shared_login = true;
}
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
}
@@ -1133,7 +1144,7 @@ void SensorMesh::loop() {
memcpy(reply_data, &c->extra.sensor.push_tag, 4);
uint32_t timestamp = getRTCClock()->getCurrentTimeUnique();
memcpy(&reply_data[4], &timestamp, 4);
if (c->permissions & PERM_ACL_TRANSIENT) {
if (c->shared_login) {
tlen = copyTelemWithoutGPS(&reply_data[8], telemetry.getBuffer(), telemetry.getSize()); // shared read-only password, no location
} else {
tlen = telemetry.getSize();