Search in sources :

Example 36 with EncryptedValue

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);
}
Also used : Encryptor(org.cloudfoundry.credhub.domain.Encryptor) UUID(java.util.UUID) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Before(org.junit.Before)

Example 37 with EncryptedValue

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);
}
Also used : EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue)

Example 38 with EncryptedValue

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;
}
Also used : EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue)

Example 39 with EncryptedValue

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;
}
Also used : EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) IOException(java.io.IOException)

Example 40 with EncryptedValue

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()));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)56 Test (org.junit.Test)31 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)12 Before (org.junit.Before)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)7 Credential (org.cloudfoundry.credhub.entity.Credential)7 UUID (java.util.UUID)6 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)6 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)6 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)5 UserCredentialVersionData (org.cloudfoundry.credhub.entity.UserCredentialVersionData)5 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)5 ProviderException (java.security.ProviderException)4 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)4 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)4 EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Key (java.security.Key)3 KeyNotFoundException (org.cloudfoundry.credhub.exceptions.KeyNotFoundException)3