Full checking of all loaded keys
authorPieter Wuille <pieter.wuille@gmail.com>
Thu, 26 Jan 2012 18:26:34 +0000 (19:26 +0100)
committerLuke Dashjr <luke-jr+git@utopios.org>
Fri, 3 Feb 2012 01:03:26 +0000 (20:03 -0500)
src/db.cpp
src/key.h

index bd31bd7..600afe3 100644 (file)
@@ -879,7 +879,7 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
                     CPrivKey pkey;
                     ssValue >> pkey;
                     key.SetPrivKey(pkey);
-                    if (key.GetPubKey() != vchPubKey)
+                    if (key.GetPubKey() != vchPubKey || !key.IsValid())
                         return DB_CORRUPT;
                 }
                 else
@@ -887,6 +887,8 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
                     CWalletKey wkey;
                     ssValue >> wkey;
                     key.SetPrivKey(wkey.vchPrivKey);
+                    if (key.GetPubKey() != vchPubKey || !key.IsValid())
+                        return DB_CORRUPT;
                 }
                 if (!pwallet->LoadKey(key))
                     return DB_CORRUPT;
index d2e6689..0d0b6d8 100644 (file)
--- a/src/key.h
+++ b/src/key.h
@@ -233,6 +233,17 @@ public:
     {
         return CBitcoinAddress(GetPubKey());
     }
+
+    bool IsValid()
+    {
+        if (!fSet)
+            return false;
+
+        CSecret secret = GetSecret();
+        CKey key2;
+        key2.SetSecret(secret);
+        return GetPubKey() == key2.GetPubKey();
+    }
 };
 
 #endif