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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to