@@ -832,7 +832,7 @@ void NodeDB::installDefaultNodeDatabase()
832832void NodeDB::installDefaultConfig (bool preserveKey = false )
833833{
834834 uint8_t private_key_temp[32 ];
835- bool shouldPreserveKey = preserveKey && config.has_security && config.security .private_key .size > 0 ;
835+ bool shouldPreserveKey = preserveKey && config.has_security && config.security .private_key .size == 32 ;
836836 if (shouldPreserveKey) {
837837 memcpy (private_key_temp, config.security .private_key .bytes , config.security .private_key .size );
838838 }
@@ -2722,6 +2722,11 @@ void NodeDB::loadFromDisk()
27222722 moduleConfig.version = POSITION_TELEMETRY_OPTIN_VER ;
27232723 saveToDisk (SEGMENT_MODULECONFIG );
27242724 }
2725+
2726+ if (channels.ensureLicensedOperation ()) {
2727+ LOG_WARN (" Licensed operation removed persisted channel encryption/admin access" );
2728+ saveToDisk (SEGMENT_CHANNELS );
2729+ }
27252730#if ARCH_PORTDUINO
27262731 // set any config overrides
27272732 if (portduino_config.has_configDisplayMode ) {
@@ -4161,15 +4166,14 @@ bool NodeDB::checkLowEntropyPublicKey(const meshtastic_Config_SecurityConfig_pub
41614166bool NodeDB::generateCryptoKeyPair (const uint8_t *privateKey)
41624167{
41634168#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN || MESHTASTIC_EXCLUDE_PKI)
4164- // Only generate keys for non-licensed users and if the LoRa region is set. The native simulator
4165- // boots region-UNSET but still needs a keypair so PKI-encrypted DMs work between sim nodes, so
4166- // allow keygen there regardless of region.
4169+ // Generate identity keys once a LoRa region is set. Licensed operation still needs the identity
4170+ // key for plaintext signatures, even though the key is never used for PKI encryption.
41674171 bool regionBlocksKeygen = config.lora .region == meshtastic_Config_LoRaConfig_RegionCode_UNSET;
41684172#if ARCH_PORTDUINO
41694173 if (portduino_config.lora_module == use_simradio)
41704174 regionBlocksKeygen = false ;
41714175#endif
4172- if (owner. is_licensed || regionBlocksKeygen) {
4176+ if (regionBlocksKeygen) {
41734177 return false ;
41744178 }
41754179
@@ -4219,15 +4223,30 @@ bool NodeDB::generateCryptoKeyPair(const uint8_t *privateKey)
42194223 LOG_DEBUG (" Set DH private key for crypto operations" );
42204224 crypto->setDHPrivateKey (config.security .private_key .bytes );
42214225
4222- // Conditionally create new identity based on parameter
4223- createNewIdentity () ;
4226+ if ( createNewIdentity () && owner. is_licensed )
4227+ licensedIdentityMigrationPending = true ;
42244228 }
42254229 return keygenSuccess;
42264230#else
42274231 return false ;
42284232#endif
42294233}
42304234
4235+ bool NodeDB::notifyPendingLicensedIdentityMigration ()
4236+ {
4237+ if (!licensedIdentityMigrationPending || !service)
4238+ return false ;
4239+ meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed ();
4240+ if (!notification)
4241+ return false ;
4242+ notification->level = meshtastic_LogRecord_Level_WARNING;
4243+ notification->time = getValidTime (RTCQualityFromNet);
4244+ snprintf (notification->message , sizeof (notification->message ), " %s" , LICENSED_IDENTITY_MIGRATION_WARNING );
4245+ service->sendClientNotification (notification);
4246+ licensedIdentityMigrationPending = false ;
4247+ return true ;
4248+ }
4249+
42314250bool NodeDB::createNewIdentity ()
42324251{
42334252 uint32_t oldNodeNum = getNodeNum ();
@@ -4331,6 +4350,13 @@ bool NodeDB::restorePreferences(meshtastic_AdminMessage_BackupLocation location,
43314350 LOG_DEBUG (" Restored channels" );
43324351 }
43334352
4353+ if (owner.is_licensed && channels.ensureLicensedOperation ()) {
4354+ restoreWhat |= SEGMENT_CHANNELS ;
4355+ LOG_WARN (" Licensed operation sanitized restored channel encryption/admin access" );
4356+ }
4357+ if (restoreWhat & SEGMENT_CHANNELS )
4358+ channels.onConfigChanged ();
4359+
43344360 success = saveToDisk (restoreWhat);
43354361 if (success) {
43364362 LOG_INFO (" Restored preferences from backup" );
0 commit comments