@@ -243,7 +243,7 @@ static uint8_t putFloat(uint8_t * dest, float value, uint8_t size, uint32_t mult
243243uint8_t SensorMesh::handleRequest (uint8_t perms, uint32_t sender_timestamp, uint8_t req_type, uint8_t * payload, size_t payload_len) {
244244 memcpy (reply_data, &sender_timestamp, 4 ); // reflect sender_timestamp back in response packet (kind of like a 'tag')
245245
246- if (req_type == REQ_TYPE_GET_TELEMETRY_DATA && (perms & PERM_GET_TELEMETRY) != 0 ) {
246+ if (req_type == REQ_TYPE_GET_TELEMETRY_DATA) { // allow all
247247 telemetry.reset ();
248248 telemetry.addVoltage (TELEM_CHANNEL_SELF, (float )board.getBattMilliVolts () / 1000 .0f );
249249 // query other sensors -- target specific
@@ -254,7 +254,7 @@ uint8_t SensorMesh::handleRequest(uint8_t perms, uint32_t sender_timestamp, uint
254254 memcpy (&reply_data[4 ], telemetry.getBuffer (), tlen);
255255 return 4 + tlen; // reply_len
256256 }
257- if (req_type == REQ_TYPE_GET_AVG_MIN_MAX && (perms & PERM_GET_OTHER_STATS) != 0 ) {
257+ if (req_type == REQ_TYPE_GET_AVG_MIN_MAX && (perms & PERM_ACL_ROLE_MASK) >= PERM_ACL_READ_ONLY ) {
258258 uint32_t start_secs_ago, end_secs_ago;
259259 memcpy (&start_secs_ago, &payload[0 ], 4 );
260260 memcpy (&end_secs_ago, &payload[4 ], 4 );
@@ -288,13 +288,14 @@ uint8_t SensorMesh::handleRequest(uint8_t perms, uint32_t sender_timestamp, uint
288288 }
289289 return ofs;
290290 }
291- if (req_type == REQ_TYPE_GET_ACCESS_LIST && (perms & PERM_ACL_ROLE_MASK) == PERM_ACL_LEVEL3 ) {
291+ if (req_type == REQ_TYPE_GET_ACCESS_LIST && (perms & PERM_ACL_ROLE_MASK) == PERM_ACL_ADMIN ) {
292292 uint8_t res1 = payload[0 ]; // reserved for future (extra query params)
293293 uint8_t res2 = payload[1 ];
294294 if (res1 == 0 && res2 == 0 ) {
295295 uint8_t ofs = 4 ;
296296 for (int i = 0 ; i < num_contacts && ofs + 7 <= sizeof (reply_data) - 4 ; i++) {
297297 auto c = &contacts[i];
298+ if (c->permissions == 0 ) continue ; // skip deleted entries
298299 memcpy (&reply_data[ofs], c->id .pub_key , 6 ); ofs += 6 ; // just 6-byte pub_key prefix
299300 reply_data[ofs++] = c->permissions ;
300301 }
@@ -315,7 +316,7 @@ mesh::Packet* SensorMesh::createSelfAdvert() {
315316 return createAdvert (self_id, app_data, app_data_len);
316317}
317318
318- ContactInfo* SensorMesh::putContact (const mesh::Identity& id) {
319+ ContactInfo* SensorMesh::putContact (const mesh::Identity& id, uint8_t init_perms ) {
319320 uint32_t min_time = 0xFFFFFFFF ;
320321 ContactInfo* oldest = &contacts[MAX_CONTACTS - 1 ];
321322 for (int i = 0 ; i < num_contacts; i++) {
@@ -333,14 +334,15 @@ ContactInfo* SensorMesh::putContact(const mesh::Identity& id) {
333334 c = oldest; // evict least active contact
334335 }
335336 memset (c, 0 , sizeof (*c));
337+ c->permissions = init_perms;
336338 c->id = id;
337339 c->out_path_len = -1 ; // initially out_path is unknown
338340 return c;
339341}
340342
341343void SensorMesh::applyContactPermissions (const uint8_t * pubkey, uint8_t perms) {
342344 mesh::Identity id (pubkey);
343- auto c = putContact (id);
345+ auto c = putContact (id, 0 );
344346
345347 if ((perms & PERM_ACL_ROLE_MASK) == PERM_ACL_GUEST) { // guest role is not persisted in contacts
346348 memset (c, 0 , sizeof (*c));
@@ -441,7 +443,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
441443 return 0 ;
442444 }
443445
444- auto client = putContact (sender); // add to contacts (if not already known)
446+ auto client = putContact (sender, PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO ); // add to contacts (if not already known)
445447 if (sender_timestamp <= client->last_timestamp ) {
446448 MESH_DEBUG_PRINTLN (" Possible login replay attack!" );
447449 return 0 ; // FATAL: client table is full -OR- replay attack
@@ -450,7 +452,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
450452 MESH_DEBUG_PRINTLN (" Login success!" );
451453 client->last_timestamp = sender_timestamp;
452454 client->last_activity = getRTCClock ()->getCurrentTime ();
453- client->permissions = PERM_ACL_LEVEL3 | PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO; // initially opt-in to receive alerts (can opt out)
455+ client->permissions |= PERM_ACL_ADMIN;
454456 memcpy (client->shared_secret , secret, PUB_KEY_SIZE);
455457
456458 dirty_contacts_expiry = futureMillis (LAZY_CONTACTS_WRITE_DELAY);
@@ -502,6 +504,7 @@ void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* r
502504 Serial.println (" ACL:" );
503505 for (int i = 0 ; i < num_contacts; i++) {
504506 auto c = &contacts[i];
507+ if (c->permissions == 0 ) continue ; // skip deleted entries
505508
506509 Serial.printf (" %02X " , c->permissions );
507510 mesh::Utils::printHex (Serial, c->id .pub_key , PUB_KEY_SIZE);
@@ -569,7 +572,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
569572 memcpy (×tamp, data, 4 );
570573
571574 if (timestamp > from.last_timestamp ) { // prevent replay attacks
572- uint8_t reply_len = handleRequest (from.isAdmin () ? 0xFFFF : from.permissions , timestamp, data[4 ], &data[5 ], len - 5 );
575+ uint8_t reply_len = handleRequest (from.isAdmin () ? 0xFF : from.permissions , timestamp, data[4 ], &data[5 ], len - 5 );
573576 if (reply_len == 0 ) return ; // invalid command
574577
575578 from.last_timestamp = timestamp;
0 commit comments