1
mirror of https://github.com/monero-project/monero synced 2024-11-18 00:36:30 +01:00

simplewallet: add --untrusted-daemon option

This commit is contained in:
moneromooo-monero 2018-03-21 19:00:27 +00:00
parent 06b0f9e870
commit f6dbb967f8
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
2 changed files with 38 additions and 29 deletions

View File

@ -131,6 +131,7 @@ namespace
const command_line::arg_descriptor<bool> arg_restore_multisig_wallet = {"restore-multisig-wallet", sw::tr("Recover multisig wallet using Electrum-style mnemonic seed"), false}; const command_line::arg_descriptor<bool> arg_restore_multisig_wallet = {"restore-multisig-wallet", sw::tr("Recover multisig wallet using Electrum-style mnemonic seed"), false};
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Generate non-deterministic view and spend keys"), false}; const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Generate non-deterministic view and spend keys"), false};
const command_line::arg_descriptor<bool> arg_trusted_daemon = {"trusted-daemon", sw::tr("Enable commands which rely on a trusted daemon"), false}; const command_line::arg_descriptor<bool> arg_trusted_daemon = {"trusted-daemon", sw::tr("Enable commands which rely on a trusted daemon"), false};
const command_line::arg_descriptor<bool> arg_untrusted_daemon = {"untrusted-daemon", sw::tr("Disable commands which rely on a trusted daemon"), false};
const command_line::arg_descriptor<bool> arg_allow_mismatched_daemon_version = {"allow-mismatched-daemon-version", sw::tr("Allow communicating with a daemon that uses a different RPC version"), false}; const command_line::arg_descriptor<bool> arg_allow_mismatched_daemon_version = {"allow-mismatched-daemon-version", sw::tr("Allow communicating with a daemon that uses a different RPC version"), false};
const command_line::arg_descriptor<uint64_t> arg_restore_height = {"restore-height", sw::tr("Restore from specific blockchain height"), 0}; const command_line::arg_descriptor<uint64_t> arg_restore_height = {"restore-height", sw::tr("Restore from specific blockchain height"), 0};
const command_line::arg_descriptor<bool> arg_do_not_relay = {"do-not-relay", sw::tr("The newly created transaction will not be relayed to the monero network"), false}; const command_line::arg_descriptor<bool> arg_do_not_relay = {"do-not-relay", sw::tr("The newly created transaction will not be relayed to the monero network"), false};
@ -1077,7 +1078,7 @@ bool simple_wallet::import_multisig(const std::vector<std::string> &args)
fail_msg_writer() << tr("Failed to import multisig info: ") << e.what(); fail_msg_writer() << tr("Failed to import multisig info: ") << e.what();
return true; return true;
} }
if (m_trusted_daemon) if (is_daemon_trusted())
{ {
try try
{ {
@ -1229,7 +1230,7 @@ bool simple_wallet::submit_multisig(const std::vector<std::string> &args)
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
handle_transfer_exception(std::current_exception(), m_trusted_daemon); handle_transfer_exception(std::current_exception(), is_daemon_trusted());
} }
catch (...) catch (...)
{ {
@ -3117,18 +3118,21 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false; return false;
} }
// set --trusted-daemon if local // set --trusted-daemon if local and not overridden
try
{
if (tools::is_local_address(m_wallet->get_daemon_address()))
{
MINFO(tr("Daemon is local, assuming trusted"));
m_trusted_daemon = true;
}
}
catch (const std::exception &e) { }
if (!m_trusted_daemon) if (!m_trusted_daemon)
{
try
{
if (tools::is_local_address(m_wallet->get_daemon_address()))
{
MINFO(tr("Daemon is local, assuming trusted"));
m_trusted_daemon = true;
}
}
catch (const std::exception &e) { }
}
if (!is_daemon_trusted())
message_writer() << (boost::format(tr("Warning: using an untrusted daemon at %s, privacy will be lessened")) % m_wallet->get_daemon_address()).str(); message_writer() << (boost::format(tr("Warning: using an untrusted daemon at %s, privacy will be lessened")) % m_wallet->get_daemon_address()).str();
if (m_wallet->get_ring_database().empty()) if (m_wallet->get_ring_database().empty())
@ -3162,7 +3166,10 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_restore_deterministic_wallet = command_line::get_arg(vm, arg_restore_deterministic_wallet); m_restore_deterministic_wallet = command_line::get_arg(vm, arg_restore_deterministic_wallet);
m_restore_multisig_wallet = command_line::get_arg(vm, arg_restore_multisig_wallet); m_restore_multisig_wallet = command_line::get_arg(vm, arg_restore_multisig_wallet);
m_non_deterministic = command_line::get_arg(vm, arg_non_deterministic); m_non_deterministic = command_line::get_arg(vm, arg_non_deterministic);
m_trusted_daemon = command_line::get_arg(vm, arg_trusted_daemon); if (!command_line::is_arg_defaulted(vm, arg_trusted_daemon) || !command_line::is_arg_defaulted(vm, arg_untrusted_daemon))
m_trusted_daemon = command_line::get_arg(vm, arg_trusted_daemon) && !command_line::get_arg(vm, arg_untrusted_daemon);
if (!command_line::is_arg_defaulted(vm, arg_trusted_daemon) && !command_line::is_arg_defaulted(vm, arg_untrusted_daemon))
message_writer() << tr("--trusted-daemon and --untrusted-daemon are both seen, assuming untrusted");
m_allow_mismatched_daemon_version = command_line::get_arg(vm, arg_allow_mismatched_daemon_version); m_allow_mismatched_daemon_version = command_line::get_arg(vm, arg_allow_mismatched_daemon_version);
m_restore_height = command_line::get_arg(vm, arg_restore_height); m_restore_height = command_line::get_arg(vm, arg_restore_height);
m_do_not_relay = command_line::get_arg(vm, arg_do_not_relay); m_do_not_relay = command_line::get_arg(vm, arg_do_not_relay);
@ -3649,7 +3656,7 @@ bool simple_wallet::save_watch_only(const std::vector<std::string> &args/* = std
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool simple_wallet::start_mining(const std::vector<std::string>& args) bool simple_wallet::start_mining(const std::vector<std::string>& args)
{ {
if (!m_trusted_daemon) if (!is_daemon_trusted())
{ {
fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon"); fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon");
return true; return true;
@ -4145,7 +4152,7 @@ bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool simple_wallet::rescan_spent(const std::vector<std::string> &args) bool simple_wallet::rescan_spent(const std::vector<std::string> &args)
{ {
if (!m_trusted_daemon) if (!is_daemon_trusted())
{ {
fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon"); fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon");
return true; return true;
@ -4491,16 +4498,16 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
return true; return true;
} }
unlock_block = bc_height + locked_blocks; unlock_block = bc_height + locked_blocks;
ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, unlock_block /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, m_trusted_daemon); ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, unlock_block /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, is_daemon_trusted());
break; break;
case TransferNew: case TransferNew:
ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, m_trusted_daemon); ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, is_daemon_trusted());
break; break;
default: default:
LOG_ERROR("Unknown transfer method, using original"); LOG_ERROR("Unknown transfer method, using original");
/* FALLTHRU */ /* FALLTHRU */
case TransferOriginal: case TransferOriginal:
ptx_vector = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, m_trusted_daemon); ptx_vector = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, is_daemon_trusted());
break; break;
} }
@ -4676,7 +4683,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
handle_transfer_exception(std::current_exception(), m_trusted_daemon); handle_transfer_exception(std::current_exception(), is_daemon_trusted());
} }
catch (...) catch (...)
{ {
@ -4713,7 +4720,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
try try
{ {
// figure out what tx will be necessary // figure out what tx will be necessary
auto ptx_vector = m_wallet->create_unmixable_sweep_transactions(m_trusted_daemon); auto ptx_vector = m_wallet->create_unmixable_sweep_transactions(is_daemon_trusted());
if (ptx_vector.empty()) if (ptx_vector.empty())
{ {
@ -4784,7 +4791,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
handle_transfer_exception(std::current_exception(), m_trusted_daemon); handle_transfer_exception(std::current_exception(), is_daemon_trusted());
} }
catch (...) catch (...)
{ {
@ -4933,7 +4940,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
try try
{ {
// figure out what tx will be necessary // figure out what tx will be necessary
auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, m_trusted_daemon); auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, is_daemon_trusted());
if (ptx_vector.empty()) if (ptx_vector.empty())
{ {
@ -5017,7 +5024,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
handle_transfer_exception(std::current_exception(), m_trusted_daemon); handle_transfer_exception(std::current_exception(), is_daemon_trusted());
} }
catch (...) catch (...)
{ {
@ -5146,7 +5153,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
try try
{ {
// figure out what tx will be necessary // figure out what tx will be necessary
auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, fake_outs_count, 0 /* unlock_time */, priority, extra, m_trusted_daemon); auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, fake_outs_count, 0 /* unlock_time */, priority, extra, is_daemon_trusted());
if (ptx_vector.empty()) if (ptx_vector.empty())
{ {
@ -5216,7 +5223,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
handle_transfer_exception(std::current_exception(), m_trusted_daemon); handle_transfer_exception(std::current_exception(), is_daemon_trusted());
} }
catch (...) catch (...)
{ {
@ -5521,7 +5528,7 @@ bool simple_wallet::submit_transfer(const std::vector<std::string> &args_)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
handle_transfer_exception(std::current_exception(), m_trusted_daemon); handle_transfer_exception(std::current_exception(), is_daemon_trusted());
} }
catch (...) catch (...)
{ {
@ -7109,7 +7116,7 @@ bool simple_wallet::import_key_images(const std::vector<std::string> &args)
fail_msg_writer() << tr("command not supported by HW wallet"); fail_msg_writer() << tr("command not supported by HW wallet");
return true; return true;
} }
if (!m_trusted_daemon) if (!is_daemon_trusted())
{ {
fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon"); fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon");
return true; return true;
@ -7495,6 +7502,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_non_deterministic ); command_line::add_arg(desc_params, arg_non_deterministic );
command_line::add_arg(desc_params, arg_electrum_seed ); command_line::add_arg(desc_params, arg_electrum_seed );
command_line::add_arg(desc_params, arg_trusted_daemon); command_line::add_arg(desc_params, arg_trusted_daemon);
command_line::add_arg(desc_params, arg_untrusted_daemon);
command_line::add_arg(desc_params, arg_allow_mismatched_daemon_version); command_line::add_arg(desc_params, arg_allow_mismatched_daemon_version);
command_line::add_arg(desc_params, arg_restore_height); command_line::add_arg(desc_params, arg_restore_height);
command_line::add_arg(desc_params, arg_do_not_relay); command_line::add_arg(desc_params, arg_do_not_relay);

View File

@ -229,6 +229,7 @@ namespace cryptonote
bool print_ring_members(const std::vector<tools::wallet2::pending_tx>& ptx_vector, std::ostream& ostr); bool print_ring_members(const std::vector<tools::wallet2::pending_tx>& ptx_vector, std::ostream& ostr);
std::string get_prompt() const; std::string get_prompt() const;
bool print_seed(bool encrypted); bool print_seed(bool encrypted);
bool is_daemon_trusted() const { return *m_trusted_daemon; }
/*! /*!
* \brief Prints the seed with a nice message * \brief Prints the seed with a nice message
@ -331,7 +332,7 @@ namespace cryptonote
bool m_restore_deterministic_wallet; // recover flag bool m_restore_deterministic_wallet; // recover flag
bool m_restore_multisig_wallet; // recover flag bool m_restore_multisig_wallet; // recover flag
bool m_non_deterministic; // old 2-random generation bool m_non_deterministic; // old 2-random generation
bool m_trusted_daemon; boost::optional<bool> m_trusted_daemon;
bool m_allow_mismatched_daemon_version; bool m_allow_mismatched_daemon_version;
bool m_restoring; // are we restoring, by whatever method? bool m_restoring; // are we restoring, by whatever method?
uint64_t m_restore_height; // optional uint64_t m_restore_height; // optional