use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method init.
@BeforeAll
public static void init() throws IOException, ProtocolAdapterException {
byteArray1 = Files.readAllBytes(new ClassPathResource(fwFilename1).getFile().toPath());
// Same firmware file but now with wildcarded mbusversion (Florian firmware)
final FirmwareFile firmwareFile2 = new FirmwareFile(byteArray1);
firmwareFile2.setMbusVersion(255);
byteArray2 = firmwareFile2.getByteArray();
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method createFirmwareFile.
private FirmwareFile createFirmwareFile(final byte[] byteArray, final String mbusDeviceIdentificationNumber) throws ProtocolAdapterException {
final FirmwareFile firmwareFile = new FirmwareFile(byteArray.clone());
System.out.println(firmwareFile.getHeader());
firmwareFile.setMbusDeviceIdentificationNumber(mbusDeviceIdentificationNumber);
firmwareFile.setMbusVersion(80);
System.out.println(firmwareFile.getHeader());
return firmwareFile;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method assertExceptionContainsMessageOnCalculateMac.
private void assertExceptionContainsMessageOnCalculateMac(final Class<? extends Exception> exceptionClass, final byte[] malformedFirmwareFile, final String partOfExceptionMessage, final String deviceIdentification) throws ProtocolAdapterException {
final FirmwareFile firmwareFile = new FirmwareFile(malformedFirmwareFile);
firmwareFile.setMbusDeviceIdentificationNumber(deviceIdentification.substring(7, 15));
final Exception exception = assertThrows(exceptionClass, () -> {
this.macGenerationService.calculateMac(messageMetadata, deviceIdentification, firmwareFile);
});
assertThat(exception).hasMessageContaining(partOfExceptionMessage);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method testNoKey.
@Test
void testNoKey() throws IOException, ProtocolAdapterException {
when(this.secretManagementService.getKey(messageMetadata, this.deviceIdentification1, SecurityKeyType.G_METER_FIRMWARE_UPDATE_AUTHENTICATION)).thenReturn(null);
final FirmwareFile firmwareFile = this.createFirmwareFile(byteArray1, this.deviceIdentification1.substring(7, 15));
final Exception exception = assertThrows(ProtocolAdapterException.class, () -> {
this.macGenerationService.calculateMac(messageMetadata, this.deviceIdentification1, firmwareFile);
});
assertThat(exception).hasMessageContaining("No key of type G_METER_FIRMWARE_UPDATE_AUTHENTICATION found for device");
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareCommandExecutor method getFirmwareFile.
private FirmwareFile getFirmwareFile(final UpdateFirmwareRequestDto updateFirmwareRequestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
log.debug("Getting firmware file from caching repository for firmware {}", updateFirmwareRequestDto.getFirmwareIdentification());
final byte[] firmwareFileByteArray = this.firmwareFileCachingRepository.retrieve(updateFirmwareRequestDto.getFirmwareIdentification());
if (firmwareFileByteArray == null) {
throw new ProtocolAdapterException(EXCEPTION_MSG_FIRMWARE_FILE_NOT_AVAILABLE);
}
final FirmwareFile firmwareFile = new FirmwareFile(firmwareFileByteArray);
if (firmwareFile.isMbusFirmware()) {
firmwareFile.checkLengths();
this.addMac(messageMetadata, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile);
}
return firmwareFile;
}
Aggregations