some refactoring,renaming
MODIFY
src/integration/asset/schneider/SchneiderAssetIntegration.ts
src/integration/asset/schneider/SchneiderAssetIntegration.ts
@@ -127,7 +127,7 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
const params = new URLSearchParams();
params.append('grant_type', 'password');
params.append('username', this.connection.connection.user);
- params.append('password', (await Cypher.decrypt(this.connection.connection.password, this.tenantID)));
+ params.append('password', await Cypher.decrypt(this.connection.connection.password, this.tenantID));
return params;
}

MODIFY
src/server/rest/v1/service/SettingService.ts
src/server/rest/v1/service/SettingService.ts
@@ -184,7 +184,7 @@ export default class SettingService {
}
} else {
// Value in db is empty then encrypt
- _.set(settingUpdate, property, Cypher.encrypt(valueInRequest, req.user.tenantID));
+ _.set(settingUpdate, property, await Cypher.encrypt(valueInRequest, req.user.tenantID));
}
}
}

MODIFY
src/utils/Cypher.ts
src/utils/Cypher.ts
@@ -13,7 +13,7 @@ export default class Cypher {
public static async encrypt(data: string, tenantID: string): Promise<string> {
const iv = crypto.randomBytes(IV_LENGTH);
- const cryptoSetting = await this.getCryptoSetting(tenantID);
+ const cryptoSetting = await Cypher.getCryptoSetting(tenantID);
const cipher = crypto.createCipheriv(Utils.buildAlgorithm(cryptoSetting.keyProperties), Buffer.from(cryptoSetting.key), iv);
let encryptedData = cipher.update(data);
encryptedData = Buffer.concat([encryptedData, cipher.final()]);
@@ -24,7 +24,7 @@ export default class Cypher {
const dataParts = data.split(':');
const iv = Buffer.from(dataParts.shift(), 'hex');
const encryptedData = Buffer.from(dataParts.join(':'), 'hex');
- const cryptoSetting = await this.getCryptoSetting(tenantID);
+ const cryptoSetting = await Cypher.getCryptoSetting(tenantID);
const decipher = crypto.createDecipheriv(Utils.buildAlgorithm(cryptoSetting.keyProperties), Buffer.from(cryptoSetting.key), iv);
let decrypted = decipher.update(encryptedData);
decrypted = Buffer.concat([decrypted, decipher.final()]);
@@ -140,7 +140,7 @@ export default class Cypher {
source: Constants.CENTRAL_SERVER,
module: MODULE_NAME,
method: 'getCryptoSetting',
- message: 'No Crypto Settings found in the database'
+ message: `Tenant with ID: ${tenantID} does not have crypto settings.`
});
}
return cryptoSettings;

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1345,13 +1345,13 @@ export default class Utils {
const [blockCypher, blockSize, operationMode] = algo.split('-');
return {
blockCypher: blockCypher,
- blockSize: parseInt(blockSize),
+ blockSize: Utils.convertToInt(blockSize),
operationMode: operationMode
};
}
public static buildAlgorithm(properties: CryptoKeyProperties): string {
- return `${properties.blockCypher.toLowerCase()}-${properties.blockSize}-${properties.operationMode.toLowerCase()}`;
+ return `${properties.blockCypher}-${properties.blockSize}-${properties.operationMode}`;
}
public static generateKey(): string {
@@ -1361,9 +1361,9 @@ export default class Utils {
public static getDefaultKeyProperties(): CryptoKeyProperties {
return {
- blockCypher: 'AES',
+ blockCypher: 'aes',
blockSize: 256,
- operationMode: 'GCM'
+ operationMode: 'gcm'
};
}

some refactoring,renaming