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);
}
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;
}
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);
}
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);
}
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();
}
Aggregations