Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cpp/src/parquet/arrow/arrow_reader_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1990,8 +1990,8 @@ TEST(ExternalDbpaConcurrencyTest, FailsWhenUseThreadsTrue) {
parquet::ExternalFileEncryptionProperties::Builder fep_builder(footer_key);
fep_builder.footer_key_metadata("kf")
->encrypted_columns(enc_cols)
->algorithm(parquet::ParquetCipher::AES_GCM_V1)
->connection_config({{parquet::ParquetCipher::EXTERNAL_DBPA_V1,
->algorithm(parquet::ParquetCipher::AES_GCM_V1)
->configuration_properties({{parquet::ParquetCipher::EXTERNAL_DBPA_V1,
{{"agent_library_path", lib_path},
{"file_path", "/tmp/test"}}}});

Expand All @@ -2010,8 +2010,8 @@ TEST(ExternalDbpaConcurrencyTest, FailsWhenUseThreadsTrue) {

parquet::ExternalFileDecryptionProperties::Builder dep_builder;
dep_builder.key_retriever(kr)
->app_context("{}")
->connection_config({{parquet::ParquetCipher::EXTERNAL_DBPA_V1,
->app_context("{}")
->configuration_properties({{parquet::ParquetCipher::EXTERNAL_DBPA_V1,
{{"agent_library_path", lib_path},
{"file_path", "/tmp/test"}}}});
parquet::ReaderProperties rp = parquet::default_reader_properties();
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/parquet/column_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ TEST_F(TestColumnWriterEncryption, ExternalDBPAEncryption) {
->set_plaintext_footer()
->algorithm(ParquetCipher::AES_GCM_V1)
->app_context(app_context_)
->connection_config({{ParquetCipher::EXTERNAL_DBPA_V1, connection_config_}});
->configuration_properties({{ParquetCipher::EXTERNAL_DBPA_V1, connection_config_}});
auto file_encryption_properties = fep_builder.build_external();

auto writer_properties_builder = WriterProperties::Builder();
Expand Down Expand Up @@ -2017,7 +2017,7 @@ TEST_F(TestColumnWriterEncryption, ExternalDBPAEncryption) {
decryption_properties_builder.footer_key(kFooterEncryptionKey_)
->column_keys(decryption_columns)
->app_context(app_context_)
->connection_config({{ParquetCipher::EXTERNAL_DBPA_V1, connection_config_}});
->configuration_properties({{ParquetCipher::EXTERNAL_DBPA_V1, connection_config_}});
reader_properties.file_decryption_properties(decryption_properties_builder.build_external());

auto file_reader = ParquetFileReader::Open(
Expand Down Expand Up @@ -2062,7 +2062,7 @@ TEST_F(TestColumnWriterEncryption, ExternalDBPAEncryption_MultiplePagesNoConflic
->set_plaintext_footer()
->algorithm(ParquetCipher::AES_GCM_V1)
->app_context(app_context_)
->connection_config({{ParquetCipher::EXTERNAL_DBPA_V1, connection_config_}});
->configuration_properties({{ParquetCipher::EXTERNAL_DBPA_V1, connection_config_}});
auto file_encryption_properties = fep_builder.build_external();

auto writer_properties_builder = WriterProperties::Builder();
Expand Down Expand Up @@ -2113,7 +2113,7 @@ TEST_F(TestColumnWriterEncryption, ExternalDBPAEncryption_ConflictingMetadataThr
->set_plaintext_footer()
->algorithm(ParquetCipher::AES_GCM_V1)
->app_context(app_context_)
->connection_config({{ParquetCipher::EXTERNAL_DBPA_V1, {
->configuration_properties({{ParquetCipher::EXTERNAL_DBPA_V1, {
{"dbpa_test_force_conflicting_metadata", "1"},
{"agent_library_path", library_path_}
}}});
Expand Down
22 changes: 11 additions & 11 deletions cpp/src/parquet/encryption/crypto_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ int ValidateAndGetKeyLength(int32_t dek_length_bits) {
return dek_length_bits / 8;
}

std::map<ParquetCipher::type, std::map<std::string, std::string>> ConvertConnectionConfig(
std::map<ParquetCipher::type, std::map<std::string, std::string>> ConvertConfigurationProperties(
const std::unordered_map<ParquetCipher::type,
std::unordered_map<std::string, std::string>>& connection_config) {
std::unordered_map<std::string, std::string>>& configuration_properties) {

std::map<ParquetCipher::type, std::map<std::string, std::string>> converted_config;

for (const auto& [cipher_type, inner_config] : connection_config) {
for (const auto& [cipher_type, inner_config] : configuration_properties) {
if (!IsParquetCipherSupported(cipher_type)) {
throw ParquetException("Invalid ParquetCipher type: " +
std::to_string(static_cast<int>(cipher_type)));
Expand All @@ -88,10 +88,10 @@ std::map<ParquetCipher::type, std::map<std::string, std::string>> ConvertConnect
std::map<std::string, std::string> converted_inner;
for (const auto& [key, value] : inner_config) {
if (key.empty()) {
throw ParquetException("Empty key in connection config");
throw ParquetException("Empty key in configuration properties");
}
if (value.empty()) {
throw ParquetException("Empty value for key '" + key + "' in connection config");
throw ParquetException("Empty value for key '" + key + "' in configuration properties");
}
converted_inner[key] = value;
}
Expand Down Expand Up @@ -239,9 +239,9 @@ CryptoFactory::GetExternalFileEncryptionProperties(
external_properties_builder.app_context(external_encryption_config.app_context);
}

if (!external_encryption_config.connection_config.empty()) {
external_properties_builder.connection_config(ConvertConnectionConfig(
external_encryption_config.connection_config));
if (!external_encryption_config.configuration_properties.empty()) {
external_properties_builder.configuration_properties(ConvertConfigurationProperties(
external_encryption_config.configuration_properties));
}

if (key_material_store != nullptr) {
Expand Down Expand Up @@ -353,9 +353,9 @@ CryptoFactory::GetExternalFileDecryptionProperties(
builder.app_context(external_decryption_config.app_context);
}

if (!external_decryption_config.connection_config.empty()) {
builder.connection_config(ConvertConnectionConfig(
external_decryption_config.connection_config));
if (!external_decryption_config.configuration_properties.empty()) {
builder.configuration_properties(ConvertConfigurationProperties(
external_decryption_config.configuration_properties));
}

return builder.build_external();
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/parquet/encryption/crypto_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ std::string app_context;
/// For security, these values should never be sent in this config, only the locations of
/// the files that the external encryptor will know how to access.
std::unordered_map<ParquetCipher::type, std::unordered_map<std::string, std::string>>
connection_config;
configuration_properties;
};

struct PARQUET_EXPORT DecryptionConfiguration {
Expand All @@ -163,7 +163,7 @@ struct PARQUET_EXPORT ExternalDecryptionConfiguration : public DecryptionConfigu
/// For security, these values should never be sent in this config, only the locations of
/// the files that the external decryptor will know how to access.
std::unordered_map<ParquetCipher::type, std::unordered_map<std::string, std::string>>
connection_config;
configuration_properties;
};

/// This is a core class, that translates the parameters of high level encryption (like
Expand Down
38 changes: 19 additions & 19 deletions cpp/src/parquet/encryption/crypto_factory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TEST_F(CryptoFactoryTest, ExternalEncryptionConfig) {
config.per_column_encryption = per_column_encryption;
config.app_context =
"{\"user_id\": \"abc123\", \"location\": {\"lat\": 9.7489, \"lon\": -83.7534}}";
config.connection_config = {
config.configuration_properties = {
{ParquetCipher::EXTERNAL_DBPA_V1, {{"file_path", "path/to/file"}}}
};

Expand Down Expand Up @@ -177,15 +177,15 @@ TEST_F(CryptoFactoryTest, ExternalEncryptionConfig) {
EXPECT_FALSE(column_properties_3->parquet_cipher().has_value());

EXPECT_FALSE(properties->app_context().empty());
EXPECT_FALSE(properties->connection_config().empty());
EXPECT_FALSE(properties->configuration_properties().empty());
EXPECT_EQ(properties->app_context(), config.app_context);
EXPECT_NE(properties->connection_config().find(ParquetCipher::EXTERNAL_DBPA_V1),
properties->connection_config().end());
EXPECT_EQ(properties->connection_config().find(ParquetCipher::AES_GCM_CTR_V1),
properties->connection_config().end());
EXPECT_NE(properties->connection_config().at(ParquetCipher::EXTERNAL_DBPA_V1).find("file_path"),
properties->connection_config().at(ParquetCipher::EXTERNAL_DBPA_V1).end());
EXPECT_EQ(properties->connection_config().at(ParquetCipher::EXTERNAL_DBPA_V1).at("file_path"),
EXPECT_NE(properties->configuration_properties().find(ParquetCipher::EXTERNAL_DBPA_V1),
properties->configuration_properties().end());
EXPECT_EQ(properties->configuration_properties().find(ParquetCipher::AES_GCM_CTR_V1),
properties->configuration_properties().end());
EXPECT_NE(properties->configuration_properties().at(ParquetCipher::EXTERNAL_DBPA_V1).find("file_path"),
properties->configuration_properties().at(ParquetCipher::EXTERNAL_DBPA_V1).end());
EXPECT_EQ(properties->configuration_properties().at(ParquetCipher::EXTERNAL_DBPA_V1).at("file_path"),
"path/to/file");
}

Expand Down Expand Up @@ -244,15 +244,15 @@ TEST_F(CryptoFactoryTest, BasicDecryptionConfig) {
EXPECT_TRUE(properties->plaintext_files_allowed());
EXPECT_THAT(properties->key_retriever(), testing::NotNull());
EXPECT_TRUE(properties->app_context().empty());
EXPECT_TRUE(properties->connection_config().empty());
EXPECT_TRUE(properties->configuration_properties().empty());
}

TEST_F(CryptoFactoryTest, ExternalDecryptionConfig) {
ExternalDecryptionConfiguration config;
config.cache_lifetime_seconds = 600;
config.app_context =
"{\"user_id\": \"abc123\", \"location\": {\"lat\": 9.7489, \"lon\": -83.7534}}";
config.connection_config = {
config.configuration_properties = {
{ParquetCipher::EXTERNAL_DBPA_V1, {{"file_path", "path/to/file"}}}
};

Expand All @@ -261,15 +261,15 @@ TEST_F(CryptoFactoryTest, ExternalDecryptionConfig) {
EXPECT_TRUE(properties->plaintext_files_allowed());
EXPECT_THAT(properties->key_retriever(), testing::NotNull());
EXPECT_FALSE(properties->app_context().empty());
EXPECT_FALSE(properties->connection_config().empty());
EXPECT_FALSE(properties->configuration_properties().empty());
EXPECT_EQ(properties->app_context(), config.app_context);
EXPECT_NE(properties->connection_config().find(ParquetCipher::EXTERNAL_DBPA_V1),
properties->connection_config().end());
EXPECT_EQ(properties->connection_config().find(ParquetCipher::AES_GCM_CTR_V1),
properties->connection_config().end());
EXPECT_NE(properties->connection_config().at(ParquetCipher::EXTERNAL_DBPA_V1).find("file_path"),
properties->connection_config().at(ParquetCipher::EXTERNAL_DBPA_V1).end());
EXPECT_EQ(properties->connection_config().at(ParquetCipher::EXTERNAL_DBPA_V1).at("file_path"),
EXPECT_NE(properties->configuration_properties().find(ParquetCipher::EXTERNAL_DBPA_V1),
properties->configuration_properties().end());
EXPECT_EQ(properties->configuration_properties().find(ParquetCipher::AES_GCM_CTR_V1),
properties->configuration_properties().end());
EXPECT_NE(properties->configuration_properties().at(ParquetCipher::EXTERNAL_DBPA_V1).find("file_path"),
properties->configuration_properties().at(ParquetCipher::EXTERNAL_DBPA_V1).end());
EXPECT_EQ(properties->configuration_properties().at(ParquetCipher::EXTERNAL_DBPA_V1).at("file_path"),
"path/to/file");
}

Expand Down
28 changes: 14 additions & 14 deletions cpp/src/parquet/encryption/encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ ExternalFileDecryptionProperties::Builder* ExternalFileDecryptionProperties::Bui
}

ExternalFileDecryptionProperties::Builder*
ExternalFileDecryptionProperties::Builder::connection_config(
ExternalFileDecryptionProperties::Builder::configuration_properties(
std::map<ParquetCipher::type, std::map<std::string, std::string>> config) {
if (connection_config_.size() != 0) {
throw ParquetException("Connection config already set");
if (configuration_properties_.size() != 0) {
throw ParquetException("Configuration properties already set");
}

if (config.size() == 0) {
return this;
}
connection_config_ = std::move(config);
configuration_properties_ = std::move(config);
return this;
}

Expand All @@ -178,7 +178,7 @@ ExternalFileDecryptionProperties::Builder::build_external() {
return std::shared_ptr<ExternalFileDecryptionProperties>(new ExternalFileDecryptionProperties(
footer_key_, key_retriever_, check_plaintext_footer_integrity_, aad_prefix_,
aad_prefix_verifier_, column_decryption_properties_, plaintext_files_allowed_,
app_context_, connection_config_));
app_context_, configuration_properties_));
}

ExternalFileDecryptionProperties::ExternalFileDecryptionProperties(
Expand All @@ -189,12 +189,12 @@ ExternalFileDecryptionProperties::ExternalFileDecryptionProperties(
ColumnPathToDecryptionPropertiesMap column_decryption_properties,
bool plaintext_files_allowed,
std::string app_context,
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config)
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties)
: FileDecryptionProperties(footer_key, key_retriever, check_plaintext_footer_integrity,
aad_prefix, aad_prefix_verifier, column_decryption_properties,
plaintext_files_allowed),
app_context_(app_context),
connection_config_(connection_config) {}
configuration_properties_(configuration_properties) {}

ColumnDecryptionProperties::Builder* ColumnDecryptionProperties::Builder::key(
SecureString key) {
Expand Down Expand Up @@ -404,25 +404,25 @@ ExternalFileEncryptionProperties::Builder* ExternalFileEncryptionProperties::Bui
}

ExternalFileEncryptionProperties::Builder*
ExternalFileEncryptionProperties::Builder::connection_config(
ExternalFileEncryptionProperties::Builder::configuration_properties(
std::map<ParquetCipher::type, std::map<std::string, std::string>> config) {
if (connection_config_.size() != 0) {
throw ParquetException("Connection config already set");
if (configuration_properties_.size() != 0) {
throw ParquetException("Configuration properties already set");
}

if (config.size() == 0) {
return this;
}

connection_config_ = std::move(config);
configuration_properties_ = std::move(config);
return this;
}

std::shared_ptr<ExternalFileEncryptionProperties>
ExternalFileEncryptionProperties::Builder::build_external() {
return std::shared_ptr<ExternalFileEncryptionProperties>(new ExternalFileEncryptionProperties(
parquet_cipher_, footer_key_, footer_key_metadata_, encrypted_footer_, aad_prefix_,
store_aad_prefix_in_file_, encrypted_columns_, app_context_, connection_config_));
store_aad_prefix_in_file_, encrypted_columns_, app_context_, configuration_properties_));
}

ExternalFileEncryptionProperties::ExternalFileEncryptionProperties(
Expand All @@ -431,11 +431,11 @@ ExternalFileEncryptionProperties::ExternalFileEncryptionProperties(
std::string aad_prefix, bool store_aad_prefix_in_file,
ColumnPathToEncryptionPropertiesMap encrypted_columns,
std::string app_context,
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config)
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties)
: FileEncryptionProperties(cipher, footer_key, footer_key_metadata, encrypted_footer,
aad_prefix, store_aad_prefix_in_file, encrypted_columns),
app_context_(app_context),
connection_config_(connection_config) {}
configuration_properties_(configuration_properties) {}


} // namespace parquet
26 changes: 13 additions & 13 deletions cpp/src/parquet/encryption/encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class PARQUET_EXPORT ExternalFileDecryptionProperties : public FileDecryptionPro

Builder* app_context(std::string context);

Builder* connection_config(
Builder* configuration_properties(
std::map<ParquetCipher::type, std::map<std::string, std::string>> config);

/// Forward all base class property methods to the base class Builder so we can return the
Expand Down Expand Up @@ -423,21 +423,21 @@ class PARQUET_EXPORT ExternalFileDecryptionProperties : public FileDecryptionPro

private:
std::string app_context_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties_;
};

const std::string& app_context() const {
return app_context_;
}

const std::map<ParquetCipher::type, std::map<std::string, std::string>>&
connection_config() const {
return connection_config_;
const std::map<ParquetCipher::type, std::map<std::string, std::string>>&
configuration_properties() const {
return configuration_properties_;
}

private:
std::string app_context_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties_;

ExternalFileDecryptionProperties(
::arrow::util::SecureString footer_key,
Expand All @@ -447,7 +447,7 @@ class PARQUET_EXPORT ExternalFileDecryptionProperties : public FileDecryptionPro
ColumnPathToDecryptionPropertiesMap column_decryption_properties,
bool plaintext_files_allowed,
std::string app_context,
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config);
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties);
};

class PARQUET_EXPORT FileEncryptionProperties {
Expand Down Expand Up @@ -565,7 +565,7 @@ class PARQUET_EXPORT ExternalFileEncryptionProperties : public FileEncryptionPro
/// needed by the external encryptors, including location of a dynamically-linked library,
/// or config files where the external encryptors can find urls, certificates, and parameters
/// needed to make a remote call.
Builder* connection_config(
Builder* configuration_properties(
std::map<ParquetCipher::type, std::map<std::string, std::string>> config);

/// Forward all base class property methods to the base class Builder so we can return the
Expand Down Expand Up @@ -609,29 +609,29 @@ class PARQUET_EXPORT ExternalFileEncryptionProperties : public FileEncryptionPro

private:
std::string app_context_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties_;
};

const std::string& app_context() const {
return app_context_;
}

const std::map<ParquetCipher::type, std::map<std::string, std::string>>&
connection_config() const {
return connection_config_;
configuration_properties() const {
return configuration_properties_;
}

private:
std::string app_context_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config_;
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties_;

ExternalFileEncryptionProperties(ParquetCipher::type cipher,
::arrow::util::SecureString footer_key,
std::string footer_key_metadata, bool encrypted_footer,
std::string aad_prefix, bool store_aad_prefix_in_file,
ColumnPathToEncryptionPropertiesMap encrypted_columns,
std::string app_context,
std::map<ParquetCipher::type, std::map<std::string, std::string>> connection_config);
std::map<ParquetCipher::type, std::map<std::string, std::string>> configuration_properties);
};

} // namespace parquet
Loading
Loading