wallet2: fix key encryption when changing ask-password from 0/1 to 2
we reuse the wallet_keys_unlocker object, which does the right thing in conjunction with other users of decrypt/encrypt (ie, refresh).
This commit is contained in:
parent
753dc901a1
commit
2cad563060
|
@ -1229,8 +1229,6 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std
|
||||||
m_ring_history_saved(false),
|
m_ring_history_saved(false),
|
||||||
m_ringdb(),
|
m_ringdb(),
|
||||||
m_last_block_reward(0),
|
m_last_block_reward(0),
|
||||||
m_encrypt_keys_after_refresh(boost::none),
|
|
||||||
m_decrypt_keys_lockers(0),
|
|
||||||
m_unattended(unattended),
|
m_unattended(unattended),
|
||||||
m_devices_registered(false),
|
m_devices_registered(false),
|
||||||
m_device_last_key_image_sync(0),
|
m_device_last_key_image_sync(0),
|
||||||
|
@ -1882,8 +1880,7 @@ void wallet2::scan_output(const cryptonote::transaction &tx, bool miner_tx, cons
|
||||||
boost::optional<epee::wipeable_string> pwd = m_callback->on_get_password(pool ? "output found in pool" : "output received");
|
boost::optional<epee::wipeable_string> pwd = m_callback->on_get_password(pool ? "output found in pool" : "output received");
|
||||||
THROW_WALLET_EXCEPTION_IF(!pwd, error::password_needed, tr("Password is needed to compute key image for incoming monero"));
|
THROW_WALLET_EXCEPTION_IF(!pwd, error::password_needed, tr("Password is needed to compute key image for incoming monero"));
|
||||||
THROW_WALLET_EXCEPTION_IF(!verify_password(*pwd), error::password_needed, tr("Invalid password: password is needed to compute key image for incoming monero"));
|
THROW_WALLET_EXCEPTION_IF(!verify_password(*pwd), error::password_needed, tr("Invalid password: password is needed to compute key image for incoming monero"));
|
||||||
decrypt_keys(*pwd);
|
m_encrypt_keys_after_refresh.reset(new wallet_keys_unlocker(*this, m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only, *pwd));
|
||||||
m_encrypt_keys_after_refresh = *pwd;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3015,11 +3012,7 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction,
|
||||||
MTRACE("update_pool_state start");
|
MTRACE("update_pool_state start");
|
||||||
|
|
||||||
auto keys_reencryptor = epee::misc_utils::create_scope_leave_handler([&, this]() {
|
auto keys_reencryptor = epee::misc_utils::create_scope_leave_handler([&, this]() {
|
||||||
if (m_encrypt_keys_after_refresh)
|
m_encrypt_keys_after_refresh.reset();
|
||||||
{
|
|
||||||
encrypt_keys(*m_encrypt_keys_after_refresh);
|
|
||||||
m_encrypt_keys_after_refresh = boost::none;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// get the pool state
|
// get the pool state
|
||||||
|
@ -3450,11 +3443,7 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
||||||
start_height = 0;
|
start_height = 0;
|
||||||
|
|
||||||
auto keys_reencryptor = epee::misc_utils::create_scope_leave_handler([&, this]() {
|
auto keys_reencryptor = epee::misc_utils::create_scope_leave_handler([&, this]() {
|
||||||
if (m_encrypt_keys_after_refresh)
|
m_encrypt_keys_after_refresh.reset();
|
||||||
{
|
|
||||||
encrypt_keys(*m_encrypt_keys_after_refresh);
|
|
||||||
m_encrypt_keys_after_refresh = boost::none;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
auto scope_exit_handler_hwdev = epee::misc_utils::create_scope_leave_handler([&](){hwdev.computing_key_images(false);});
|
auto scope_exit_handler_hwdev = epee::misc_utils::create_scope_leave_handler([&](){hwdev.computing_key_images(false);});
|
||||||
|
@ -4594,18 +4583,12 @@ bool wallet2::verify_password(const std::string& keys_file_name, const epee::wip
|
||||||
|
|
||||||
void wallet2::encrypt_keys(const crypto::chacha_key &key)
|
void wallet2::encrypt_keys(const crypto::chacha_key &key)
|
||||||
{
|
{
|
||||||
boost::lock_guard<boost::mutex> lock(m_decrypt_keys_lock);
|
|
||||||
if (--m_decrypt_keys_lockers) // another lock left ?
|
|
||||||
return;
|
|
||||||
m_account.encrypt_keys(key);
|
m_account.encrypt_keys(key);
|
||||||
m_account.decrypt_viewkey(key);
|
m_account.decrypt_viewkey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet2::decrypt_keys(const crypto::chacha_key &key)
|
void wallet2::decrypt_keys(const crypto::chacha_key &key)
|
||||||
{
|
{
|
||||||
boost::lock_guard<boost::mutex> lock(m_decrypt_keys_lock);
|
|
||||||
if (m_decrypt_keys_lockers++) // already unlocked ?
|
|
||||||
return;
|
|
||||||
m_account.encrypt_viewkey(key);
|
m_account.encrypt_viewkey(key);
|
||||||
m_account.decrypt_keys(key);
|
m_account.decrypt_keys(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1798,9 +1798,7 @@ private:
|
||||||
crypto::secret_key m_original_view_secret_key;
|
crypto::secret_key m_original_view_secret_key;
|
||||||
|
|
||||||
crypto::chacha_key m_cache_key;
|
crypto::chacha_key m_cache_key;
|
||||||
boost::optional<epee::wipeable_string> m_encrypt_keys_after_refresh;
|
std::shared_ptr<wallet_keys_unlocker> m_encrypt_keys_after_refresh;
|
||||||
boost::mutex m_decrypt_keys_lock;
|
|
||||||
unsigned int m_decrypt_keys_lockers;
|
|
||||||
|
|
||||||
bool m_unattended;
|
bool m_unattended;
|
||||||
bool m_devices_registered;
|
bool m_devices_registered;
|
||||||
|
|
Loading…
Reference in New Issue