Search in sources :

Example 6 with SetKeysRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.

the class AbstractReplaceKeyCommandExecutor method decryptRsaKeys.

private SetKeysRequestDto decryptRsaKeys(final SetKeysRequestDto setKeysRequestDto) throws FunctionalException {
    try {
        final byte[] authenticationKey = this.decrypterForGxfSmartMetering.decrypt(setKeysRequestDto.getAuthenticationKey());
        final byte[] encryptionKey = this.decrypterForGxfSmartMetering.decrypt(setKeysRequestDto.getEncryptionKey());
        return new SetKeysRequestDto(authenticationKey, encryptionKey);
    } catch (final EncrypterException e) {
        throw new FunctionalException(FunctionalExceptionType.DECRYPTION_EXCEPTION, ComponentType.PROTOCOL_DLMS, e);
    }
}
Also used : SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto) EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 7 with SetKeysRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.

the class SetKeysRequestMappingTest method testWithNullArrays.

// To test mapping when arrays are null
@Test
public void testWithNullArrays() {
    // build test data
    final byte[] authenthicationKey = null;
    final byte[] encryptionKey = null;
    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()).isNull();
    assertThat(keySetDto.getEncryptionKey()).isNull();
}
Also used : SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto) SetKeysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetKeysRequestData) Test(org.junit.jupiter.api.Test)

Example 8 with SetKeysRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.

the class SetKeysRequestMappingTest method testWithArrays.

// To test mapping when arrays hold a value
@Test
public void testWithArrays() {
    // build test data
    final byte[] authenthicationKey = { 1 };
    final byte[] encryptionKey = { 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);
    assertThat(keySetDto.getAuthenticationKey()[0]).isEqualTo(keySet.getAuthenticationKey()[0]);
    assertThat(keySetDto.getEncryptionKey()[0]).isEqualTo(keySet.getEncryptionKey()[0]);
}
Also used : SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto) SetKeysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetKeysRequestData) Test(org.junit.jupiter.api.Test)

Example 9 with SetKeysRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto in project open-smart-grid-platform by OSGP.

the class ReplaceKeysRequestMessageProcessor method handleMessage.

@Override
protected Serializable handleMessage(final DlmsConnectionManager conn, final DlmsDevice device, final Serializable requestObject, final MessageMetadata messageMetadata) throws OsgpException {
    this.assertRequestObjectType(SetKeysRequestDto.class, requestObject);
    final SetKeysRequestDto keySet = (SetKeysRequestDto) requestObject;
    this.configurationService.replaceKeys(conn, device, keySet, messageMetadata);
    return null;
}
Also used : SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto)

Aggregations

SetKeysRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto)9 Test (org.junit.jupiter.api.Test)3 SetKeysRequestData (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetKeysRequestData)3 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)1 SecurityKeyType (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)1 DeviceKeyProcessAlreadyRunningException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException)1 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)1 ActionResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto)1