From d4097940c441fa35620734eaa6b5c571ac7d44be Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 17 Nov 2016 14:11:58 +0800 Subject: [PATCH] show viewkey in key images file checker --- main.cpp | 18 +++++------------- src/page.h | 26 ++++++++++++++++++-------- src/templates/checkrawkeyimgs.html | 1 + 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/main.cpp b/main.cpp index 1fa1921..665bc08 100644 --- a/main.cpp +++ b/main.cpp @@ -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 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); }); diff --git a/src/page.h b/src/page.h index 0c3777f..aeaf856 100644 --- a/src/page.h +++ b/src/page.h @@ -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"); + // 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{}} diff --git a/src/templates/checkrawkeyimgs.html b/src/templates/checkrawkeyimgs.html index f73de6c..ee11a25 100644 --- a/src/templates/checkrawkeyimgs.html +++ b/src/templates/checkrawkeyimgs.html @@ -22,6 +22,7 @@

Key images for address: {{address}}

+

Viewkey: {{viewkey}}

{{#has_total_xmr}}

Total value of xmr spend: {{total_xmr}}

{{/has_total_xmr}}