diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-02-04 17:18:38 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-02-04 17:18:38 +0200 |
commit | 31cf4e736203d687be97d3f65425fcdbcbe77ac6 (patch) | |
tree | 5e7a1f85ac4fd46589609260b690d8e82880a53d /src/simplewallet | |
parent | Merge pull request #1663 (diff) | |
parent | simplewallet: option to always ask password for any crytical operations (diff) | |
download | monero-31cf4e736203d687be97d3f65425fcdbcbe77ac6.tar.xz |
Merge pull request #1640
f97526e6 simplewallet: option to always ask password for any crytical operations (kenshi84)
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 42 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index f5e20be48..049125268 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<std::string> &args/* = std::vector<std::string>()*/) { + 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<std::string> &args/* = std::vector bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { + 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<std::string> &args/* = std::vector<st fail_msg_writer() << tr("wallet is watch-only and has no seed"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (m_wallet->is_deterministic()) { if (m_wallet->get_seed_language().empty()) @@ -571,6 +579,17 @@ bool simple_wallet::set_confirm_missing_payment_id(const std::vector<std::string return true; } +bool simple_wallet::set_ask_password(const std::vector<std::string> &args/* = std::vector<std::string>()*/) +{ + 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<std::string> &args/* = std::vector<std::string>()*/) { success_msg_writer() << get_commands_str(); @@ -643,6 +662,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &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 @@ -765,6 +785,19 @@ bool simple_wallet::set_variable(const std::vector<std::string> &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; @@ -2054,6 +2087,7 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending //---------------------------------------------------------------------------------------------------- bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2412,6 +2446,7 @@ bool simple_wallet::locked_transfer(const std::vector<std::string> &args_) bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2574,6 +2609,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::sweep_all(const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2835,6 +2871,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::donate(const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::vector<std::string> local_args = args_; if(local_args.empty() || local_args.size() > 3) { @@ -2975,6 +3012,7 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &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<tools::wallet2::pending_tx> ptx; try @@ -3123,6 +3161,7 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_) fail_msg_writer() << tr("usage: get_tx_key <txid>"); 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)) @@ -3891,6 +3930,7 @@ bool simple_wallet::sign(const std::vector<std::string> &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); @@ -3956,6 +3996,7 @@ bool simple_wallet::export_key_images(const std::vector<std::string> &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 @@ -4014,6 +4055,7 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args) fail_msg_writer() << tr("usage: export_outputs <filename>"); 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 9918300df..ce0a24be7 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -115,6 +115,7 @@ namespace cryptonote bool set_auto_refresh(const std::vector<std::string> &args = std::vector<std::string>()); bool set_refresh_type(const std::vector<std::string> &args = std::vector<std::string>()); bool set_confirm_missing_payment_id(const std::vector<std::string> &args = std::vector<std::string>()); + bool set_ask_password(const std::vector<std::string> &args = std::vector<std::string>()); bool help(const std::vector<std::string> &args = std::vector<std::string>()); bool start_mining(const std::vector<std::string> &args); bool stop_mining(const std::vector<std::string> &args); |