init scheduler task
MODIFY
src/scheduler/SchedulerManager.ts
src/scheduler/SchedulerManager.ts
@@ -9,6 +9,7 @@ import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
import Logging from '../utils/Logging';
import LoggingDatabaseTableCleanupTask from './tasks/LoggingDatabaseTableCleanupTask';
+import MigrateSensitiveDataTask from './tasks/MigrateSensitiveDataTask';
import OCPICheckCdrsTask from './tasks/ocpi/OCPICheckCdrsTask';
import OCPICheckLocationsTask from './tasks/ocpi/OCPICheckLocationsTask';
import OCPICheckSessionsTask from './tasks/ocpi/OCPICheckSessionsTask';
@@ -122,6 +123,9 @@ export default class SchedulerManager {
case 'CheckChargingStationTemplateTask':
schedulerTask = new CheckChargingStationTemplateTask();
break;
+ case 'MigrateSensitiveDataTask':
+ schedulerTask = new MigrateSensitiveDataTask();
+ break;
default:
Logging.logError({
tenantID: Constants.DEFAULT_TENANT,

ADD
src/scheduler/tasks/MigrateSensitiveDataTask.ts
+import Cypher from '../../utils/Cypher';
+import SchedulerTask from '../SchedulerTask';
+import SettingStorage from '../../storage/mongodb/SettingStorage';
+import { TaskConfig } from '../../types/TaskConfig';
+import Tenant from '../../types/Tenant';
+
+export default class MigrateSensitiveDataTask extends SchedulerTask {
+
+ public async processTenant(tenant: Tenant, config: TaskConfig): Promise<void> {
+ const keySettings = await SettingStorage.getCryptoSettings(tenant.id);
+ if (keySettings?.crypto.migrationToBeDone === true) {
+ await Cypher.handleCryptoSettingsChange(tenant.id);
+ }
+ }
+}

MODIFY
src/storage/mongodb/SettingStorage.ts
src/storage/mongodb/SettingStorage.ts
@@ -56,7 +56,7 @@ export default class SettingStorage {
identifier: settingToSave.identifier,
content: settingToSave.content,
sensitiveData: settingToSave.sensitiveData,
- formerSenitiveData: settingToSave.formerSensitiveData
+ formerSensitiveData: settingToSave.formerSensitiveData
};
DatabaseUtils.addLastChangedCreatedProps(settingMDB, settingToSave);
// Modify
@@ -345,7 +345,8 @@ export default class SettingStorage {
blockCypher: settings.result[0].content.crypto.keyProperties.blockCypher,
blockSize: settings.result[0].content.crypto.keyProperties.blockSize,
operationMode: settings.result[0].content.crypto.keyProperties.operationMode,
- }
+ },
+ migrationToBeDone: settings.result[0].content.crypto.migrationToBeDone
} as CryptoSetting;
const keySetting = {
id: settings.result[0].id,

MODIFY
src/utils/Cypher.ts
src/utils/Cypher.ts
@@ -190,6 +190,7 @@ export default class Cypher {
// Migrate
for (const setting of settingsToMigrate) {
if (!setting.formerSensitiveData && Utils.isEmptyArray(setting.formerSensitiveData)) {
+ delete setting.formerSensitiveData;
// Save former senitive data in setting
const formerSensitiveData = Cypher.prepareFormerSenitiveData(setting);
formerSensitiveData['formerKeyHash'] = Cypher.hash(cryptoSetting.formerKey);

init scheduler task