ClientACL: the replay floor survives a reboot -- a captured admin command no longer works after every boot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7949fb4274
commit
1171d8f972
8 files changed
+410
-1
No files matched your search
+27
-1
@@ -18,7 +18,8 @@ struct ClientInfo {
|
||||
uint8_t out_path_len;
|
||||
uint8_t out_path[MAX_PATH_SIZE];
|
||||
uint8_t shared_secret[PUB_KEY_SIZE];
|
||||
uint32_t last_timestamp; // by THEIR clock (transient)
|
||||
uint32_t last_timestamp; // by THEIR clock (restored from /s_acl_ts* on boot)
|
||||
uint32_t saved_timestamp; // last_timestamp as last written to /s_acl_ts*
|
||||
uint32_t last_activity; // by OUR clock (transient)
|
||||
union {
|
||||
struct {
|
||||
@@ -45,20 +46,45 @@ struct ClientInfo {
|
||||
#define MAX_CLIENTS 32
|
||||
#endif
|
||||
|
||||
// CUSTOM (TeTeHacko): a timestamp further ahead of our clock than this is accepted
|
||||
// but not persisted, so a companion with a runaway RTC cannot lock its admin out
|
||||
// across reboots.
|
||||
#ifndef ACL_TS_MAX_AHEAD
|
||||
#define ACL_TS_MAX_AHEAD (24 * 3600)
|
||||
#endif
|
||||
|
||||
class ClientACL {
|
||||
FILESYSTEM* _fs;
|
||||
ClientInfo clients[MAX_CLIENTS];
|
||||
int num_clients;
|
||||
uint8_t _ts_slot;
|
||||
uint32_t _ts_seq;
|
||||
struct TsOrphan { uint8_t prefix[8]; uint32_t ts; };
|
||||
TsOrphan _ts_orphans[MAX_CLIENTS]; // floors of clients not (or no longer) in clients[]
|
||||
int _num_ts_orphans;
|
||||
|
||||
void loadTimestamps();
|
||||
void saveTimestamps();
|
||||
void orphanTimestamp(const ClientInfo* c);
|
||||
|
||||
public:
|
||||
ClientACL() {
|
||||
memset(clients, 0, sizeof(clients));
|
||||
num_clients = 0;
|
||||
_ts_slot = 0;
|
||||
_ts_seq = 0;
|
||||
_num_ts_orphans = 0;
|
||||
}
|
||||
void load(FILESYSTEM* _fs, const mesh::LocalIdentity& self_id);
|
||||
void save(FILESYSTEM* _fs, bool (*filter)(ClientInfo*)=NULL);
|
||||
bool clear();
|
||||
|
||||
// CUSTOM (TeTeHacko): replay protection that survives a reboot. last_timestamp
|
||||
// used to live only in RAM, so after any reboot a captured command (a `reboot`
|
||||
// among them) was accepted again -- forever. Call this BEFORE acting on an
|
||||
// authenticated packet; it writes the new high-water mark synchronously.
|
||||
void persistTimestamp(ClientInfo* c, uint32_t sender_timestamp, uint32_t now);
|
||||
|
||||
ClientInfo* getClient(const uint8_t* pubkey, int key_len);
|
||||
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms);
|
||||
bool applyPermissions(const mesh::LocalIdentity& self_id, const uint8_t* pubkey, int key_len, uint8_t perms);
|
||||
|
||||
Reference in new issue
Block a user