Search in sources :

Example 11 with CryptoCodec

use of org.apache.hadoop.crypto.CryptoCodec in project hbase by apache.

the class FanOutOneBlockAsyncDFSOutputSaslHelper method createTransparentCryptoHelperWithoutHDFS12396.

private static TransparentCryptoHelper createTransparentCryptoHelperWithoutHDFS12396() throws NoSuchMethodException {
    Method decryptEncryptedDataEncryptionKeyMethod = DFSClient.class.getDeclaredMethod("decryptEncryptedDataEncryptionKey", FileEncryptionInfo.class);
    decryptEncryptedDataEncryptionKeyMethod.setAccessible(true);
    return new TransparentCryptoHelper() {

        @Override
        public Encryptor createEncryptor(Configuration conf, FileEncryptionInfo feInfo, DFSClient client) throws IOException {
            try {
                KeyVersion decryptedKey = (KeyVersion) decryptEncryptedDataEncryptionKeyMethod.invoke(client, feInfo);
                CryptoCodec cryptoCodec = CryptoCodec.getInstance(conf, feInfo.getCipherSuite());
                Encryptor encryptor = cryptoCodec.createEncryptor();
                encryptor.init(decryptedKey.getMaterial(), feInfo.getIV());
                return encryptor;
            } catch (InvocationTargetException e) {
                Throwables.propagateIfPossible(e.getTargetException(), IOException.class);
                throw new RuntimeException(e.getTargetException());
            } catch (GeneralSecurityException e) {
                throw new IOException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) Configuration(org.apache.hadoop.conf.Configuration) KeyVersion(org.apache.hadoop.crypto.key.KeyProvider.KeyVersion) GeneralSecurityException(java.security.GeneralSecurityException) Encryptor(org.apache.hadoop.crypto.Encryptor) Method(java.lang.reflect.Method) IOException(java.io.IOException) FileEncryptionInfo(org.apache.hadoop.fs.FileEncryptionInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) CryptoCodec(org.apache.hadoop.crypto.CryptoCodec)

Aggregations

CryptoCodec (org.apache.hadoop.crypto.CryptoCodec)11 IOException (java.io.IOException)5 KeyVersion (org.apache.hadoop.crypto.key.KeyProvider.KeyVersion)5 FileEncryptionInfo (org.apache.hadoop.fs.FileEncryptionInfo)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 GeneralSecurityException (java.security.GeneralSecurityException)3 Configuration (org.apache.hadoop.conf.Configuration)3 CryptoInputStream (org.apache.hadoop.crypto.CryptoInputStream)3 Encryptor (org.apache.hadoop.crypto.Encryptor)3 DFSClient (org.apache.hadoop.hdfs.DFSClient)3 CipherSuite (org.apache.hadoop.crypto.CipherSuite)2 CryptoOutputStream (org.apache.hadoop.crypto.CryptoOutputStream)2 EncryptedKeyVersion (org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.EncryptedKeyVersion)2 ByteString (com.google.protobuf.ByteString)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 CipherOption (org.apache.hadoop.crypto.CipherOption)1 CryptoFSDataInputStream (org.apache.hadoop.fs.crypto.CryptoFSDataInputStream)1 HdfsDataInputStream (org.apache.hadoop.hdfs.client.HdfsDataInputStream)1