use of org.platformlayer.core.model.SecretInfo in project platformlayer by platformlayer.
the class SecretProvider method from.
public static SecretProvider from(final ProjectInfo project) {
if (project == null) {
throw new IllegalArgumentException();
}
return new SecretProvider() {
@Override
public CryptoKey getItemSecret(SecretInfo secret) {
SecretStore secretStore = new SecretStore(secret.getEncoded());
CryptoKey secretKey = secretStore.getSecretFromProject(project);
return secretKey;
}
};
}
use of org.platformlayer.core.model.SecretInfo in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method mapToModel.
static <T extends ItemBase> T mapToModel(ProjectId project, ServiceType serviceType, ItemType itemType, ItemEntity entity, JaxbHelper jaxb, SecretProvider secretProvider) throws RepositoryException {
try {
int id = entity.id;
String key = entity.key;
int stateCode = entity.state;
byte[] data = entity.data;
SecretInfo secret = new SecretInfo(entity.secret);
CryptoKey itemSecret = secretProvider.getItemSecret(secret);
if (itemSecret == null) {
throw new RepositoryException("Could not get secret to decrypt item");
}
if (itemSecret instanceof AesCryptoKey) {
log.warn("Legacy AES crypto key on {} {} {} {}", new Object[] { project, serviceType, itemType, entity });
}
secret.unlock(itemSecret);
byte[] plaintext = FathomdbCrypto.decrypt(itemSecret, data);
String xml = new String(plaintext, Charsets.UTF_8);
T model = (T) jaxb.unmarshal(xml);
model.state = ManagedItemState.fromCode(stateCode);
model.secret = secret;
PlatformLayerKey plk = new PlatformLayerKey(null, project, serviceType, itemType, new ManagedItemId(key));
model.setKey(plk);
return model;
} catch (JAXBException e) {
throw new RepositoryException("Error deserializing data", e);
}
}
Aggregations