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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
