show viewkey in key images file checker

This commit is contained in:
moneroexamples 2016-11-17 14:11:58 +08:00
parent 2d2ba48b7d
commit d4097940c4
3 changed files with 25 additions and 22 deletions

View file

@ -249,23 +249,15 @@ int main(int ac, const char* av[]) {
return string("Raw key images data not given");
}
string raw_data = post_body["rawkeyimgsdata"];
return xmrblocks.show_checkrawkeyimgs(raw_data);
});
CROW_ROUTE(app, "/genrawkeyimgs").methods("POST"_method)
([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
for (auto& kv: post_body)
if (post_body.count("viewkey") == 0)
{
cout << kv.first << ": " << kv.second << endl;
return string("Viewkey not provided. Cant decrypt key image file without it");
}
string raw_data = post_body["rawkeyimgsdata"];
string viewkey = post_body["viewkey"];
return xmrblocks.show_checkrawkeyimgs(string{});
return xmrblocks.show_checkrawkeyimgs(raw_data, viewkey);
});

View file

@ -1999,25 +1999,34 @@ namespace xmreg {
}
string
show_checkrawkeyimgs(string raw_data)
show_checkrawkeyimgs(string raw_data, string viewkey_str)
{
// remove white characters
boost::trim(raw_data);
boost::erase_all(raw_data, "\r\n");
boost::erase_all(raw_data, "\n");
string decoded_raw_data = epee::string_encoding::base64_decode(raw_data);
// remove white characters
boost::trim(viewkey_str);
string decoded_raw_data = epee::string_encoding::base64_decode(raw_data);
secret_key prv_view_key;
if (!xmreg::parse_str_secret_key(viewkey_str, prv_view_key))
{
cerr << "Cant parse the private key: " << viewkey_str << endl;
return string("Cant parse private key: " + viewkey_str);
}
const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
if (!strncmp(decoded_raw_data.c_str(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen) == 0)
{
cout << "This does not seem to be key image export data" << endl;
return string {"This does not seem to be key image export data"};
}
// if (!strncmp(decoded_raw_data.c_str(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen) == 0)
// {
// cout << "This does not seem to be key image export data" << endl;
// return string {"This does not seem to be key image export data"};
// }
// header is magic + public spend and keys
// header is public spend and keys
const size_t header_lenght = 2 * sizeof(crypto::public_key);
const size_t key_img_size = sizeof(crypto::key_image);
const size_t record_lenght = key_img_size + sizeof(crypto::signature);
@ -2036,7 +2045,8 @@ namespace xmreg {
// initalize page template context map
mstch::map context {
{"testnet" , testnet},
{"address" , xmreg::print_address(*xmr_address, testnet)},
{"address" , REMOVE_HASH_BRAKETS(xmreg::print_address(*xmr_address, testnet))},
{"viewkey" , REMOVE_HASH_BRAKETS(fmt::format("{:s}", prv_view_key))},
{"has_total_xmr" , false},
{"total_xmr" , string{}},
{"key_imgs" , mstch::array{}}

View file

@ -22,6 +22,7 @@
</div>
<h4>Key images for address: {{address}}</h4>
<h4>Viewkey: {{viewkey}}</h4>
{{#has_total_xmr}}
<h4>Total value of xmr spend: {{total_xmr}}</h4>
{{/has_total_xmr}}