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