Package com.emc.vipr.transform

Examples of com.emc.vipr.transform.TransformException


    public Map<String, String> rekey(Map<String, String> metadata)
            throws TransformException {
        String oldKeyId = metadata
                .get(TransformConstants.META_ENCRYPTION_KEY_ID);
        if (oldKeyId == null) {
            throw new TransformException(
                    "Metadata does not contain a master key ID");
        }
        if (oldKeyId.equals(masterEncryptionKeyFingerprint)) {
            // This object is already using the current key.
            logger.info("Object is already using the current master key");
            throw new DoesNotNeedRekeyException(
                    "Object is already using the current master key");
        }
        // Make sure we have the old key
        if (!masterDecryptionKeys.containsKey(oldKeyId)) {
            throw new TransformException("Master key with fingerprint "
                    + oldKeyId + " not found");
        }
       
        KeyPair oldKey = masterDecryptionKeys.get(oldKeyId);
        String encodedKey = metadata.get(TransformConstants.META_ENCRYPTION_OBJECT_KEY);
        if(encodedKey == null) {
            throw new TransformException("Encrypted object key not found");
        }
       
        String algorithm = getEncryptionAlgorithm();
       
        SecretKey objectKey = KeyUtils.decryptKey(encodedKey, algorithm, provider,
                oldKey.getPrivate());
       
        // Re-encrypt key with the current master key
        String newKey;
        try {
            newKey = KeyUtils.encryptKey(objectKey, provider,
                    masterEncryptionKey.getPublic());
        } catch (GeneralSecurityException e) {
            throw new TransformException("Could not re-encrypt key: " + e, e);
        }
       
        Map<String, String> newMetadata = new HashMap<String, String>();
        newMetadata.putAll(metadata);
        newMetadata.remove(TransformConstants.META_ENCRYPTION_META_SIG);
View Full Code Here


        try {
            if(!keyStore.containsAlias(masterEncryptionKeyAlias)) {
                throw new InvalidKeyException("No certificate found in keystore for alias " + masterEncryptionKeyAlias);
            }
        } catch (KeyStoreException e) {
            throw new TransformException("Could not access KeyStore", e);
        }
       
        // Index all the certificate fingerprints
        try {
            for(Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();) {
                String alias = aliases.nextElement();
               
                String fingerprint = getFingerprint(alias);
                idToAliasMap.put(fingerprint, alias);
                if(alias.equals(masterEncryptionKeyAlias)) {
                    masterEncryptionKeyFingerprint = fingerprint;
                }
            }
        } catch(KeyStoreException e) {
            throw new TransformException("Could not init factory from KeyStore", e);
        }
    }
View Full Code Here

    @Override
    public Map<String, String> rekey(Map<String, String> metadata) throws TransformException, DoesNotNeedRekeyException{
        String oldKeyId = metadata
                .get(TransformConstants.META_ENCRYPTION_KEY_ID);
        if (oldKeyId == null) {
            throw new TransformException(
                    "Metadata does not contain a master key ID");
        }
        if (oldKeyId.equals(masterEncryptionKeyFingerprint)) {
            // This object is already using the current key.
            logger.info("Object is already using the current master key");
            throw new DoesNotNeedRekeyException(
                    "Object is already using the current master key");
        }
        // Make sure we have the old key
        if (!idToAliasMap.containsKey(oldKeyId)) {
            throw new TransformException("Master key with fingerprint "
                    + oldKeyId + " not found");
        }
       
        String oldAlias = idToAliasMap.get(oldKeyId);
        KeyPair oldMasterKey = getKeyPair(oldAlias);
        String encodedKey = metadata.get(TransformConstants.META_ENCRYPTION_OBJECT_KEY);
        if(encodedKey == null) {
            throw new TransformException("Encrypted object key not found");
        }
       
        String algorithm = getEncryptionAlgorithm();
       
        SecretKey objectKey = KeyUtils.decryptKey(encodedKey, algorithm, provider, oldMasterKey.getPrivate());
       
        // Re-encrypt key with the current master key
        KeyPair newMasterKey = getKeyPair(masterEncryptionKeyAlias);
        String newKey;
        try {
            newKey = KeyUtils.encryptKey(objectKey, provider, newMasterKey.getPublic());
        } catch (GeneralSecurityException e) {
            throw new TransformException("Error encrypting key: " + e, e);
        }
       
        Map<String, String> newMetadata = new HashMap<String, String>();
        newMetadata.putAll(metadata);
        newMetadata.remove(TransformConstants.META_ENCRYPTION_META_SIG);
View Full Code Here

        try {
            keyCert = keyStore.getCertificate(alias);
            privateKey =  (PrivateKey) keyStore.getKey(alias,
                masterKeyPassword);
            if(keyCert == null) {
                throw new TransformException("Certificate for alias " +
                        masterEncryptionKeyAlias + " not found");
            }
            if(privateKey == null) {
                throw new TransformException("Private key for alias " +
                        masterEncryptionKeyAlias + " not found");
            }
        } catch (KeyStoreException e) {
            throw new TransformException("Could not access keystore", e);
        } catch(UnrecoverableKeyException e) {
            throw new TransformException("Error loading private key from keystore", e);
        } catch(NoSuchAlgorithmException e) {
            throw new TransformException("Error loading private key from keystore", e);
        }
        return new KeyPair(keyCert.getPublicKey(), privateKey);
    }
View Full Code Here

    public BasicEncryptionInputTransform getInputTransform(
            String transformConfig, InputStream streamToDecode,
            Map<String, String> metadata) throws IOException, TransformException {
        String[] transformTuple = splitTransformConfig(transformConfig);
        if (transformTuple.length != 2) {
            throw new TransformException("Invalid transform configuration: "
                    + transformConfig);
        }

        if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) {
            throw new TransformException("Unsupported transform class: "
                    + transformTuple[0]);
        }

        // Find master key
        String masterKeyId = metadata
                .get(TransformConstants.META_ENCRYPTION_KEY_ID);
        if (masterKeyId == null) {
            throw new TransformException(
                    "Could not decrypt object. No master key ID set on object.");
        }
        String masterKeyAlias = idToAliasMap.get(masterKeyId);
        if(masterKeyAlias == null) {
            throw new TransformException("Could not find master key for ID " + masterKeyId);
        }
       
        KeyPair asymmetricKey = getKeyPair(masterKeyAlias);
       
        return new BasicEncryptionInputTransform(transformTuple[1], streamToDecode,
View Full Code Here

    public void setMasterEncryptionKeyAlias(String alias) throws TransformException {
        try {
            // Make sure it exists
            if(!keyStore.containsAlias(alias)) {
                throw new TransformException("Certificate with alias " + alias + " not found in keystore");
            }
           
            // Get the fingerprint too
            String fingerprint = getFingerprint(alias);
            masterEncryptionKeyFingerprint = fingerprint;
            masterEncryptionKeyAlias = alias;
        } catch (KeyStoreException e) {
            throw new TransformException("Could not access keystore", e);
        } catch (NoSuchAlgorithmException e) {
            throw new TransformException("Could not load certificate for alias " + alias );
        }
    }
View Full Code Here

        super(streamToDecode, metadataToDecode, provider);
       
        // Check the transformConfig
        String[] transformParams = transformConfig.split("/");
        if(transformParams.length != 3) {
            throw new TransformException("Encryption configuration should be in the form Alg/Mode/Padding: " + transformConfig);
        }
       
        // Decrypt the object key
        String encodedObjectKey = metadataToDecode.get(TransformConstants.META_ENCRYPTION_OBJECT_KEY);
        if(encodedObjectKey == null) {
            throw new TransformException("Object key not found in object metadata");
        }
       
        SecretKey sk = KeyUtils.decryptKey(encodedObjectKey, transformParams[0], provider,
                masterKey.getPrivate());
       
        // Get IV
        String encodedIv = metadataToDecode.get(TransformConstants.META_ENCRYPTION_IV);
        if(encodedIv == null) {
            throw new TransformException("Initialization Vector (IV) not found in object metadata");
        }
        byte[] ivData = KeyUtils.urlSafeDecodeBase64(encodedIv);
       
        // Init the cipher
        try {
            Cipher cipher = null;
            if(provider != null) {
                cipher = Cipher.getInstance(transformConfig, provider);
            } else {
                cipher = Cipher.getInstance(transformConfig);
            }
           
            IvParameterSpec ivspec = new IvParameterSpec(ivData);
            cipher.init(Cipher.DECRYPT_MODE, sk, ivspec);
           
            decryptedInput = new CipherInputStream(streamToDecode, cipher);
        } catch(GeneralSecurityException e) {
            throw new TransformException("Could not initialize cipher", e);
        }
    }
View Full Code Here

            Map<String, String> metadata) throws IOException,
            TransformException {

        String[] transformTuple = splitTransformConfig(transformConfig);
        if (transformTuple.length != 2) {
            throw new TransformException("Invalid transform configuration: "
                    + transformConfig);
        }

        if (!TransformConstants.ENCRYPTION_CLASS.equals(transformTuple[0])) {
            throw new TransformException("Unsupported transform class: "
                    + transformTuple[0]);
        }

        // Find master key
        String masterKeyId = metadata
                .get(TransformConstants.META_ENCRYPTION_KEY_ID);
        if (masterKeyId == null) {
            throw new TransformException(
                    "Could not decrypt object. No master key ID set on object.");
        }

        KeyPair masterKey = masterDecryptionKeys.get(masterKeyId);
        if (masterKey == null) {
            throw new TransformException(
                    "Could not decrypt object. No master key with ID "
                            + masterKeyId + " found");
        }

        return new BasicEncryptionInputTransform(transformTuple[1],
View Full Code Here

TOP

Related Classes of com.emc.vipr.transform.TransformException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.