mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-22 20:58:54 +00:00
Merge pull request #200
cfc8c55
Add simple_wallet::seed_set_language method (warptangent)26b87df
Add wallet2::verify_password method (warptangent)
This commit is contained in:
commit
f5c2a5ec9c
@ -231,6 +231,36 @@ bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<st
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
if (!m_wallet->is_deterministic())
|
||||||
|
{
|
||||||
|
fail_msg_writer() << "This wallet is non-deterministic and doesn't have a seed.";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
tools::password_container pwd_container;
|
||||||
|
success = pwd_container.read_password();
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << "failed to read wallet password";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* verify password before using so user doesn't accidentally set a new password for rewritten wallet */
|
||||||
|
success = m_wallet->verify_password(pwd_container.password());
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << "invalid password";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string mnemonic_language = get_mnemonic_language();
|
||||||
|
m_wallet->set_seed_language(mnemonic_language);
|
||||||
|
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>()*/)
|
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
{
|
{
|
||||||
success_msg_writer() << get_commands_str();
|
success_msg_writer() << get_commands_str();
|
||||||
@ -255,9 +285,39 @@ simple_wallet::simple_wallet()
|
|||||||
m_cmd_binder.set_handler("save", boost::bind(&simple_wallet::save, this, _1), "Save wallet synchronized data");
|
m_cmd_binder.set_handler("save", boost::bind(&simple_wallet::save, this, _1), "Save wallet synchronized data");
|
||||||
m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), "Get viewkey");
|
m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), "Get viewkey");
|
||||||
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), "Get deterministic seed");
|
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), "Get deterministic seed");
|
||||||
|
m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), "available options: seed language - Set wallet seed langage");
|
||||||
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help");
|
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help");
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
||||||
|
{
|
||||||
|
if (args.empty())
|
||||||
|
{
|
||||||
|
fail_msg_writer() << "set: needs an argument. available options: seed";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (args[0] == "seed")
|
||||||
|
{
|
||||||
|
if (args.size() == 1)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << "set seed: needs an argument. available options: language";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (args[1] == "language")
|
||||||
|
{
|
||||||
|
std::vector<std::string> local_args = args;
|
||||||
|
local_args.erase(local_args.begin(), local_args.begin()+2);
|
||||||
|
seed_set_language(local_args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail_msg_writer() << "set: unrecognized argument(s)";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::set_log(const std::vector<std::string> &args)
|
bool simple_wallet::set_log(const std::vector<std::string> &args)
|
||||||
{
|
{
|
||||||
if(args.size() != 1)
|
if(args.size() != 1)
|
||||||
|
@ -81,6 +81,17 @@ namespace cryptonote
|
|||||||
|
|
||||||
bool viewkey(const std::vector<std::string> &args = std::vector<std::string>());
|
bool viewkey(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool seed(const std::vector<std::string> &args = std::vector<std::string>());
|
bool seed(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets seed language.
|
||||||
|
*
|
||||||
|
* interactive
|
||||||
|
* - prompts for password so wallet can be rewritten
|
||||||
|
* - calls get_mnemonic_language() which prompts for language
|
||||||
|
*
|
||||||
|
* \return success status
|
||||||
|
*/
|
||||||
|
bool seed_set_language(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool help(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 start_mining(const std::vector<std::string> &args);
|
||||||
bool stop_mining(const std::vector<std::string> &args);
|
bool stop_mining(const std::vector<std::string> &args);
|
||||||
@ -96,6 +107,7 @@ namespace cryptonote
|
|||||||
);
|
);
|
||||||
bool print_address(const std::vector<std::string> &args = std::vector<std::string>());
|
bool print_address(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool save(const std::vector<std::string> &args);
|
bool save(const std::vector<std::string> &args);
|
||||||
|
bool set_variable(const std::vector<std::string> &args);
|
||||||
bool set_log(const std::vector<std::string> &args);
|
bool set_log(const std::vector<std::string> &args);
|
||||||
|
|
||||||
uint64_t get_daemon_blockchain_height(std::string& err);
|
uint64_t get_daemon_blockchain_height(std::string& err);
|
||||||
|
@ -570,6 +570,54 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
|
|||||||
THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password);
|
THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief verify password for default wallet keys file.
|
||||||
|
* \param password Password to verify
|
||||||
|
*
|
||||||
|
* for verification only
|
||||||
|
* should not mutate state, unlike load_keys()
|
||||||
|
* can be used prior to rewriting wallet keys file, to ensure user has entered the correct password
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool wallet2::verify_password(const std::string& password)
|
||||||
|
{
|
||||||
|
const std::string keys_file_name = m_keys_file;
|
||||||
|
wallet2::keys_file_data keys_file_data;
|
||||||
|
std::string buf;
|
||||||
|
bool r = epee::file_io_utils::load_file_to_string(keys_file_name, buf);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, keys_file_name);
|
||||||
|
|
||||||
|
// Decrypt the contents
|
||||||
|
r = ::serialization::parse_binary(buf, keys_file_data);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + keys_file_name + '\"');
|
||||||
|
crypto::chacha8_key key;
|
||||||
|
crypto::generate_chacha8_key(password, key);
|
||||||
|
std::string account_data;
|
||||||
|
account_data.resize(keys_file_data.account_data.size());
|
||||||
|
crypto::chacha8(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
|
||||||
|
|
||||||
|
// The contents should be JSON if the wallet follows the new format.
|
||||||
|
rapidjson::Document json;
|
||||||
|
if (json.Parse(account_data.c_str(), keys_file_data.account_data.size()).HasParseError())
|
||||||
|
{
|
||||||
|
// old format before JSON wallet key file format
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
account_data = std::string(json["key_data"].GetString(), json["key_data"].GetString() +
|
||||||
|
json["key_data"].GetStringLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
cryptonote::account_base account_data_check;
|
||||||
|
|
||||||
|
r = epee::serialization::load_t_from_binary(account_data_check, account_data);
|
||||||
|
const cryptonote::account_keys& keys = account_data_check.get_keys();
|
||||||
|
|
||||||
|
r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key);
|
||||||
|
r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Generates a wallet or restores one.
|
* \brief Generates a wallet or restores one.
|
||||||
* \param wallet_ Name of wallet file
|
* \param wallet_ Name of wallet file
|
||||||
|
@ -153,6 +153,11 @@ namespace tools
|
|||||||
void rewrite(const std::string& wallet_name, const std::string& password);
|
void rewrite(const std::string& wallet_name, const std::string& password);
|
||||||
void load(const std::string& wallet, const std::string& password);
|
void load(const std::string& wallet, const std::string& password);
|
||||||
void store();
|
void store();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief verifies given password is correct for default wallet keys file
|
||||||
|
*/
|
||||||
|
bool verify_password(const std::string& password);
|
||||||
cryptonote::account_base& get_account(){return m_account;}
|
cryptonote::account_base& get_account(){return m_account;}
|
||||||
|
|
||||||
// upper_transaction_size_limit as defined below is set to
|
// upper_transaction_size_limit as defined below is set to
|
||||||
|
Loading…
Reference in New Issue
Block a user