diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index b439f90..76eebf8 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -717,7 +717,7 @@ public: *dp = 0; // null terminator } - const uint8_t* getSelfIdPubKey() override { return self_id.pub_key; } + mesh::LocalIdentity& getSelfId() override { return self_id; } void clearStats() override { radio_driver.resetStats(); @@ -780,7 +780,7 @@ void halt() { while (1) ; } -static char command[80]; +static char command[160]; void setup() { Serial.begin(115200); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 9a28462..34b94ad 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -863,7 +863,7 @@ public: strcpy(reply, "not supported"); } - const uint8_t* getSelfIdPubKey() override { return self_id.pub_key; } + mesh::LocalIdentity& getSelfId() override { return self_id; } void clearStats() override { radio_driver.resetStats(); diff --git a/examples/simple_sensor/SensorMesh.h b/examples/simple_sensor/SensorMesh.h index 8f6e3bc..0d87617 100644 --- a/examples/simple_sensor/SensorMesh.h +++ b/examples/simple_sensor/SensorMesh.h @@ -88,7 +88,7 @@ public: void formatNeighborsReply(char *reply) override { strcpy(reply, "not supported"); } - const uint8_t* getSelfIdPubKey() override { return self_id.pub_key; } + mesh::LocalIdentity& getSelfId() override { return self_id; } void clearStats() override { } void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; diff --git a/examples/simple_sensor/main.cpp b/examples/simple_sensor/main.cpp index c9e282a..2dacd1b 100644 --- a/examples/simple_sensor/main.cpp +++ b/examples/simple_sensor/main.cpp @@ -50,7 +50,7 @@ void halt() { while (1) ; } -static char command[120]; +static char command[160]; void setup() { Serial.begin(115200); diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index d62253f..2abb4f7 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -206,6 +206,11 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch sprintf(reply, "> %d", ((uint32_t) _prefs->advert_interval) * 2); } else if (memcmp(config, "guest.password", 14) == 0) { sprintf(reply, "> %s", _prefs->guest_password); + } else if (sender_timestamp == 0 && memcmp(config, "prv.key", 7) == 0) { // from serial command line only + uint8_t prv_key[PRV_KEY_SIZE]; + int len = _callbacks->getSelfId().writeTo(prv_key, PRV_KEY_SIZE); + mesh::Utils::toHex(tmp, prv_key, len); + sprintf(reply, "> %s", tmp); } else if (memcmp(config, "name", 4) == 0) { sprintf(reply, "> %s", _prefs->node_name); } else if (memcmp(config, "repeat", 6) == 0) { @@ -233,7 +238,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch sprintf(reply, "> %s", StrHelper::ftoa(_prefs->freq)); } else if (memcmp(config, "public.key", 10) == 0) { strcpy(reply, "> "); - mesh::Utils::toHex(&reply[2], _callbacks->getSelfIdPubKey(), PUB_KEY_SIZE); + mesh::Utils::toHex(&reply[2], _callbacks->getSelfId().pub_key, PUB_KEY_SIZE); } else if (memcmp(config, "role", 4) == 0) { sprintf(reply, "> %s", _callbacks->getRole()); } else { @@ -285,6 +290,15 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch StrHelper::strncpy(_prefs->guest_password, &config[15], sizeof(_prefs->guest_password)); savePrefs(); strcpy(reply, "OK"); + } else if (sender_timestamp == 0 && memcmp(config, "prv.key ", 8) == 0) { // from serial command line only + uint8_t prv_key[PRV_KEY_SIZE]; + bool success = mesh::Utils::fromHex(prv_key, PRV_KEY_SIZE, &config[8]); + if (success) { + _callbacks->getSelfId().readFrom(prv_key, PRV_KEY_SIZE); + strcpy(reply, "OK"); + } else { + strcpy(reply, "Error, invalid key"); + } } else if (memcmp(config, "name ", 5) == 0) { StrHelper::strncpy(_prefs->node_name, &config[5], sizeof(_prefs->node_name)); savePrefs(); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index e260837..92deb71 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -43,7 +43,7 @@ public: virtual void dumpLogFile() = 0; virtual void setTxPower(uint8_t power_dbm) = 0; virtual void formatNeighborsReply(char *reply) = 0; - virtual const uint8_t* getSelfIdPubKey() = 0; + virtual mesh::LocalIdentity& getSelfId() = 0; virtual void clearStats() = 0; virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0; }; @@ -53,7 +53,7 @@ class CommonCLI { NodePrefs* _prefs; CommonCLICallbacks* _callbacks; mesh::MainBoard* _board; - char tmp[80]; + char tmp[PRV_KEY_SIZE*2 + 4]; mesh::RTCClock* getRTCClock() { return _rtc; } void savePrefs();