use of org.opensmartgridplatform.secretmanagement.application.domain.SecretType in project open-smart-grid-platform by OSGP.
the class SecretManagementEndpoint method getNewSecrets.
public GetNewSecretsResponse getNewSecrets(final GetNewSecretsRequest request) throws OsgpException {
final GetNewSecretsResponse response = new GetNewSecretsResponse();
final SecretTypes soapSecretTypes = request.getSecretTypes();
final List<SecretType> secretTypeList = this.converter.convertToSecretTypes(soapSecretTypes);
final List<TypedSecret> typedSecrets = this.secretManagementService.retrieveNewSecrets(request.getDeviceId(), secretTypeList);
final TypedSecrets soapTypedSecrets = this.converter.convertToSoapTypedSecrets(typedSecrets);
response.setTypedSecrets(soapTypedSecrets);
return response;
}
use of org.opensmartgridplatform.secretmanagement.application.domain.SecretType in project open-smart-grid-platform by OSGP.
the class SecretManagementEndpoint method getSecrets.
public GetSecretsResponse getSecrets(final GetSecretsRequest request) throws OsgpException {
final GetSecretsResponse response = new GetSecretsResponse();
final SecretTypes soapSecretTypes = request.getSecretTypes();
final List<SecretType> secretTypeList = this.converter.convertToSecretTypes(soapSecretTypes);
final List<TypedSecret> typedSecrets = this.secretManagementService.retrieveSecrets(request.getDeviceId(), secretTypeList);
final TypedSecrets soapTypedSecrets = this.converter.convertToSoapTypedSecrets(typedSecrets);
response.setTypedSecrets(soapTypedSecrets);
return response;
}
use of org.opensmartgridplatform.secretmanagement.application.domain.SecretType in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method generateAndStoreSecretsWhenNewSecretsAlreadyExists.
@Test
public void generateAndStoreSecretsWhenNewSecretsAlreadyExists() 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 DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
keyReference.setReference(reference);
keyReference.setEncryptionProviderType(ENCRYPTION_PROVIDER_TYPE);
keyReference.setValidFrom(now);
final DbEncryptedSecret secretOldEncryption = this.getSecret(SecretType.E_METER_ENCRYPTION_KEY_UNICAST, 100);
final DbEncryptedSecret secretOlderEncryption = this.getSecret(SecretType.E_METER_ENCRYPTION_KEY_UNICAST, 1000);
final Date originalCreationTimeEncryptionSecret = secretOldEncryption.getCreationTime();
final Date olderCreationTime = secretOlderEncryption.getCreationTime();
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(secretOldEncryption, secretOlderEncryption));
when(this.encryptionDelegate.decrypt(any(), any())).thenReturn(secret);
when(this.encrypterForSecretManagementClient.encrypt(any())).thenReturn(rsaSecret);
final SecretType encryptionSecretType = SecretType.E_METER_ENCRYPTION_KEY_UNICAST;
final SecretType authenticationSecretType = SecretType.E_METER_AUTHENTICATION_KEY;
this.service.generateAndStoreSecrets(SOME_DEVICE, Arrays.asList(encryptionSecretType, authenticationSecretType));
verify(this.secretRepository, never()).saveAll(Arrays.asList(secretOldEncryption));
verify(this.secretRepository, never()).saveAll(Arrays.asList(secretOldEncryption));
assertThat(secretOldEncryption.getCreationTime()).isEqualTo(originalCreationTimeEncryptionSecret);
assertThat(secretOldEncryption.getSecretStatus()).isEqualTo(SecretStatus.WITHDRAWN);
assertThat(secretOlderEncryption.getCreationTime().getTime()).isEqualTo(olderCreationTime.getTime());
assertThat(secretOlderEncryption.getSecretStatus()).isEqualTo(SecretStatus.WITHDRAWN);
}
use of org.opensmartgridplatform.secretmanagement.application.domain.SecretType in project open-smart-grid-platform by OSGP.
the class DlmsDeviceSteps method simulateFailureOfChangeFromPreviousKeyOfDevice.
@Given("simulate failure of change from previous key of device \"{}\"")
public void simulateFailureOfChangeFromPreviousKeyOfDevice(final String id, final Map<String, String> inputSettings) {
for (final String keyTypeInputName : inputSettings.keySet()) {
final String securityTypeInputName = inputSettings.get(keyTypeInputName);
final SecretType secretType = this.getSecretTypeByKeyTypeInputName(keyTypeInputName);
final String key = SecurityKey.valueOf(securityTypeInputName).getDatabaseKey();
final List<DbEncryptedSecret> currentlyActiveKeys = this.encryptedSecretRepository.findSecrets(id, secretType, SecretStatus.ACTIVE);
for (final DbEncryptedSecret currentlyActiveKey : currentlyActiveKeys) {
currentlyActiveKey.setSecretStatus(SecretStatus.NEW);
this.encryptedSecretRepository.save(currentlyActiveKey);
}
final DbEncryptionKeyReference encryptionKeyRef = this.encryptionKeyRepository.findByTypeAndValid(EncryptionProviderType.JRE, new Date()).iterator().next();
final DbEncryptedSecret secret = new SecretBuilder().withDeviceIdentification(id).withSecretType(secretType).withKey(key).withSecretStatus(SecretStatus.ACTIVE).withEncryptionKeyReference(encryptionKeyRef).withCreationTime(new Date()).build();
this.encryptedSecretRepository.save(secret);
}
}
use of org.opensmartgridplatform.secretmanagement.application.domain.SecretType in project open-smart-grid-platform by OSGP.
the class DlmsDeviceSteps method registerNewKeys.
private void registerNewKeys(final long minutesAgo, final Map<String, String> inputSettings) {
if (!inputSettings.containsKey(PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION)) {
throw new IllegalArgumentException("No device identification provided");
}
final String deviceIdentification = inputSettings.get(PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION);
final List<SecretType> secretTypesToCreate = Arrays.asList(E_METER_AUTHENTICATION_KEY, E_METER_ENCRYPTION_KEY_UNICAST);
final List<String> keyTypeInputNames = secretTypesToCreate.stream().map(this::getKeyTypeInputName).collect(Collectors.toList());
if (Collections.disjoint(inputSettings.keySet(), keyTypeInputNames)) {
throw new IllegalArgumentException("None of the following keys provided: " + keyTypeInputNames);
}
final DbEncryptionKeyReference encryptionKeyRef = this.encryptionKeyRepository.findByTypeAndValid(EncryptionProviderType.JRE, new Date()).iterator().next();
for (int i = 0; i < secretTypesToCreate.size(); i++) {
if (inputSettings.containsKey(keyTypeInputNames.get(i))) {
final String inputKeyName = inputSettings.get(keyTypeInputNames.get(i));
final String key = SecurityKey.valueOf(inputKeyName).getDatabaseKey();
final DbEncryptedSecret secret = new SecretBuilder().withDeviceIdentification(deviceIdentification).withSecretType(secretTypesToCreate.get(i)).withKey(key).withSecretStatus(SecretStatus.NEW).withEncryptionKeyReference(encryptionKeyRef).withCreationTime(new Date(System.currentTimeMillis() - (minutesAgo * 60000L))).build();
this.encryptedSecretRepository.save(secret);
}
}
}
Aggregations