mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* new CommonCLI commands: "get prv.key", "set prv.key {hex}"
This commit is contained in:
parent
0a2d132d84
commit
28af68c187
6 changed files with 22 additions and 8 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ void halt() {
|
|||
while (1) ;
|
||||
}
|
||||
|
||||
static char command[120];
|
||||
static char command[160];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue