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);
}
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));
}
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);
}
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));
}
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/")));
}
Aggregations