use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysResponseDto in project open-smart-grid-platform by OSGP.
the class GetKeysServiceTest method getKeysWithoutKeyTypes.
@Test
void getKeysWithoutKeyTypes() {
final GetKeysRequestDto request = new GetKeysRequestDto(Collections.emptyList());
final GetKeysResponseDto response = this.getKeysService.getKeys(DEVICE, request, messageMetadata);
assertThat(response).isNotNull();
assertThat(response.getKeys()).isEmpty();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysResponseDto in project open-smart-grid-platform by OSGP.
the class GetKeysServiceTest method getKeys.
@Test
void getKeys() {
final Map<SecurityKeyType, byte[]> keys = new EnumMap<>(SecurityKeyType.class);
keys.put(SecurityKeyType.E_METER_MASTER, KEY_1_UNENCRYPTED);
keys.put(SecurityKeyType.E_METER_AUTHENTICATION, KEY_2_UNENCRYPTED);
when(this.secretManagementService.getKeys(messageMetadata, DEVICE_ID, Arrays.asList(SecurityKeyType.E_METER_MASTER, SecurityKeyType.E_METER_AUTHENTICATION))).thenReturn(keys);
when(this.rsaEncrypter.encrypt(KEY_1_UNENCRYPTED)).thenReturn(KEY_1_ENCRYPTED);
when(this.rsaEncrypter.encrypt(KEY_2_UNENCRYPTED)).thenReturn(KEY_2_ENCRYPTED);
final GetKeysResponseDto response = this.getKeysService.getKeys(DEVICE, REQUEST, messageMetadata);
final GetKeysResponseDto expectedResponse = new GetKeysResponseDto(Arrays.asList(new KeyDto(SecretTypeDto.E_METER_MASTER_KEY, KEY_1_ENCRYPTED), new KeyDto(SecretTypeDto.E_METER_AUTHENTICATION_KEY, KEY_2_ENCRYPTED)));
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysResponseDto in project open-smart-grid-platform by OSGP.
the class ConfigurationService method handleGetKeysResponse.
public void handleGetKeysResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType resultType, final OsgpException exception, final GetKeysResponseDto getKeysResponseDto) {
log.info("handleGetKeysResponse for MessageType: {}", messageMetadata.getMessageType());
final List<KeyDto> keys = getKeysResponseDto.getKeys();
final List<GetKeysResponseData> getKeysResponseData = keys.stream().map(key -> new GetKeysResponseData(SecretType.valueOf(key.getSecretType().name()), key.getSecret())).collect(Collectors.toList());
final GetKeysResponse getKeysResponse = new GetKeysResponse(getKeysResponseData);
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(resultType).withOsgpException(exception).withDataObject(getKeysResponse).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysResponseDto in project open-smart-grid-platform by OSGP.
the class GetKeysServiceTest method getKeysWhenKeyNotFound.
@Test
void getKeysWhenKeyNotFound() {
final Map<SecurityKeyType, byte[]> keys = new EnumMap<>(SecurityKeyType.class);
keys.put(SecurityKeyType.E_METER_MASTER, KEY_1_UNENCRYPTED);
keys.put(SecurityKeyType.E_METER_AUTHENTICATION, null);
when(this.secretManagementService.getKeys(messageMetadata, DEVICE_ID, Arrays.asList(SecurityKeyType.E_METER_MASTER, SecurityKeyType.E_METER_AUTHENTICATION))).thenReturn(keys);
when(this.rsaEncrypter.encrypt(KEY_1_UNENCRYPTED)).thenReturn(KEY_1_ENCRYPTED);
final GetKeysResponseDto response = this.getKeysService.getKeys(DEVICE, REQUEST, messageMetadata);
final GetKeysResponseDto expectedResponse = new GetKeysResponseDto(Arrays.asList(new KeyDto(SecretTypeDto.E_METER_MASTER_KEY, KEY_1_ENCRYPTED), new KeyDto(SecretTypeDto.E_METER_AUTHENTICATION_KEY, null)));
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}
Aggregations