use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.
the class ConfigurationService method replaceKeys.
public void replaceKeys(final MessageMetadata messageMetadata, final SetKeysRequestData keySet) throws FunctionalException {
log.info("replaceKeys for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
final SetKeysRequestDto requestDto = this.configurationMapper.map(keySet, SetKeysRequestDto.class);
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.
the class SetKeysRequestMappingTest method testWithEmptyArrays.
// To test mapping when arrays are empty
@Test
public void testWithEmptyArrays() {
// build test data
final byte[] authenthicationKey = new byte[1];
final byte[] encryptionKey = new byte[1];
final SetKeysRequestData keySet = new SetKeysRequestData(authenthicationKey, encryptionKey);
// actual mapping
final SetKeysRequestDto keySetDto = this.configurationMapper.map(keySet, SetKeysRequestDto.class);
// check if mapping succeeded
assertThat(keySetDto).isNotNull();
assertThat(keySetDto.getAuthenticationKey()).isNotNull();
assertThat(keySetDto.getEncryptionKey()).isNotNull();
assertThat(keySetDto.getAuthenticationKey().length).isEqualTo(keySet.getAuthenticationKey().length);
assertThat(keySet.getEncryptionKey().length).isEqualTo(keySetDto.getEncryptionKey().length);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.
the class AbstractReplaceKeyCommandExecutor method replaceKeys.
protected ActionResponseDto replaceKeys(final DlmsConnectionManager conn, final DlmsDevice device, final SetKeysRequestDto setKeysRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
log.info("Keys set on device :{}", device.getDeviceIdentification());
SetKeysRequestDto setDecryptedKeysRequestDto = setKeysRequestDto;
if (!setKeysRequestDto.isGeneratedKeys()) {
setDecryptedKeysRequestDto = this.decryptRsaKeys(setKeysRequestDto);
}
// if keys are generated, then they are unencrypted by the GenerateAndReplaceKeyCommandExecutor
final DlmsDevice devicePostSave = this.storeAndSendToDevice(conn, device, wrap(setDecryptedKeysRequestDto.getAuthenticationKey(), KeyId.AUTHENTICATION_KEY, SecurityKeyType.E_METER_AUTHENTICATION, setDecryptedKeysRequestDto.isGeneratedKeys()), messageMetadata);
this.storeAndSendToDevice(conn, devicePostSave, wrap(setDecryptedKeysRequestDto.getEncryptionKey(), KeyId.GLOBAL_UNICAST_ENCRYPTION_KEY, SecurityKeyType.E_METER_ENCRYPTION, setDecryptedKeysRequestDto.isGeneratedKeys()), messageMetadata);
return new ActionResponseDto(String.format("Replace keys for device %s was successful", device.getDeviceIdentification()));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.
the class GenerateAndReplaceKeyCommandExecutor method execute.
@Override
public ActionResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final GenerateAndReplaceKeysRequestDataDto actionRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
try {
this.deviceKeyProcessingService.startProcessing(messageMetadata.getDeviceIdentification());
} catch (final DeviceKeyProcessAlreadyRunningException e) {
// This exception will be caught in the DeviceRequestMessageProcessor.
// The request will NOT be sent back to Core to retry but put back on the queue
LOGGER.info("Key changing process already running on device :{}", device.getDeviceIdentification());
throw e;
}
try {
LOGGER.info("Generate new keys for device {}", device.getDeviceIdentification());
final SetKeysRequestDto setKeysRequest = this.generateSetKeysRequest(messageMetadata, device.getDeviceIdentification());
return this.replaceKeys(conn, device, setKeysRequest, messageMetadata);
} finally {
this.deviceKeyProcessingService.stopProcessing(messageMetadata.getDeviceIdentification());
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.
the class GenerateAndReplaceKeyCommandExecutor method generateSetKeysRequest.
private SetKeysRequestDto generateSetKeysRequest(final MessageMetadata messageMetadata, final String deviceIdentification) throws FunctionalException {
try {
final List<SecurityKeyType> keyTypes = Arrays.asList(E_METER_AUTHENTICATION, E_METER_ENCRYPTION);
final Map<SecurityKeyType, byte[]> generatedKeys = this.secretManagementService.generate128BitsKeysAndStoreAsNewKeys(messageMetadata, deviceIdentification, keyTypes);
final SetKeysRequestDto setKeysRequest = new SetKeysRequestDto(generatedKeys.get(E_METER_AUTHENTICATION), generatedKeys.get(E_METER_ENCRYPTION));
setKeysRequest.setGeneratedKeys(true);
return setKeysRequest;
} catch (final EncrypterException e) {
throw new FunctionalException(FunctionalExceptionType.ENCRYPTION_EXCEPTION, ComponentType.PROTOCOL_DLMS, e);
}
}
Aggregations