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
52 changes: 3 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,13 @@ target_include_directories(dbps_byte_buffer_lib INTERFACE
)
target_link_libraries(dbps_byte_buffer_lib INTERFACE tcb_span)

# TODO: Update this when deprecating BasicEncryptor
# Standalone XOR encryptor library (kept parallel to legacy basic_encryptor path)
add_library(dbps_xor_encryptor_lib STATIC
src/processing/encryptors/basic_xor_encryptor.cpp
)
target_link_libraries(dbps_xor_encryptor_lib PUBLIC dbps_common_lib tcb_span)
target_include_directories(dbps_xor_encryptor_lib PUBLIC
src/processing
src/processing/encryptors
src/common
)

# Server components library
add_library(dbps_server_lib STATIC
src/processing/encryption_sequencer.cpp
src/server/auth_utils.cpp
src/processing/parquet_utils.cpp
src/processing/compression_utils.cpp
src/processing/value_encryption_utils.cpp
src/processing/typed_list_values.cpp
src/processing/encryptors/basic_encryptor.cpp
src/processing/encryptors/basic_xor_encryptor.cpp
)
target_link_libraries(dbps_server_lib PUBLIC dbps_common_lib snappy)
target_include_directories(dbps_server_lib PUBLIC
Expand Down Expand Up @@ -294,22 +280,6 @@ if(BUILD_TESTS)
gtest_main
)

# Value encryption utils tests
add_executable(value_encryption_utils_test src/processing/value_encryption_utils_test.cpp)
target_link_libraries(value_encryption_utils_test
dbps_server_lib
dbps_common_lib
gtest_main
)

# Typed list values tests
add_executable(typed_list_values_test src/processing/typed_list_values_test.cpp)
target_link_libraries(typed_list_values_test
dbps_server_lib
dbps_common_lib
gtest_main
)

# Encryption sequencer tests
add_executable(encryption_sequencer_test src/processing/encryption_sequencer_test.cpp)
target_link_libraries(encryption_sequencer_test
Expand Down Expand Up @@ -362,18 +332,9 @@ if(BUILD_TESTS)
target_include_directories(typed_buffer_values_test PRIVATE src/processing src/common)

# Basic encryptor tests
add_executable(basic_encryptor_test src/processing/encryptors/basic_encryptor_test.cpp)
target_link_libraries(basic_encryptor_test
dbps_server_lib
dbps_common_lib
gtest_main
)
target_include_directories(basic_encryptor_test PRIVATE src/processing src/processing/encryptors)

# Basic XOR encryptor tests (parallel path; does not replace BasicEncryptor callers)
add_executable(basic_xor_encryptor_test src/processing/encryptors/basic_xor_encryptor_test.cpp)
target_link_libraries(basic_xor_encryptor_test
dbps_xor_encryptor_lib
dbps_server_lib
dbps_common_lib
gtest_main
)
Expand Down Expand Up @@ -534,7 +495,6 @@ add_custom_target(libraries
dbps_local_lib
COMMENT "Building all libraries"
)
add_dependencies(libraries dbps_xor_encryptor_lib)

add_custom_target(shared_libraries
DEPENDS
Expand All @@ -558,15 +518,13 @@ if(BUILD_TESTS)
DEPENDS
json_request_test
enum_utils_test
value_encryption_utils_test
typed_list_values_test
encryption_sequencer_test
parquet_utils_test
bytes_utils_test
compression_utils_test
typed_buffer_test
typed_buffer_values_test
basic_encryptor_test
basic_xor_encryptor_test
auth_utils_test
dbpa_interface_test
dbpa_utils_test
Expand All @@ -578,20 +536,16 @@ if(BUILD_TESTS)
http_client_base_test
COMMENT "Building all tests"
)
add_dependencies(tests basic_xor_encryptor_test)

# Register tests with CTest via GoogleTest discovery
gtest_discover_tests(json_request_test)
gtest_discover_tests(enum_utils_test)
gtest_discover_tests(value_encryption_utils_test)
gtest_discover_tests(typed_list_values_test)
gtest_discover_tests(encryption_sequencer_test)
gtest_discover_tests(parquet_utils_test)
gtest_discover_tests(bytes_utils_test)
gtest_discover_tests(compression_utils_test)
gtest_discover_tests(typed_buffer_test)
gtest_discover_tests(typed_buffer_values_test)
gtest_discover_tests(basic_encryptor_test)
gtest_discover_tests(basic_xor_encryptor_test)
gtest_discover_tests(auth_utils_test)
gtest_discover_tests(dbpa_interface_test)
Expand Down
7 changes: 4 additions & 3 deletions src/common/dbpa_local_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "dbpa_local.h"
#include "../processing/parquet_utils.h"
#include "../processing/parquet_testing_utils.h"
#include <gtest/gtest.h>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -48,7 +49,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulEncryption) {
EXPECT_NO_THROW(agent.init("test_column", configuration_map, app_context, "test_key",
Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, std::nullopt));

std::vector<uint8_t> test_data = BuildByteArrayValueBytes("test_ABC");
std::vector<uint8_t> test_data = BuildByteArrayValueBytesForTesting("test_ABC");
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
auto result = agent.Encrypt(test_data, encoding_attributes);

Expand Down Expand Up @@ -91,7 +92,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulDecryption) {
EXPECT_NO_THROW(agent.init("test_column", configuration_map, app_context, "test_key",
Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, DBPS_ENCRYPTION_METADATA));

std::vector<uint8_t> test_data = BuildByteArrayValueBytes("test_EFG");
std::vector<uint8_t> test_data = BuildByteArrayValueBytesForTesting("test_EFG");
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
auto result = agent.Decrypt(test_data, encoding_attributes);

Expand All @@ -111,7 +112,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, RoundTripEncryptDecrypt) {
Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, std::nullopt));

// Original data to encrypt
std::vector<uint8_t> original_data = BuildByteArrayValueBytes("roundtrip_XYZ");
std::vector<uint8_t> original_data = BuildByteArrayValueBytesForTesting("roundtrip_XYZ");
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};

// Encrypt the data
Expand Down
20 changes: 10 additions & 10 deletions src/processing/encryption_sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../common/bytes_utils.h"
#include "compression_utils.h"
#include "../common/exceptions.h"
#include "encryptors/basic_encryptor.h"
#include "encryptors/basic_xor_encryptor.h"
#include <functional>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -52,8 +52,8 @@ static std::unique_ptr<DBPSEncryptor> CreateEncryptor(
const std::string& application_context,
Type::type datatype) {

// Return a BasicEncryptor instance.
return std::make_unique<BasicEncryptor>(key_id, column_name, user_id, application_context, datatype);
// Return a BasicXorEncryptor instance.
return std::make_unique<BasicXorEncryptor>(key_id, column_name, user_id, application_context, datatype);
}

// Constructor implementation
Expand Down Expand Up @@ -141,11 +141,11 @@ bool DataBatchEncryptionSequencer::DecodeAndEncrypt(tcb::span<const uint8_t> pla
auto [level_bytes, value_bytes] = DecompressAndSplit(
plaintext, compression_, encoding_attributes_converted_);

// Parse value bytes into typed list
auto typed_list = ParseValueBytesIntoTypedList(value_bytes, datatype_, datatype_length_, encoding_);
// Parse value bytes into typed values buffer
auto typed_buffer = ReinterpretValueBytesAsTypedValuesBuffer(value_bytes, datatype_, datatype_length_, encoding_);

// Encrypt the typed list and level bytes, then join them into a single encrypted byte vector.
auto encrypted_value_bytes = encryptor_->EncryptValueList(typed_list);
// Encrypt the typed values buffer and level bytes, then join them into a single encrypted byte vector.
auto encrypted_value_bytes = encryptor_->EncryptValueList(typed_buffer);
auto encrypted_level_bytes = encryptor_->EncryptBlock(level_bytes);
auto joined_encrypted_bytes = JoinWithLengthPrefix(encrypted_level_bytes, encrypted_value_bytes);

Expand Down Expand Up @@ -237,10 +237,10 @@ bool DataBatchEncryptionSequencer::DecryptAndEncode(tcb::span<const uint8_t> cip
auto [encrypted_level_bytes, encrypted_value_bytes] =
SplitWithLengthPrefix(tcb::span<const uint8_t>(decompressed_encrypted_bytes));
auto level_bytes = encryptor_->DecryptBlock(encrypted_level_bytes);
auto typed_list = encryptor_->DecryptValueList(encrypted_value_bytes);
auto typed_buffer = encryptor_->DecryptValueList(encrypted_value_bytes);

// Convert the decrypted typed list back to value bytes
auto value_bytes = GetTypedListAsValueBytes(typed_list, datatype_, datatype_length_, encoding_);
// Convert the decrypted typed values buffer back to value bytes
auto value_bytes = GetTypedValuesBufferAsValueBytes(std::move(typed_buffer));

// Join the decrypted level and value bytes, then compress to get plaintext
decrypted_result_ = CompressAndJoin(
Expand Down
7 changes: 4 additions & 3 deletions src/processing/encryption_sequencer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "encryption_sequencer.h"
#include "compression_utils.h"
#include "parquet_utils.h"
#include "parquet_testing_utils.h"
#include "../common/enums.h"
#include "../common/bytes_utils.h"
#include <iostream>
Expand All @@ -32,10 +33,10 @@ using namespace dbps::compression;
using namespace dbps::external;

// Test data constants - pure binary data
const std::vector<uint8_t> HELLO_WORLD_DATA = BuildByteArrayValueBytes("Hello, World!");
const std::vector<uint8_t> BINARY_DATA = BuildByteArrayValueBytes(
const std::vector<uint8_t> HELLO_WORLD_DATA = BuildByteArrayValueBytesForTesting("Hello, World!");
const std::vector<uint8_t> BINARY_DATA = BuildByteArrayValueBytesForTesting(
std::string("\x00\x01\x02\x03\x04\x05", 6));
const std::vector<uint8_t> SINGLE_CHAR_DATA = BuildByteArrayValueBytes("A");
const std::vector<uint8_t> SINGLE_CHAR_DATA = BuildByteArrayValueBytesForTesting("A");
const std::vector<uint8_t> EMPTY_DATA = {};
const std::vector<uint8_t> FIXED_LEN_BYTE_ARRAY_DATA = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
Expand Down
133 changes: 0 additions & 133 deletions src/processing/encryptors/basic_encryptor.cpp

This file was deleted.

Loading