Search in sources :

Example 1 with CertificateCredentialVersionData

use of org.cloudfoundry.credhub.entity.CertificateCredentialVersionData in project credhub by cloudfoundry-incubator.

the class CertificateVersionDataService method setTransitionalVersion.

public void setTransitionalVersion(UUID newTransitionalVersionUuid) {
    CertificateCredentialVersionData newTransitionalCertificate = (CertificateCredentialVersionData) credentialVersionRepository.findOneByUuid(newTransitionalVersionUuid);
    newTransitionalCertificate.setTransitional(true);
    credentialVersionRepository.save(newTransitionalCertificate);
}
Also used : CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)

Example 2 with CertificateCredentialVersionData

use of org.cloudfoundry.credhub.entity.CertificateCredentialVersionData in project credhub by cloudfoundry-incubator.

the class EncryptionKeyRotatorTest method rotation_canRotateCertificateCredentials.

@Test
public void rotation_canRotateCertificateCredentials() throws Exception {
    String certificateName = name + "-certificate";
    MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "  \"name\": \"" + certificateName + "\"," + "  \"type\": \"certificate\"," + "  \"parameters\": { " + "    \"is_ca\": true,\n" + "    \"common_name\": \"Pivotal CA\"" + "  }" + "}");
    String content = this.mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    String originalCert = parse(content).get("value").get("private_key").textValue();
    Credential credential = credentialDataService.find(certificateName);
    final byte[] firstEncryption = credentialVersionRepository.findAllByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid()).get(0).getEncryptedValueData().getEncryptedValue().clone();
    setActiveKey(1);
    encryptionKeyRotator.rotate();
    final CertificateCredentialVersionData secondEncryption = (CertificateCredentialVersionData) credentialVersionRepository.findAllByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid()).get(0);
    assertThat(firstEncryption, not(equalTo(secondEncryption.getEncryptedValueData().getEncryptedValue())));
    final MockHttpServletRequestBuilder get = get("/api/v1/data?name=" + certificateName).header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    this.mockMvc.perform(get).andExpect(status().isOk()).andExpect(jsonPath("$.data[0].value.private_key").value(originalCert));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with CertificateCredentialVersionData

use of org.cloudfoundry.credhub.entity.CertificateCredentialVersionData in project credhub by cloudfoundry-incubator.

the class EncryptionKeyRotatorTest method createCredentialWithUnknownKey.

private void createCredentialWithUnknownKey() {
    CertificateCredentialVersionData certificateCredentialData2 = new CertificateCredentialVersionData("/unknown-key");
    credentialWithUnknownKey = new CertificateCredentialVersion(certificateCredentialData2);
    credentialWithUnknownKey.setEncryptor(encryptor).setPrivateKey("cert-private-key");
    certificateCredentialData2.getEncryptedValueData().setEncryptionKeyUuid(unknownCanary.getUuid());
    credentialVersionDataService.save(credentialWithUnknownKey);
}
Also used : CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 4 with CertificateCredentialVersionData

use of org.cloudfoundry.credhub.entity.CertificateCredentialVersionData in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataRepositoryTest method canSaveCertificatesOfLength7000WhichMeans7016ForGCM.

@Test
public void canSaveCertificatesOfLength7000WhichMeans7016ForGCM() {
    byte[] encryptedValue = new byte[7016];
    Arrays.fill(encryptedValue, (byte) 'A');
    final StringBuilder stringBuilder = new StringBuilder(7000);
    Stream.generate(() -> "a").limit(stringBuilder.capacity()).forEach(stringBuilder::append);
    Credential credential = credentialRepository.save(new Credential(name));
    final String longString = stringBuilder.toString();
    CertificateCredentialVersionData entity = new CertificateCredentialVersionData();
    entity.setCredential(credential);
    entity.setCa(longString);
    entity.setCertificate(longString);
    entity.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(canaryUuid).setEncryptedValue(encryptedValue).setNonce("nonce".getBytes()));
    subject.save(entity);
    CertificateCredentialVersionData credentialData = (CertificateCredentialVersionData) subject.findFirstByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid());
    assertThat(credentialData.getCa().length(), equalTo(7000));
    assertThat(credentialData.getCertificate().length(), equalTo(7000));
    assertThat(credentialData.getEncryptedValueData().getEncryptedValue(), equalTo(encryptedValue));
    assertThat(credentialData.getEncryptedValueData().getEncryptedValue().length, equalTo(7016));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 5 with CertificateCredentialVersionData

use of org.cloudfoundry.credhub.entity.CertificateCredentialVersionData in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findAllPaths_returnsCompleteDirectoryStructure.

@Test
public void findAllPaths_returnsCompleteDirectoryStructure() {
    String valueOther = "/fubario";
    String valueName = "/value/Credential";
    String passwordName = "/password/Credential";
    String certificateName = "/certif/ic/ateCredential";
    ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(valueOther);
    ValueCredentialVersion valueCredential = new ValueCredentialVersion(valueCredentialData);
    subject.save(valueCredential);
    valueCredentialData = new ValueCredentialVersionData(valueName);
    valueCredential = new ValueCredentialVersion(valueCredentialData);
    subject.save(valueCredential);
    PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData(passwordName);
    PasswordCredentialVersion passwordCredential = new PasswordCredentialVersion(passwordCredentialData);
    subject.save(passwordCredential);
    CertificateCredentialVersionData certificateCredentialData = new CertificateCredentialVersionData(certificateName);
    CertificateCredentialVersion certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
    subject.save(certificateCredential);
    assertThat(subject.findAllPaths(), equalTo(newArrayList("/", "/certif/", "/certif/ic/", "/password/", "/value/")));
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)11 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)5 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)4 Test (org.junit.Test)4 Credential (org.cloudfoundry.credhub.entity.Credential)3 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)2 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)2 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)2 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Before (org.junit.Before)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1