aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorJohn Moffett <john.moff@gmail.com>2023-02-10 16:13:40 -0500
committerJohn Moffett <john.moff@gmail.com>2023-02-10 20:21:23 -0500
commit3a11adc7004d21b3dfe028b190d83add31691c55 (patch)
treef4dffef9a23ab47a9d3c9f38b405b2af7b0383cf /src/wallet
parentb92d609fb25637ccda000e182da854d4b762eee9 (diff)
Zero out wallet master key upon lock
When an encrypted wallet is locked (for instance via the RPC `walletlock`), the docs indicate that the key is removed from memory. However, the vector (with a secure allocator) is merely cleared. This allows the key to persist indefinitely in memory. Instead, manually fill the bytes with zeroes before clearing.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 5a92dbe428..b709bd9650 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -26,6 +26,7 @@
#include <script/descriptor.h>
#include <script/script.h>
#include <script/signingprovider.h>
+#include <support/cleanse.h>
#include <txmempool.h>
#include <util/bip32.h>
#include <util/check.h>
@@ -3407,7 +3408,10 @@ bool CWallet::Lock()
{
LOCK(cs_wallet);
- vMasterKey.clear();
+ if (!vMasterKey.empty()) {
+ memory_cleanse(vMasterKey.data(), vMasterKey.size() * sizeof(decltype(vMasterKey)::value_type));
+ vMasterKey.clear();
+ }
}
NotifyStatusChanged(this);