Certificate encryption fix
MODIFY
src/server/oicp/OICPUtils.ts
src/server/oicp/OICPUtils.ts
@@ -204,18 +204,18 @@ export default class OICPUtils {
const roamingSettings = await SettingStorage.getOICPSettings(tenantID);
// Encrypt key and certificate if not already encrypted
// CPO
- if (roamingSettings.oicp.cpo?.key !== oicpSetting.cpo.key) {
+ if (oicpSetting.cpo.key && roamingSettings.oicp.cpo?.key !== oicpSetting.cpo.key) {
oicpSetting.cpo.key = sanitize(Cypher.encrypt(oicpSetting.cpo.key));
}
- if (roamingSettings.oicp.cpo?.cert !== oicpSetting.cpo.cert) {
+ if (oicpSetting.cpo.cert && roamingSettings.oicp.cpo?.cert !== oicpSetting.cpo.cert) {
oicpSetting.cpo.cert = sanitize(Cypher.encrypt(oicpSetting.cpo.cert));
}
// EMSP
- if (roamingSettings.oicp.emsp?.key !== oicpSetting.emsp.key) {
+ if (oicpSetting.emsp.key && roamingSettings.oicp.emsp?.key !== oicpSetting.emsp.key) {
oicpSetting.emsp.key = sanitize(Cypher.encrypt(oicpSetting.emsp.key));
}
- if (roamingSettings.oicp.emsp?.cert !== oicpSetting.emsp.cert) {
+ if (oicpSetting.emsp.cert && roamingSettings.oicp.emsp?.cert !== oicpSetting.emsp.cert) {
oicpSetting.emsp.cert = sanitize(Cypher.encrypt(oicpSetting.emsp.cert));
}
}

MODIFY
src/server/rest/v1/service/SettingService.ts
src/server/rest/v1/service/SettingService.ts
@@ -142,6 +142,9 @@ export default class SettingService {
public static async handleUpdateSetting(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const settingUpdate = SettingSecurity.filterSettingUpdateRequest(req.body);
+ if (settingUpdate.content.oicp?.cpo?.cert) {
+ await OICPUtils.encryptCertificates(req.user.tenantID, settingUpdate.content.oicp);
+ }
UtilsService.assertIdIsProvided(action, settingUpdate.id, MODULE_NAME, 'handleUpdateSetting', req.user);
// Check auth
if (!Authorizations.canUpdateSetting(req.user)) {

MODIFY
src/server/rest/v1/service/security/SettingSecurity.ts
src/server/rest/v1/service/security/SettingSecurity.ts
@@ -123,16 +123,16 @@ export default class SettingSecurity {
settings.content.oicp.cpo = {
countryCode: sanitize(request.content.oicp.cpo.countryCode),
partyID: sanitize(request.content.oicp.cpo.partyID),
- key: '',
- cert:''
+ key: sanitize(request.content.oicp.cpo.key),
+ cert:sanitize(request.content.oicp.cpo.cert)
};
}
if (request.content.oicp.emsp) {
settings.content.oicp.emsp = {
countryCode: sanitize(request.content.oicp.emsp.countryCode),
partyID: sanitize(request.content.oicp.emsp.partyID),
- key: '',
- cert:''
+ key: sanitize(request.content.oicp.emsp.key),
+ cert:sanitize(request.content.oicp.emsp.cert)
};
}
if (request.content.oicp.currency) {

Certificate encryption fix