-
Notifications
You must be signed in to change notification settings - Fork 0
Modifying ExternalDBPAEncryptor/DecryptorAdapter to obtain agent instance from shared lib (DLL) #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modifying ExternalDBPAEncryptor/DecryptorAdapter to obtain agent instance from shared lib (DLL) #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| #include <map> | ||
| #include <vector> | ||
|
|
||
| #include "parquet/encryption/external/third_party/dbpa_interface.h" | ||
|
|
||
| #include "parquet/encryption/encryptor_interface.h" | ||
| #include "parquet/encryption/decryptor_interface.h" | ||
| #include "parquet/metadata.h" | ||
|
|
@@ -46,7 +48,7 @@ class ExternalDBPAEncryptorAdapter : public EncryptorInterface { | |
| ::arrow::util::span<uint8_t> encrypted_footer) override; | ||
|
|
||
| private: | ||
| int32_t CallExternalDBPA( | ||
| int32_t InvokeExternalEncrypt( | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made this name change so source files are easier to navigate. Sharing the same name among encryptor and decryptor was confusing. |
||
| ::arrow::util::span<const uint8_t> plaintext, ::arrow::util::span<uint8_t> ciphertext); | ||
|
|
||
| ParquetCipher::type algorithm_; | ||
|
|
@@ -57,6 +59,9 @@ class ExternalDBPAEncryptorAdapter : public EncryptorInterface { | |
| Encoding::type encoding_type_; | ||
| std::string app_context_; | ||
| std::map<std::string, std::string> connection_config_; | ||
|
|
||
| std::unique_ptr<dbps::external::DataBatchProtectionAgentInterface> agent_instance_; | ||
| bool agent_initialized_ = false; | ||
| }; | ||
|
|
||
| /// Factory for ExternalDBPAEncryptorAdapter instances. The cache exists while the write | ||
|
|
@@ -104,7 +109,7 @@ class ExternalDBPADecryptorAdapter : public DecryptorInterface { | |
| ::arrow::util::span<uint8_t> plaintext) override; | ||
|
|
||
| private: | ||
| int32_t CallExternalDBPA( | ||
| int32_t InvokeExternalDecrypt( | ||
| ::arrow::util::span<const uint8_t> ciphertext, ::arrow::util::span<uint8_t> plaintext); | ||
|
|
||
| ParquetCipher::type algorithm_; | ||
|
|
@@ -116,6 +121,9 @@ class ExternalDBPADecryptorAdapter : public DecryptorInterface { | |
| std::vector<Encoding::type> encoding_types_; | ||
| std::string app_context_; | ||
| std::map<std::string, std::string> connection_config_; | ||
|
|
||
| std::unique_ptr<dbps::external::DataBatchProtectionAgentInterface> agent_instance_; | ||
| bool agent_initialized_ = false; | ||
| }; | ||
|
|
||
| /// Factory for ExternalDBPADecryptorAdapter instances. No cache exists for decryptors. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,17 +17,18 @@ class ExternalDBPAEncryptorAdapterTest : public ::testing::Test { | |
| "{\"user_id\": \"abc123\", \"location\": {\"lat\": 9.7489, \"lon\": -83.7534}}"; | ||
| connection_config_ = { | ||
| {"lib_name", "dbpa_lib.so"}, | ||
| {"config_path", "path/to/file"} | ||
| {"config_path", "path/to/file"}, | ||
| {"agent_library_path", "libDBPATestAgent.so"} | ||
| }; | ||
| } | ||
|
|
||
| void RoundtripEncryption( | ||
| ParquetCipher::type algorithm, std::string column_name, std::string key_id, | ||
| Type::type data_type, Compression::type compression_type, Encoding::type encoding_type, | ||
| std::string plaintext) { | ||
| ExternalDBPAEncryptorAdapter encryptor( | ||
| algorithm, column_name, key_id, data_type, compression_type, encoding_type, | ||
| app_context_, connection_config_); | ||
| ExternalDBPAEncryptorAdapter encryptor(algorithm, column_name, key_id, data_type, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just formatting, so that the encryptor and decryptor construction are similar in the code (no functional changes) |
||
| compression_type, encoding_type, app_context_, | ||
| connection_config_); | ||
|
|
||
| int32_t expected_ciphertext_length = plaintext.size(); | ||
| int32_t actual_ciphertext_length = encryptor.CiphertextLength(plaintext.size()); | ||
|
|
@@ -39,7 +40,19 @@ class ExternalDBPAEncryptorAdapterTest : public ::testing::Test { | |
| ASSERT_EQ(expected_ciphertext_length, encryption_length); | ||
|
|
||
| std::string ciphertext_str(ciphertext_buffer.begin(), ciphertext_buffer.end()); | ||
| ASSERT_EQ(plaintext, ciphertext_str); | ||
|
|
||
| // We know this uses XOR encryption. Therefore, the ciphertext is the same as the plaintext. | ||
| // XOR encrytion encrypts each byte of the plaintext with 0xAA. | ||
| // See external/dbpa_test_agent.cc for the implementation. | ||
|
|
||
| // Assert that plaintext and ciphertext have the same length | ||
| ASSERT_EQ(plaintext.size(), ciphertext_str.size()); | ||
|
|
||
| // Assert that ciphertext is plaintext XOR'd with 0xAA | ||
| for (size_t i = 0; i < plaintext.size(); i++) { | ||
| ASSERT_EQ(static_cast<uint8_t>(ciphertext_str[i]), | ||
| static_cast<uint8_t>(plaintext[i]) ^ 0xAA); | ||
| } | ||
|
|
||
| ExternalDBPADecryptorAdapter decryptor(algorithm, column_name, key_id, data_type, | ||
| compression_type, {encoding_type}, app_context_, | ||
|
|
@@ -55,6 +68,8 @@ class ExternalDBPAEncryptorAdapterTest : public ::testing::Test { | |
| ASSERT_EQ(expected_plaintext_length, decryption_length); | ||
|
|
||
| std::string plaintext_str(plaintext_buffer.begin(), plaintext_buffer.end()); | ||
|
|
||
| // Assert that the decrypted plaintext matches the original plaintext | ||
| ASSERT_EQ(plaintext, plaintext_str); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We missed this in an earlier PR. Because the code was not being used at the time, there were no compilation errors.