From f97526e641a96ce7525673704ade98b3b3ee19d3 Mon Sep 17 00:00:00 2001 From: kenshi84 Date: Fri, 27 Jan 2017 21:26:52 +0900 Subject: simplewallet: option to always ask password for any crytical operations --- src/simplewallet/simplewallet.cpp | 42 +++++++++++++++++++++++++++++++++++++++ src/simplewallet/simplewallet.h | 1 + 2 files changed, 43 insertions(+) (limited to 'src/simplewallet') diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 50509040c..321f2b137 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -286,6 +286,7 @@ std::string simple_wallet::get_commands_str() bool simple_wallet::viewkey(const std::vector &args/* = std::vector()*/) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } // don't log std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl; std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_view_public_key) << std::endl; @@ -295,6 +296,12 @@ bool simple_wallet::viewkey(const std::vector &args/* = std::vector bool simple_wallet::spendkey(const std::vector &args/* = std::vector()*/) { + if (m_wallet->watch_only()) + { + fail_msg_writer() << tr("wallet is watch-only and has no spend key"); + return true; + } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } // don't log std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl; std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_spend_public_key) << std::endl; @@ -312,6 +319,7 @@ bool simple_wallet::seed(const std::vector &args/* = std::vectorask_password() && !get_and_verify_password()) { return true; } if (m_wallet->is_deterministic()) { if (m_wallet->get_seed_language().empty()) @@ -544,6 +552,17 @@ bool simple_wallet::set_confirm_missing_payment_id(const std::vector &args/* = std::vector()*/) +{ + const auto pwd_container = get_and_verify_password(); + if (pwd_container) + { + m_wallet->ask_password(is_it_true(args[1])); + m_wallet->rewrite(m_wallet_file, pwd_container->password()); + } + return true; +} + bool simple_wallet::help(const std::vector &args/* = std::vector()*/) { success_msg_writer() << get_commands_str(); @@ -616,6 +635,7 @@ bool simple_wallet::set_variable(const std::vector &args) success_msg_writer() << "refresh-type = " << get_refresh_type_name(m_wallet->get_refresh_type()); success_msg_writer() << "priority = " << m_wallet->get_default_priority(); success_msg_writer() << "confirm-missing-payment-id = " << m_wallet->confirm_missing_payment_id(); + success_msg_writer() << "ask-password = " << m_wallet->ask_password(); return true; } else @@ -738,6 +758,19 @@ bool simple_wallet::set_variable(const std::vector &args) return true; } } + else if (args[0] == "ask-password") + { + if (args.size() <= 1) + { + fail_msg_writer() << tr("set ask-password: needs an argument (0 or 1)"); + return true; + } + else + { + set_ask_password(args); + return true; + } + } } fail_msg_writer() << tr("set: unrecognized argument(s)"); return true; @@ -2053,6 +2086,7 @@ bool simple_wallet::print_ring_members(const std::vector &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2411,6 +2445,7 @@ bool simple_wallet::locked_transfer(const std::vector &args_) bool simple_wallet::sweep_unmixable(const std::vector &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2573,6 +2608,7 @@ bool simple_wallet::sweep_unmixable(const std::vector &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::sweep_all(const std::vector &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2834,6 +2870,7 @@ bool simple_wallet::sweep_all(const std::vector &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::donate(const std::vector &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::vector local_args = args_; if(local_args.empty() || local_args.size() > 3) { @@ -2974,6 +3011,7 @@ bool simple_wallet::sign_transfer(const std::vector &args_) fail_msg_writer() << tr("This is a watch only wallet"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::vector ptx; try @@ -3122,6 +3160,7 @@ bool simple_wallet::get_tx_key(const std::vector &args_) fail_msg_writer() << tr("usage: get_tx_key "); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } cryptonote::blobdata txid_data; if(!epee::string_tools::parse_hexstr_to_binbuff(local_args.front(), txid_data)) @@ -3890,6 +3929,7 @@ bool simple_wallet::sign(const std::vector &args) fail_msg_writer() << tr("wallet is watch-only and cannot sign"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::string filename = args[0]; std::string data; bool r = epee::file_io_utils::load_file_to_string(filename, data); @@ -3955,6 +3995,7 @@ bool simple_wallet::export_key_images(const std::vector &args) fail_msg_writer() << tr("wallet is watch-only and cannot export key images"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::string filename = args[0]; try @@ -4013,6 +4054,7 @@ bool simple_wallet::export_outputs(const std::vector &args) fail_msg_writer() << tr("usage: export_outputs "); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::string filename = args[0]; try diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 237c1e3e1..7139cdea2 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -115,6 +115,7 @@ namespace cryptonote bool set_auto_refresh(const std::vector &args = std::vector()); bool set_refresh_type(const std::vector &args = std::vector()); bool set_confirm_missing_payment_id(const std::vector &args = std::vector()); + bool set_ask_password(const std::vector &args = std::vector()); bool help(const std::vector &args = std::vector()); bool start_mining(const std::vector &args); bool stop_mining(const std::vector &args); -- cgit v1.2.3