Search in sources :

Example 11 with TypedSecret

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;
}
Also used : TypedSecrets(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)

Example 12 with TypedSecret

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)));
}
Also used : DbEncryptionKeyReference(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret) Test(org.junit.jupiter.api.Test)

Example 13 with 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)));
}
Also used : TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test)

Example 14 with 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);
}
Also used : DbEncryptionKeyReference(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 15 with TypedSecret

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();
}
Also used : DbEncryptionKeyReference(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) List(java.util.List) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret) EncryptedSecret(org.opensmartgridplatform.shared.security.EncryptedSecret) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) Test(org.junit.jupiter.api.Test)

Aggregations

TypedSecret (org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)15 Test (org.junit.jupiter.api.Test)8 DbEncryptionKeyReference (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference)7 DbEncryptedSecret (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret)4 SecretType (org.opensmartgridplatform.secretmanagement.application.domain.SecretType)4 TypedSecrets (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets)4 List (java.util.List)3 EncryptedSecret (org.opensmartgridplatform.shared.security.EncryptedSecret)3 SecretTypes (org.opensmartgridplatform.ws.schema.core.secret.management.SecretTypes)3 Date (java.util.Date)2 GenerateAndStoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse)2 NoSuchElementException (java.util.NoSuchElementException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)1 GetNewSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse)1 GetSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse)1 StoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.StoreSecretsResponse)1