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)
CBitcoinSecret vchSecret; CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret); bool fGood = vchSecret.SetString(strSecret);
if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
if( !fAllowNewUser ) { CKey key = vchSecret.GetKey();
CTransaction txOut; CPubKey pubkey = key.GetPubKey();
uint256 hashBlock; CKeyID vchAddress = pubkey.GetID();
if( !GetTransaction(strUsername, txOut, hashBlock) ) {
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)"); 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); LOCK2(cs_main, pwalletMain->cs_wallet);

Loading…
Cancel
Save