Skip to content

Commit 97c0374

Browse files
committed
Move Unlock implementation to LegacyScriptPubKeyMan
CWallet::Unlock is changed to call ScriptPubKeyMan::CheckDecryptionKey and the original implementation of Unlock is renamed to CheckDecryptionKey.
1 parent e576b13 commit 97c0374

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ isminetype LegacyScriptPubKeyMan::IsMine(const CScript& script) const
202202
assert(false);
203203
}
204204

205-
bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys)
205+
bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys)
206206
{
207207
{
208208
LOCK(cs_KeyStore);
@@ -217,7 +217,7 @@ bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys)
217217
const CPubKey &vchPubKey = (*mi).second.first;
218218
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
219219
CKey key;
220-
if (!DecryptKey(vMasterKeyIn, vchCryptedSecret, vchPubKey, key))
220+
if (!DecryptKey(master_key, vchCryptedSecret, vchPubKey, key))
221221
{
222222
keyFail = true;
223223
break;
@@ -233,10 +233,8 @@ bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys)
233233
}
234234
if (keyFail || (!keyPass && !accept_no_keys))
235235
return false;
236-
vMasterKey = vMasterKeyIn;
237236
fDecryptionThoroughlyChecked = true;
238237
}
239-
NotifyStatusChanged(this);
240238
return true;
241239
}
242240

src/wallet/scriptpubkeyman.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ class ScriptPubKeyMan
152152
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
153153
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
154154

155+
//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
156+
virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) { return false; }
157+
155158
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; }
156159
virtual void KeepDestination(int64_t index, const OutputType& type) {}
157160
virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) {}
@@ -276,6 +279,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
276279

277280
//! will encrypt previously unencrypted keys
278281
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
282+
bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
279283

280284
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override;
281285
void KeepDestination(int64_t index, const OutputType& type) override;

src/wallet/wallet.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,21 @@ bool CWallet::Lock()
40374037
return true;
40384038
}
40394039

4040+
bool CWallet::Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys)
4041+
{
4042+
{
4043+
LOCK(cs_KeyStore);
4044+
if (m_spk_man) {
4045+
if (!m_spk_man->CheckDecryptionKey(vMasterKeyIn, accept_no_keys)) {
4046+
return false;
4047+
}
4048+
}
4049+
vMasterKey = vMasterKeyIn;
4050+
}
4051+
NotifyStatusChanged(this);
4052+
return true;
4053+
}
4054+
40404055
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const CScript& script) const
40414056
{
40424057
return m_spk_man.get();

0 commit comments

Comments
 (0)