Browse Source

check for key mismatch when importing keys

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
74470ebddb
  1. 18
      src/rpcdump.cpp

18
src/rpcdump.cpp

@ -87,20 +87,22 @@ Value importprivkey(const Array& params, bool fHelp) @@ -87,20 +87,22 @@ Value importprivkey(const Array& params, bool fHelp)
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);
if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
if( !fAllowNewUser ) {
CTransaction txOut;
uint256 hashBlock;
if( !GetTransaction(strUsername, txOut, hashBlock) ) {
CKey key = vchSecret.GetKey();
CPubKey pubkey = key.GetPubKey();
CKeyID vchAddress = pubkey.GetID();
CPubKey pubkeyInDb;
bool userExists = getUserPubKey(strUsername, pubkeyInDb);
if( !userExists && !fAllowNewUser ) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "User must exist (or allow_new_user flag must be set)");
}
if( userExists && pubkey != pubkeyInDb ) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key mismatch to existing public key (wrong username?)");
}
CKey key = vchSecret.GetKey();
CPubKey pubkey = key.GetPubKey();
CKeyID vchAddress = pubkey.GetID();
{
LOCK2(cs_main, pwalletMain->cs_wallet);

Loading…
Cancel
Save