forked from lthn/blockchain
unit tests expended to cover secure seed cases
This commit is contained in:
parent
03cb013695
commit
5889b84acd
3 changed files with 48 additions and 6 deletions
|
|
@ -1358,13 +1358,21 @@ bool simple_wallet::show_seed(const std::vector<std::string> &args)
|
|||
success_msg_writer() << "Please enter a password to secure this seed. Securing your seed is HIGHLY recommended. Leave password blank to stay unsecured.";
|
||||
success_msg_writer(true) << "Remember, restoring a wallet from Secured Seed can only be done if you know its password.";
|
||||
|
||||
std::string pass_1 = get_password("Enter seed password: ");
|
||||
std::string pass_2 = get_password("Confirm seed password: ");
|
||||
if(pass_1 != pass_2)
|
||||
tools::password_container seed_password_container1;
|
||||
if (!seed_password_container1.read_password("Enter seed password: "))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
tools::password_container seed_password_container2;
|
||||
if (!seed_password_container2.read_password("Confirm seed password: "))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(seed_password_container1.password() != seed_password_container2.password())
|
||||
{
|
||||
std::cout << "Error: password mismatch. Please make sure you entered the correct password and confirmed it" << std::endl << std::flush;
|
||||
}
|
||||
std::cout << m_wallet->get_account().get_seed_phrase(pass_1) << std::endl << std::flush;
|
||||
std::cout << m_wallet->get_account().get_seed_phrase(seed_password_container2.password()) << std::endl << std::flush;
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ public:
|
|||
struct request_get_smart_wallet_info
|
||||
{
|
||||
uint64_t wallet_id;
|
||||
uint64_t seed_password;
|
||||
std::string seed_password;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(wallet_id)
|
||||
|
|
@ -445,7 +445,7 @@ public:
|
|||
|
||||
struct is_valid_restore_wallet_text_param
|
||||
{
|
||||
uint64_t seed_phrase;
|
||||
std::string seed_phrase;
|
||||
std::string seed_password;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
|
|||
|
|
@ -149,6 +149,40 @@ TEST(wallet_seed, basic_test)
|
|||
try
|
||||
{
|
||||
r = acc.restore_from_seed_phrase(wse.seed_phrase, "");
|
||||
if (r)
|
||||
{
|
||||
for (size_t j = 0; j != 100; j++)
|
||||
{
|
||||
//generate random password
|
||||
std::string pass = epee::string_tools::pod_to_hex(crypto::cn_fast_hash(&j, sizeof(j)));
|
||||
if (j!= 0 && j < 64)
|
||||
{
|
||||
pass.resize(j);
|
||||
}
|
||||
//get secured seed
|
||||
std::string secured_seed = acc.get_seed_phrase(pass);
|
||||
|
||||
//try to restore it without password(should fail)
|
||||
currency::account_base acc2;
|
||||
bool r_fail = acc2.restore_from_seed_phrase(secured_seed, "");
|
||||
ASSERT_EQ(r_fail, false);
|
||||
|
||||
//try to restore it with wrong password
|
||||
bool r_fake_pass = acc2.restore_from_seed_phrase(secured_seed, "fake_password");
|
||||
if (r_fake_pass)
|
||||
{
|
||||
//accidentally checksumm matched(quite possible)
|
||||
ASSERT_EQ(false, acc2.get_keys() == acc.get_keys());
|
||||
}
|
||||
|
||||
//try to restore it from right password
|
||||
currency::account_base acc3;
|
||||
bool r_true_res = acc3.restore_from_seed_phrase(secured_seed, pass);
|
||||
ASSERT_EQ(true, r_true_res);
|
||||
ASSERT_EQ(true, acc3.get_keys() == acc.get_keys());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue