use of org.cloudfoundry.credhub.config.EncryptionKeyMetadata in project credhub by cloudfoundry-incubator.
the class EncryptionKeyCanaryMapper method mapUuidsToKeys.
void mapUuidsToKeys(EncryptionKeySet keySet) throws Exception {
List<EncryptionKeyCanary> encryptionKeyCanaries = encryptionKeyCanaryDataService.findAll();
for (EncryptionKeyMetadata keyMetadata : encryptionKeysConfiguration.getKeys()) {
EncryptionService encryptionService = providerFactory.getEncryptionService(keyMetadata.getProviderType());
KeyProxy keyProxy = encryptionService.createKeyProxy(keyMetadata);
EncryptionKeyCanary matchingCanary = null;
for (EncryptionKeyCanary canary : encryptionKeyCanaries) {
if (keyProxy.matchesCanary(canary)) {
matchingCanary = canary;
break;
}
}
if (matchingCanary == null) {
if (keyMetadata.isActive()) {
matchingCanary = createCanary(keyProxy, encryptionService);
} else {
continue;
}
}
if (keyMetadata.isActive()) {
keySet.setActive(matchingCanary.getUuid());
}
try {
keySet.add(new EncryptionKey(providerFactory.getEncryptionService(keyMetadata.getProviderType()), matchingCanary.getUuid(), keyProxy.getKey()));
} catch (Exception e) {
throw new RuntimeException("Failed to connect to encryption provider", e);
}
}
if (keySet.getActive() == null) {
throw new RuntimeException("No active key was found");
}
}
use of org.cloudfoundry.credhub.config.EncryptionKeyMetadata in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method setActiveKey.
private void setActiveKey(int index) throws Exception {
List<EncryptionKeyMetadata> keys = new ArrayList<>();
for (EncryptionKeyMetadata encryptionKeyMetadata : encryptionKeysConfiguration.getKeys()) {
EncryptionKeyMetadata clonedKey = new EncryptionKeyMetadata();
clonedKey.setActive(false);
clonedKey.setEncryptionPassword(encryptionKeyMetadata.getEncryptionPassword());
clonedKey.setProviderType(encryptionKeyMetadata.getProviderType());
keys.add(clonedKey);
}
keys.get(index).setActive(true);
doReturn(keys).when(encryptionKeysConfiguration).getKeys();
keySet.reload();
}
use of org.cloudfoundry.credhub.config.EncryptionKeyMetadata in project credhub by cloudfoundry-incubator.
the class InternalEncryptionServiceTest method createsPasswordBasedKeyProxy.
@Test
public void createsPasswordBasedKeyProxy() throws Exception {
InternalEncryptionService subject = new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl());
EncryptionKeyMetadata keyMetadata = new EncryptionKeyMetadata();
keyMetadata.setEncryptionPassword("foobar");
final KeyProxy keyProxy = subject.createKeyProxy(keyMetadata);
assertThat(keyProxy, instanceOf(PasswordBasedKeyProxy.class));
}
Aggregations