use of org.opensmartgridplatform.shared.exceptionhandling.EncrypterException in project open-smart-grid-platform by OSGP.
the class SecurityConfig method getDefaultEncryptionProviders.
private List<EncryptionProvider> getDefaultEncryptionProviders() {
final List<EncryptionProvider> encryptionProviderList = new ArrayList<>();
try {
final JreEncryptionProvider jreEncryptionProvider = new JreEncryptionProvider(this.jreEncryptionKeyResource.getFile());
encryptionProviderList.add(jreEncryptionProvider);
if (this.hsmKeystoreResource.isPresent()) {
final HsmEncryptionProvider hsmEncryptionProvider = new HsmEncryptionProvider(this.hsmKeystoreResource.get().getFile());
encryptionProviderList.add(hsmEncryptionProvider);
}
return encryptionProviderList;
} catch (final IOException | EncrypterException e) {
throw new IllegalStateException("Error creating default encryption providers", e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.EncrypterException in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method storeSecretsEncryptionError.
@Test
public void storeSecretsEncryptionError() throws EncrypterException {
final TypedSecret typedSecret = new TypedSecret("$3cr3t".getBytes(), SecretType.E_METER_MASTER_KEY);
final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
keyReference.setEncryptionProviderType(ENCRYPTION_PROVIDER_TYPE);
keyReference.setReference("keyReferenceString");
when(this.keyRepository.findByTypeAndValid(any(), any())).thenReturn(Arrays.asList(keyReference));
when(this.encryptionDelegate.encrypt(any(), any(), anyString())).thenThrow(new EncrypterException("Encryption error"));
assertThatIllegalStateException().isThrownBy(() -> this.service.storeSecrets(SOME_DEVICE, Arrays.asList(typedSecret)));
}
use of org.opensmartgridplatform.shared.exceptionhandling.EncrypterException in project open-smart-grid-platform by OSGP.
the class SecretManagementServiceTest method retrieveSecretsDecryptionError.
@Test
public void retrieveSecretsDecryptionError() throws EncrypterException {
final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
keyReference.setEncryptionProviderType(ENCRYPTION_PROVIDER_TYPE);
keyReference.setReference("1");
final DbEncryptedSecret secret = new DbEncryptedSecret();
secret.setSecretType(SecretType.E_METER_MASTER_KEY);
secret.setEncryptionKeyReference(keyReference);
secret.setEncodedSecret("0123456789ABCDEF0123456789ABCDEF");
final List<DbEncryptedSecret> secretPage = Arrays.asList(secret);
when(this.secretRepository.findSecrets(SOME_DEVICE, SecretType.E_METER_MASTER_KEY, SecretStatus.ACTIVE)).thenReturn(secretPage);
when(this.encryptionDelegate.decrypt(any(), any())).thenThrow(new EncrypterException("Decryption error"));
assertThatIllegalStateException().isThrownBy(() -> this.service.retrieveSecrets(SOME_DEVICE, Arrays.asList(SecretType.E_METER_MASTER_KEY)));
}
use of org.opensmartgridplatform.shared.exceptionhandling.EncrypterException in project open-smart-grid-platform by OSGP.
the class SecretManagementService method generateAes128BitsSecret.
private EncryptedTypedSecret generateAes128BitsSecret(final SecretType secretType) {
try {
final DbEncryptionKeyReference currentKey = this.getCurrentKey();
final byte[] aesEncrypted = this.encryptionDelegateForKeyStorage.generateAes128BitsSecret(this.encryptionProviderType, currentKey.getReference());
return new EncryptedTypedSecret(aesEncrypted, secretType, currentKey.getReference(), currentKey.getEncryptionProviderType());
} catch (final EncrypterException ee) {
throw new IllegalStateException("Eror generating secret", ee);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.EncrypterException in project open-smart-grid-platform by OSGP.
the class AbstractReplaceKeyCommandExecutor method decryptRsaKeys.
private SetKeysRequestDto decryptRsaKeys(final SetKeysRequestDto setKeysRequestDto) throws FunctionalException {
try {
final byte[] authenticationKey = this.decrypterForGxfSmartMetering.decrypt(setKeysRequestDto.getAuthenticationKey());
final byte[] encryptionKey = this.decrypterForGxfSmartMetering.decrypt(setKeysRequestDto.getEncryptionKey());
return new SetKeysRequestDto(authenticationKey, encryptionKey);
} catch (final EncrypterException e) {
throw new FunctionalException(FunctionalExceptionType.DECRYPTION_EXCEPTION, ComponentType.PROTOCOL_DLMS, e);
}
}
Aggregations