* Add cli command to regenerate key pair

This commit is contained in:
Matthias Wientapper
2025-10-25 13:20:04 +02:00
parent 61cd01db27
commit 178ebf7282
4 changed files with 20 additions and 0 deletions

View File

@@ -807,6 +807,19 @@ void MyMesh::clearStats() {
((SimpleMeshTables *)getTables())->resetStats();
}
void MyMesh::regenerateKeys() {
MESH_DEBUG_PRINTLN("Generating new keypair");
mesh::LocalIdentity new_id = radio_new_identity();
int count = 0;
while (count < 10 && (new_id.pub_key[0] == 0x00 || new_id.pub_key[0] == 0xFF)) {
new_id = radio_new_identity();
count++;
}
saveIdentity(new_id);
}
void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply) {
while (*command == ' ')
command++; // skip leading spaces

View File

@@ -188,6 +188,7 @@ public:
void saveIdentity(const mesh::LocalIdentity& new_id) override;
void clearStats() override;
void regenerateKeys() override;
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
void loop();

View File

@@ -245,6 +245,11 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
} else if (memcmp(command, "clear stats", 11) == 0) {
_callbacks->clearStats();
strcpy(reply, "(OK - stats reset)");
} else if (memcmp(command, "regeneratekeys", 14) == 0) {
// regenerate key pair
MESH_DEBUG_PRINTLN("Generating new keypair");
_callbacks->regenerateKeys();
_board->reboot(); // doesn't return
/*
* GET commands
*/

View File

@@ -69,6 +69,7 @@ public:
virtual mesh::LocalIdentity& getSelfId() = 0;
virtual void saveIdentity(const mesh::LocalIdentity& new_id) = 0;
virtual void clearStats() = 0;
virtual void regenerateKeys() = 0;
virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;
virtual void setBridgeState(bool enable) {