mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
add build flags to enable and disable private key import and export
This commit is contained in:
parent
6af9774976
commit
9faba8f184
1 changed files with 35 additions and 12 deletions
|
|
@ -46,6 +46,14 @@
|
||||||
#define OFFLINE_QUEUE_SIZE 16
|
#define OFFLINE_QUEUE_SIZE 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENABLE_PRIVATE_KEY_EXPORT
|
||||||
|
#define ENABLE_PRIVATE_KEY_EXPORT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENABLE_PRIVATE_KEY_IMPORT
|
||||||
|
#define ENABLE_PRIVATE_KEY_IMPORT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <helpers/BaseChatMesh.h>
|
#include <helpers/BaseChatMesh.h>
|
||||||
|
|
||||||
#define SEND_TIMEOUT_BASE_MILLIS 500
|
#define SEND_TIMEOUT_BASE_MILLIS 500
|
||||||
|
|
@ -139,6 +147,7 @@ static uint32_t _atoi(const char* sp) {
|
||||||
#define RESP_CODE_BATTERY_VOLTAGE 12 // a reply to a CMD_GET_BATTERY_VOLTAGE
|
#define RESP_CODE_BATTERY_VOLTAGE 12 // a reply to a CMD_GET_BATTERY_VOLTAGE
|
||||||
#define RESP_CODE_DEVICE_INFO 13 // a reply to CMD_DEVICE_QEURY
|
#define RESP_CODE_DEVICE_INFO 13 // a reply to CMD_DEVICE_QEURY
|
||||||
#define RESP_CODE_PRIVATE_KEY 14 // a reply to CMD_EXPORT_PRIVATE_KEY
|
#define RESP_CODE_PRIVATE_KEY 14 // a reply to CMD_EXPORT_PRIVATE_KEY
|
||||||
|
#define RESP_CODE_DISABLED 15
|
||||||
|
|
||||||
// these are _pushed_ to client app at any time
|
// these are _pushed_ to client app at any time
|
||||||
#define PUSH_CODE_ADVERT 0x80
|
#define PUSH_CODE_ADVERT 0x80
|
||||||
|
|
@ -326,6 +335,12 @@ class MyMesh : public BaseChatMesh {
|
||||||
_serial->writeFrame(buf, 1);
|
_serial->writeFrame(buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeDisabledFrame() {
|
||||||
|
uint8_t buf[1];
|
||||||
|
buf[0] = RESP_CODE_DISABLED;
|
||||||
|
_serial->writeFrame(buf, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void writeContactRespFrame(uint8_t code, const ContactInfo& contact) {
|
void writeContactRespFrame(uint8_t code, const ContactInfo& contact) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
out_frame[i++] = code;
|
out_frame[i++] = code;
|
||||||
|
|
@ -862,19 +877,27 @@ public:
|
||||||
memcpy(&reply[1], &battery_millivolts, 2);
|
memcpy(&reply[1], &battery_millivolts, 2);
|
||||||
_serial->writeFrame(reply, 3);
|
_serial->writeFrame(reply, 3);
|
||||||
} else if (cmd_frame[0] == CMD_EXPORT_PRIVATE_KEY) {
|
} else if (cmd_frame[0] == CMD_EXPORT_PRIVATE_KEY) {
|
||||||
uint8_t reply[65];
|
if(ENABLE_PRIVATE_KEY_EXPORT == 1){
|
||||||
reply[0] = RESP_CODE_PRIVATE_KEY;
|
uint8_t reply[65];
|
||||||
uint8_t private_key[64];
|
reply[0] = RESP_CODE_PRIVATE_KEY;
|
||||||
self_id.writeTo(private_key, 64);
|
uint8_t private_key[64];
|
||||||
memcpy(&reply[1], &private_key, 64);
|
self_id.writeTo(private_key, 64);
|
||||||
_serial->writeFrame(reply, 65);
|
memcpy(&reply[1], &private_key, 64);
|
||||||
} else if (cmd_frame[0] == CMD_IMPORT_PRIVATE_KEY && len >= 65) {
|
_serial->writeFrame(reply, 65);
|
||||||
mesh::LocalIdentity identity = mesh::LocalIdentity();
|
|
||||||
identity.readFrom(&cmd_frame[1], 64);
|
|
||||||
if(saveMainIdentity(identity)){
|
|
||||||
writeOKFrame();
|
|
||||||
} else {
|
} else {
|
||||||
writeErrFrame();
|
writeDisabledFrame();
|
||||||
|
}
|
||||||
|
} else if (cmd_frame[0] == CMD_IMPORT_PRIVATE_KEY && len >= 65) {
|
||||||
|
if(ENABLE_PRIVATE_KEY_IMPORT == 1){
|
||||||
|
mesh::LocalIdentity identity = mesh::LocalIdentity();
|
||||||
|
identity.readFrom(&cmd_frame[1], 64);
|
||||||
|
if(saveMainIdentity(identity)){
|
||||||
|
writeOKFrame();
|
||||||
|
} else {
|
||||||
|
writeErrFrame();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
writeDisabledFrame();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeErrFrame();
|
writeErrFrame();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue