diff --git a/rai/core_test/wallet.cpp b/rai/core_test/wallet.cpp index 56f3375d27..d0438a3744 100644 --- a/rai/core_test/wallet.cpp +++ b/rai/core_test/wallet.cpp @@ -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); + } \ No newline at end of file diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index 751a6a948f..3159b3fc3c 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -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); @@ -617,7 +620,7 @@ 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) @@ -625,6 +628,19 @@ void rai::wallet_store::upgrade_v1_v2 () // 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);