Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50986 from arenadata/ADQM-822
Implement support of encrypted elements in configuration file
- Loading branch information
Showing
21 changed files
with
423 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <Common/Config/ConfigProcessor.h> | ||
#include <Compression/ICompressionCodec.h> | ||
#include <Compression/CompressionCodecEncrypted.h> | ||
#include <iostream> | ||
|
||
/** This test program encrypts or decrypts text values using a symmetric encryption codec like AES_128_GCM_SIV or AES_256_GCM_SIV. | ||
* Keys for codecs are loaded from <encryption_codecs> section of configuration file. | ||
* | ||
* How to use: | ||
* ./encrypt_decrypt /etc/clickhouse-server/config.xml -e AES_128_GCM_SIV text_to_encrypt | ||
*/ | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
try | ||
{ | ||
if (argc != 5) | ||
{ | ||
std::cerr << "Usage:" << std::endl | ||
<< " " << argv[0] << " path action codec value" << std::endl | ||
<< "path: path to configuration file." << std::endl | ||
<< "action: -e for encryption and -d for decryption." << std::endl | ||
<< "codec: AES_128_GCM_SIV or AES_256_GCM_SIV." << std::endl << std::endl | ||
<< "Example:" << std::endl | ||
<< " ./encrypt_decrypt /etc/clickhouse-server/config.xml -e AES_128_GCM_SIV text_to_encrypt"; | ||
return 3; | ||
} | ||
|
||
std::string action = argv[2]; | ||
std::string codec_name = argv[3]; | ||
std::string value = argv[4]; | ||
|
||
DB::ConfigProcessor processor(argv[1], false, true); | ||
auto loaded_config = processor.loadConfig(); | ||
DB::CompressionCodecEncrypted::Configuration::instance().tryLoad(*loaded_config.configuration, "encryption_codecs"); | ||
|
||
if (action == "-e") | ||
std::cout << processor.encryptValue(codec_name, value) << std::endl; | ||
else if (action == "-d") | ||
std::cout << processor.decryptValue(codec_name, value) << std::endl; | ||
else | ||
std::cerr << "Unknown action: " << action << std::endl; | ||
} | ||
catch (Poco::Exception & e) | ||
{ | ||
std::cerr << "Exception: " << e.displayText() << std::endl; | ||
return 1; | ||
} | ||
catch (std::exception & e) | ||
{ | ||
std::cerr << "std::exception: " << e.what() << std::endl; | ||
return 3; | ||
} | ||
catch (...) | ||
{ | ||
std::cerr << "Some exception" << std::endl; | ||
return 2; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.