Search in sources :

Example 1 with SecretType

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

the class SoapEndpointDataTypeConverter method encryptAndConvertSoapTypedSecret.

private org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret encryptAndConvertSoapTypedSecret(final TypedSecret typedSecret) {
    final org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret soapTypedSecret = new org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret();
    final byte[] rsaSecret = typedSecret.getSecret();
    soapTypedSecret.setSecret(HexUtils.toHexString(rsaSecret));
    final SecretType secretType = typedSecret.getSecretType();
    soapTypedSecret.setType(this.convertToSoapSecretType(secretType));
    return soapTypedSecret;
}
Also used : SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)

Example 2 with SecretType

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

the class SecretManagementServiceTest method generateAndStoreSecretWhenNewSecretAlreadyExists.

@Test
public void generateAndStoreSecretWhenNewSecretAlreadyExists() throws Exception {
    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 DbEncryptedSecret dbEncryptedSecret = this.getSecret(SecretType.E_METER_ENCRYPTION_KEY_UNICAST, 100);
    final Date originalCreationTime = dbEncryptedSecret.getCreationTime();
    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.secretRepository.findSecrets(SOME_DEVICE, SecretType.E_METER_ENCRYPTION_KEY_UNICAST, SecretStatus.NEW)).thenReturn(Arrays.asList(dbEncryptedSecret));
    when(this.encryptionDelegate.decrypt(any(), any())).thenReturn(secret);
    when(this.encrypterForSecretManagementClient.encrypt(any())).thenReturn(rsaSecret);
    final SecretType secretType = SecretType.E_METER_ENCRYPTION_KEY_UNICAST;
    this.service.generateAndStoreSecrets(SOME_DEVICE, Arrays.asList(secretType));
    final List<DbEncryptedSecret> foundSecrets = this.secretRepository.findSecrets(SOME_DEVICE, SecretType.E_METER_ENCRYPTION_KEY_UNICAST, SecretStatus.NEW);
    assertThat(foundSecrets).hasSize(1);
    verify(this.secretRepository, never()).saveAll(Arrays.asList(dbEncryptedSecret));
    assertThat(dbEncryptedSecret.getCreationTime()).isEqualTo(originalCreationTime);
    assertThat(dbEncryptedSecret.getSecretStatus()).isEqualTo(SecretStatus.WITHDRAWN);
}
Also used : DbEncryptionKeyReference(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference) SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with SecretType

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

the class SecretManagementEndpoint method hasNewSecret.

public HasNewSecretResponse hasNewSecret(final HasNewSecretRequest request) {
    final SecretType type = this.converter.convertToSecretType(request.getSecretType());
    final boolean result = this.secretManagementService.hasNewSecret(request.getDeviceId(), type);
    final HasNewSecretResponse response = new HasNewSecretResponse();
    response.setHasNewSecret(result);
    return response;
}
Also used : SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType) HasNewSecretResponse(org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse)

Example 4 with SecretType

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

the class SecretManagementService method generateAndStoreSecrets.

public synchronized List<TypedSecret> generateAndStoreSecrets(final String deviceIdentification, final List<SecretType> secretTypes) {
    for (final SecretType secretType : secretTypes) {
        this.withdrawExistingKeysWithStatusNew(deviceIdentification, secretType);
    }
    final List<EncryptedTypedSecret> encryptedTypedSecrets = secretTypes.stream().map(this::generateAes128BitsSecret).collect(Collectors.toList());
    this.storeAesSecrets(deviceIdentification, encryptedTypedSecrets);
    return encryptedTypedSecrets.stream().map(this::reencryptAes2Rsa).map(EncryptedTypedSecret::toTypedSecret).collect(Collectors.toList());
}
Also used : SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType)

Example 5 with SecretType

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

the class SecretManagementEndpoint method generateAndStoreSecrets.

public GenerateAndStoreSecretsResponse generateAndStoreSecrets(final GenerateAndStoreSecretsRequest request) throws OsgpException {
    final GenerateAndStoreSecretsResponse response = new GenerateAndStoreSecretsResponse();
    final SecretTypes soapSecretTypes = request.getSecretTypes();
    final List<SecretType> secretTypeList = this.converter.convertToSecretTypes(soapSecretTypes);
    final List<TypedSecret> typedSecretList = this.secretManagementService.generateAndStoreSecrets(request.getDeviceId(), secretTypeList);
    response.setTypedSecrets(this.converter.convertToSoapTypedSecrets(typedSecretList));
    return response;
}
Also used : GenerateAndStoreSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse) SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType) SecretTypes(org.opensmartgridplatform.ws.schema.core.secret.management.SecretTypes) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)

Aggregations

SecretType (org.opensmartgridplatform.secretmanagement.application.domain.SecretType)11 DbEncryptedSecret (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret)5 Date (java.util.Date)4 DbEncryptionKeyReference (org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptionKeyReference)4 TypedSecret (org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)4 SecretTypes (org.opensmartgridplatform.ws.schema.core.secret.management.SecretTypes)3 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SecretBuilder (org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.SecretBuilder)2 TypedSecrets (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets)2 Given (io.cucumber.java.en.Given)1 Then (io.cucumber.java.en.Then)1 GenerateAndStoreSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GenerateAndStoreSecretsResponse)1 GetNewSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse)1 GetSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse)1 HasNewSecretResponse (org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse)1