You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/05/31 10:43:01 UTC
[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
adamdebreceni opened a new pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090
Depends on #1071
---
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
- [ ] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file?
- [ ] If applicable, have you updated the NOTICE file?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664012699
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
I was using CLion, I think with the LLDB backend.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664315450
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
Review comment:
we are using the `CTREncryptionProvider`, which wraps our block cipher and provides the appropriate iv and counter per block
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664333508
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
based on the interface of `BlockAccessCipherStream` (which an `EncryptionProvider` should produce) I am under the impression that authenticated encryption is not yet supported by `rocksdb`
```
// Encrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize.
virtual Status Encrypt(uint64_t fileOffset, char* data, size_t dataSize);
// Decrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize.
virtual Status Decrypt(uint64_t fileOffset, char* data, size_t dataSize);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663939260
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
if only there wasn't now three different ways to create a temporary directory (now 2 in TestController, and 1 standalone in TestUtils.h) but I felt like removing all the single-use `format` variables in all the tests deserves its own PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664027439
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +231,24 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
- checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
- } else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
- }
- } else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) < 0) {
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
+ return;
+ }
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not create checkpoint object: %s", checkpoint_status.ToString());
+ return;
+ }
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not initialize checkpoint: %s", checkpoint_status.ToString());
+ return;
+ }
Review comment:
Shouldn't we `delete checkpoint;` if this fails? Or put it in a `unique_ptr` if `NewCheckpoint` was successful.
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
Review comment:
We should use a random initialization vector. It prevents the same plaintext from becoming the same ciphertext when encrypted with the same key. It can be stored as plaintext next to the ciphertext.
https://stackoverflow.com/a/8041580
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
Review comment:
I would change the signatures here to take [`gsl::span<unsigned char /*, BLOCK_SIZE*/>`](https://github.com/gsl-lite/gsl-lite/blob/master/include/gsl/gsl-lite.hpp#L3935) (gsl::span doesn't support static extents) and later `std::span<std::byte, BLOCK_SIZE>` for documentation.
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
Why do you want to disable padding? It pads so that the output is always a multiple of the block size. In theory we should always get one BLOCK_SIZE output for one BLOCK_SIZE input, so it shouldn't matter.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Can you explain why you chose ECB encryption mode? According to wikipedia, it's not recommended for for use in cryptographic protocols. https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_(ECB)
Block cipher modes also don't ensure data integrity and I don't know whether rocksdb has built-in data authentication mechanisms.
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
Review comment:
Not sure about the openssl version, but if 1.1.1+ (or libressl equivalent), [`RAND_priv_bytes`](https://www.openssl.org/docs/manmaster/man3/RAND_bytes.html) may be a better choice.
I would also forward the library error message to `handleError`.
```suggestion
unsigned char key[KEY_SIZE];
if (1 != RAND_priv_bytes(key, KEY_SIZE)) {
std::array<char, 128> errmsg = {0};
const auto errcode = ERR_get_error();
ERR_error_string_n(errcode, errmsg.data(), errmsg.size());
handleError("Couldn't generate key: %s", errmsg.data());
}
return Bytes(key, key + KEY_SIZE);
```
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
Review comment:
I failed to notice the `override` keyword, my fault. Nevermind then, thanks for the clarification.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664491131
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
Since `database_` is only used for logging, I still think that what we now call `hasEqualKey` is semantically an equality comparison.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663937231
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
Review comment:
done
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
if only there wasn't now three different ways to create a temporary directory (now 2 in TestController, and 1 standalone in TestUtils.h) but I felt like removing all the single-use `format` variables in all the tests deserves its own PR
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
https://issues.apache.org/jira/browse/MINIFICPP-1600
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ }
+ if (checkpoint_status.ok()) {
checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
+ logger_->log_trace("Created checkpoint in directory '%s'", checkpoint_dir_);
} else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
+ logger_->log_error("Could not create checkpoint: %s", checkpoint_status.ToString());
}
} else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
Review comment:
@lordgamez had the same concern, done in commit [3db64f](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/3db64f47d25f9067fd23ade4e1100a666c542efa)
##########
File path: extensions/rocksdb-repos/DatabaseContentRepository.cpp
##########
@@ -42,14 +43,31 @@ bool DatabaseContentRepository::initialize(const std::shared_ptr<minifi::Configu
} else {
directory_ = configuration->getHome() + "/dbcontentrepository";
}
- auto set_db_opts = [] (internal::Writable<rocksdb::DBOptions>& db_opts) {
+ std::shared_ptr<rocksdb::Env> encrypted_env = [&] {
+ DbEncryptionOptions encryption_opts;
+ encryption_opts.database = directory_;
+ encryption_opts.encryption_key_name = ENCRYPTION_KEY_NAME;
+ auto env = createEncryptingEnv(utils::crypto::EncryptionManager{configuration->getHome()}, encryption_opts);
+ if (env) {
+ logger_->log_info("Using encrypted DatabaseContentRepository");
+ } else {
+ logger_->log_info("Using plaintext DatabaseContentRepository");
+ }
+ return env;
+ }();
Review comment:
done in [9d07c8e](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/9d07c8e9c534a87ab31acd5d7dbf843ce047da04) (also for other applicable occurrences)
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
I forgot to rename it, renamed it to `hasEqualKey` in [7793d6f](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/7793d6faf7460f37f69cd2576c8ad2979ac16bd3)
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
+ << "805D7B95EF44DC27C87FFBC4DFDE376DAE604D55DB2C5496DEEF5236362DE62E"
+ << "\n";
+ }
+
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ auto flowfile = std::make_shared<minifi::FlowFileRecord>();
+ flowfile->setAttribute("my little pony", "my horse is amazing");
+ flowfile->setConnection(container_);
+ putFlowFile(flowfile, repo);
+ });
+
+ REQUIRE(container_->isEmpty());
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& /*repo*/) {
+ // wait for the flowfiles to be loaded from the checkpoint
+ bool success = utils::verifyEventHappenedInPollTime(std::chrono::seconds{5}, [&] {
+ return !container_->isEmpty();
+ });
+ REQUIRE(success);
+ REQUIRE(utils::verifyLogLinePresenceInPollTime(
+ std::chrono::seconds{5},
+ "Successfully opened checkpoint database at '" + checkpoint_dir_.str() + "'"));
+ std::set<std::shared_ptr<core::FlowFile>> expired;
+ auto flowfile = container_->poll(expired);
+ REQUIRE(expired.empty());
+ REQUIRE(flowfile);
+ REQUIRE(flowfile->getAttribute("my little pony") == "my horse is amazing");
Review comment:
as I understand encryption does not happen on the key-value pair level, but on the file level, so there is no way to get the encrypted value (or key)
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
Review comment:
the interface is not my design, `rocksdb::BlockCipher` is the base class for this cipher, and there both `Encrypt` and `Decrypt` have the comment: `"Length of data is equal to BlockSize()."`
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
+
+ static Bytes generateKey();
+
+ bool equals(const Aes256EcbCipher& other) const;
+
+ private:
+ template<typename ...Args>
+ static void handleError(Args&& ...args) {
+ std::string error_msg = core::logging::format_string(-1, "%s", std::forward<Args>(args)...);
+ logger_->log_error("%s", error_msg);
+ throw CipherError(error_msg);
+ }
Review comment:
indeed this would have misbehaved, fixed in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471)
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
done, for future reference do you remember which debugger struggled?
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
done in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471) for future reference do you remember which debugger struggled?
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
done in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471), for future reference do you remember which debugger struggled?
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +231,24 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
- checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
- } else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
- }
- } else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) < 0) {
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
+ return;
+ }
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not create checkpoint object: %s", checkpoint_status.ToString());
+ return;
+ }
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not initialize checkpoint: %s", checkpoint_status.ToString());
+ return;
+ }
Review comment:
done in [0e20dfe8](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/0e20dfe88485cade5969d1e42769d3c3ea02c0ea)
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
Review comment:
there is no `RAND_priv_bytes` neither on my machine nor on libressl's main, added error handling in [cfa43ced6](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/cfa43ced6793e2f7be94f8d92c92f84d712a8989)
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
Review comment:
we are using the `CTREncryptionProvider`, which wraps our block cipher and provides the appropriate iv and counter per block
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
in theory yes, in practice I found that on BLOCK_SIZE input we get 2*BLOCK_SIZE output because `EVP_EncryptFinal_ex` interprets 'no more data' as 'please pad this to a block' for some reason, `EVP_EncryptUpdate` provides no guarantees of full encryption of all incoming data, so unfortunately we cannot drop the `EVP_EncryptFinal_ex` call
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
Review comment:
done in [cfa43ced](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/cfa43ced6793e2f7be94f8d92c92f84d712a8989)
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
based on the interface of `BlockAccessCipherStream` (which an `EncryptionProvider` should produce) I am under the impression that authenticated encryption is not yet supported by `rocksdb`
```
// Encrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize.
virtual Status Encrypt(uint64_t fileOffset, char* data, size_t dataSize);
// Decrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize.
virtual Status Decrypt(uint64_t fileOffset, char* data, size_t dataSize);
```
##########
File path: extensions/rocksdb-repos/database/RocksDbInstance.cpp
##########
@@ -99,6 +112,7 @@ utils::optional<OpenRocksDb> RocksDbInstance::open(const std::string& column, co
return utils::nullopt;
}
gsl_Expects(db_instance);
+ db_options_patch_ = db_options_patch;
Review comment:
added comment why we must store this object in [b13b5b7d](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/b13b5b7d24b681c15e15850d36ce2922b5f2b9e9)
##########
File path: extensions/rocksdb-repos/database/RocksDbUtils.h
##########
@@ -38,19 +38,14 @@ class Writable {
public:
explicit Writable(T& target) : target_(target) {}
- template<typename F>
- void set(F T::* member, typename utils::type_identity<F>::type value) {
- if (!(target_.*member == value)) {
+ template<typename F, typename Comparator = std::equal_to<F>>
+ void set(F T::* member, typename utils::type_identity<F>::type value, const Comparator& comparator = Comparator{}) {
+ if (!comparator(target_.*member, value)) {
target_.*member = value;
is_modified_ = true;
}
}
- template<typename Transformer, typename F>
- void transform(F T::* member) {
- set(member, Transformer::transform(target_.*member));
- }
Review comment:
yes, removed in [b13b5b7](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/b13b5b7d24b681c15e15850d36ce2922b5f2b9e9)
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
Review comment:
changed it to use `utils::crypto::randomBytes` in [b13b5b7d](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/b13b5b7d24b681c15e15850d36ce2922b5f2b9e9)
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
Review comment:
since we have an rvalue ref stream `operator<<` will resolve to a forwarding template function
```
template <class _Stream, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_lvalue_reference<_Stream>::value &&
is_base_of<ios_base, _Stream>::value,
_Stream&&
>::type
operator<<(_Stream&& __os, const _Tp& __x)
{
__os << __x;
return _VSTD::move(__os);
}
```
which takes the argument by reference, which makes the static member [odr-used](https://en.cppreference.com/w/cpp/language/definition#ODR-use), adding a `static_cast` makes an lvalue-to-rvalue conversion which evaluates to a constant expression, and no longer odr-used, from `c++17` we won't need this cast
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
Review comment:
since we have an rvalue ref stream, `operator<<` will resolve to a forwarding template function
```
template <class _Stream, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_lvalue_reference<_Stream>::value &&
is_base_of<ios_base, _Stream>::value,
_Stream&&
>::type
operator<<(_Stream&& __os, const _Tp& __x)
{
__os << __x;
return _VSTD::move(__os);
}
```
which takes the argument by reference, which makes the static member [odr-used](https://en.cppreference.com/w/cpp/language/definition#ODR-use), adding a `static_cast` makes an lvalue-to-rvalue conversion which evaluates to a constant expression, and no longer odr-used, from `c++17` we won't need this cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664556602
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
Review comment:
I've found CTREncryptionProvider in the rocksdb code, but couldn't find where we specify that we use it in this PR. Is it always used with rocksdb?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663918197
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
This simplifies things a bit :+1:
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
Review comment:
I may go with an early return and a separate error message here, just to know which call failed in case of failure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r665119508
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
Review comment:
added documentation and comments on safety in [650a76f](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/650a76f0ecbf23f6f32e54d51b9f769192ff532c)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664097397
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Can you explain why you chose ECB encryption mode? According to wikipedia, it's not recommended for for use in cryptographic protocols. https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_(ECB)
Block cipher modes also don't ensure data integrity, so we need a way to sign and verify the data. Rocksdb can't have one built in unless we pass the key to it when opening the db.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664492706
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
Could you add a comment about the 2*BLOCK_SIZE padding above these lines? This is useful context for the future reader IMO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664378255
##########
File path: extensions/rocksdb-repos/database/RocksDbUtils.h
##########
@@ -38,19 +38,14 @@ class Writable {
public:
explicit Writable(T& target) : target_(target) {}
- template<typename F>
- void set(F T::* member, typename utils::type_identity<F>::type value) {
- if (!(target_.*member == value)) {
+ template<typename F, typename Comparator = std::equal_to<F>>
+ void set(F T::* member, typename utils::type_identity<F>::type value, const Comparator& comparator = Comparator{}) {
+ if (!comparator(target_.*member, value)) {
target_.*member = value;
is_modified_ = true;
}
}
- template<typename Transformer, typename F>
- void transform(F T::* member) {
- set(member, Transformer::transform(target_.*member));
- }
Review comment:
yes, removed in [b13b5b7](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/b13b5b7d24b681c15e15850d36ce2922b5f2b9e9)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663967644
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
+ << "805D7B95EF44DC27C87FFBC4DFDE376DAE604D55DB2C5496DEEF5236362DE62E"
+ << "\n";
+ }
+
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ auto flowfile = std::make_shared<minifi::FlowFileRecord>();
+ flowfile->setAttribute("my little pony", "my horse is amazing");
+ flowfile->setConnection(container_);
+ putFlowFile(flowfile, repo);
+ });
+
+ REQUIRE(container_->isEmpty());
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& /*repo*/) {
+ // wait for the flowfiles to be loaded from the checkpoint
+ bool success = utils::verifyEventHappenedInPollTime(std::chrono::seconds{5}, [&] {
+ return !container_->isEmpty();
+ });
+ REQUIRE(success);
+ REQUIRE(utils::verifyLogLinePresenceInPollTime(
+ std::chrono::seconds{5},
+ "Successfully opened checkpoint database at '" + checkpoint_dir_.str() + "'"));
+ std::set<std::shared_ptr<core::FlowFile>> expired;
+ auto flowfile = container_->poll(expired);
+ REQUIRE(expired.empty());
+ REQUIRE(flowfile);
+ REQUIRE(flowfile->getAttribute("my little pony") == "my horse is amazing");
Review comment:
ok, I see.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663928848
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
Review comment:
I prefer using separate buffers for input and output, unless we can realize significant efficiency gains by reusing mutable memory.
How do we ensure that the buffer size is sufficient for the output? Plaintext and cipher size can be different in either direction.
Tip: use `gsl::span` for the input
##########
File path: extensions/rocksdb-repos/DatabaseContentRepository.cpp
##########
@@ -42,14 +43,31 @@ bool DatabaseContentRepository::initialize(const std::shared_ptr<minifi::Configu
} else {
directory_ = configuration->getHome() + "/dbcontentrepository";
}
- auto set_db_opts = [] (internal::Writable<rocksdb::DBOptions>& db_opts) {
+ std::shared_ptr<rocksdb::Env> encrypted_env = [&] {
+ DbEncryptionOptions encryption_opts;
+ encryption_opts.database = directory_;
+ encryption_opts.encryption_key_name = ENCRYPTION_KEY_NAME;
+ auto env = createEncryptingEnv(utils::crypto::EncryptionManager{configuration->getHome()}, encryption_opts);
+ if (env) {
+ logger_->log_info("Using encrypted DatabaseContentRepository");
+ } else {
+ logger_->log_info("Using plaintext DatabaseContentRepository");
+ }
+ return env;
+ }();
Review comment:
This looks like a lot of boilerplate for two lines of meaning. My preference is more dense code, but admittedly it results in longer lines. I find 2 lines repeated 5x less scary than 5 lines repeated 5x.
```suggestion
const auto encrypted_env = createEncryptingEnv(utils::crypto::EncryptionManager{configuration->getHome()}, DbEncryptionOptions{directory_, ENCRYPTION_KEY_NAME});
logger_->log_info("Using %s DatabaseContentRepository", env ? "encrypted" : "plaintext");
```
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ }
+ if (checkpoint_status.ok()) {
checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
+ logger_->log_trace("Created checkpoint in directory '%s'", checkpoint_dir_);
} else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
+ logger_->log_error("Could not create checkpoint: %s", checkpoint_status.ToString());
}
} else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
Review comment:
Did you consider extracting this to a function with early returns on errors in each step? I think it would further improve the flow of the code, keeping the happy path operations below each other on the same indentation level.
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
+ << "805D7B95EF44DC27C87FFBC4DFDE376DAE604D55DB2C5496DEEF5236362DE62E"
+ << "\n";
+ }
+
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ auto flowfile = std::make_shared<minifi::FlowFileRecord>();
+ flowfile->setAttribute("my little pony", "my horse is amazing");
+ flowfile->setConnection(container_);
+ putFlowFile(flowfile, repo);
+ });
+
+ REQUIRE(container_->isEmpty());
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& /*repo*/) {
+ // wait for the flowfiles to be loaded from the checkpoint
+ bool success = utils::verifyEventHappenedInPollTime(std::chrono::seconds{5}, [&] {
+ return !container_->isEmpty();
+ });
+ REQUIRE(success);
+ REQUIRE(utils::verifyLogLinePresenceInPollTime(
+ std::chrono::seconds{5},
+ "Successfully opened checkpoint database at '" + checkpoint_dir_.str() + "'"));
+ std::set<std::shared_ptr<core::FlowFile>> expired;
+ auto flowfile = container_->poll(expired);
+ REQUIRE(expired.empty());
+ REQUIRE(flowfile);
+ REQUIRE(flowfile->getAttribute("my little pony") == "my horse is amazing");
Review comment:
Can we have an assertion to the ciphertext value in the repository? It would be a great proof that everything is indeed encrypted on disk and not just working.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
[`systemd::libwrapper::DlopenJournal`](https://github.com/apache/nifi-minifi-cpp/blob/main/extensions/systemd/libwrapper/DlopenWrapper.cpp#L35) also started out with static linkage. The reason I changed it was because debuggers have a hard time showing symbols that are not there and this can make debugging much harder. I think I had to step through asm instructions at one point to debug something.
If you think having type info for these types while debugging is worth the overhead, consider moving the classes out of the anonymous namespace.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
Why not `operator==`? Same with `EncryptingEnv`.
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
+
+ static Bytes generateKey();
+
+ bool equals(const Aes256EcbCipher& other) const;
+
+ private:
+ template<typename ...Args>
+ static void handleError(Args&& ...args) {
+ std::string error_msg = core::logging::format_string(-1, "%s", std::forward<Args>(args)...);
+ logger_->log_error("%s", error_msg);
+ throw CipherError(error_msg);
+ }
Review comment:
This seems to just print the passed first argument string as is, but it's passed a format string in the constructor. If this function is supposed to expect format strings, line 57 shouldn't have the `"%s"` arguments. Consider making this function take a c string and handle the formatting in the constructor.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664729323
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Back to the first question, you mentioned CTR (a.k.a counter mode encryption) in a different answer. This makes me think that we are just using ECB functions to encrypt the nonce + counter as a block, but not really using ECB mode encryption. Am I correct with this assumption?
Here's the rocksdb CTR function: https://github.com/facebook/rocksdb/commit/51778612c9cf4cb842eed10f270ec0ed29ff22f1#diff-31e5f5f565771d096323f879c644c2792db9bf42018b12ca0441f09b2c876b39R803
Second (authentication): I agree, I can't see anything related to message authentication codes in the above commit or the latest rocksdb env/env_encryption* source files. This is a pity, because an attacker can easily flip bits in the plaintext by just flipping the corresponding bits in the ciphertext.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663948441
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ }
+ if (checkpoint_status.ok()) {
checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
+ logger_->log_trace("Created checkpoint in directory '%s'", checkpoint_dir_);
} else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
+ logger_->log_error("Could not create checkpoint: %s", checkpoint_status.ToString());
}
} else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
Review comment:
@lordgamez had the same concern, done in commit [3db64f](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/3db64f47d25f9067fd23ade4e1100a666c542efa)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663940506
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
Yes I thought the same, it should definitely be in a separate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663968714
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
Review comment:
the interface is not my design, `rocksdb::BlockCipher` is the base class for this cipher, and there both `Encrypt` and `Decrypt` have the comment: `"Length of data is equal to BlockSize()."`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663970462
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
done in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471) for future reference do you remember which debugger struggled?
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
done in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471), for future reference do you remember which debugger struggled?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664074774
##########
File path: extensions/rocksdb-repos/database/RocksDbUtils.h
##########
@@ -38,19 +38,14 @@ class Writable {
public:
explicit Writable(T& target) : target_(target) {}
- template<typename F>
- void set(F T::* member, typename utils::type_identity<F>::type value) {
- if (!(target_.*member == value)) {
+ template<typename F, typename Comparator = std::equal_to<F>>
+ void set(F T::* member, typename utils::type_identity<F>::type value, const Comparator& comparator = Comparator{}) {
+ if (!comparator(target_.*member, value)) {
target_.*member = value;
is_modified_ = true;
}
}
- template<typename Transformer, typename F>
- void transform(F T::* member) {
- set(member, Transformer::transform(target_.*member));
- }
Review comment:
can `StringAppender::transform()` be removed, too?
##########
File path: extensions/rocksdb-repos/database/RocksDbInstance.cpp
##########
@@ -99,6 +112,7 @@ utils::optional<OpenRocksDb> RocksDbInstance::open(const std::string& column, co
return utils::nullopt;
}
gsl_Expects(db_instance);
+ db_options_patch_ = db_options_patch;
Review comment:
this seems to be the only place where we use `RocksDbInstance::db_options_patch_`; can it be removed?
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
Review comment:
why is this cast needed? `FlowFileRepository::ENCRYPTION_KEY_NAME` is already a `const char*`
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
Review comment:
we already have `utils::crypto::randomBytes()` in EncryptionUtils which does the same thing (but instead of libressl it uses libsodium, which is better according to @alopresto)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664312849
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
Review comment:
there is no `RAND_priv_bytes` neither on my machine nor on libressl's main, added error handling in [cfa43ced6](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/cfa43ced6793e2f7be94f8d92c92f84d712a8989)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663937231
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
Review comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664290173
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +231,24 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
- checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
- } else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
- }
- } else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) < 0) {
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
+ return;
+ }
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not create checkpoint object: %s", checkpoint_status.ToString());
+ return;
+ }
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not initialize checkpoint: %s", checkpoint_status.ToString());
+ return;
+ }
Review comment:
done in [0e20dfe8](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/0e20dfe88485cade5969d1e42769d3c3ea02c0ea)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664399347
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
Review comment:
since we have an rvalue ref stream `operator<<` will resolve to a forwarding template function
```
template <class _Stream, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_lvalue_reference<_Stream>::value &&
is_base_of<ios_base, _Stream>::value,
_Stream&&
>::type
operator<<(_Stream&& __os, const _Tp& __x)
{
__os << __x;
return _VSTD::move(__os);
}
```
which takes the argument by reference, which makes the static member [odr-used](https://en.cppreference.com/w/cpp/language/definition#ODR-use), adding a `static_cast` makes an lvalue-to-rvalue conversion which evaluates to a constant expression, and no longer odr-used, from `c++17` we won't need this cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r665101279
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
ECB mode would be `ciphertext := encrypt(plaintext)`, whereas CTR is `ciphertext := plantext XOR encrypt(concat(iv, counter))`, I could remove the `"Ecb"` from the `"Aes256EcbCipher"` as these modes do not really describe the cipher but the way they are used for encryption, but I feel like it prompts (as prompted in you) careful consideration (as it should) when used in the future
I share your disappointment for the lack of authentication, that is why we had to use the openssl library instead of the libsodium, as the latter only provides authenticated encryption
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663966555
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
+ << "805D7B95EF44DC27C87FFBC4DFDE376DAE604D55DB2C5496DEEF5236362DE62E"
+ << "\n";
+ }
+
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ auto flowfile = std::make_shared<minifi::FlowFileRecord>();
+ flowfile->setAttribute("my little pony", "my horse is amazing");
+ flowfile->setConnection(container_);
+ putFlowFile(flowfile, repo);
+ });
+
+ REQUIRE(container_->isEmpty());
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& /*repo*/) {
+ // wait for the flowfiles to be loaded from the checkpoint
+ bool success = utils::verifyEventHappenedInPollTime(std::chrono::seconds{5}, [&] {
+ return !container_->isEmpty();
+ });
+ REQUIRE(success);
+ REQUIRE(utils::verifyLogLinePresenceInPollTime(
+ std::chrono::seconds{5},
+ "Successfully opened checkpoint database at '" + checkpoint_dir_.str() + "'"));
+ std::set<std::shared_ptr<core::FlowFile>> expired;
+ auto flowfile = container_->poll(expired);
+ REQUIRE(expired.empty());
+ REQUIRE(flowfile);
+ REQUIRE(flowfile->getAttribute("my little pony") == "my horse is amazing");
Review comment:
as I understand encryption does not happen on the key-value pair level, but on the file level, so there is no way to get the encrypted value (or key)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663945127
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
https://issues.apache.org/jira/browse/MINIFICPP-1600
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664729323
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Back to the first question, you mentioned CTR (a.k.a counter mode encryption) in a different answer. This makes me think that we are just using ECB functions to encrypt the nonce + counter as a block, but not really using ECB mode encryption. Am I correct with this assumption?
Here's the rocksdb CTR function: https://github.com/facebook/rocksdb/commit/51778612c9cf4cb842eed10f270ec0ed29ff22f1#diff-31e5f5f565771d096323f879c644c2792db9bf42018b12ca0441f09b2c876b39R803
Second (authentication): I agree, I can't see anything related to message authentication codes in the above commit or the latest rocksdb env/env_encryption* source files. This is a pity, because an attacker can easily flip bits in the plaintext by just flipping the corresponding bits in the ciphertext.
disclaimer: I'm by no means an crypto expert, just researched the topic while reviewing this PR.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Back to the first question, you mentioned CTR (a.k.a counter mode encryption) in a different answer. This makes me think that we are just using ECB functions to encrypt the nonce + counter as a block, but not really using ECB mode encryption. Am I correct with this assumption?
Here's the rocksdb CTR function: https://github.com/facebook/rocksdb/commit/51778612c9cf4cb842eed10f270ec0ed29ff22f1#diff-31e5f5f565771d096323f879c644c2792db9bf42018b12ca0441f09b2c876b39R803
Second (authentication): I agree, I can't see anything related to message authentication codes in the above commit or the latest rocksdb env/env_encryption* source files. This is a pity, because an attacker can easily flip bits in the plaintext by just flipping the corresponding bits in the ciphertext.
disclaimer: I'm by no means a crypto expert, just researched the topic while reviewing this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664399347
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
Review comment:
since we have an rvalue ref stream, `operator<<` will resolve to a forwarding template function
```
template <class _Stream, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_lvalue_reference<_Stream>::value &&
is_base_of<ios_base, _Stream>::value,
_Stream&&
>::type
operator<<(_Stream&& __os, const _Tp& __x)
{
__os << __x;
return _VSTD::move(__os);
}
```
which takes the argument by reference, which makes the static member [odr-used](https://en.cppreference.com/w/cpp/language/definition#ODR-use), adding a `static_cast` makes an lvalue-to-rvalue conversion which evaluates to a constant expression, and no longer odr-used, from `c++17` we won't need this cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663928848
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
Review comment:
I prefer using separate buffers for input and output, unless we can realize significant efficiency gains by reusing mutable memory.
How do we ensure that the buffer size is sufficient for the output? Plaintext and cipher size can be different in either direction.
Tip: use `gsl::span` for the input
##########
File path: extensions/rocksdb-repos/DatabaseContentRepository.cpp
##########
@@ -42,14 +43,31 @@ bool DatabaseContentRepository::initialize(const std::shared_ptr<minifi::Configu
} else {
directory_ = configuration->getHome() + "/dbcontentrepository";
}
- auto set_db_opts = [] (internal::Writable<rocksdb::DBOptions>& db_opts) {
+ std::shared_ptr<rocksdb::Env> encrypted_env = [&] {
+ DbEncryptionOptions encryption_opts;
+ encryption_opts.database = directory_;
+ encryption_opts.encryption_key_name = ENCRYPTION_KEY_NAME;
+ auto env = createEncryptingEnv(utils::crypto::EncryptionManager{configuration->getHome()}, encryption_opts);
+ if (env) {
+ logger_->log_info("Using encrypted DatabaseContentRepository");
+ } else {
+ logger_->log_info("Using plaintext DatabaseContentRepository");
+ }
+ return env;
+ }();
Review comment:
This looks like a lot of boilerplate for two lines of meaning. My preference is more dense code, but admittedly it results in longer lines. I find 2 lines repeated 5x less scary than 5 lines repeated 5x.
```suggestion
const auto encrypted_env = createEncryptingEnv(utils::crypto::EncryptionManager{configuration->getHome()}, DbEncryptionOptions{directory_, ENCRYPTION_KEY_NAME});
logger_->log_info("Using %s DatabaseContentRepository", env ? "encrypted" : "plaintext");
```
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ }
+ if (checkpoint_status.ok()) {
checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
+ logger_->log_trace("Created checkpoint in directory '%s'", checkpoint_dir_);
} else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
+ logger_->log_error("Could not create checkpoint: %s", checkpoint_status.ToString());
}
} else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
Review comment:
Did you consider extracting this to a function with early returns on errors in each step? I think it would further improve the flow of the code, keeping the happy path operations below each other on the same indentation level.
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
+ << "805D7B95EF44DC27C87FFBC4DFDE376DAE604D55DB2C5496DEEF5236362DE62E"
+ << "\n";
+ }
+
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ auto flowfile = std::make_shared<minifi::FlowFileRecord>();
+ flowfile->setAttribute("my little pony", "my horse is amazing");
+ flowfile->setConnection(container_);
+ putFlowFile(flowfile, repo);
+ });
+
+ REQUIRE(container_->isEmpty());
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& /*repo*/) {
+ // wait for the flowfiles to be loaded from the checkpoint
+ bool success = utils::verifyEventHappenedInPollTime(std::chrono::seconds{5}, [&] {
+ return !container_->isEmpty();
+ });
+ REQUIRE(success);
+ REQUIRE(utils::verifyLogLinePresenceInPollTime(
+ std::chrono::seconds{5},
+ "Successfully opened checkpoint database at '" + checkpoint_dir_.str() + "'"));
+ std::set<std::shared_ptr<core::FlowFile>> expired;
+ auto flowfile = container_->poll(expired);
+ REQUIRE(expired.empty());
+ REQUIRE(flowfile);
+ REQUIRE(flowfile->getAttribute("my little pony") == "my horse is amazing");
Review comment:
Can we have an assertion to the ciphertext value in the repository? It would be a great proof that everything is indeed encrypted on disk and not just working.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
[`systemd::libwrapper::DlopenJournal`](https://github.com/apache/nifi-minifi-cpp/blob/main/extensions/systemd/libwrapper/DlopenWrapper.cpp#L35) also started out with static linkage. The reason I changed it was because debuggers have a hard time showing symbols that are not there and this can make debugging much harder. I think I had to step through asm instructions at one point to debug something.
If you think having type info for these types while debugging is worth the overhead, consider moving the classes out of the anonymous namespace.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
Why not `operator==`? Same with `EncryptingEnv`.
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
+
+ static Bytes generateKey();
+
+ bool equals(const Aes256EcbCipher& other) const;
+
+ private:
+ template<typename ...Args>
+ static void handleError(Args&& ...args) {
+ std::string error_msg = core::logging::format_string(-1, "%s", std::forward<Args>(args)...);
+ logger_->log_error("%s", error_msg);
+ throw CipherError(error_msg);
+ }
Review comment:
This seems to just print the passed first argument string as is, but it's passed a format string in the constructor. If this function is supposed to expect format strings, line 57 shouldn't have the `"%s"` arguments. Consider making this function take a c string and handle the formatting in the constructor.
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
+ << "805D7B95EF44DC27C87FFBC4DFDE376DAE604D55DB2C5496DEEF5236362DE62E"
+ << "\n";
+ }
+
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ auto flowfile = std::make_shared<minifi::FlowFileRecord>();
+ flowfile->setAttribute("my little pony", "my horse is amazing");
+ flowfile->setConnection(container_);
+ putFlowFile(flowfile, repo);
+ });
+
+ REQUIRE(container_->isEmpty());
+
+ runWithNewRepository([&] (const std::shared_ptr<core::repository::FlowFileRepository>& /*repo*/) {
+ // wait for the flowfiles to be loaded from the checkpoint
+ bool success = utils::verifyEventHappenedInPollTime(std::chrono::seconds{5}, [&] {
+ return !container_->isEmpty();
+ });
+ REQUIRE(success);
+ REQUIRE(utils::verifyLogLinePresenceInPollTime(
+ std::chrono::seconds{5},
+ "Successfully opened checkpoint database at '" + checkpoint_dir_.str() + "'"));
+ std::set<std::shared_ptr<core::FlowFile>> expired;
+ auto flowfile = container_->poll(expired);
+ REQUIRE(expired.empty());
+ REQUIRE(flowfile);
+ REQUIRE(flowfile->getAttribute("my little pony") == "my horse is amazing");
Review comment:
ok, I see.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
I was using CLion, I think with the LLDB backend.
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +231,24 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
- checkpoint_ = std::unique_ptr<rocksdb::Checkpoint>(checkpoint);
- logger_->log_trace("Created checkpoint directory");
- } else {
- logger_->log_trace("Could not create checkpoint. Corrupt?");
- }
- } else
- logger_->log_trace("Could not create checkpoint directory. Not properly deleted?");
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) < 0) {
+ logger_->log_error("Could not delete existing checkpoint directory '%s'", checkpoint_dir_);
+ return;
+ }
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not create checkpoint object: %s", checkpoint_status.ToString());
+ return;
+ }
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
+ if (!checkpoint_status.ok()) {
+ logger_->log_error("Could not initialize checkpoint: %s", checkpoint_status.ToString());
+ return;
+ }
Review comment:
Shouldn't we `delete checkpoint;` if this fails? Or put it in a `unique_ptr` if `NewCheckpoint` was successful.
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
Review comment:
We should use a random initialization vector. It prevents the same plaintext from becoming the same ciphertext when encrypted with the same key. It can be stored as plaintext next to the ciphertext.
https://stackoverflow.com/a/8041580
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
Review comment:
I would change the signatures here to take [`gsl::span<unsigned char /*, BLOCK_SIZE*/>`](https://github.com/gsl-lite/gsl-lite/blob/master/include/gsl/gsl-lite.hpp#L3935) (gsl::span doesn't support static extents) and later `std::span<std::byte, BLOCK_SIZE>` for documentation.
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
Why do you want to disable padding? It pads so that the output is always a multiple of the block size. In theory we should always get one BLOCK_SIZE output for one BLOCK_SIZE input, so it shouldn't matter.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Can you explain why you chose ECB encryption mode? According to wikipedia, it's not recommended for for use in cryptographic protocols. https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_(ECB)
Block cipher modes also don't ensure data integrity and I don't know whether rocksdb has built-in data authentication mechanisms.
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
Review comment:
Not sure about the openssl version, but if 1.1.1+ (or libressl equivalent), [`RAND_priv_bytes`](https://www.openssl.org/docs/manmaster/man3/RAND_bytes.html) may be a better choice.
I would also forward the library error message to `handleError`.
```suggestion
unsigned char key[KEY_SIZE];
if (1 != RAND_priv_bytes(key, KEY_SIZE)) {
std::array<char, 128> errmsg = {0};
const auto errcode = ERR_get_error();
ERR_error_string_n(errcode, errmsg.data(), errmsg.size());
handleError("Couldn't generate key: %s", errmsg.data());
}
return Bytes(key, key + KEY_SIZE);
```
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
Review comment:
I failed to notice the `override` keyword, my fault. Nevermind then, thanks for the clarification.
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
Can you explain why you chose ECB encryption mode? According to wikipedia, it's not recommended for for use in cryptographic protocols. https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_(ECB)
Block cipher modes also don't ensure data integrity, so we need a way to sign and verify the data. Rocksdb can't have one built in unless we pass the key to it when opening the db.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664492706
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
Could you add a comment with this info above these lines? This is useful context for the future reader IMO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663955548
##########
File path: extensions/rocksdb-repos/DatabaseContentRepository.cpp
##########
@@ -42,14 +43,31 @@ bool DatabaseContentRepository::initialize(const std::shared_ptr<minifi::Configu
} else {
directory_ = configuration->getHome() + "/dbcontentrepository";
}
- auto set_db_opts = [] (internal::Writable<rocksdb::DBOptions>& db_opts) {
+ std::shared_ptr<rocksdb::Env> encrypted_env = [&] {
+ DbEncryptionOptions encryption_opts;
+ encryption_opts.database = directory_;
+ encryption_opts.encryption_key_name = ENCRYPTION_KEY_NAME;
+ auto env = createEncryptingEnv(utils::crypto::EncryptionManager{configuration->getHome()}, encryption_opts);
+ if (env) {
+ logger_->log_info("Using encrypted DatabaseContentRepository");
+ } else {
+ logger_->log_info("Using plaintext DatabaseContentRepository");
+ }
+ return env;
+ }();
Review comment:
done in [9d07c8e](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/9d07c8e9c534a87ab31acd5d7dbf843ce047da04) (also for other applicable occurrences)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664318601
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
in theory yes, in practice I found that on BLOCK_SIZE input we get 2*BLOCK_SIZE output because `EVP_EncryptFinal_ex` interprets 'no more data' as 'please pad this to a block' for some reason, `EVP_EncryptUpdate` provides no guarantees of full encryption of all incoming data, so unfortunately we cannot drop the `EVP_EncryptFinal_ex` call
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664555210
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
ok, that makes sense
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664378631
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
Review comment:
changed it to use `utils::crypto::randomBytes` in [b13b5b7d](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/b13b5b7d24b681c15e15850d36ce2922b5f2b9e9)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663960336
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
I forgot to rename it, renamed it to `hasEqualKey` in [7793d6f](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/7793d6faf7460f37f69cd2576c8ad2979ac16bd3)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663970159
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
+
+ static Bytes generateKey();
+
+ bool equals(const Aes256EcbCipher& other) const;
+
+ private:
+ template<typename ...Args>
+ static void handleError(Args&& ...args) {
+ std::string error_msg = core::logging::format_string(-1, "%s", std::forward<Args>(args)...);
+ logger_->log_error("%s", error_msg);
+ throw CipherError(error_msg);
+ }
Review comment:
indeed this would have misbehaved, fixed in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
lordgamez commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663918197
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
This simplifies things a bit :+1:
##########
File path: extensions/rocksdb-repos/FlowFileRepository.cpp
##########
@@ -220,17 +240,21 @@ void FlowFileRepository::initialize_repository() {
logger_->log_trace("Do not need checkpoint");
return;
}
- rocksdb::Checkpoint *checkpoint;
// delete any previous copy
- if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0 && opendb->NewCheckpoint(&checkpoint).ok()) {
- if (checkpoint->CreateCheckpoint(checkpoint_dir_).ok()) {
+ if (utils::file::FileUtils::delete_dir(checkpoint_dir_) >= 0) {
+ rocksdb::Checkpoint* checkpoint = nullptr;
+ rocksdb::Status checkpoint_status = opendb->NewCheckpoint(&checkpoint);
+ if (checkpoint_status.ok()) {
+ checkpoint_status = checkpoint->CreateCheckpoint(checkpoint_dir_);
Review comment:
I may go with an early return and a separate error message here, just to know which call failed in case of failure.
##########
File path: libminifi/test/TestBase.h
##########
@@ -445,6 +445,13 @@ class TestController {
return dir;
}
+ template<size_t N>
+ utils::Path createTempDirectory(const char (&format)[N]) {
Review comment:
Yes I thought the same, it should definitely be in a separate PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664074774
##########
File path: extensions/rocksdb-repos/database/RocksDbUtils.h
##########
@@ -38,19 +38,14 @@ class Writable {
public:
explicit Writable(T& target) : target_(target) {}
- template<typename F>
- void set(F T::* member, typename utils::type_identity<F>::type value) {
- if (!(target_.*member == value)) {
+ template<typename F, typename Comparator = std::equal_to<F>>
+ void set(F T::* member, typename utils::type_identity<F>::type value, const Comparator& comparator = Comparator{}) {
+ if (!comparator(target_.*member, value)) {
target_.*member = value;
is_modified_ = true;
}
}
- template<typename Transformer, typename F>
- void transform(F T::* member) {
- set(member, Transformer::transform(target_.*member));
- }
Review comment:
can `StringAppender::transform()` be removed, too?
##########
File path: extensions/rocksdb-repos/database/RocksDbInstance.cpp
##########
@@ -99,6 +112,7 @@ utils::optional<OpenRocksDb> RocksDbInstance::open(const std::string& column, co
return utils::nullopt;
}
gsl_Expects(db_instance);
+ db_options_patch_ = db_options_patch;
Review comment:
this seems to be the only place where we use `RocksDbInstance::db_options_patch_`; can it be removed?
##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+ FFRepoFixture() {
+ LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+ LogTestController::getInstance().setDebug<minifi::Connection>();
+ LogTestController::getInstance().setTrace<FlowFileRepository>();
+ home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+ repo_dir_ = home_ / "flowfile_repo";
+ checkpoint_dir_ = home_ / "checkpoint_dir";
+ config_ = std::make_shared<minifi::Configure>();
+ config_->setHome(home_.str());
+ container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, "container");
+ content_repo_ = std::make_shared<core::repository::VolatileContentRepository>();
+ content_repo_->initialize(config_);
+ }
+
+ static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+ minifi::io::BufferStream buffer;
+ flowfile->Serialize(buffer);
+ REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), buffer.size()));
+ }
+
+ template<typename Fn>
+ void runWithNewRepository(Fn&& fn) {
+ auto repository = std::make_shared<FlowFileRepository>("ff", checkpoint_dir_.str(), repo_dir_.str());
+ repository->initialize(config_);
+ std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+ container_map[container_->getUUIDStr()] = container_;
+ repository->setContainers(container_map);
+ repository->loadComponent(content_repo_);
+ repository->start();
+ std::forward<Fn>(fn)(repository);
+ repository->stop();
+ }
+
+ protected:
+ std::shared_ptr<minifi::Connection> container_;
+ Path home_;
+ Path repo_dir_;
+ Path checkpoint_dir_;
+ std::shared_ptr<minifi::Configure> config_;
+ std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads flowfiles") {
+ SECTION("Without encryption") {
+ // pass
+ }
+ SECTION("With encryption") {
+ utils::file::FileUtils::create_dir((home_ / "conf").str());
+ std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+ << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << "="
Review comment:
why is this cast needed? `FlowFileRepository::ENCRYPTION_KEY_NAME` is already a `const char*`
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
Review comment:
we already have `utils::crypto::randomBytes()` in EncryptionUtils which does the same thing (but instead of libressl it uses libsodium, which is better according to @alopresto)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664551154
##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : encryption_key_(std::move(encryption_key)) {
+ if (encryption_key_.size() != KEY_SIZE) {
+ handleError("Invalid key length %zu bytes, expected %zu bytes", encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+ }
+}
+
+Bytes Aes256EcbCipher::generateKey() {
+ unsigned char key[KEY_SIZE];
+ if (1 != RAND_bytes(key, KEY_SIZE)) {
+ handleError("Couldn't generate key");
+ }
+ return Bytes(key, key + KEY_SIZE);
+}
+
+void Aes256EcbCipher::encrypt(unsigned char *data) const {
+ EVP_CIPHER_CTX_ptr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
+ if (!ctx) {
+ handleError("Could not create cipher context");
+ }
+
+ if (1 != EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_ecb(), nullptr, encryption_key_.data(), nullptr)) {
+ handleError("Could not initialize encryption cipher context");
+ }
+
+ if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) {
+ handleError("Could not disable padding for cipher");
+ }
Review comment:
added comment in [2b211f45](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/2b211f4547de1e60e4b37bf8c86480e54d723d67)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
arpadboda closed pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r665101279
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,119 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool hasEqualKey(const AES256BlockCipher& other) const {
+ return cipher_impl_.hasEqualKey(other.cipher_impl_);
+ }
+
+ rocksdb::Status Encrypt(char *data) override;
+
+ rocksdb::Status Decrypt(char *data) override;
+
+ private:
+ const std::string database_;
+ const Aes256EcbCipher cipher_impl_;
+};
+
+class EncryptingEnv : public rocksdb::EnvWrapper {
+ public:
+ EncryptingEnv(Env* target, std::shared_ptr<AES256BlockCipher> cipher) : EnvWrapper(target), env_(target), cipher_(std::move(cipher)) {}
+
+ bool hasEqualKey(const EncryptingEnv& other) const {
+ return cipher_->hasEqualKey(*other.cipher_);
+ }
+
+ private:
+ std::unique_ptr<Env> env_;
+ std::shared_ptr<AES256BlockCipher> cipher_;
+};
+
+std::shared_ptr<logging::Logger> AES256BlockCipher::logger_ = logging::LoggerFactory<AES256BlockCipher>::getLogger();
+
+std::shared_ptr<rocksdb::Env> createEncryptingEnv(const utils::crypto::EncryptionManager& manager, const DbEncryptionOptions& options) {
+ auto cipher_impl = manager.createAes256EcbCipher(options.encryption_key_name);
Review comment:
ECB mode would be `ciphertext := encrypt(plaintext)`, whereas CTR is `ciphertext := plantext XOR encrypt(concat(iv, counter))`, I could remove the `"Ecb"` from the `"Aes256EcbCipher"` as these modes do not really describe the cipher but the way they are used for encryption, but I feel like it prompts (as prompted in you) careful consideration when used in the future (as it should)
I share your disappointment for the lack of authentication, that is why we had to use the openssl library instead of the libsodium, as the latter only provides authenticated encryption
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664550892
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
+ static std::shared_ptr<logging::Logger> logger_;
+ public:
+ AES256BlockCipher(std::string database, Aes256EcbCipher cipher_impl)
+ : database_(std::move(database)),
+ cipher_impl_(std::move(cipher_impl)) {}
+
+ const char *Name() const override {
+ return "AES256BlockCipher";
+ }
+
+ size_t BlockSize() override {
+ return Aes256EcbCipher::BLOCK_SIZE;
+ }
+
+ bool equals(const AES256BlockCipher& other) const {
+ return cipher_impl_.equals(other.cipher_impl_);
+ }
Review comment:
changed them to `operator==` for the ciphers, but left the `hasEqualKey` for the `EncryptingEnv` in [2b211f45](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/2b211f4547de1e60e4b37bf8c86480e54d723d67)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664378028
##########
File path: extensions/rocksdb-repos/database/RocksDbInstance.cpp
##########
@@ -99,6 +112,7 @@ utils::optional<OpenRocksDb> RocksDbInstance::open(const std::string& column, co
return utils::nullopt;
}
gsl_Expects(db_instance);
+ db_options_patch_ = db_options_patch;
Review comment:
added comment why we must store this object in [b13b5b7d](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/b13b5b7d24b681c15e15850d36ce2922b5f2b9e9)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664747093
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
Review comment:
This and any ECB-related class needs a comment that it is unsafe to use for anything except with a CTR/counter mode implementation like the one in rocksdb.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663970462
##########
File path: extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp
##########
@@ -0,0 +1,123 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "RocksDbEncryptionProvider.h"
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace core {
+namespace repository {
+
+using utils::crypto::Bytes;
+using utils::crypto::Aes256EcbCipher;
+
+namespace {
+
+class AES256BlockCipher final : public rocksdb::BlockCipher {
Review comment:
done, for future reference do you remember which debugger struggled?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #1090: MINIFICPP-1561 - Allow rocksdb encryption
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664320998
##########
File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "utils/crypto/EncryptionUtils.h"
+#include "Exception.h"
+#include "core/logging/Logger.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+class CipherError : public Exception {
+ public:
+ explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {}
+};
+
+class Aes256EcbCipher {
+ static std::shared_ptr<core::logging::Logger> logger_;
+ public:
+ static constexpr size_t BLOCK_SIZE = 16;
+ static constexpr size_t KEY_SIZE = 32;
+
+ explicit Aes256EcbCipher(Bytes encryption_key);
+ void encrypt(unsigned char* data) const;
+ void decrypt(unsigned char* data) const;
Review comment:
done in [cfa43ced](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/cfa43ced6793e2f7be94f8d92c92f84d712a8989)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org