use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType in project open-smart-grid-platform by OSGP.
the class DlmsDeviceSteps method getAppropriateSecretBuilder.
private SecretBuilder getAppropriateSecretBuilder(final String keyTypeInputName, final Map<String, String> inputSettings) {
final SecurityKeyType keyType = this.securityKeyTypesByInputName.get(keyTypeInputName);
if (keyType == null) {
throw new IllegalArgumentException(String.format("Unknown key type name %s; available types names: %s", keyTypeInputName, this.securityKeyTypesByInputName.keySet()));
}
if (inputSettings.containsKey(keyTypeInputName)) {
final String inputKeyName = inputSettings.get(keyTypeInputName);
final String dbEncryptedKey = SecurityKey.valueOf(inputKeyName).getDatabaseKey();
if (dbEncryptedKey != null && !dbEncryptedKey.trim().isEmpty()) {
return new SecretBuilder().withSecurityKeyType(keyType).withKey(dbEncryptedKey);
} else {
// secret storing
return null;
}
} else {
return this.getDefaultSecretBuilder(keyType);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType in project open-smart-grid-platform by OSGP.
the class InstallationService method storeAndActivateKeys.
private void storeAndActivateKeys(final MessageMetadata messageMetadata, final SmartMeteringDeviceDto deviceDto) throws FunctionalException {
final Map<SecurityKeyType, byte[]> keysByType = new EnumMap<>(SecurityKeyType.class);
final List<SecurityKeyType> keyTypesToStore = this.determineKeyTypesToStore(deviceDto);
for (final SecurityKeyType keyType : keyTypesToStore) {
final byte[] key = this.getKeyFromDeviceDto(deviceDto, keyType);
if (ArrayUtils.isNotEmpty(key)) {
keysByType.put(keyType, this.decrypterForGxfSmartMetering.decrypt(key));
} else {
final Exception rootCause = new NoSuchElementException(keyType.name());
throw new FunctionalException(FunctionalExceptionType.KEY_NOT_PRESENT, ComponentType.PROTOCOL_DLMS, rootCause);
}
}
this.secretManagementService.storeNewKeys(messageMetadata, deviceDto.getDeviceIdentification(), keysByType);
this.secretManagementService.activateNewKeys(messageMetadata, deviceDto.getDeviceIdentification(), keyTypesToStore);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method testGenerateAndStoreKeys.
@Test
public void testGenerateAndStoreKeys() {
final List<SecurityKeyType> keyTypes = Arrays.asList(KEY_TYPE);
final GenerateAndStoreSecretsResponse response = new GenerateAndStoreSecretsResponse();
response.setResult(OsgpResultType.OK);
response.setTypedSecrets(new TypedSecrets());
response.getTypedSecrets().getTypedSecret().add(TYPED_SECRET);
when(this.secretManagementClient.generateAndStoreSecrets(same(messageMetadata), any())).thenReturn(response);
when(this.decrypterForProtocolAdapterDlms.decrypt(SOAP_SECRET)).thenReturn(UNENCRYPTED_SECRET);
// EXECUTE
final Map<SecurityKeyType, byte[]> keys = this.secretManagementTestService.generate128BitsKeysAndStoreAsNewKeys(messageMetadata, DEVICE_IDENTIFICATION, keyTypes);
// ASSERT
assertThat(keys.get(KEY_TYPE)).isEqualTo(UNENCRYPTED_SECRET);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method testActivateKeys.
@Test
public void testActivateKeys() throws ProtocolAdapterException {
final List<SecurityKeyType> keyTypes = Arrays.asList(KEY_TYPE);
final ArgumentCaptor<ActivateSecretsRequest> activateSecretsCaptor = ArgumentCaptor.forClass(ActivateSecretsRequest.class);
// EXECUTE
this.secretManagementTestService.activateNewKeys(messageMetadata, DEVICE_IDENTIFICATION, keyTypes);
// ASSERT
verify(this.secretManagementClient).activateSecretsRequest(same(messageMetadata), activateSecretsCaptor.capture());
final ActivateSecretsRequest capturedArgument = activateSecretsCaptor.getValue();
assertThat(capturedArgument.getDeviceId()).isEqualTo(DEVICE_IDENTIFICATION);
assertThat(capturedArgument.getSecretTypes().getSecretType().get(0)).isEqualTo(KEY_TYPE.toSecretType());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method testGetKeys.
@Test
public void testGetKeys() {
// SETUP
final List<SecurityKeyType> keyTypes = Arrays.asList(KEY_TYPE);
final GetSecretsResponse response = new GetSecretsResponse();
response.setResult(OsgpResultType.OK);
response.setTypedSecrets(new TypedSecrets());
response.getTypedSecrets().getTypedSecret().add(TYPED_SECRET);
when(this.secretManagementClient.getSecretsRequest(same(messageMetadata), any(GetSecretsRequest.class))).thenReturn(response);
when(this.decrypterForProtocolAdapterDlms.decrypt(SOAP_SECRET)).thenReturn(UNENCRYPTED_SECRET);
// EXECUTE
final Map<SecurityKeyType, byte[]> result = this.secretManagementTestService.getKeys(messageMetadata, DEVICE_IDENTIFICATION, keyTypes);
// ASSERT
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(1);
assertThat(result.keySet().iterator().next()).isEqualTo(KEY_TYPE);
assertThat(result.values().iterator().next()).isEqualTo(UNENCRYPTED_SECRET);
}
Aggregations