Full checking of all loaded keys
authorPieter Wuille <pieter.wuille@gmail.com>
Thu, 26 Jan 2012 18:26:34 +0000 (19:26 +0100)
committerPieter Wuille <pieter.wuille@gmail.com>
Thu, 26 Jan 2012 18:26:43 +0000 (19:26 +0100)
src/db.cpp
src/key.h

index 9ad05ba..07f58ef 100644 (file)
@@ -862,7 +862,7 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
                     ssValue >> pkey;
                     key.SetPubKey(vchPubKey);
                     key.SetPrivKey(pkey);
-                    if (key.GetPubKey() != vchPubKey)
+                    if (key.GetPubKey() != vchPubKey || !key.IsValid())
                         return DB_CORRUPT;
                 }
                 else
@@ -871,6 +871,8 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
                     ssValue >> wkey;
                     key.SetPubKey(vchPubKey);
                     key.SetPrivKey(wkey.vchPrivKey);
+                    if (key.GetPubKey() != vchPubKey || !key.IsValid())
+                        return DB_CORRUPT;
                 }
                 if (!pwallet->LoadKey(key))
                     return DB_CORRUPT;
index c28222a..f7bdc87 100644 (file)
--- a/src/key.h
+++ b/src/key.h
@@ -307,6 +307,18 @@ public:
             return false;
         return true;
     }
+
+    bool IsValid()
+    {
+        if (!fSet)
+            return false;
+
+        bool fCompr;
+        CSecret secret = GetSecret(fCompr);
+        CKey key2;
+        key2.SetSecret(secret, fCompr);
+        return GetPubKey() == key2.GetPubKey();
+    }
 };
 
 #endif