Added allowed user pubkey list for hpsh

This commit is contained in:
chalith
2023-11-01 18:27:05 +05:30
parent c4c304a106
commit 0f0df53913
14 changed files with 117 additions and 27 deletions

View File

@@ -528,6 +528,20 @@ namespace conf
std::cerr << "Invalid format for hpsh run as config (\"uid>0:gid>0\" expected).\n";
return -1;
}
jpath = "hpsh.users";
cfg.hpsh.users.clear();
for (auto &userpk : hpsh["users"].array_range())
{
// Convert the public key hex of each node to binary and store it.
const std::string bin_pubkey = util::to_bin(userpk.as<std::string_view>());
if (bin_pubkey.empty())
{
std::cerr << "Error decoding user pubkey list.\n";
return -1;
}
cfg.hpsh.users.emplace(bin_pubkey);
}
}
catch (const std::exception &e)
{
@@ -653,6 +667,12 @@ namespace conf
jsoncons::ojson hpsh_config;
hpsh_config.insert_or_assign("enabled", cfg.hpsh.enabled);
hpsh_config.insert_or_assign("run_as", cfg.hpsh.run_as.to_string());
jsoncons::ojson users(jsoncons::json_array_arg);
for (const auto &userpk : cfg.hpsh.users)
{
users.push_back(util::to_hex(userpk));
}
hpsh_config.insert_or_assign("users", users);
d.insert_or_assign("hpsh", hpsh_config);
}