aboutsummaryrefslogtreecommitdiff
path: root/src/crypter.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2013-11-30 06:09:32 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2013-12-04 12:46:13 +0100
commit829c9203874277265613185c73f96760ae4b9356 (patch)
tree5df689e450592e2e0636662c4d613fda9e6b063e /src/crypter.h
parentae6ea5a6fa4a674fc1c989df6f4ec945df1aa534 (diff)
downloadbitcoin-829c9203874277265613185c73f96760ae4b9356.tar.xz
Move CCryptoKeyStore to crypter.cpp
This breaks the dependency on crypter for disable-wallet builds.
Diffstat (limited to 'src/crypter.h')
-rw-r--r--src/crypter.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/crypter.h b/src/crypter.h
index 861c4f9441..4791428b48 100644
--- a/src/crypter.h
+++ b/src/crypter.h
@@ -7,6 +7,7 @@
#include "allocators.h"
#include "serialize.h"
+#include "keystore.h"
class uint256;
@@ -106,4 +107,86 @@ public:
bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext);
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext);
+/** Keystore which keeps the private keys encrypted.
+ * It derives from the basic key store, which is used if no encryption is active.
+ */
+class CCryptoKeyStore : public CBasicKeyStore
+{
+private:
+ CryptedKeyMap mapCryptedKeys;
+
+ CKeyingMaterial vMasterKey;
+
+ // if fUseCrypto is true, mapKeys must be empty
+ // if fUseCrypto is false, vMasterKey must be empty
+ bool fUseCrypto;
+
+protected:
+ bool SetCrypted();
+
+ // will encrypt previously unencrypted keys
+ bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
+
+ bool Unlock(const CKeyingMaterial& vMasterKeyIn);
+
+public:
+ CCryptoKeyStore() : fUseCrypto(false)
+ {
+ }
+
+ bool IsCrypted() const
+ {
+ return fUseCrypto;
+ }
+
+ bool IsLocked() const
+ {
+ if (!IsCrypted())
+ return false;
+ bool result;
+ {
+ LOCK(cs_KeyStore);
+ result = vMasterKey.empty();
+ }
+ return result;
+ }
+
+ bool Lock();
+
+ virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
+ bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
+ bool HaveKey(const CKeyID &address) const
+ {
+ {
+ LOCK(cs_KeyStore);
+ if (!IsCrypted())
+ return CBasicKeyStore::HaveKey(address);
+ return mapCryptedKeys.count(address) > 0;
+ }
+ return false;
+ }
+ bool GetKey(const CKeyID &address, CKey& keyOut) const;
+ bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
+ void GetKeys(std::set<CKeyID> &setAddress) const
+ {
+ if (!IsCrypted())
+ {
+ CBasicKeyStore::GetKeys(setAddress);
+ return;
+ }
+ setAddress.clear();
+ CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
+ while (mi != mapCryptedKeys.end())
+ {
+ setAddress.insert((*mi).first);
+ mi++;
+ }
+ }
+
+ /* Wallet status (encrypted, locked) changed.
+ * Note: Called without locks held.
+ */
+ boost::signals2::signal<void (CCryptoKeyStore* wallet)> NotifyStatusChanged;
+};
+
#endif