Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/cli_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ This document provides an overview of CLI commands that can be sent to MeshCore
**Usage:**
- `get prv.key`
- `set prv.key <private_key>`
- `set prv.key random`

**Parameters:**
- `private_key`: Private key in hex format (64 hex characters)
- `private_key`: Private key in hex format (64 hex characters), or `random` to generate a new random key

**Serial Only:**
- `get prv.key`: Yes
Expand Down
1 change: 1 addition & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ You can get the latitude and longitude from Google Maps by right-clicking the lo

`get prv.key` to print a repeater's private key on the serial console
`set prv.key <hex>` to set a repeater's private key on the serial console
`set prv.key random` to generate a new random private key

Reboot the repeater after `set prv.key <hex>` command for the new private key to take effect.

Expand Down
1 change: 1 addition & 0 deletions examples/simple_repeater/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
mesh::LocalIdentity& getSelfId() override { return self_id; }

void saveIdentity(const mesh::LocalIdentity& new_id) override;
mesh::LocalIdentity generateIdentity() override { return radio_new_identity(); }
void clearStats() override;

void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
Expand Down
1 change: 1 addition & 0 deletions examples/simple_room_server/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
static bool saveFilter(ClientInfo* client);

void saveIdentity(const mesh::LocalIdentity& new_id) override;
mesh::LocalIdentity generateIdentity() override { return radio_new_identity(); }
void clearStats() override;
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
void loop();
Expand Down
1 change: 1 addition & 0 deletions examples/simple_sensor/SensorMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class SensorMesh : public mesh::Mesh, public CommonCLICallbacks {
void formatPacketStatsReply(char *reply) override;
mesh::LocalIdentity& getSelfId() override { return self_id; }
void saveIdentity(const mesh::LocalIdentity& new_id) override;
mesh::LocalIdentity generateIdentity() override { return radio_new_identity(); }
void clearStats() override { }
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override;
void startRegionsLoad() override;
Expand Down
20 changes: 15 additions & 5 deletions src/helpers/CommonCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,21 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
strcpy(reply, "OK");
} else if (memcmp(config, "prv.key ", 8) == 0) {
uint8_t prv_key[PRV_KEY_SIZE];
bool success = mesh::Utils::fromHex(prv_key, PRV_KEY_SIZE, &config[8]);
// only allow rekey if key is valid
if (success && mesh::LocalIdentity::validatePrivateKey(prv_key)) {
mesh::LocalIdentity new_id;
new_id.readFrom(prv_key, PRV_KEY_SIZE);
bool success = true;
mesh::LocalIdentity new_id;
if (strcmp(&config[8], "random") == 0) {
new_id = _callbacks->generateIdentity();
int count = 0;
while (count < 10 && (new_id.pub_key[0] == 0x00 || new_id.pub_key[0] == 0xFF)) { // reserved id hashes
new_id = _callbacks->generateIdentity(); count++;
}
} else {
success = mesh::Utils::fromHex(prv_key, PRV_KEY_SIZE, &config[8]);
// only allow rekey if key is valid
success = success && mesh::LocalIdentity::validatePrivateKey(prv_key);
if (success) new_id.readFrom(prv_key, PRV_KEY_SIZE);
}
if (success) {
_callbacks->saveIdentity(new_id);
strcpy(reply, "OK, reboot to apply! New pubkey: ");
mesh::Utils::toHex(&reply[33], new_id.pub_key, PUB_KEY_SIZE);
Expand Down
1 change: 1 addition & 0 deletions src/helpers/CommonCLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class CommonCLICallbacks {
virtual void formatPacketStatsReply(char *reply) = 0;
virtual mesh::LocalIdentity& getSelfId() = 0;
virtual void saveIdentity(const mesh::LocalIdentity& new_id) = 0;
virtual mesh::LocalIdentity generateIdentity() = 0;
virtual void clearStats() = 0;
virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;

Expand Down