1
0
Fork 0
forked from lthn/blockchain

do not allow watch-only wallets be opened by GUI + refactoring

This commit is contained in:
sowle 2019-12-26 18:08:57 +03:00
parent 0f04017d2e
commit 29a276f180
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
8 changed files with 40 additions and 6 deletions

View file

@ -28,16 +28,21 @@ namespace currency
//-----------------------------------------------------------------
account_base::account_base()
:m_keys{}
,m_creation_timestamp{}
,m_seed{}
{
set_null();
}
//-----------------------------------------------------------------
void account_base::set_null()
{
// fill sensitive data with random bytes
crypto::generate_random_bytes(sizeof m_keys.m_spend_secret_key, &m_keys.m_spend_secret_key);
crypto::generate_random_bytes(sizeof m_keys.m_view_secret_key, &m_keys.m_view_secret_key);
crypto::generate_random_bytes(m_seed.size(), &m_seed[0]);
// clear
m_keys = account_keys();
m_creation_timestamp = 0;
m_seed.clear();
}
//-----------------------------------------------------------------
void account_base::generate()
@ -65,6 +70,8 @@ namespace currency
std::string account_base::get_restore_braindata() const
{
std::string restore_buff = get_restore_data();
if (restore_buff.empty())
return "";
std::vector<unsigned char> v;
v.assign((unsigned char*)restore_buff.data(), (unsigned char*)restore_buff.data() + restore_buff.size());
std::string seed_brain_data = tools::mnemonic_encoding::binary2text(v);
@ -124,7 +131,23 @@ namespace currency
//-----------------------------------------------------------------
void account_base::make_account_watch_only()
{
m_keys.m_spend_secret_key = currency::null_skey;
// keep only:
// timestamp
// view pub & spend pub (public address)
// view sec
// store to local tmp
uint64_t local_ts = m_creation_timestamp;
account_public_address local_addr = m_keys.m_account_address;
crypto::secret_key local_view_sec = m_keys.m_view_secret_key;
// clear
set_null();
// restore
m_creation_timestamp = local_ts;
m_keys.m_account_address = local_addr;
m_keys.m_view_secret_key = local_view_sec;
}
//-----------------------------------------------------------------
std::string transform_addr_to_str(const account_public_address& addr)

View file

@ -676,7 +676,9 @@ std::string daemon_backend::open_wallet(const std::wstring& path, const std::str
{
try
{
w->load(path, password);
w->load(path, password);
if (w->is_watch_only())
return API_RETURN_CODE_WALLET_WATCH_ONLY_NOT_SUPPORTED;
w->get_recent_transfers_history(owr.recent_history.history, 0, txs_to_return, owr.recent_history.total_history_items);
//w->get_unconfirmed_transfers(owr.recent_history.unconfirmed);
w->get_unconfirmed_transfers(owr.recent_history.history);

View file

@ -736,6 +736,7 @@ public:
#define API_RETURN_CODE_BAD_ARG_WRONG_PAYMENT_ID "BAD_ARG_WRONG_PAYMENT_ID"
#define API_RETURN_CODE_WRONG_PASSWORD "WRONG_PASSWORD"
#define API_RETURN_CODE_WALLET_WRONG_ID "WALLET_WRONG_ID"
#define API_RETURN_CODE_WALLET_WATCH_ONLY_NOT_SUPPORTED "WALLET_WATCH_ONLY_NOT_SUPPORTED"
#define API_RETURN_CODE_FILE_NOT_FOUND "FILE_NOT_FOUND"
#define API_RETURN_CODE_ALREADY_EXISTS "ALREADY_EXISTS"
#define API_RETURN_CODE_CANCELED "CANCELED"

View file

@ -581,6 +581,7 @@
"TRANSACTION_ERROR": "Error. Transaction not completed.",
"BAD_ARG": "Invalid argument",
"WALLET_WRONG_ID": "Invalid wallet ID",
"WALLET_WATCH_ONLY_NOT_SUPPORTED": "Watch-only wallets can only be opened by simplewallet",
"WRONG_PASSWORD": "Invalid password",
"FILE_RESTORED": "The wallet file was corrupted. We have recovered the keys and the wallet from the blockchain",
"FILE_NOT_FOUND": "File not found",

View file

@ -1843,6 +1843,9 @@ var BackendService = /** @class */ (function () {
case 'WALLET_WRONG_ID':
error_translate = 'ERRORS.WALLET_WRONG_ID';
break;
case 'WALLET_WATCH_ONLY_NOT_SUPPORTED':
error_translate = 'ERRORS.WALLET_WATCH_ONLY_NOT_SUPPORTED';
break;
case 'WRONG_PASSWORD':
case 'WRONG_PASSWORD:invalid password':
params = JSON.parse(params);

View file

@ -109,6 +109,9 @@ export class BackendService {
case 'WALLET_WRONG_ID':
error_translate = 'ERRORS.WALLET_WRONG_ID';
break;
case 'WALLET_WATCH_ONLY_NOT_SUPPORTED':
error_translate = 'ERRORS.WALLET_WATCH_ONLY_NOT_SUPPORTED';
break;
case 'WRONG_PASSWORD':
case 'WRONG_PASSWORD:invalid password':
params = JSON.parse(params);

View file

@ -581,6 +581,7 @@
"TRANSACTION_ERROR": "Error. Transaction not completed.",
"BAD_ARG": "Invalid argument",
"WALLET_WRONG_ID": "Invalid wallet ID",
"WALLET_WATCH_ONLY_NOT_SUPPORTED": "Watch-only wallets can only be opened by simplewallet",
"WRONG_PASSWORD": "Invalid password",
"FILE_RESTORED": "The wallet file was corrupted. We have recovered the keys and the wallet from the blockchain",
"FILE_NOT_FOUND": "File not found",

View file

@ -2097,7 +2097,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor
//prepare data
std::string keys_buff;
bool r = store_keys(keys_buff, password);
bool r = store_keys(keys_buff, password, m_watch_only);
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(r, "failed to store_keys for wallet " << ascii_path_to_save);
//store data