Skip to content

Commit

Permalink
Also attempting empty password which would be set on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Mar 10, 2016
1 parent 6e85583 commit 993bcd7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
20 changes: 20 additions & 0 deletions rai/core_test/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,24 @@ TEST (wallet, version_1_2_upgrade)
rai::raw_key prv;
ASSERT_FALSE (wallet->store.fetch (rai::transaction (wallet->store.environment, nullptr, false), key.pub, prv));
ASSERT_EQ (key.prv, prv);

{
rai::transaction transaction (wallet->store.environment, nullptr, true);
rai::raw_key password_l;
rai::wallet_value value (wallet->store.entry_get_raw (transaction, rai::wallet_store::wallet_key_special));
rai::raw_key kdf;
wallet->store.derive_key (kdf, transaction, "");
password_l.decrypt (value.key, kdf, wallet->store.salt (transaction).owords [0]);
rai::uint256_union ciphertext;
ciphertext.encrypt (key.prv, password_l, wallet->store.salt (transaction).owords [0]);
wallet->store.entry_put_raw (transaction, key.pub, rai::wallet_value (ciphertext));
wallet->store.version_put (transaction, 1);
}
wallet->enter_password ("1");
ASSERT_EQ (true, wallet->valid_password ());
ASSERT_EQ (2, wallet->store.version (rai::transaction (wallet->store.environment, nullptr, false)));
rai::raw_key prv2;
ASSERT_FALSE (wallet->store.fetch (rai::transaction (wallet->store.environment, nullptr, false), key.pub, prv2));
ASSERT_EQ (key.prv, prv2);

}
22 changes: 19 additions & 3 deletions rai/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,14 @@ void rai::wallet_store::upgrade_v1_v2 ()
{
rai::transaction transaction (environment, nullptr, true);
assert (version (transaction) == 1);
rai::raw_key password_l;
rai::raw_key zero_password;
rai::wallet_value value (entry_get_raw (transaction, rai::wallet_store::wallet_key_special));
rai::raw_key kdf;
kdf.data.clear ();
password_l.decrypt (value.key, kdf, salt (transaction).owords [0]);
zero_password.decrypt (value.key, kdf, salt (transaction).owords [0]);
derive_key (kdf, transaction, "");
rai::raw_key empty_password;
empty_password.decrypt (value.key, kdf, salt (transaction).owords [0]);
for (auto i (begin (transaction)), n (end ()); i != n; ++i)
{
rai::public_key key (i->first);
Expand All @@ -617,14 +620,27 @@ void rai::wallet_store::upgrade_v1_v2 ()
{
// Key failed to decrypt despite valid password
rai::wallet_value data (entry_get_raw (transaction, key));
prv.decrypt (data.key, password_l, salt (transaction).owords [0]);
prv.decrypt (data.key, zero_password, salt (transaction).owords [0]);
rai::public_key compare;
ed25519_publickey (prv.data.bytes.data (), compare.bytes.data ());
if (compare == key)
{
// If we successfully decrypted it, rewrite the key back with the correct wallet key
insert (transaction, prv);
}
else
{
// Also try the empty password
rai::wallet_value data (entry_get_raw (transaction, key));
prv.decrypt (data.key, empty_password, salt (transaction).owords [0]);
rai::public_key compare;
ed25519_publickey (prv.data.bytes.data (), compare.bytes.data ());
if (compare == key)
{
// If we successfully decrypted it, rewrite the key back with the correct wallet key
insert (transaction, prv);
}
}
}
}
version_put (transaction, 2);
Expand Down

0 comments on commit 993bcd7

Please sign in to comment.