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();
}
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);
}
}
Aggregations