Add vitastor-cli create & modify --enc-key parameter
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
// Copyright (c) Vitaliy Filippov, 2019+
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
|
||||
#ifdef WITH_OPENSSL
|
||||
#include <openssl/rand.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include "cli.h"
|
||||
#include "cluster_client.h"
|
||||
@@ -29,6 +33,8 @@ struct image_creator_t
|
||||
uint64_t size = 0;
|
||||
bool force = false;
|
||||
bool force_size = false;
|
||||
std::string enc_key;
|
||||
bool set_key = false;
|
||||
|
||||
pool_id_t old_pool_id = 0;
|
||||
inode_t new_parent_id = 0;
|
||||
@@ -448,6 +454,13 @@ resume_3:
|
||||
.readonly = false,
|
||||
.meta = new_meta,
|
||||
};
|
||||
if (set_key)
|
||||
{
|
||||
new_cfg.enc_key.resize(enc_key.size()/2);
|
||||
fromhexstr(enc_key, new_cfg.enc_key.size(), new_cfg.enc_key.data());
|
||||
}
|
||||
else if (new_snap != "")
|
||||
new_cfg.enc_key = cur_cfg.enc_key;
|
||||
json11::Json::array checks = json11::Json::array {
|
||||
json11::Json::object {
|
||||
{ "target", "VERSION" },
|
||||
@@ -584,6 +597,31 @@ std::function<bool(cli_result_t &)> cli_tool_t::start_create(json11::Json cfg)
|
||||
{
|
||||
image_creator->new_snap = cfg["snapshot"].string_value();
|
||||
}
|
||||
if (!cfg["enc_key"].is_null())
|
||||
{
|
||||
image_creator->set_key = true;
|
||||
image_creator->enc_key = cfg["enc_key"].string_value();
|
||||
if (image_creator->enc_key != "" &&
|
||||
#ifdef WITH_OPENSSL
|
||||
image_creator->enc_key != "random" &&
|
||||
#endif
|
||||
(!ishexstr(image_creator->enc_key) || image_creator->enc_key.size() != 128))
|
||||
{
|
||||
return [](cli_result_t & result)
|
||||
{
|
||||
result = (cli_result_t){ .err = EINVAL, .text = "Encryption key is not a 512-bit hex string, not \"\" and not \"random\"" };
|
||||
return true;
|
||||
};
|
||||
}
|
||||
#ifdef WITH_OPENSSL
|
||||
if (image_creator->enc_key == "random")
|
||||
{
|
||||
uint8_t newkey[64];
|
||||
RAND_bytes(newkey, 64);
|
||||
image_creator->enc_key = tohexstr(newkey, 64);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
image_creator->new_parent = cfg["parent"].string_value();
|
||||
if (!cfg["size"].is_null())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user