Retry identity startup and harden replay state and permissions
Read identities up to three times before allowing replacement, publish only complete reads, and require new startup keys to be saved with bounded retries. Use authoritative replay-file metadata throughout persistence and clock recovery. Validate setperm input before narrowing or mutating roles, and add production-path regression coverage.
This commit is contained in:
1 parent
24b1b1167f
commit
b847b46ef7
21 files changed
+272
-73
No files matched your search
@@ -58,15 +58,16 @@ void loadOrCreateIdentity() {
|
||||
bool identity_ready = true;
|
||||
if (needs_identity) {
|
||||
identity_ready = mesh::generateUsableLocalIdentity(identity, radio_new_identity);
|
||||
if (identity_ready) store.save("_main", identity);
|
||||
if (identity_ready) identity_ready = store.saveWithRetry("_main", identity);
|
||||
}
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
mesh::discardESP32TrueRandom();
|
||||
#endif
|
||||
if (!identity_ready) {
|
||||
MESH_DEBUG_PRINTLN("Identity generation exhausted all attempts; rebooting");
|
||||
MESH_DEBUG_PRINTLN("Identity generation or persistence failed after retries; rebooting");
|
||||
board.reboot();
|
||||
halt(); // Never let setup continue if a platform's reboot returns.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11974,8 +11974,10 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
|
||||
uint8_t pubkey[PUB_KEY_SIZE];
|
||||
if (hex_len > 0 && hex_len <= PUB_KEY_SIZE * 2 && (hex_len & 1) == 0
|
||||
&& mesh::Utils::fromHex(pubkey, (int)(hex_len / 2), hex)) {
|
||||
uint8_t perms = atoi(sp);
|
||||
if (acl.applyPermissions(self_id, pubkey, (int)(hex_len / 2), perms)) {
|
||||
uint32_t perms;
|
||||
if (!mesh::cli::parseUnsignedIntegerStrict(sp, perms) || perms > UINT8_MAX) {
|
||||
strcpy(reply, "Err - permissions must be 0-255");
|
||||
} else if (acl.applyPermissions(self_id, pubkey, (int)(hex_len / 2), static_cast<uint8_t>(perms))) {
|
||||
mesh::scheduleLazyPersistenceMutation(
|
||||
dirty_contacts_expiry, contacts_save_failures,
|
||||
futureMillis(LAZY_CONTACTS_WRITE_DELAY));
|
||||
|
||||
@@ -177,14 +177,14 @@ void setup() {
|
||||
if (needs_identity) {
|
||||
MESH_DEBUG_PRINTLN("Generating new keypair");
|
||||
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
|
||||
if (identity_ready) store.save("_main", the_mesh.self_id);
|
||||
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
|
||||
}
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
mesh::discardESP32TrueRandom();
|
||||
#endif
|
||||
if (!identity_ready) {
|
||||
MESH_DEBUG_PRINTLN("Identity generation exhausted all attempts; rebooting");
|
||||
MESH_DEBUG_PRINTLN("Identity generation or persistence failed after retries; rebooting");
|
||||
board.reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2376,8 +2376,10 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
||||
uint8_t pubkey[PUB_KEY_SIZE];
|
||||
if (hex_len > 0 && hex_len <= PUB_KEY_SIZE * 2 && (hex_len & 1) == 0
|
||||
&& mesh::Utils::fromHex(pubkey, (int)(hex_len / 2), hex)) {
|
||||
uint8_t perms = atoi(sp);
|
||||
if (acl.applyPermissions(self_id, pubkey, (int)(hex_len / 2), perms)) {
|
||||
uint32_t perms;
|
||||
if (!mesh::cli::parseUnsignedIntegerStrict(sp, perms) || perms > UINT8_MAX) {
|
||||
strcpy(reply, "Err - permissions must be 0-255");
|
||||
} else if (acl.applyPermissions(self_id, pubkey, (int)(hex_len / 2), static_cast<uint8_t>(perms))) {
|
||||
mesh::scheduleLazyPersistenceMutation(
|
||||
dirty_contacts_expiry, contacts_save_failures,
|
||||
futureMillis(LAZY_CONTACTS_WRITE_DELAY));
|
||||
|
||||
@@ -103,14 +103,14 @@ void setup() {
|
||||
bool identity_ready = true;
|
||||
if (needs_identity) {
|
||||
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
|
||||
if (identity_ready) store.save("_main", the_mesh.self_id);
|
||||
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
|
||||
}
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
mesh::discardESP32TrueRandom();
|
||||
#endif
|
||||
if (!identity_ready) {
|
||||
MESH_DEBUG_PRINTLN("Identity generation exhausted all attempts; rebooting");
|
||||
MESH_DEBUG_PRINTLN("Identity generation or persistence failed after retries; rebooting");
|
||||
board.reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -348,14 +348,14 @@ public:
|
||||
identity_ready = mesh::generateUsableLocalIdentity(
|
||||
self_id, [this]() { return mesh::LocalIdentity(getRNG()); });
|
||||
#endif
|
||||
if (identity_ready) store.save("_main", self_id);
|
||||
if (identity_ready) identity_ready = store.saveWithRetry("_main", self_id);
|
||||
}
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
mesh::discardESP32TrueRandom();
|
||||
#endif
|
||||
if (!identity_ready) {
|
||||
MESH_DEBUG_PRINTLN("Identity generation exhausted all attempts; rebooting");
|
||||
MESH_DEBUG_PRINTLN("Identity generation or persistence failed after retries; rebooting");
|
||||
board.reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -626,8 +626,10 @@ void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* r
|
||||
uint8_t pubkey[PUB_KEY_SIZE];
|
||||
if (hex_len > 0 && hex_len <= PUB_KEY_SIZE * 2 && (hex_len & 1) == 0
|
||||
&& mesh::Utils::fromHex(pubkey, (int)(hex_len / 2), hex)) {
|
||||
uint8_t perms = atoi(sp);
|
||||
if (acl.applyPermissions(self_id, pubkey, (int)(hex_len / 2), perms)) {
|
||||
uint32_t perms;
|
||||
if (!mesh::cli::parseUnsignedIntegerStrict(sp, perms) || perms > UINT8_MAX) {
|
||||
strcpy(reply, "Err - permissions must be 0-255");
|
||||
} else if (acl.applyPermissions(self_id, pubkey, (int)(hex_len / 2), static_cast<uint8_t>(perms))) {
|
||||
mesh::scheduleLazyPersistenceMutation(
|
||||
dirty_contacts_expiry, contacts_save_failures,
|
||||
futureMillis(LAZY_CONTACTS_WRITE_DELAY));
|
||||
|
||||
@@ -116,14 +116,14 @@ void setup() {
|
||||
if (needs_identity) {
|
||||
MESH_DEBUG_PRINTLN("Generating new keypair");
|
||||
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
|
||||
if (identity_ready) store.save("_main", the_mesh.self_id);
|
||||
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
|
||||
}
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
mesh::discardESP32TrueRandom();
|
||||
#endif
|
||||
if (!identity_ready) {
|
||||
MESH_DEBUG_PRINTLN("Identity generation exhausted all attempts; rebooting");
|
||||
MESH_DEBUG_PRINTLN("Identity generation or persistence failed after retries; rebooting");
|
||||
board.reboot();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user