use of org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret in project open-smart-grid-platform by OSGP.
the class SoapEndpointDataTypeConverter method convertToSoapTypedSecrets.
public TypedSecrets convertToSoapTypedSecrets(final List<TypedSecret> typedSecrets) {
final TypedSecrets soapTypedSecrets = new TypedSecrets();
final List<org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret> soapTypedSecretList = soapTypedSecrets.getTypedSecret();
for (final TypedSecret typedSecret : typedSecrets) {
final org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret soapTypedSecret = this.encryptAndConvertSoapTypedSecret(typedSecret);
soapTypedSecretList.add(soapTypedSecret);
}
return soapTypedSecrets;
}
use of org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method storeSecretsMultipleKeys.
@Test
public void storeSecretsMultipleKeys() {
final TypedSecret typedSecret = new TypedSecret("$3cr3t".getBytes(), SecretType.E_METER_MASTER_KEY);
when(this.keyRepository.findByTypeAndValid(any(), any())).thenReturn(Arrays.asList(new DbEncryptionKeyReference(), new DbEncryptionKeyReference()));
assertThatIllegalStateException().isThrownBy(() -> this.service.storeSecrets(SOME_DEVICE, Arrays.asList(typedSecret)));
}
use of org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method storeSecretsNoKey.
@Test
public void storeSecretsNoKey() {
final TypedSecret typedSecret = new TypedSecret("$3cr3t".getBytes(), SecretType.E_METER_MASTER_KEY);
when(this.keyRepository.findByTypeAndValid(any(), any())).thenReturn(Arrays.asList());
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> this.service.storeSecrets(SOME_DEVICE, Arrays.asList(typedSecret)));
}
use of org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method generateAndStoreSecrets.
@Test
public void generateAndStoreSecrets() throws EncrypterException {
final Date now = new Date();
final String reference = "1";
final byte[] aesSecret = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
final byte[] secret = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
final byte[] rsaSecret = { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
keyReference.setReference(reference);
keyReference.setEncryptionProviderType(ENCRYPTION_PROVIDER_TYPE);
keyReference.setValidFrom(now);
when(this.keyRepository.findByTypeAndValid(any(), any())).thenReturn(Arrays.asList(keyReference));
when(this.encryptionDelegate.generateAes128BitsSecret(ENCRYPTION_PROVIDER_TYPE, reference)).thenReturn(aesSecret);
when(this.encryptionDelegate.decrypt(any(), any())).thenReturn(secret);
when(this.encrypterForSecretManagementClient.encrypt(any())).thenReturn(rsaSecret);
final List<TypedSecret> secrets = this.service.generateAndStoreSecrets(SOME_DEVICE, Arrays.asList(SecretType.E_METER_AUTHENTICATION_KEY));
assertThat(secrets.size()).isEqualTo(1);
final TypedSecret typedSecret = secrets.get(0);
assertThat(typedSecret.getSecretType()).isEqualTo(SecretType.E_METER_AUTHENTICATION_KEY);
assertThat(typedSecret.getSecret()).isEqualTo(rsaSecret);
}
use of org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method storeSecrets.
@Test
public void storeSecrets() throws Exception {
final TypedSecret typedSecret = new TypedSecret("rsaSecret00000001".getBytes(), SecretType.E_METER_ENCRYPTION_KEY_UNICAST);
final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
keyReference.setEncryptionProviderType(ENCRYPTION_PROVIDER_TYPE);
keyReference.setReference("1");
final EncryptedSecret encryptedSecret = new EncryptedSecret(ENCRYPTION_PROVIDER_TYPE, "aesSecret0000001".getBytes());
when(this.keyRepository.findByTypeAndValid(any(), any())).thenReturn(Arrays.asList(keyReference));
when(this.keyRepository.findByTypeAndReference(ENCRYPTION_PROVIDER_TYPE, "1")).thenReturn(keyReference);
when(this.encryptionDelegate.encrypt(any(), any(), anyString())).thenReturn(encryptedSecret);
this.service.storeSecrets(SOME_DEVICE, Arrays.asList(typedSecret));
final ArgumentCaptor<List<DbEncryptedSecret>> secretListArgumentCaptor = this.getListOfDbEncryptedSecretsArgumentCaptor();
verify(this.secretRepository).saveAll(secretListArgumentCaptor.capture());
final List<DbEncryptedSecret> savedSecrets = secretListArgumentCaptor.getValue();
assertThat(savedSecrets).isNotNull();
assertThat(savedSecrets.size()).isEqualTo(1);
final DbEncryptedSecret savedSecret = savedSecrets.get(0);
assertThat(savedSecret.getDeviceIdentification()).isEqualTo(SOME_DEVICE);
assertThat(savedSecret.getSecretType()).isEqualTo(typedSecret.getSecretType());
assertThat(savedSecret.getEncodedSecret()).isEqualTo(HexUtils.toHexString(encryptedSecret.getSecret()));
assertThat(savedSecret.getEncryptionKeyReference()).isEqualTo(keyReference);
assertThat(savedSecret.getCreationTime()).isNotNull();
}
Aggregations