use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method saveCertificate.
private CertificateCredentialVersion saveCertificate(long timeMillis, String name, String caName, UUID canaryUuid, boolean transitional) {
fakeTimeSetter.accept(timeMillis);
Credential credential = credentialDataService.find(name);
if (credential == null) {
credential = credentialDataService.save(new Credential(name));
}
CertificateCredentialVersionData credentialObject = new CertificateCredentialVersionData();
credentialObject.setCredential(credential);
credentialObject.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(canaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
if (caName != null) {
credentialObject.setCaName(caName);
}
credentialObject.setTransitional(transitional);
return subject.save(credentialObject);
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CertificateCredentialVersionTest method setup.
@Before
public void setup() {
TestHelper.getBouncyCastleProvider();
encryptor = mock(Encryptor.class);
encryptedValue = "fake-encrypted-value".getBytes();
nonce = "fake-nonce".getBytes();
canaryUuid = UUID.randomUUID();
final EncryptedValue encryption = new EncryptedValue(canaryUuid, encryptedValue, nonce);
when(encryptor.encrypt("my-priv")).thenReturn(encryption);
when(encryptor.decrypt(encryption)).thenReturn("my-priv");
certificateCredentialData = new CertificateCredentialVersionData("/Foo");
subject = new CertificateCredentialVersion(certificateCredentialData).setEncryptor(encryptor).setCa("my-ca").setCertificate("my-cert").setPrivateKey("my-priv");
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialRotationTest method beforeEach.
@Before
public void beforeEach() throws Exception {
encryptionService = mock(RetryingEncryptionService.class);
encryptor = new Encryptor(encryptionService);
oldEncryptionKeyUuid = UUID.randomUUID();
activeEncryptionKeyUuid = UUID.randomUUID();
when(encryptionService.decrypt(new EncryptedValue(oldEncryptionKeyUuid, "old-encrypted-value".getBytes(), "old-nonce".getBytes()))).thenReturn("plaintext");
when(encryptionService.encrypt("plaintext")).thenReturn(new EncryptedValue(activeEncryptionKeyUuid, "new-encrypted-value".getBytes(), "new-nonce".getBytes()));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptorTest method decrypt_failsToEncryptWhenGivenWrongKeyUuid.
@Test(expected = RuntimeException.class)
public void decrypt_failsToEncryptWhenGivenWrongKeyUuid() {
EncryptedValue encryption = subject.encrypt("the expected clear text");
encryptedValue = encryption.getEncryptedValue();
nonce = encryption.getNonce();
subject.decrypt(new EncryptedValue(oldUuid, encryptedValue, nonce));
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptorTest method encrypt_returnsNullForNullInput.
@Test
public void encrypt_returnsNullForNullInput() {
EncryptedValue encryption = subject.encrypt(null);
assertThat(encryption.getEncryptedValue(), nullValue());
assertThat(encryption.getNonce(), nullValue());
}
Aggregations