ask password for export_key, derive secret view key

This commit is contained in:
wowario 2021-06-18 21:21:02 +03:00
parent 2016b83300
commit 016bdedf73
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)
{
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;
}
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_mine_address = adr;
m_threads_total = static_cast<uint32_t>(threads_count);
@ -585,21 +597,13 @@ namespace cryptonote
// Miner Block Header Signing
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
crypto::key_derivation derivation;
cryptonote::keypair in_ephemeral;
crypto::secret_key eph_secret_key;
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::derive_secret_key(derivation, 0, spendkey, in_ephemeral.sec);
crypto::generate_key_derivation(tx_pub_key, m_viewkey, derivation);
crypto::derive_secret_key(derivation, 0, m_spendkey, in_ephemeral.sec);
eph_secret_key = in_ephemeral.sec;
// keccak hash and sign block header data
crypto::signature signature;

View file

@ -136,6 +136,8 @@ namespace cryptonote
i_miner_handler* m_phandler;
get_block_hash_t m_gbh;
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<2> m_update_merge_hr_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))
{
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);
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))
{
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);
res.status = Message::STATUS_FAILED;
return;

View file

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

View file

@ -160,7 +160,7 @@ namespace cryptonote
bool apropos(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 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 set_daemon(const std::vector<std::string> &args);
bool save_bc(const std::vector<std::string> &args);