mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-02-10 22:04:22 +00:00
check for key mismatch when importing keys
This commit is contained in:
parent
9aec1f6c73
commit
74470ebddb
@ -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 ) {
|
|
||||||
CTransaction txOut;
|
|
||||||
uint256 hashBlock;
|
|
||||||
if( !GetTransaction(strUsername, txOut, hashBlock) ) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "User must exist (or allow_new_user flag must be set)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CKey key = vchSecret.GetKey();
|
CKey key = vchSecret.GetKey();
|
||||||
CPubKey pubkey = key.GetPubKey();
|
CPubKey pubkey = key.GetPubKey();
|
||||||
CKeyID vchAddress = pubkey.GetID();
|
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?)");
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user