Search in sources :

Example 1 with SecurityKeyType

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);
    }
}
Also used : SecretBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.SecretBuilder) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)

Example 2 with SecurityKeyType

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);
}
Also used : FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) EnumMap(java.util.EnumMap) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) NoSuchElementException(java.util.NoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with SecurityKeyType

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);
}
Also used : GenerateAndStoreSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse) TypedSecrets(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) Test(org.junit.jupiter.api.Test)

Example 4 with SecurityKeyType

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());
}
Also used : ActivateSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.ActivateSecretsRequest) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) Test(org.junit.jupiter.api.Test)

Example 5 with SecurityKeyType

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);
}
Also used : GetSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse) GetSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsRequest) TypedSecrets(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityKeyType (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)13 Test (org.junit.jupiter.api.Test)6 EnumMap (java.util.EnumMap)4 GenerateAndStoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse)4 TypedSecrets (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets)4 TypedSecret (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret)3 GetKeysResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysResponseDto)2 KeyDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.KeyDto)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 GenerateAndStoreSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsRequest)2 GetSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsRequest)2 GetSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse)2 StoreSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsRequest)2 StoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 SecuritySuite (org.openmuc.jdlms.SecuritySuite)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1