From 302cc9c7001a4b5a6d09a5ca3e65a3227991fa07 Mon Sep 17 00:00:00 2001 From: Fabian Hirschmann Date: Sat, 9 Jan 2016 02:49:41 +0100 Subject: [PATCH 1/3] add --password-file option --- src/simplewallet/simplewallet.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 00bdc689..73214818 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,7 @@ namespace const command_line::arg_descriptor arg_daemon_address = {"daemon-address", sw::tr("Use daemon instance at :"), ""}; const command_line::arg_descriptor arg_daemon_host = {"daemon-host", sw::tr("Use daemon instance at host instead of localhost"), ""}; const command_line::arg_descriptor arg_password = {"password", sw::tr("Wallet password"), "", true}; + const command_line::arg_descriptor arg_password_file = {"password-file", sw::tr("Wallet password file"), "", true}; const command_line::arg_descriptor arg_electrum_seed = {"electrum-seed", sw::tr("Specify Electrum seed for wallet recovery/creation"), ""}; const command_line::arg_descriptor arg_restore_deterministic_wallet = {"restore-deterministic-wallet", sw::tr("Recover wallet using Electrum-style mnemonic seed"), false}; const command_line::arg_descriptor arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false}; @@ -793,11 +795,27 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (m_daemon_address.empty()) m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port); + if (has_arg(vm, arg_password) && has_arg(vm, arg_password_file)) + { + fail_msg_writer() << tr("can't specify more than one of --password and --password-file"); + return false; + } + tools::password_container pwd_container; if (command_line::has_arg(vm, arg_password)) { pwd_container.password(command_line::get_arg(vm, arg_password)); } + else if (command_line::has_arg(vm, arg_password_file)) + { + std::ifstream pfs(command_line::get_arg(vm, arg_password_file)); + std::string password((std::istreambuf_iterator(pfs)), + (std::istreambuf_iterator())); + // Remove line breaks the user might have inserted + password.erase(std::remove(password.begin(), password.end(), '\r'), password.end()); + password.erase(std::remove(password.begin(), password.end(), '\n'), password.end()); + pwd_container.password(password.c_str()); + } else { bool r = pwd_container.read_password(); @@ -2418,6 +2436,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_generate_new_wallet); command_line::add_arg(desc_params, arg_generate_from_view_key); command_line::add_arg(desc_params, arg_password); + command_line::add_arg(desc_params, arg_password_file); command_line::add_arg(desc_params, arg_daemon_address); command_line::add_arg(desc_params, arg_daemon_host); command_line::add_arg(desc_params, arg_daemon_port); From 7b2d27f89a40cc68976dfb3dd625628dbb6ce7a0 Mon Sep 17 00:00:00 2001 From: Fabian Hirschmann Date: Sat, 9 Jan 2016 18:59:39 +0100 Subject: [PATCH 2/3] remove new lines at the end of the password only --- src/simplewallet/simplewallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 73214818..2e1337ce 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -812,8 +812,8 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) std::string password((std::istreambuf_iterator(pfs)), (std::istreambuf_iterator())); // Remove line breaks the user might have inserted - password.erase(std::remove(password.begin(), password.end(), '\r'), password.end()); - password.erase(std::remove(password.begin(), password.end(), '\n'), password.end()); + password.erase(std::remove(password.begin() - 1, password.end(), '\n'), password.end()); + password.erase(std::remove(password.end() - 1, password.end(), '\r'), password.end()); pwd_container.password(password.c_str()); } else From c5baf30208817ebb6f07541ed49f9067b910272a Mon Sep 17 00:00:00 2001 From: Fabian Hirschmann Date: Sat, 9 Jan 2016 19:11:34 +0100 Subject: [PATCH 3/3] use load_file_to_string and exit with error on file read errors --- src/simplewallet/simplewallet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 2e1337ce..2484cd3a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -808,9 +808,15 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) } else if (command_line::has_arg(vm, arg_password_file)) { - std::ifstream pfs(command_line::get_arg(vm, arg_password_file)); - std::string password((std::istreambuf_iterator(pfs)), - (std::istreambuf_iterator())); + std::string password; + bool r = epee::file_io_utils::load_file_to_string(command_line::get_arg(vm, arg_password_file), + password); + if (!r) + { + fail_msg_writer() << tr("the password file specified could not be read"); + return false; + } + // Remove line breaks the user might have inserted password.erase(std::remove(password.begin() - 1, password.end(), '\n'), password.end()); password.erase(std::remove(password.end() - 1, password.end(), '\r'), password.end());