use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CertificateCredentialTest method beforeEach.
@Before
public void beforeEach() {
getBouncyCastleProvider();
UUID canaryUuid = UUID.randomUUID();
byte[] encryptedValue = "fake-encrypted-value".getBytes();
byte[] nonce = "fake-nonce".getBytes();
encryptor = mock(Encryptor.class);
final EncryptedValue encryption = new EncryptedValue(canaryUuid, encryptedValue, nonce);
when(encryptor.encrypt("priv")).thenReturn(encryption);
when(encryptor.decrypt(encryption)).thenReturn("priv");
credentialName = "/foo";
uuid = UUID.randomUUID();
entity = new CertificateCredentialVersion(credentialName).setEncryptor(encryptor).setCa("ca").setCertificate("cert").setPrivateKey("priv").setUuid(uuid);
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class EncryptedValueDataService method rotate.
public void rotate(EncryptedValue encryptedValue) {
String decryptedValue = encryptor.decrypt(encryptedValue);
EncryptedValue newEncryptedValue = encryptor.encrypt(decryptedValue);
newEncryptedValue.setUuid(encryptedValue.getUuid());
encryptedValueRepository.saveAndFlush(newEncryptedValue);
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersion method setValue.
public Z setValue(String value) {
final EncryptedValue encryption = encryptor.encrypt(value);
delegate.setEncryptedValueData(encryption);
return (Z) this;
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class UserCredentialVersion method setGenerationParameters.
public UserCredentialVersion setGenerationParameters(StringGenerationParameters generationParameters) {
EncryptedValue encryptedParameters;
try {
String generationParameterJson = generationParameters != null ? jsonObjectMapper.writeValueAsString(generationParameters) : null;
if (generationParameterJson != null) {
encryptedParameters = encryptor.encrypt(generationParameterJson);
delegate.setEncryptedGenerationParameters(encryptedParameters);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return this;
}
use of org.cloudfoundry.credhub.entity.EncryptedValue in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findByUuid_givenAUuid_findsTheCredential.
@Test
public void findByUuid_givenAUuid_findsTheCredential() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential");
passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce("nonce".getBytes()));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
PasswordCredentialVersion savedCredential = subject.save(credential);
assertNotNull(savedCredential.getUuid());
PasswordCredentialVersion oneByUuid = (PasswordCredentialVersion) subject.findByUuid(savedCredential.getUuid().toString());
assertThat(oneByUuid.getName(), equalTo("/my-credential"));
assertThat(passwordCredentialData.getEncryptedValueData().getEncryptedValue(), equalTo("credential-password".getBytes()));
}
Aggregations