Search in sources :

Example 46 with EncryptedValue

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

Example 47 with EncryptedValue

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

Example 48 with EncryptedValue

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

Example 49 with EncryptedValue

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

Example 50 with EncryptedValue

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