From 103c9733b374fed562aff6c62743ac72e26e282b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 19 Oct 2021 19:34:33 +0000 Subject: 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). --- src/wallet/wallet2.cpp | 23 +++-------------------- src/wallet/wallet2.h | 4 +--- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0218d47a1..913b25d83 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1229,8 +1229,6 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std m_ring_history_saved(false), m_ringdb(), m_last_block_reward(0), - m_encrypt_keys_after_refresh(boost::none), - m_decrypt_keys_lockers(0), m_unattended(unattended), m_devices_registered(false), m_device_last_key_image_sync(0), @@ -1838,8 +1836,7 @@ void wallet2::scan_output(const cryptonote::transaction &tx, bool miner_tx, cons boost::optional 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(!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 = *pwd; + m_encrypt_keys_after_refresh.reset(new wallet_keys_unlocker(*this, m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only, *pwd)); } } @@ -2971,11 +2968,7 @@ void wallet2::update_pool_state(std::vector lock(m_decrypt_keys_lock); - if (--m_decrypt_keys_lockers) // another lock left ? - return; m_account.encrypt_keys(key); m_account.decrypt_viewkey(key); } void wallet2::decrypt_keys(const crypto::chacha_key &key) { - boost::lock_guard lock(m_decrypt_keys_lock); - if (m_decrypt_keys_lockers++) // already unlocked ? - return; m_account.encrypt_viewkey(key); m_account.decrypt_keys(key); } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f75e0b813..d72a90101 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1791,9 +1791,7 @@ private: crypto::secret_key m_original_view_secret_key; crypto::chacha_key m_cache_key; - boost::optional m_encrypt_keys_after_refresh; - boost::mutex m_decrypt_keys_lock; - unsigned int m_decrypt_keys_lockers; + std::shared_ptr m_encrypt_keys_after_refresh; bool m_unattended; bool m_devices_registered; -- cgit v1.2.3