use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class RetryingEncryptionServiceTest method encryption_whenTheOperationSucceedsOnlyAfterReconnection_shouldReturnTheEncryptedString.
@Test
public void encryption_whenTheOperationSucceedsOnlyAfterReconnection_shouldReturnTheEncryptedString() throws Exception {
EncryptedValue expectedEncryption = mock(EncryptedValue.class);
when(keySet.getActive()).thenReturn(firstActiveKey).thenReturn(secondActiveKey);
when(firstActiveKey.encrypt("fake-plaintext")).thenThrow(new IllegalBlockSizeException("test exception"));
when(secondActiveKey.encrypt("fake-plaintext")).thenReturn(expectedEncryption);
assertThat(subject.encrypt("fake-plaintext"), equalTo(expectedEncryption));
verify(keySet.getActive(), times(1)).reconnect(any(IllegalBlockSizeException.class));
verify(keySet, times(1)).reload();
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class RetryingEncryptionServiceTest method decrypt_locksAndUnlocksTheReconnectLockWhenLoginError.
@Test
public void decrypt_locksAndUnlocksTheReconnectLockWhenLoginError() throws Exception {
when(keySet.get(activeKeyUuid)).thenReturn(firstActiveKey);
when(firstActiveKey.decrypt(any(byte[].class), any(byte[].class))).thenThrow(new ProviderException("function 'C_GenerateRandom' returns 0x30"));
reset(writeLock);
doThrow(new RuntimeException()).when(encryptionService).reconnect(any(Exception.class));
try {
subject.decrypt(new EncryptedValue(activeKeyUuid, "an encrypted value".getBytes(), "a nonce".getBytes()));
} catch (IllegalBlockSizeException | RuntimeException e) {
// expected
}
verify(readLock, times(2)).lock();
verify(readLock, times(2)).unlock();
verify(writeLock, times(1)).lock();
verify(writeLock, times(1)).unlock();
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EventAuditLogServiceTest method beforeEach.
@Before
public void beforeEach() {
canaries = encryptionKeyCanaryRepository.findAll();
mockOutCurrentTimeProvider(currentTimeProvider).accept(now.toEpochMilli());
userContext = mockUserContext(true);
userContextHolder.setUserContext(userContext);
entity = new ValueCredentialVersionData("keyName");
entity.setEncryptedValueData(new EncryptedValue(canaries.get(0).getUuid(), "value", "nonce"));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method createCertificateWithOldKey.
private void createCertificateWithOldKey(Key oldKey) throws Exception {
final EncryptedValue encryption = encryptionService.encrypt(oldCanary.getUuid(), oldKey, "old-certificate-private-key");
CertificateCredentialVersionData certificateCredentialData1 = new CertificateCredentialVersionData("/old-key");
certificateCredentialData1.setEncryptedValueData(encryption);
credentialVersionWithOldKey = new CertificateCredentialVersion(certificateCredentialData1);
credentialVersionDataService.save(credentialVersionWithOldKey);
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method createPasswordWithOldKey.
private void createPasswordWithOldKey(Key oldKey) throws Exception {
final EncryptedValue credentialEncryption = encryptionService.encrypt(oldCanary.getUuid(), oldKey, "test-password-plaintext");
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData(passwordName);
passwordCredentialData.setEncryptedValueData(credentialEncryption);
StringGenerationParameters parameters = new StringGenerationParameters();
parameters.setExcludeNumber(true);
final EncryptedValue parameterEncryption = encryptionService.encrypt(oldCanary.getUuid(), oldKey, new ObjectMapper().writeValueAsString(parameters));
passwordCredentialData.setEncryptedGenerationParameters(parameterEncryption);
password = new PasswordCredentialVersion(passwordCredentialData);
credentialVersionDataService.save(password);
}
Aggregations