Search in sources :

Example 21 with ParquetCryptoRuntimeException

use of org.apache.parquet.crypto.ParquetCryptoRuntimeException in project parquet-mr by apache.

the class FileKeyUnwrapper method getKey.

@Override
public byte[] getKey(byte[] keyMetadataBytes) {
    KeyMetadata keyMetadata = KeyMetadata.parse(keyMetadataBytes);
    if (!checkedKeyMaterialInternalStorage) {
        if (!keyMetadata.keyMaterialStoredInternally()) {
            try {
                keyMaterialStore = new HadoopFSKeyMaterialStore(parquetFilePath.getFileSystem(hadoopConfiguration));
                keyMaterialStore.initialize(parquetFilePath, hadoopConfiguration, false);
            } catch (IOException e) {
                throw new ParquetCryptoRuntimeException("Failed to open key material store", e);
            }
        }
        checkedKeyMaterialInternalStorage = true;
    }
    KeyMaterial keyMaterial;
    if (keyMetadata.keyMaterialStoredInternally()) {
        // Internal key material storage: key material is inside key metadata
        keyMaterial = keyMetadata.getKeyMaterial();
    } else {
        // External key material storage: key metadata contains a reference to a key in the material store
        String keyIDinFile = keyMetadata.getKeyReference();
        String keyMaterialString = keyMaterialStore.getKeyMaterial(keyIDinFile);
        if (null == keyMaterialString) {
            throw new ParquetCryptoRuntimeException("Null key material for keyIDinFile: " + keyIDinFile);
        }
        keyMaterial = KeyMaterial.parse(keyMaterialString);
    }
    return getDEKandMasterID(keyMaterial).getDataKey();
}
Also used : ParquetCryptoRuntimeException(org.apache.parquet.crypto.ParquetCryptoRuntimeException) IOException(java.io.IOException)

Example 22 with ParquetCryptoRuntimeException

use of org.apache.parquet.crypto.ParquetCryptoRuntimeException in project parquet-mr by apache.

the class HadoopFSKeyMaterialStore method loadKeyMaterialMap.

private void loadKeyMaterialMap() {
    try (FSDataInputStream keyMaterialStream = hadoopFileSystem.open(keyMaterialFile)) {
        JsonNode keyMaterialJson = objectMapper.readTree(keyMaterialStream);
        keyMaterialMap = objectMapper.readValue(keyMaterialJson.traverse(), new TypeReference<Map<String, String>>() {
        });
    } catch (FileNotFoundException e) {
        throw new ParquetCryptoRuntimeException("External key material not found at " + keyMaterialFile, e);
    } catch (IOException e) {
        throw new ParquetCryptoRuntimeException("Failed to get key material from " + keyMaterialFile, e);
    }
}
Also used : ParquetCryptoRuntimeException(org.apache.parquet.crypto.ParquetCryptoRuntimeException) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException)

Aggregations

ParquetCryptoRuntimeException (org.apache.parquet.crypto.ParquetCryptoRuntimeException)22 IOException (java.io.IOException)15 ColumnPath (org.apache.parquet.hadoop.metadata.ColumnPath)7 HashMap (java.util.HashMap)5 Path (org.apache.hadoop.fs.Path)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ColumnEncryptionProperties (org.apache.parquet.crypto.ColumnEncryptionProperties)3 FileDecryptionProperties (org.apache.parquet.crypto.FileDecryptionProperties)3 ColumnMetaData (org.apache.parquet.format.ColumnMetaData)3 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)2 FileEncryptionProperties (org.apache.parquet.crypto.FileEncryptionProperties)2 InternalColumnDecryptionSetup (org.apache.parquet.crypto.InternalColumnDecryptionSetup)2 SingleRow (org.apache.parquet.crypto.SingleRow)2 Group (org.apache.parquet.example.data.Group)2 BlockCipher (org.apache.parquet.format.BlockCipher)2 ColumnChunk (org.apache.parquet.format.ColumnChunk)2 RowGroup (org.apache.parquet.format.RowGroup)2 Util.writeColumnMetaData (org.apache.parquet.format.Util.writeColumnMetaData)2