Search in sources :

Example 1 with SecretInfo

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;
        }
    };
}
Also used : SecretInfo(org.platformlayer.core.model.SecretInfo) CryptoKey(com.fathomdb.crypto.CryptoKey)

Example 2 with SecretInfo

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);
    }
}
Also used : AesCryptoKey(com.fathomdb.crypto.AesCryptoKey) SecretInfo(org.platformlayer.core.model.SecretInfo) JAXBException(javax.xml.bind.JAXBException) CryptoKey(com.fathomdb.crypto.CryptoKey) AesCryptoKey(com.fathomdb.crypto.AesCryptoKey) RepositoryException(org.platformlayer.RepositoryException) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Aggregations

CryptoKey (com.fathomdb.crypto.CryptoKey)2 SecretInfo (org.platformlayer.core.model.SecretInfo)2 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)1 JAXBException (javax.xml.bind.JAXBException)1 RepositoryException (org.platformlayer.RepositoryException)1 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)1 ManagedItemId (org.platformlayer.ids.ManagedItemId)1