use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method retrieveSecretsDecryptionError.
@Test
public void retrieveSecretsDecryptionError() throws EncrypterException {
final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
keyReference.setEncryptionProviderType(ENCRYPTION_PROVIDER_TYPE);
keyReference.setReference("1");
final DbEncryptedSecret secret = new DbEncryptedSecret();
secret.setSecretType(SecretType.E_METER_MASTER_KEY);
secret.setEncryptionKeyReference(keyReference);
secret.setEncodedSecret("0123456789ABCDEF0123456789ABCDEF");
final List<DbEncryptedSecret> secretPage = Arrays.asList(secret);
when(this.secretRepository.findSecrets(SOME_DEVICE, SecretType.E_METER_MASTER_KEY, SecretStatus.ACTIVE)).thenReturn(secretPage);
when(this.encryptionDelegate.decrypt(any(), any())).thenThrow(new EncrypterException("Decryption error"));
assertThatIllegalStateException().isThrownBy(() -> this.service.retrieveSecrets(SOME_DEVICE, Arrays.asList(SecretType.E_METER_MASTER_KEY)));
}
use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementService method createDbEncrypted.
private DbEncryptedSecret createDbEncrypted(final String deviceIdentification, final EncryptedTypedSecret secret, final DbEncryptionKeyReference keyReference) {
final Date now = new Date();
final DbEncryptedSecret dbEncryptedSecret = new DbEncryptedSecret();
dbEncryptedSecret.setDeviceIdentification(deviceIdentification);
dbEncryptedSecret.setEncodedSecret(HexUtils.toHexString(secret.encryptedSecret));
dbEncryptedSecret.setSecretType(secret.type);
dbEncryptedSecret.setSecretStatus(SecretStatus.NEW);
dbEncryptedSecret.setEncryptionKeyReference(keyReference);
dbEncryptedSecret.setCreationTime(now);
return dbEncryptedSecret;
}
use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementService method withdrawExistingKeysWithStatusNew.
private void withdrawExistingKeysWithStatusNew(final String deviceIdentification, final SecretType secretType) {
// All NEW keys of the device and type are set to status WITHDRAWN.
final List<DbEncryptedSecret> foundSecrets = this.secretRepository.findSecrets(deviceIdentification, secretType, SecretStatus.NEW);
for (final DbEncryptedSecret foundSecret : foundSecrets) {
foundSecret.setSecretStatus(SecretStatus.WITHDRAWN);
this.secretRepository.save(foundSecret);
log.warn(String.format("During (GenerateOr)Replace Key Process one or more keys with status NEW of type %s for " + "device %s have been found. These keys will be withdrawn (status WITHDRAWN)", secretType.name(), deviceIdentification));
}
}
use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.
the class SoapServiceSecretManagementIT method generateAndStoreSecrets.
@Test
public void generateAndStoreSecrets() throws IOException {
final Resource generateAndStoreRequest = new ClassPathResource("test-requests/generateAndStoreSecrets.xml");
this.mockWebServiceClient.sendRequest(withSoapEnvelope(generateAndStoreRequest)).andExpect(ResponseMatchers.noFault()).andExpect((request, response) -> {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
response.writeTo(outputStream);
assertThat(outputStream.toString()).contains("Result>OK");
});
final List<DbEncryptedSecret> authKeys = this.secretRepository.findSecrets(DEVICE_IDENTIFICATION, SecretType.E_METER_AUTHENTICATION_KEY, SecretStatus.NEW);
assertThat(authKeys).hasSize(1);
final DbEncryptedSecret authKey = authKeys.get(0);
assertThat(authKey.getEncodedSecret()).hasSize(64);
}
use of org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret in project open-smart-grid-platform by OSGP.
the class SoapServiceSecretManagementIT method createTestData.
/**
* Create test data for encrypted secrets and related encryptionkey reference(s). So that the
* EncryptionService can encrypt and decrypt, using the JRE encryption provider.
*
* <p>Two secrets (for two types of meter key secrets) and one reference key (valid as of
* now-1minute) is created.
*/
private void createTestData() {
final DbEncryptionKeyReference encryptionKey = new DbEncryptionKeyReference();
encryptionKey.setCreationTime(new Date());
encryptionKey.setReference("1");
encryptionKey.setEncryptionProviderType(EncryptionProviderType.JRE);
encryptionKey.setValidFrom(new Date(System.currentTimeMillis() - 60000));
encryptionKey.setVersion(1L);
this.testEntityManager.persist(encryptionKey);
final DbEncryptedSecret encryptedSecret = new DbEncryptedSecret();
encryptedSecret.setCreationTime(new Date());
encryptedSecret.setDeviceIdentification(DEVICE_IDENTIFICATION);
encryptedSecret.setSecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType.E_METER_AUTHENTICATION_KEY);
encryptedSecret.setEncodedSecret(E_METER_AUTHENTICATION_KEY_ENCRYPTED_FOR_DB);
encryptedSecret.setSecretStatus(SecretStatus.ACTIVE);
encryptedSecret.setEncryptionKeyReference(encryptionKey);
this.testEntityManager.persist(encryptedSecret);
final DbEncryptedSecret encryptedSecret2 = new DbEncryptedSecret();
encryptedSecret2.setCreationTime(new Date());
encryptedSecret2.setDeviceIdentification(DEVICE_IDENTIFICATION);
encryptedSecret2.setSecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType.E_METER_ENCRYPTION_KEY_UNICAST);
encryptedSecret2.setEncodedSecret(E_METER_ENCRYPTION_KEY_UNICAST_ENCRYPTED_FOR_DB);
encryptedSecret2.setSecretStatus(SecretStatus.ACTIVE);
encryptedSecret2.setEncryptionKeyReference(encryptionKey);
this.testEntityManager.persist(encryptedSecret2);
this.testEntityManager.flush();
}
Aggregations