mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-10 07:02:11 +00:00
Backup / migrate pub private keys when upgrading to new files in 2.6 (#6096)
* Save a backup of pub/private keys before factory reset * Fix licensed mode warning * Unlock spi on else file doesn't exist
This commit is contained in:
parent
a7c4361d7c
commit
1961bcaf9d
@ -972,6 +972,8 @@ void NodeDB::loadFromDisk()
|
||||
// disk we will still factoryReset to restore things.
|
||||
devicestate.version = 0;
|
||||
|
||||
meshtastic_Config_SecurityConfig backupSecurity = meshtastic_Config_SecurityConfig_init_zero;
|
||||
|
||||
#ifdef ARCH_ESP32
|
||||
spiLock->lock();
|
||||
// If the legacy deviceState exists, start over with a factory reset
|
||||
@ -982,9 +984,21 @@ void NodeDB::loadFromDisk()
|
||||
#ifdef FSCom
|
||||
spiLock->lock();
|
||||
if (FSCom.exists(legacyPrefFileName)) {
|
||||
spiLock->unlock();
|
||||
LOG_WARN("Legacy prefs version found, factory resetting");
|
||||
if (loadProto(configFileName, meshtastic_LocalConfig_size, sizeof(meshtastic_LocalConfig), &meshtastic_LocalConfig_msg,
|
||||
&config) == LoadFileResult::LOAD_SUCCESS &&
|
||||
config.has_security && config.security.private_key.size > 0) {
|
||||
LOG_DEBUG("Saving backup of security config and keys");
|
||||
backupSecurity = config.security;
|
||||
}
|
||||
spiLock->lock();
|
||||
rmDir("/prefs");
|
||||
spiLock->unlock();
|
||||
} else {
|
||||
spiLock->unlock();
|
||||
}
|
||||
spiLock->unlock();
|
||||
|
||||
#endif
|
||||
auto state = loadProto(nodeDatabaseFileName, getMaxNodesAllocatedSize(), sizeof(meshtastic_NodeDatabase),
|
||||
&meshtastic_NodeDatabase_msg, &nodeDatabase);
|
||||
@ -1034,6 +1048,11 @@ void NodeDB::loadFromDisk()
|
||||
LOG_INFO("Loaded saved config version %d", config.version);
|
||||
}
|
||||
}
|
||||
if (backupSecurity.private_key.size > 0) {
|
||||
LOG_DEBUG("Restoring backup of security config");
|
||||
config.security = backupSecurity;
|
||||
saveToDisk(SEGMENT_CONFIG);
|
||||
}
|
||||
|
||||
// Make sure we load hard coded admin keys even when the configuration file has none.
|
||||
// Initialize admin_key_count to zero
|
||||
|
@ -64,7 +64,8 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>, public Obser
|
||||
void sendWarning(const char *message);
|
||||
};
|
||||
|
||||
static constexpr char *licensedModeMessage = "Licensed mode activated, removing admin channel and encryption from all channels";
|
||||
static constexpr const char *licensedModeMessage =
|
||||
"Licensed mode activated, removing admin channel and encryption from all channels";
|
||||
|
||||
extern AdminModule *adminModule;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user