mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-23 17:18:52 +00:00
wallet: add encrypted seed functionality
This uses luigi1111's CN_Add method. See https://xmr.llcoins.net for details.
This commit is contained in:
parent
02e5dcd2fa
commit
651baaec46
@ -869,4 +869,21 @@ namespace cryptonote
|
|||||||
block_hashes_calculated = block_hashes_calculated_count;
|
block_hashes_calculated = block_hashes_calculated_count;
|
||||||
block_hashes_cached = block_hashes_cached_count;
|
block_hashes_cached = block_hashes_cached_count;
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
crypto::secret_key encrypt_key(const crypto::secret_key &key, const std::string &passphrase)
|
||||||
|
{
|
||||||
|
crypto::hash hash;
|
||||||
|
crypto::cn_slow_hash(passphrase.data(), passphrase.size(), hash);
|
||||||
|
sc_add((unsigned char*)key.data, (const unsigned char*)key.data, (const unsigned char*)hash.data);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
crypto::secret_key decrypt_key(const crypto::secret_key &key, const std::string &passphrase)
|
||||||
|
{
|
||||||
|
crypto::hash hash;
|
||||||
|
crypto::cn_slow_hash(passphrase.data(), passphrase.size(), hash);
|
||||||
|
sc_sub((unsigned char*)key.data, (const unsigned char*)key.data, (const unsigned char*)hash.data);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -212,6 +212,8 @@ namespace cryptonote
|
|||||||
bool is_valid_decomposed_amount(uint64_t amount);
|
bool is_valid_decomposed_amount(uint64_t amount);
|
||||||
void get_hash_stats(uint64_t &tx_hashes_calculated, uint64_t &tx_hashes_cached, uint64_t &block_hashes_calculated, uint64_t & block_hashes_cached);
|
void get_hash_stats(uint64_t &tx_hashes_calculated, uint64_t &tx_hashes_cached, uint64_t &block_hashes_calculated, uint64_t & block_hashes_cached);
|
||||||
|
|
||||||
|
crypto::secret_key encrypt_key(const crypto::secret_key &key, const std::string &passphrase);
|
||||||
|
crypto::secret_key decrypt_key(const crypto::secret_key &key, const std::string &passphrase);
|
||||||
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val) \
|
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val) \
|
||||||
CHECK_AND_ASSERT_MES(variant_var.type() == typeid(specific_type), fail_return_val, "wrong variant type: " << variant_var.type().name() << ", expected " << typeid(specific_type).name()); \
|
CHECK_AND_ASSERT_MES(variant_var.type() == typeid(specific_type), fail_return_val, "wrong variant type: " << variant_var.type().name() << ", expected " << typeid(specific_type).name()); \
|
||||||
specific_type& variable_name = boost::get<specific_type>(variant_var);
|
specific_type& variable_name = boost::get<specific_type>(variant_var);
|
||||||
|
@ -290,7 +290,7 @@ bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vecto
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
bool simple_wallet::print_seed(bool encrypted)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
std::string electrum_words;
|
std::string electrum_words;
|
||||||
@ -311,7 +311,16 @@ bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<st
|
|||||||
m_wallet->set_seed_language(mnemonic_language);
|
m_wallet->set_seed_language(mnemonic_language);
|
||||||
}
|
}
|
||||||
|
|
||||||
success = m_wallet->get_seed(electrum_words);
|
std::string seed_pass;
|
||||||
|
if (encrypted)
|
||||||
|
{
|
||||||
|
auto pwd_container = tools::password_container::prompt(true, tr("Enter optional seed encryption passphrase, empty to see raw seed"));
|
||||||
|
if (std::cin.eof() || !pwd_container)
|
||||||
|
return true;
|
||||||
|
seed_pass = pwd_container->password();
|
||||||
|
}
|
||||||
|
|
||||||
|
success = m_wallet->get_seed(electrum_words, seed_pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
@ -325,6 +334,16 @@ bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<st
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
|
{
|
||||||
|
return print_seed(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool simple_wallet::encrypted_seed(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
|
{
|
||||||
|
return print_seed(true);
|
||||||
|
}
|
||||||
|
|
||||||
bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
{
|
{
|
||||||
if (m_wallet->watch_only())
|
if (m_wallet->watch_only())
|
||||||
@ -757,6 +776,7 @@ simple_wallet::simple_wallet()
|
|||||||
m_cmd_binder.set_handler("spendkey", boost::bind(&simple_wallet::spendkey, this, _1), tr("Display private spend key"));
|
m_cmd_binder.set_handler("spendkey", boost::bind(&simple_wallet::spendkey, this, _1), tr("Display private spend key"));
|
||||||
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), tr("Display Electrum-style mnemonic seed"));
|
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), tr("Display Electrum-style mnemonic seed"));
|
||||||
m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), tr("Available options: seed language - set wallet seed language; always-confirm-transfers <1|0> - whether to confirm unsplit txes; print-ring-members <1|0> - whether to print detailed information about ring members during confirmation; store-tx-info <1|0> - whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference; default-ring-size <n> - set default ring size (default is 5); auto-refresh <1|0> - whether to automatically sync new blocks from the daemon; refresh-type <full|optimize-coinbase|no-coinbase|default> - set wallet refresh behaviour; priority [0|1|2|3|4] - default/unimportant/normal/elevated/priority fee; confirm-missing-payment-id <1|0>; ask-password <1|0>; unit <monero|millinero|micronero|nanonero|piconero> - set default monero (sub-)unit; min-outputs-count [n] - try to keep at least that many outputs of value at least min-outputs-value; min-outputs-value [n] - try to keep at least min-outputs-count outputs of at least that value; merge-destinations <1|0> - whether to merge multiple payments to the same destination address; confirm-backlog <1|0> - whether to warn if there is transaction backlog"));
|
m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), tr("Available options: seed language - set wallet seed language; always-confirm-transfers <1|0> - whether to confirm unsplit txes; print-ring-members <1|0> - whether to print detailed information about ring members during confirmation; store-tx-info <1|0> - whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference; default-ring-size <n> - set default ring size (default is 5); auto-refresh <1|0> - whether to automatically sync new blocks from the daemon; refresh-type <full|optimize-coinbase|no-coinbase|default> - set wallet refresh behaviour; priority [0|1|2|3|4] - default/unimportant/normal/elevated/priority fee; confirm-missing-payment-id <1|0>; ask-password <1|0>; unit <monero|millinero|micronero|nanonero|piconero> - set default monero (sub-)unit; min-outputs-count [n] - try to keep at least that many outputs of value at least min-outputs-value; min-outputs-value [n] - try to keep at least min-outputs-count outputs of at least that value; merge-destinations <1|0> - whether to merge multiple payments to the same destination address; confirm-backlog <1|0> - whether to warn if there is transaction backlog"));
|
||||||
|
m_cmd_binder.set_handler("encrypted_seed", boost::bind(&simple_wallet::encrypted_seed, this, _1), tr("Display encrypted Electrum-style mnemonic seed"));
|
||||||
m_cmd_binder.set_handler("rescan_spent", boost::bind(&simple_wallet::rescan_spent, this, _1), tr("Rescan blockchain for spent outputs"));
|
m_cmd_binder.set_handler("rescan_spent", boost::bind(&simple_wallet::rescan_spent, this, _1), tr("Rescan blockchain for spent outputs"));
|
||||||
m_cmd_binder.set_handler("get_tx_key", boost::bind(&simple_wallet::get_tx_key, this, _1), tr("Get transaction key (r) for a given <txid>"));
|
m_cmd_binder.set_handler("get_tx_key", boost::bind(&simple_wallet::get_tx_key, this, _1), tr("Get transaction key (r) for a given <txid>"));
|
||||||
m_cmd_binder.set_handler("check_tx_key", boost::bind(&simple_wallet::check_tx_key, this, _1), tr("Check amount going to <address> in <txid>"));
|
m_cmd_binder.set_handler("check_tx_key", boost::bind(&simple_wallet::check_tx_key, this, _1), tr("Check amount going to <address> in <txid>"));
|
||||||
@ -1026,6 +1046,13 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
fail_msg_writer() << tr("Electrum-style word list failed verification");
|
fail_msg_writer() << tr("Electrum-style word list failed verification");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto pwd_container = tools::password_container::prompt(false, tr("Enter seed encryption passphrase, empty if none"));
|
||||||
|
if (std::cin.eof() || !pwd_container)
|
||||||
|
return false;
|
||||||
|
std::string seed_pass = pwd_container->password();
|
||||||
|
if (!seed_pass.empty())
|
||||||
|
m_recovery_key = cryptonote::decrypt_key(m_recovery_key, seed_pass);
|
||||||
}
|
}
|
||||||
if (!m_generate_from_view_key.empty())
|
if (!m_generate_from_view_key.empty())
|
||||||
{
|
{
|
||||||
|
@ -97,6 +97,7 @@ 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 spendkey(const std::vector<std::string> &args = std::vector<std::string>());
|
bool spendkey(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>());
|
||||||
|
bool encrypted_seed(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sets seed language.
|
* \brief Sets seed language.
|
||||||
@ -185,6 +186,7 @@ namespace cryptonote
|
|||||||
bool accept_loaded_tx(const tools::wallet2::signed_tx_set &txs);
|
bool accept_loaded_tx(const tools::wallet2::signed_tx_set &txs);
|
||||||
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);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Prints the seed with a nice message
|
* \brief Prints the seed with a nice message
|
||||||
|
@ -296,6 +296,13 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
restore_deterministic_wallet = true;
|
restore_deterministic_wallet = true;
|
||||||
|
|
||||||
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, seed_passphrase, std::string, String, false, std::string());
|
||||||
|
if (field_seed_passphrase_found)
|
||||||
|
{
|
||||||
|
if (!field_seed_passphrase.empty())
|
||||||
|
recovery_key = cryptonote::decrypt_key(recovery_key, field_seed_passphrase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, address, std::string, String, false, std::string());
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, address, std::string, String, false, std::string());
|
||||||
@ -527,7 +534,7 @@ bool wallet2::is_deterministic() const
|
|||||||
return keys_deterministic;
|
return keys_deterministic;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool wallet2::get_seed(std::string& electrum_words) const
|
bool wallet2::get_seed(std::string& electrum_words, const std::string &passphrase) const
|
||||||
{
|
{
|
||||||
bool keys_deterministic = is_deterministic();
|
bool keys_deterministic = is_deterministic();
|
||||||
if (!keys_deterministic)
|
if (!keys_deterministic)
|
||||||
@ -541,7 +548,10 @@ bool wallet2::get_seed(std::string& electrum_words) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto::ElectrumWords::bytes_to_words(get_account().get_keys().m_spend_secret_key, electrum_words, seed_language);
|
crypto::secret_key key = get_account().get_keys().m_spend_secret_key;
|
||||||
|
if (!passphrase.empty())
|
||||||
|
key = cryptonote::encrypt_key(key, passphrase);
|
||||||
|
crypto::ElectrumWords::bytes_to_words(key, electrum_words, seed_language);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ namespace tools
|
|||||||
* \brief Checks if deterministic wallet
|
* \brief Checks if deterministic wallet
|
||||||
*/
|
*/
|
||||||
bool is_deterministic() const;
|
bool is_deterministic() const;
|
||||||
bool get_seed(std::string& electrum_words) const;
|
bool get_seed(std::string& electrum_words, const std::string &passphrase = std::string()) const;
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets the seed language
|
* \brief Gets the seed language
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user