nochowderforyou / clams

Clam Project
MIT License
62 stars 58 forks source link

clamd won't let me import two encrypted bitcoin wallets #216

Open dooglus opened 8 years ago

dooglus commented 8 years ago

I have 2 test wallets, both encrypted, with different passwords. Whichever one I import first works, but the other one doesn't:

$ clamd importwallet ~/.bitcoin/wallet.dat.tmp.password.fred 'fred' false
$ clamd importwallet ~/.bitcoin/wallet.dat.tmp.password.fred.fred 'fred fred' false
error: {"code":-14,"message":"Error: The wallet passphrase entered was incorrect for the wallet you are attempting to import."}
$ clamd stop
Clam server stopping
$ clamd
Clam server starting
$ clamd importwallet ~/.bitcoin/wallet.dat.tmp.password.fred.fred 'fred fred' false
$ clamd importwallet ~/.bitcoin/wallet.dat.tmp.password.fred 'fred' false
error: {"code":-14,"message":"Error: The wallet passphrase entered was incorrect for the wallet you are attempting to import."}

I restarted the daemon and it changed its mind about which one had the "incorrect passphrase"...

dooglus commented 8 years ago

I've been attempting to find the cause of this bug, but didn't make much progress yet.

ReadKeyValueImport() In walletdb.cpp is running this line:

pwallet->mapMasterKeys[nID] = kMasterKey;

for each wallet I import, but the kMasterKey always has the same value for the nDeriveIterations member; the value is the nDeriveIterations for whichever wallet I import first.

dooglus commented 8 years ago

One of the two wallets I'm testing with was created by copying the other wallet and then changing its passphrase.

I just tried creating two new wallets from scratch and encrypting them separately, and am able to import them both into a single clamd session.

Could the problem be that the first pair of wallets have the same salt?

kMasterKey nDeriveIterations 190170 crypted 6c6059465da8360bb951517dc33e397ac70eafcc1b554ad40ed53da2f203e9d211b3e4590d460dc7c74b3754069a301e salt e64cdd95073b1f70
kMasterKey nDeriveIterations 218307 crypted b5dbeb28c9e4dd8700a82c2457fe31c8f8acc300f763191c7d278e6cd6c268d09d0a9d8b14aa2aa510bfb6ccb9723be7 salt e64cdd95073b1f70