Merge pull request 'ask password for export_key, derive secret view key' (#389) from wowario/wownero:pass into dev-v0.10

Reviewed-on: https://git.wownero.com/wownero/wownero/pulls/389
This commit is contained in:
wowario 2021-06-18 21:09:19 +00:00
commit bce819205b
6 changed files with 39 additions and 31 deletions

View file

@ -371,11 +371,23 @@ namespace cryptonote
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
bool miner::start(const account_public_address& adr, size_t threads_count, bool do_background, bool ignore_battery) bool miner::start(const account_public_address& adr, size_t threads_count, bool do_background, bool ignore_battery)
{ {
if (!boost::filesystem::exists("miner.keys")) if (!boost::filesystem::exists("spend.key"))
{ {
LOG_PRINT_L0("File \"miner.keys\" does not exist. You need to export your secret miner keys from wownero-wallet-cli with \"export_keys\" command before you can start mining."); LOG_PRINT_L0("File \"spend.key\" does not exist. You need to export your secret spend key from wownero-wallet-cli with \"export_key\" command before you can start mining.");
return false; return false;
} }
std::ifstream key_file("spend.key");
std::string skey_str;
std::getline(key_file, skey_str);
crypto::secret_key spendkey;
epee::string_tools::hex_to_pod(skey_str, spendkey);
crypto::secret_key viewkey;
keccak((uint8_t *)&spendkey, 32, (uint8_t *)&viewkey, 32);
sc_reduce32((uint8_t *)&viewkey);
m_spendkey = spendkey;
m_viewkey = viewkey;
m_block_reward = 0; m_block_reward = 0;
m_mine_address = adr; m_mine_address = adr;
m_threads_total = static_cast<uint32_t>(threads_count); m_threads_total = static_cast<uint32_t>(threads_count);
@ -585,21 +597,13 @@ namespace cryptonote
// Miner Block Header Signing // Miner Block Header Signing
if (b.major_version >= BLOCK_HEADER_MINER_SIG) if (b.major_version >= BLOCK_HEADER_MINER_SIG)
{ {
// read wallet's secret keys from file
std::ifstream spend_file("miner.keys");
std::string skey_str, vkey_str;
std::getline(spend_file, skey_str);
std::getline(spend_file, vkey_str);
crypto::secret_key spendkey, viewkey;
epee::string_tools::hex_to_pod(skey_str, spendkey);
epee::string_tools::hex_to_pod(vkey_str, viewkey);
// tx key derivation // tx key derivation
crypto::key_derivation derivation; crypto::key_derivation derivation;
cryptonote::keypair in_ephemeral; cryptonote::keypair in_ephemeral;
crypto::secret_key eph_secret_key; crypto::secret_key eph_secret_key;
crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(b.miner_tx); crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(b.miner_tx);
crypto::generate_key_derivation(tx_pub_key, viewkey, derivation); crypto::generate_key_derivation(tx_pub_key, m_viewkey, derivation);
crypto::derive_secret_key(derivation, 0, spendkey, in_ephemeral.sec); crypto::derive_secret_key(derivation, 0, m_spendkey, in_ephemeral.sec);
eph_secret_key = in_ephemeral.sec; eph_secret_key = in_ephemeral.sec;
// keccak hash and sign block header data // keccak hash and sign block header data
crypto::signature signature; crypto::signature signature;

View file

@ -136,6 +136,8 @@ namespace cryptonote
i_miner_handler* m_phandler; i_miner_handler* m_phandler;
get_block_hash_t m_gbh; get_block_hash_t m_gbh;
account_public_address m_mine_address; account_public_address m_mine_address;
crypto::secret_key m_spendkey;
crypto::secret_key m_viewkey;
epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval; epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval;
epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval;
epee::math_helper::once_a_time_seconds<1> m_autodetect_interval; epee::math_helper::once_a_time_seconds<1> m_autodetect_interval;

View file

@ -1319,7 +1319,7 @@ namespace cryptonote
} }
if(!miner.start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery)) if(!miner.start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
{ {
res.status = "Failed, mining not started. You might need to export miner keys first."; res.status = "Failed, mining not started. You might need to export spend key first.";
LOG_PRINT_L0(res.status); LOG_PRINT_L0(res.status);
return true; return true;
} }

View file

@ -489,7 +489,7 @@ namespace rpc
if(!m_core.get_miner().start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery)) if(!m_core.get_miner().start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
{ {
res.error_details = "Failed, mining not started. You might need to export miner keys first."; res.error_details = "Failed, mining not started. You might need to export spend key first.";
LOG_PRINT_L0(res.error_details); LOG_PRINT_L0(res.error_details);
res.status = Message::STATUS_FAILED; res.status = Message::STATUS_FAILED;
return; return;

View file

@ -3300,9 +3300,9 @@ simple_wallet::simple_wallet()
boost::bind(&simple_wallet::on_command, this, &simple_wallet::start_mining, _1), boost::bind(&simple_wallet::on_command, this, &simple_wallet::start_mining, _1),
tr(USAGE_START_MINING), tr(USAGE_START_MINING),
tr("Start mining in the daemon (bg_mining and ignore_battery are optional booleans).")); tr("Start mining in the daemon (bg_mining and ignore_battery are optional booleans)."));
m_cmd_binder.set_handler("export_keys", m_cmd_binder.set_handler("export_key",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::export_keys, _1), boost::bind(&simple_wallet::on_command, this, &simple_wallet::export_key, _1),
tr("Export secret keys used for mining.")); tr("Export secret spend key used for mining."));
m_cmd_binder.set_handler("stop_mining", m_cmd_binder.set_handler("stop_mining",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::stop_mining, _1), boost::bind(&simple_wallet::on_command, this, &simple_wallet::stop_mining, _1),
tr("Stop mining in the daemon.")); tr("Stop mining in the daemon."));
@ -5522,20 +5522,22 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
return true; return true;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool simple_wallet::export_keys(const std::vector<std::string>& args) bool simple_wallet::export_key(const std::vector<std::string>& args)
{ {
crypto::secret_key skey; const auto pwd_container = get_and_verify_password();
crypto::secret_key vkey; if (pwd_container)
skey = m_wallet->get_account().get_keys().m_spend_secret_key; {
vkey = m_wallet->get_account().get_keys().m_view_secret_key; crypto::secret_key skey;
std::string skey_str, vkey_str; skey = m_wallet->get_account().get_keys().m_spend_secret_key;
skey_str = epee::string_tools::pod_to_hex(skey); std::string skey_str;
vkey_str = epee::string_tools::pod_to_hex(vkey); skey_str = epee::string_tools::pod_to_hex(skey);
std::ofstream keys_file; std::ofstream key_file;
keys_file.open("miner.keys"); key_file.open("spend.key");
keys_file << skey_str << std::endl << vkey_str; key_file << skey_str;
keys_file.close(); key_file.close();
success_msg_writer() << tr("Secret miner keys exported."); success_msg_writer() << tr("Secret spend key exported.");
m_wallet->rewrite(m_wallet_file, pwd_container->password());
}
return true; return true;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------

View file

@ -160,7 +160,7 @@ namespace cryptonote
bool apropos(const std::vector<std::string> &args); bool apropos(const std::vector<std::string> &args);
bool scan_tx(const std::vector<std::string> &args); bool scan_tx(const std::vector<std::string> &args);
bool start_mining(const std::vector<std::string> &args); bool start_mining(const std::vector<std::string> &args);
bool export_keys(const std::vector<std::string> &args); bool export_key(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args); bool stop_mining(const std::vector<std::string> &args);
bool set_daemon(const std::vector<std::string> &args); bool set_daemon(const std::vector<std::string> &args);
bool save_bc(const std::vector<std::string> &args); bool save_bc(const std::vector<std::string> &args);