Skip to content

Commit 12e7c41

Browse files
authored
Merge pull request #5 from j-berman/restore-msig-encrypted-seed
multisig: fix segfault restoring encrypted multisig seed
2 parents 401f5d9 + 848a0c0 commit 12e7c41

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4118,6 +4118,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
41184118

41194119
epee::wipeable_string multisig_keys;
41204120
epee::wipeable_string password;
4121+
epee::wipeable_string seed_pass;
41214122

41224123
if (!handle_command_line(vm))
41234124
return false;
@@ -4224,19 +4225,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
42244225
auto pwd_container = password_prompter(tr("Enter seed offset passphrase, empty if none"), false);
42254226
if (std::cin.eof() || !pwd_container)
42264227
return false;
4227-
epee::wipeable_string seed_pass = pwd_container->password();
4228-
if (!seed_pass.empty())
4229-
{
4230-
if (m_restore_multisig_wallet)
4231-
{
4232-
crypto::secret_key key;
4233-
crypto::cn_slow_hash(seed_pass.data(), seed_pass.size(), (crypto::hash&)key);
4234-
sc_reduce32((unsigned char*)key.data);
4235-
multisig_keys = m_wallet->decrypt<epee::wipeable_string>(std::string(multisig_keys.data(), multisig_keys.size()), key, true);
4236-
}
4237-
else
4238-
m_recovery_key = cryptonote::decrypt_key(m_recovery_key, seed_pass);
4239-
}
4228+
seed_pass = pwd_container->password();
4229+
if (!seed_pass.empty() && !m_restore_multisig_wallet)
4230+
m_recovery_key = cryptonote::decrypt_key(m_recovery_key, seed_pass);
42404231
}
42414232
if (!m_generate_from_view_key.empty())
42424233
{
@@ -4579,7 +4570,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
45794570
m_wallet_file = m_generate_new;
45804571
boost::optional<epee::wipeable_string> r;
45814572
if (m_restore_multisig_wallet)
4582-
r = new_wallet(vm, multisig_keys, old_language);
4573+
r = new_wallet(vm, multisig_keys, seed_pass, old_language);
45834574
else
45844575
r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
45854576
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
@@ -5070,7 +5061,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
50705061
}
50715062
//----------------------------------------------------------------------------------------------------
50725063
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
5073-
const epee::wipeable_string &multisig_keys, const std::string &old_language)
5064+
const epee::wipeable_string &multisig_keys, const epee::wipeable_string &seed_pass, const std::string &old_language)
50745065
{
50755066
std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> rc;
50765067
try { rc = tools::wallet2::make_new(vm, false, password_prompter); }
@@ -5104,7 +5095,16 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
51045095

51055096
try
51065097
{
5107-
m_wallet->generate(m_wallet_file, std::move(rc.second).password(), multisig_keys, create_address_file);
5098+
if (seed_pass.empty())
5099+
m_wallet->generate(m_wallet_file, std::move(rc.second).password(), multisig_keys, create_address_file);
5100+
else
5101+
{
5102+
crypto::secret_key key;
5103+
crypto::cn_slow_hash(seed_pass.data(), seed_pass.size(), (crypto::hash&)key);
5104+
sc_reduce32((unsigned char*)key.data);
5105+
const epee::wipeable_string &msig_keys = m_wallet->decrypt<epee::wipeable_string>(std::string(multisig_keys.data(), multisig_keys.size()), key, true);
5106+
m_wallet->generate(m_wallet_file, std::move(rc.second).password(), msig_keys, create_address_file);
5107+
}
51085108
bool ready;
51095109
uint32_t threshold, total;
51105110
if (!m_wallet->multisig(&ready, &threshold, &total) || !ready)

src/simplewallet/simplewallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace cryptonote
101101
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm, const cryptonote::account_public_address& address,
102102
const boost::optional<crypto::secret_key>& spendkey, const crypto::secret_key& viewkey);
103103
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm,
104-
const epee::wipeable_string &multisig_keys, const std::string &old_language);
104+
const epee::wipeable_string &multisig_keys, const epee::wipeable_string &seed_pass, const std::string &old_language);
105105
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm);
106106
boost::optional<epee::wipeable_string> open_wallet(const boost::program_options::variables_map& vm);
107107
bool close_wallet();

0 commit comments

Comments
 (0)