|
|
|
@ -155,14 +155,11 @@ bool CCryptoKeyStore::SetCrypted()
@@ -155,14 +155,11 @@ bool CCryptoKeyStore::SetCrypted()
|
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::IsLocked() const |
|
|
|
|
{ |
|
|
|
|
if (!IsCrypted()) |
|
|
|
|
if (!IsCrypted()) { |
|
|
|
|
return false; |
|
|
|
|
bool result; |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
result = vMasterKey.empty(); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
return vMasterKey.empty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::Lock() |
|
|
|
@ -219,20 +216,22 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
@@ -219,20 +216,22 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
|
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
if (!IsCrypted()) |
|
|
|
|
if (!IsCrypted()) { |
|
|
|
|
return CBasicKeyStore::AddKeyPubKey(key, pubkey); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (IsLocked()) |
|
|
|
|
if (IsLocked()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector<unsigned char> vchCryptedSecret; |
|
|
|
|
CKeyingMaterial vchSecret(key.begin(), key.end()); |
|
|
|
|
if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) |
|
|
|
|
if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!AddCryptedKey(pubkey, vchCryptedSecret)) |
|
|
|
|
if (!AddCryptedKey(pubkey, vchCryptedSecret)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
@ -241,34 +240,30 @@ bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
@@ -241,34 +240,30 @@ bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
if (!SetCrypted()) |
|
|
|
|
if (!SetCrypted()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::HaveKey(const CKeyID &address) const |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
if (!IsCrypted()) { |
|
|
|
|
return CBasicKeyStore::HaveKey(address); |
|
|
|
|
} |
|
|
|
|
return mapCryptedKeys.count(address) > 0; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
if (!IsCrypted()) |
|
|
|
|
if (!IsCrypted()) { |
|
|
|
|
return CBasicKeyStore::GetKey(address, keyOut); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address); |
|
|
|
|
if (mi != mapCryptedKeys.end()) |
|
|
|
@ -277,13 +272,11 @@ bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
@@ -277,13 +272,11 @@ bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
|
|
|
|
|
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second; |
|
|
|
|
return DecryptKey(vMasterKey, vchCryptedSecret, vchPubKey, keyOut); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
if (!IsCrypted()) |
|
|
|
|
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut); |
|
|
|
@ -296,7 +289,6 @@ bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) co
@@ -296,7 +289,6 @@ bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) co
|
|
|
|
|
} |
|
|
|
|
// Check for watch-only pubkeys
|
|
|
|
|
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::set<CKeyID> CCryptoKeyStore::GetKeys() const |
|
|
|
@ -314,7 +306,6 @@ std::set<CKeyID> CCryptoKeyStore::GetKeys() const
@@ -314,7 +306,6 @@ std::set<CKeyID> CCryptoKeyStore::GetKeys() const
|
|
|
|
|
|
|
|
|
|
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_KeyStore); |
|
|
|
|
if (!mapCryptedKeys.empty() || IsCrypted()) |
|
|
|
|
return false; |
|
|
|
@ -332,6 +323,5 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
@@ -332,6 +323,5 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
mapKeys.clear(); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|