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.
This commit is contained in:
1 parent
b92d609fb2
commit
3a11adc700
1 file changed
+5
-1
@@ -26,6 +26,7 @@
|
|||||||
#include <script/descriptor.h>
|
#include <script/descriptor.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
|
#include <support/cleanse.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <util/bip32.h>
|
#include <util/bip32.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
@@ -3407,7 +3408,10 @@ bool CWallet::Lock()
|
|||||||
|
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
vMasterKey.clear();
|
if (!vMasterKey.empty()) {
|
||||||
|
memory_cleanse(vMasterKey.data(), vMasterKey.size() * sizeof(decltype(vMasterKey)::value_type));
|
||||||
|
vMasterKey.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyStatusChanged(this);
|
NotifyStatusChanged(this);
|
||||||
|
|||||||
Reference in new issue
Block a user