This is an automated email from the ASF dual-hosted git repository.
adamreeve pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 7f1f38d9e0a GH-55406: [C++][Parquet] Test AES-CTR plaintext footer
example file (#55407)
7f1f38d9e0a is described below
commit 7f1f38d9e0ac7b23f1bfec59d05d9d1c22423007
Author: Adam Reeve <[email protected]>
AuthorDate: Fri Nov 6 09:49:34 2026 +1300
GH-55406: [C++][Parquet] Test AES-CTR plaintext footer example file (#55407)
### Rationale for this change
More test coverage.
### What changes are included in this PR?
* Updates the `parquet-testing` submodule.
* Adds a new test case for the test file added in
https://github.com/apache/parquet-testing/pull/130
* Allows regenerating the test files by setting a
`PARQUET_ENCRYPTION_TEST_OUTPUT_DIR` environment variable when running the
tests. This could be useful if we need to generate similar test files in the
future.
### Are these changes tested?
Yes
### Are there any user-facing changes?
No
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
**PR code and description written by:**
- [x] Human
- [x] AI (code only, not description)
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
* GitHub Issue: #55406
Authored-by: Adam Reeve <[email protected]>
Signed-off-by: Adam Reeve <[email protected]>
---
.../parquet/encryption/read_configurations_test.cc | 15 +++--
cpp/src/parquet/encryption/test_encryption_util.cc | 15 ++++-
cpp/src/parquet/encryption/test_encryption_util.h | 9 +++
.../encryption/write_configurations_test.cc | 74 +++++++++++++++++++++-
cpp/submodules/parquet-testing | 2 +-
5 files changed, 107 insertions(+), 8 deletions(-)
diff --git a/cpp/src/parquet/encryption/read_configurations_test.cc
b/cpp/src/parquet/encryption/read_configurations_test.cc
index 15c1e7df736..f322cb27a62 100644
--- a/cpp/src/parquet/encryption/read_configurations_test.cc
+++ b/cpp/src/parquet/encryption/read_configurations_test.cc
@@ -58,7 +58,7 @@
* (instead of key retrieval callback).
* - Decryption Configuration 4: PlainText Footer mode - test legacy reads,
* read the footer + all non-encrypted
columns.
- * (pairs with encryption configuration 3)
+ * (pairs with encryption configurations 3
and 7)
*
* The encrypted parquet files that are read were encrypted using one of the
* configurations below:
@@ -79,7 +79,9 @@
* identity storage in file metadata.
* - Encryption configuration 6: Encrypt two columns and the footer, with
different
* keys. Use the alternative (AES_GCM_CTR_V1)
algorithm.
-
+ * - Encryption configuration 7: Encrypt two columns, with different keys.
+ * Don't encrypt the footer.
+ * Use the alternative (AES_GCM_CTR_V1)
algorithm.
*/
namespace parquet::encryption::test {
@@ -222,8 +224,10 @@ class TestDecryptionConfiguration
}
}
- // decryption config 4 can only work when the encryption configuration is 3
- if (decryption_config_num == 4 && encryption_config_num != 3) {
+ // decryption config 4 can only work with a plaintext footer (encryption
+ // configurations 3 and 7)
+ if (decryption_config_num == 4 && encryption_config_num != 3 &&
+ encryption_config_num != 7) {
return;
}
EXPECT_NO_THROW(DecryptFile(file_name, decryption_config_num - 1));
@@ -290,6 +294,7 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple(4, "encrypt_columns_and_footer_aad.parquet.encrypted"),
std::make_tuple(
5,
"encrypt_columns_and_footer_disable_aad_storage.parquet.encrypted"),
- std::make_tuple(6,
"encrypt_columns_and_footer_ctr.parquet.encrypted")));
+ std::make_tuple(6, "encrypt_columns_and_footer_ctr.parquet.encrypted"),
+ std::make_tuple(7,
"encrypt_columns_plaintext_footer_ctr.parquet.encrypted")));
} // namespace parquet::encryption::test
diff --git a/cpp/src/parquet/encryption/test_encryption_util.cc
b/cpp/src/parquet/encryption/test_encryption_util.cc
index 86951f8264e..df7ad307fdd 100644
--- a/cpp/src/parquet/encryption/test_encryption_util.cc
+++ b/cpp/src/parquet/encryption/test_encryption_util.cc
@@ -175,6 +175,15 @@ void WriteBatch(int rows, const NextFunc get_next_column) {
FileEncryptor::FileEncryptor() { schema_ = SetupEncryptionSchema(); }
+FileEncryptor FileEncryptor::ForParquetTestingFiles() {
+ FileEncryptor encryptor;
+ encryptor.num_rowgroups_ = 1;
+ encryptor.compression_ = Compression::SNAPPY;
+ encryptor.parquet_version_ = ParquetVersion::PARQUET_2_4;
+ encryptor.rle_encode_boolean_ = true;
+ return encryptor;
+}
+
std::shared_ptr<GroupNode> FileEncryptor::SetupEncryptionSchema() {
parquet::schema::NodeVector fields;
@@ -211,7 +220,11 @@ void FileEncryptor::EncryptFile(
std::string file,
std::shared_ptr<parquet::FileEncryptionProperties>
encryption_configurations) {
WriterProperties::Builder prop_builder;
- prop_builder.compression(parquet::Compression::UNCOMPRESSED);
+ prop_builder.version(parquet_version_);
+ prop_builder.compression(compression_);
+ if (rle_encode_boolean_) {
+ prop_builder.encoding(kBooleanFieldName, Encoding::RLE);
+ }
prop_builder.encryption(encryption_configurations);
prop_builder.enable_write_page_index();
std::shared_ptr<WriterProperties> writer_properties = prop_builder.build();
diff --git a/cpp/src/parquet/encryption/test_encryption_util.h
b/cpp/src/parquet/encryption/test_encryption_util.h
index 46b84a0d0a3..158994cbc2b 100644
--- a/cpp/src/parquet/encryption/test_encryption_util.h
+++ b/cpp/src/parquet/encryption/test_encryption_util.h
@@ -34,6 +34,7 @@
#include "arrow/util/secure_string.h"
#include "parquet/encryption/encryption.h"
+#include "parquet/properties.h"
#include "parquet/test_util.h"
namespace parquet {
@@ -102,6 +103,11 @@ class FileEncryptor {
public:
FileEncryptor();
+ // Create a FileEncryptor that writes files with the same layout as the
encrypted
+ // files in the parquet-testing repository (a single row group, Snappy
compression
+ // and RLE encoding for the boolean column).
+ static FileEncryptor ForParquetTestingFiles();
+
void EncryptFile(
std::string file,
std::shared_ptr<parquet::FileEncryptionProperties>
encryption_configurations);
@@ -111,6 +117,9 @@ class FileEncryptor {
int num_rowgroups_ = 5;
int rows_per_rowgroup_ = 50;
+ Compression::type compression_ = Compression::UNCOMPRESSED;
+ ParquetVersion::type parquet_version_ = ParquetVersion::PARQUET_2_LATEST;
+ bool rle_encode_boolean_ = false;
std::shared_ptr<schema::GroupNode> schema_;
};
diff --git a/cpp/src/parquet/encryption/write_configurations_test.cc
b/cpp/src/parquet/encryption/write_configurations_test.cc
index 821130fa6c0..98e9a43e0f2 100644
--- a/cpp/src/parquet/encryption/write_configurations_test.cc
+++ b/cpp/src/parquet/encryption/write_configurations_test.cc
@@ -19,13 +19,17 @@
#include <stdio.h>
+#include <fstream>
+#include <optional>
#include <stdexcept>
#include <tuple>
#include <vector>
#include <arrow/io/file.h>
+#include "arrow/util/config.h"
#include "arrow/util/endian.h"
+#include "arrow/util/io_util.h"
#include "arrow/util/ubsan.h"
#include "parquet/column_reader.h"
@@ -43,6 +47,11 @@
* The files are saved in temporary folder and will be deleted after reading
* them in read_configurations_test.cc test.
*
+ * To regenerate the corresponding files in the parquet-testing repository,
set the
+ * PARQUET_ENCRYPTION_TEST_OUTPUT_DIR environment variable to a directory. The
files
+ * are then written with the same layout as the parquet-testing files, and a
copy of
+ * each file (without the "tmp_" prefix) is written to that directory.
+ *
* A detailed description of the Parquet Modular Encryption specification can
be found
* here:
* https://github.com/apache/parquet-format/blob/encryption/Encryption.md
@@ -66,6 +75,9 @@
* identity storage in file metadata.
* - Encryption configuration 6: Encrypt two columns and the footer, with
different
* keys. Use the alternative (AES_GCM_CTR_V1)
algorithm.
+ * - Encryption configuration 7: Encrypt two columns, with different keys.
+ * Don't encrypt the footer.
+ * Use the alternative (AES_GCM_CTR_V1)
algorithm.
*/
namespace parquet::encryption::test {
@@ -78,8 +90,19 @@ class TestEncryptionConfiguration : public ::testing::Test {
public:
static void SetUpTestCase();
+ void SetUp() override {
+#ifndef ARROW_WITH_SNAPPY
+ if (output_dir_.has_value()) {
+ FAIL() << "Generating parquet-testing files requires Snappy compression";
+ }
+#endif
+ }
+
protected:
- FileEncryptor encryptor_;
+ // Set when generating files for the parquet-testing repository
+ const std::optional<std::string> output_dir_ = GetOutputDir();
+ FileEncryptor encryptor_ =
+ output_dir_.has_value() ? FileEncryptor::ForParquetTestingFiles() :
FileEncryptor();
std::string path_to_double_field_ = kDoubleFieldName;
std::string path_to_float_field_ = kFloatFieldName;
@@ -93,6 +116,36 @@ class TestEncryptionConfiguration : public ::testing::Test {
std::string file_name) {
std::string file = temp_dir->path().ToString() + file_name;
encryptor_.EncryptFile(file, encryption_configurations);
+ CopyToOutputDir(file, file_name);
+ }
+
+ static std::optional<std::string> GetOutputDir() {
+ auto maybe_output_dir =
+ ::arrow::internal::GetEnvVar("PARQUET_ENCRYPTION_TEST_OUTPUT_DIR");
+ if (!maybe_output_dir.ok()) {
+ return std::nullopt;
+ }
+ return maybe_output_dir.MoveValueUnsafe();
+ }
+
+ // Copy the file to the output directory if it is set, so the parquet-testing
+ // files can be regenerated.
+ void CopyToOutputDir(const std::string& file, const std::string& file_name)
const {
+ if (!output_dir_.has_value()) {
+ return;
+ }
+ std::string output_name = file_name;
+ const std::string tmp_prefix = "tmp_";
+ if (output_name.rfind(tmp_prefix, 0) == 0) {
+ output_name = output_name.substr(tmp_prefix.size());
+ }
+ std::ifstream src(file, std::ios::binary);
+ std::ofstream dst(*output_dir_ + "/" + output_name, std::ios::binary);
+ ASSERT_TRUE(src.good() && dst.good())
+ << "Failed to copy " << file << " to " << *output_dir_;
+ dst << src.rdbuf();
+ dst.close();
+ ASSERT_TRUE(dst.good()) << "Failed to write " << output_name;
}
};
@@ -203,6 +256,25 @@ TEST_F(TestEncryptionConfiguration,
EncryptTwoColumnsAndFooterUseAES_GCM_CTR) {
"tmp_encrypt_columns_and_footer_ctr.parquet.encrypted"));
}
+TEST_F(TestEncryptionConfiguration,
EncryptTwoColumnsWithPlaintextFooterUseAES_GCM_CTR) {
+ std::map<std::string, std::shared_ptr<ColumnEncryptionProperties>>
encryption_cols7;
+ encryption_cols7[path_to_double_field_] =
+ ColumnEncryptionProperties::WithColumnKey(kColumnEncryptionKey1_, "kc1");
+ encryption_cols7[path_to_float_field_] =
+ ColumnEncryptionProperties::WithColumnKey(kColumnEncryptionKey2_, "kc2");
+ encryption_cols7[kBooleanFieldName] =
ColumnEncryptionProperties::Unencrypted();
+
+ FileEncryptionProperties::Builder
file_encryption_builder_7(kFooterEncryptionKey_);
+
+ EXPECT_NO_THROW(
+ this->EncryptFile(file_encryption_builder_7.footer_key_metadata("kf")
+ ->encrypted_columns(std::move(encryption_cols7))
+ ->set_plaintext_footer()
+ ->algorithm(parquet::ParquetCipher::AES_GCM_CTR_V1)
+ ->build(),
+
"tmp_encrypt_columns_plaintext_footer_ctr.parquet.encrypted"));
+}
+
enum class AadPrefixMode { None, Stored, External };
class TestGeneratedEncryptionConfiguration
diff --git a/cpp/submodules/parquet-testing b/cpp/submodules/parquet-testing
index 56653c437c8..eedfad3f086 160000
--- a/cpp/submodules/parquet-testing
+++ b/cpp/submodules/parquet-testing
@@ -1 +1 @@
-Subproject commit 56653c437c8092f704a092d0d1d4e600124cd49f
+Subproject commit eedfad3f086678d282a00d8ff3cf8932d5d29af5