Search in sources :

Example 1 with DbEncryptedSecret

use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.

the class DlmsDeviceSteps method aValidMbusUserKeyIsStored.

@Then("^a valid m-bus user key is stored$")
public void aValidMbusUserKeyIsStored(final Map<String, String> settings) {
    final String keyDeviceIdentification = PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION;
    final String deviceIdentification = settings.get(keyDeviceIdentification);
    assertThat(deviceIdentification).as("The M-Bus device identification must be in the step data for key " + keyDeviceIdentification).isNotNull();
    final String deviceDescription = "M-Bus device with identification " + deviceIdentification;
    final DlmsDevice dlmsDevice = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
    assertThat(dlmsDevice).as(deviceDescription + " must be in the protocol database").isNotNull();
    final List<DbEncryptedSecret> securityKeys = this.findAllSecretsForDevice(deviceIdentification);
    int numberOfMbusDefaultKeys = 0;
    int numberOfMbusUserKeys = 0;
    int numberOfValidMbusUserKeys = 0;
    for (final DbEncryptedSecret securityKey : securityKeys) {
        switch(securityKey.getSecretType()) {
            case G_METER_MASTER_KEY:
                numberOfMbusDefaultKeys += 1;
                break;
            case G_METER_ENCRYPTION_KEY:
                numberOfMbusUserKeys += 1;
                if (securityKey.getSecretStatus().equals(SecretStatus.ACTIVE)) {
                    numberOfValidMbusUserKeys += 1;
                }
                break;
            default:
        }
    }
    assertThat(numberOfMbusDefaultKeys).as("Number of M-Bus Default keys stored").isEqualTo(1);
    assertThat(numberOfMbusUserKeys > 0).as("At least one M-Bus User key must be stored").isTrue();
    assertThat(numberOfValidMbusUserKeys).as("Number of valid M-Bus User keys stored").isEqualTo(1);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) Then(io.cucumber.java.en.Then)

Example 2 with DbEncryptedSecret

use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.

the class DlmsDeviceSteps method findExistingSecurityKey.

private DbEncryptedSecret findExistingSecurityKey(final DlmsDevice dlmsDevice, final SecretType secretType, final String keyDescription) {
    final List<DbEncryptedSecret> validSecrets = this.encryptedSecretRepository.findSecrets(dlmsDevice.getDeviceIdentification(), secretType, SecretStatus.ACTIVE);
    assertThat(validSecrets.size()).isEqualTo(1).as("Device %s should have 1 active secret of type %s, but found %s", dlmsDevice.getDeviceIdentification(), secretType, validSecrets.size());
    final DbEncryptedSecret secret = validSecrets.get(0);
    assertThat(secret).as(keyDescription + " for DLMS device with identification " + dlmsDevice.getDeviceIdentification() + " must be stored").isNotNull();
    return secret;
}
Also used : DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret)

Example 3 with DbEncryptedSecret

use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.

the class DlmsDeviceSteps method theKeysAreNotChangedInTheSecretManagementDatabaseEncryptedSecretTable.

@Then("^the keys are not changed in the secret management database encrypted_secret table$")
public void theKeysAreNotChangedInTheSecretManagementDatabaseEncryptedSecretTable() {
    final String keyDeviceIdentification = PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION;
    final String deviceIdentification = (String) ScenarioContext.current().get(keyDeviceIdentification);
    assertThat(deviceIdentification).as("Device identification must be in the scenario context for key " + keyDeviceIdentification).isNotNull();
    final List<DbEncryptedSecret> securityKeys = this.findAllSecretsForDevice(deviceIdentification);
    /*
     * If the keys are not changed, the device should only have valid keys.
     * There should be 1 master key and one authentication and encryption
     * key.
     */
    int numberOfMasterKeys = 0;
    int numberOfAuthenticationKeys = 0;
    int numberOfEncryptionKeys = 0;
    for (final DbEncryptedSecret securityKey : securityKeys) {
        switch(securityKey.getSecretType()) {
            case E_METER_MASTER_KEY:
                numberOfMasterKeys += 1;
                break;
            case E_METER_AUTHENTICATION_KEY:
                numberOfAuthenticationKeys += 1;
                break;
            case E_METER_ENCRYPTION_KEY_UNICAST:
                numberOfEncryptionKeys += 1;
                break;
            default:
        }
        assertThat(securityKey.getSecretStatus()).as("security key " + securityKey.getSecretType() + " is active").isEqualTo(SecretStatus.ACTIVE);
    }
    assertThat(numberOfMasterKeys).as("Number of master keys").isEqualTo(1);
    assertThat(numberOfAuthenticationKeys).as("Number of authentication keys").isEqualTo(1);
    assertThat(numberOfEncryptionKeys).as("Number of encryption keys").isEqualTo(1);
}
Also used : DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) Then(io.cucumber.java.en.Then)

Example 4 with DbEncryptedSecret

use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.

the class DlmsDeviceSteps method theStoredMbusDefaultKeysIsNotEqualToTheReceivedKey.

@Then("^the stored M-Bus Default key is not equal to the received key$")
public void theStoredMbusDefaultKeysIsNotEqualToTheReceivedKey() {
    final String keyDeviceIdentification = PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION;
    final String deviceIdentification = (String) ScenarioContext.current().get(keyDeviceIdentification);
    assertThat(deviceIdentification).as("Device identification must be in the scenario context for key " + keyDeviceIdentification).isNotNull();
    final String deviceDescription = "DLMS device with identification " + deviceIdentification;
    final DlmsDevice dlmsDevice = this.findExistingDlmsDevice(deviceIdentification);
    final DbEncryptedSecret mbusDefaultKey = this.findExistingSecurityKey(dlmsDevice, G_METER_MASTER_KEY, "M-Bus Default key");
    final String receivedMbusDefaultKey = (String) ScenarioContext.current().get(PlatformSmartmeteringKeys.MBUS_DEFAULT_KEY);
    assertThat(mbusDefaultKey.getEncodedSecret()).as("Stored M-Bus Default key for " + deviceDescription + " must be different from received key").isNotEqualTo(receivedMbusDefaultKey);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) Then(io.cucumber.java.en.Then)

Example 5 with DbEncryptedSecret

use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.

the class DlmsDeviceSteps method theNewKeysAreStoredInTheSecretManagementDatabaseEncryptedSecretTable.

public void theNewKeysAreStoredInTheSecretManagementDatabaseEncryptedSecretTable() {
    final String keyDeviceIdentification = PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION;
    final String deviceIdentification = (String) ScenarioContext.current().get(keyDeviceIdentification);
    assertThat(deviceIdentification).as("Device identification must be in the scenario context for key " + keyDeviceIdentification).isNotNull();
    final List<DbEncryptedSecret> securityKeys = this.findAllSecretsForDevice(deviceIdentification);
    /*
     * If the new keys are stored, the device should have some no longer
     * valid keys. There should be 1 master key and more than one
     * authentication and encryption keys.
     */
    int numberOfMasterKeys = 0;
    int numberOfAuthenticationKeys = 0;
    int numberOfEncryptionKeys = 0;
    for (final DbEncryptedSecret securityKey : securityKeys) {
        switch(securityKey.getSecretType()) {
            case E_METER_MASTER_KEY:
                numberOfMasterKeys += 1;
                break;
            case E_METER_AUTHENTICATION_KEY:
                numberOfAuthenticationKeys += 1;
                break;
            case E_METER_ENCRYPTION_KEY_UNICAST:
                numberOfEncryptionKeys += 1;
                break;
            default:
        }
    }
    assertThat(numberOfMasterKeys).as("Number of master keys").isEqualTo(1);
    assertThat(numberOfAuthenticationKeys > 1).as("Number of authentication keys > 1").isTrue();
    assertThat(numberOfEncryptionKeys > 1).as("Number of encryption keys > 1").isTrue();
}
Also used : DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret)

Aggregations

DbEncryptedSecret (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret)29 DbEncryptionKeyReference (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference)13 Test (org.junit.jupiter.api.Test)12 Date (java.util.Date)11 Then (io.cucumber.java.en.Then)5 SecretType (org.opensmartgridplatform.secretmanagement.application.domain.SecretType)5 List (java.util.List)4 TypedSecret (org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)4 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)3 EncryptedSecret (org.opensmartgridplatform.shared.security.EncryptedSecret)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SecretBuilder (org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.SecretBuilder)2 Given (io.cucumber.java.en.Given)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1