Skip to content
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

[C++] read encrypted ORC file #1993

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions c++/include/orc/Common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@ namespace orc {
* Get the writer timezone.
*/
virtual const std::string& getWriterTimezone() const = 0;
/**
*Get the list of Localkeys for all columns in the Stripe, with each encrypted column
*corresponding to a Localkey.
* @return
*/
virtual std::shared_ptr<std::vector<std::vector<unsigned char>>>
getEncryptedLocalKeys() const = 0;
/**
*Get the Localkey for a specific column in this Stripe.
*/
virtual std::vector<unsigned char>& getEncryptedLocalKeyByVariantId(int32_t col) const = 0;
/**
* In general, only the first stripe in an ORC file will store the LocalKey.In this case, the
* stripeId and originalStripeId are equal. If an ORC file has multiple stripes storing the
* LocalKey, the values of stripeId and originalStripeId may not be equal.
* @return
*/
virtual int64_t getOriginalStripeId() const = 0;
};

// Return true if val1 < val2; otherwise return false
Expand Down
6 changes: 5 additions & 1 deletion c++/include/orc/Reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace orc {
// classes that hold data members so we can maintain binary compatibility
struct ReaderOptionsPrivate;
struct RowReaderOptionsPrivate;

class KeyProvider;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The c++/include/orc folder is public and files in it will be installed. If the KeyProvider is also public, please move its definition to the include folder as well. Otherwise, we should remove the related function from here.

/**
* Expose the reader metrics including the latency and
* number of calls of the decompression/decoding/IO modules.
Expand Down Expand Up @@ -138,6 +138,10 @@ namespace orc {
* Get the reader metrics.
*/
ReaderMetrics* getReaderMetrics() const;

ReaderOptions& setKeyProvider(std::shared_ptr<KeyProvider> keyProvider);

std::shared_ptr<KeyProvider> getKeyProvider() const;
};

/**
Expand Down
8 changes: 6 additions & 2 deletions c++/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ add_custom_command(OUTPUT orc_proto.pb.h orc_proto.pb.cc
--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
../../orc-format_ep-prefix/src/orc-format_ep/src/main/proto/orc/proto/orc_proto.proto
)

set(SOURCE_FILES
"${CMAKE_CURRENT_BINARY_DIR}/Adaptor.hh"
orc_proto.pb.h
Expand Down Expand Up @@ -187,7 +186,10 @@ set(SOURCE_FILES
Timezone.cc
TypeImpl.cc
Vector.cc
Writer.cc)
Writer.cc
security/InMemoryKeystore.cc
security/ReaderEncryption.cc
)

if(BUILD_LIBHDFSPP)
set(SOURCE_FILES ${SOURCE_FILES} OrcHdfsFile.cc)
Expand All @@ -211,6 +213,8 @@ target_link_libraries (orc
$<BUILD_INTERFACE:orc::lz4>
$<BUILD_INTERFACE:orc::zstd>
$<BUILD_INTERFACE:${LIBHDFSPP_LIBRARIES}>
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
zxf216 marked this conversation as resolved.
Show resolved Hide resolved
)

target_include_directories (orc
Expand Down
8 changes: 7 additions & 1 deletion c++/src/Compression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,13 @@ namespace orc {
throw NotImplementedYet("compression codec");
}
}

std::unique_ptr<SeekableInputStream> createDecompressorAndDecryption(
CompressionKind kind, std::unique_ptr<SeekableInputStream> input, uint64_t blockSize,
MemoryPool& pool, ReaderMetrics* metrics,std::vector<unsigned char> key,
std::vector<unsigned char> iv,const EVP_CIPHER* cipher){
auto dec = std::make_unique<DecryptionInputStream>(std::move(input),key,iv,cipher,pool);
return createDecompressor(kind,std::move(dec),blockSize,pool,metrics);
}
std::unique_ptr<SeekableInputStream> createDecompressor(
CompressionKind kind, std::unique_ptr<SeekableInputStream> input, uint64_t blockSize,
MemoryPool& pool, ReaderMetrics* metrics) {
Expand Down
4 changes: 4 additions & 0 deletions c++/src/Compression.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ namespace orc {
CompressionKind kind, std::unique_ptr<SeekableInputStream> input, uint64_t bufferSize,
MemoryPool& pool, ReaderMetrics* metrics);

std::unique_ptr<SeekableInputStream> createDecompressorAndDecryption(CompressionKind kind, std::unique_ptr<SeekableInputStream> input, uint64_t blockSize,
MemoryPool& pool, ReaderMetrics* metrics,std::vector<unsigned char> key,
std::vector<unsigned char> iv,const EVP_CIPHER* cipher);

/**
* Create a compressor for the given compression kind.
* @param kind the compression type to implement
Expand Down
8 changes: 8 additions & 0 deletions c++/src/Options.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace orc {
MemoryPool* memoryPool;
std::string serializedTail;
ReaderMetrics* metrics;
std::shared_ptr<KeyProvider> keyProvider;

ReaderOptionsPrivate() {
tailLocation = std::numeric_limits<uint64_t>::max();
Expand Down Expand Up @@ -121,7 +122,14 @@ namespace orc {
std::ostream* ReaderOptions::getErrorStream() const {
return privateBits_->errorStream;
}
ReaderOptions& ReaderOptions::setKeyProvider(std::shared_ptr<KeyProvider> keyProvider) {
privateBits_->keyProvider = keyProvider;
return *this;
}

std::shared_ptr<KeyProvider> ReaderOptions::getKeyProvider() const {
return privateBits_->keyProvider;
}
/**
* RowReaderOptions Implementation
*/
Expand Down
Loading
Loading