Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Wientapper
82242052f9 * Regenerate keys with public key matching user defined first byte 2025-10-26 20:11:30 +01:00
Matthias Wientapper
178ebf7282 * Add cli command to regenerate key pair 2025-10-25 13:20:04 +02:00
4 changed files with 37 additions and 0 deletions

View File

@@ -807,6 +807,18 @@ void MyMesh::clearStats() {
((SimpleMeshTables *)getTables())->resetStats(); ((SimpleMeshTables *)getTables())->resetStats();
} }
void MyMesh::regenerateKeys(uint8_t byte) {
if (byte >0 && byte < 0xff){
MESH_DEBUG_PRINTLN("Generating new keypair");
mesh::LocalIdentity new_id = radio_new_identity();
while (new_id.pub_key[0] != byte) {
new_id = radio_new_identity();
}
saveIdentity(new_id);
}
}
void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply) { void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply) {
while (*command == ' ') while (*command == ' ')
command++; // skip leading spaces command++; // skip leading spaces

View File

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

View File

@@ -245,6 +245,29 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
} else if (memcmp(command, "clear stats", 11) == 0) { } else if (memcmp(command, "clear stats", 11) == 0) {
_callbacks->clearStats(); _callbacks->clearStats();
strcpy(reply, "(OK - stats reset)"); strcpy(reply, "(OK - stats reset)");
} else if (memcmp(command, "regeneratekeys ", 15) == 0) {
// Parse first hex digit
int value = 0;
if (command[15] >= '0' && command[15] <= '9')
value = (command[15] - '0') << 4;
else if (command[15] >= 'a' && command[15] <= 'f')
value = (command[15] - 'a' + 10) << 4;
else if (command[15] >= 'A' && command[15] <= 'F')
value = (command[15] - 'A' + 10) << 4;
// Parse second hex digit
if (command[16] >= '0' && command[16] <= '9')
value |= (command[16] - '0');
else if (command[16] >= 'a' && command[16] <= 'f')
value |= (command[16] - 'a' + 10);
else if (command[16] >= 'A' && command[16] <= 'F')
value |= (command[16] - 'A' + 10);
// regenerate key pair
MESH_DEBUG_PRINTLN("Generating new keypair");
if ((value > 0) && (value < 0xff)){
_callbacks->regenerateKeys(value);
_board->reboot(); // doesn't return
}
sprintf(reply, "> ERROR");
/* /*
* GET commands * GET commands
*/ */

View File

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