Skip to content

Commit

Permalink
ensure wallet file access, fix #4507
Browse files Browse the repository at this point in the history
  • Loading branch information
ysangkok committed Jul 10, 2018
1 parent 04432fe commit a3aec8e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gui/kivy/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ def load_wallet_by_name(self, path, ask_if_wizard=False):
return
wallet = self.daemon.load_wallet(path, None)
if wallet:
if not wallet.storage.file_writable():
self.show_error(_("Wallet file not writable"))
return
if wallet.has_password():
self.password_dialog(wallet, _('Enter PIN code'), lambda x: self.load_wallet(wallet), self.stop)
else:
Expand Down
6 changes: 5 additions & 1 deletion gui/kivy/uix/dialogs/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ def cb(text):
d.open()

def open_wallet(self, app):
app.load_wallet_by_name(self.ids.wallet_selector.selection[0])
path = self.ids.wallet_selector.selection[0]
if not os.access(path, os.W_OK) or not os.access(path, os.R_OK):
app.show_error(_("Wallet file not writable"))
return
app.load_wallet_by_name(path)

2 changes: 2 additions & 0 deletions gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def start_new_window(self, path, uri, app_is_starting=False):
opens the wallet and creates a new window for it'''
try:
wallet = self.daemon.load_wallet(path, None)
if wallet and not wallet.storage.file_writable():
raise Exception(_("Wallet file not writable"))
except BaseException as e:
traceback.print_exc(file=sys.stdout)
d = QMessageBox(QMessageBox.Warning, _('Error'),
Expand Down
3 changes: 3 additions & 0 deletions lib/base_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ def restore_from_seed(self):
self.restore_seed_dialog(run_next=self.on_restore_seed, test=test)

def on_restore_seed(self, seed, is_bip39, is_ext):
if not self.storage.file_writable():
self.show_error(_("Wallet file not writable"))
return
self.seed_type = 'bip39' if is_bip39 else bitcoin.seed_type(seed)
if self.seed_type == 'bip39':
f = lambda passphrase: self.on_restore_bip39(seed, passphrase)
Expand Down
9 changes: 9 additions & 0 deletions lib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ def _init_encryption_version(self):
def file_exists(self):
return self.path and os.path.exists(self.path)

def file_writable(self):
if not self.file_exists():
if not os.access(os.path.dirname(self.path), os.W_OK):
return False
else:
if not os.access(self.path, os.W_OK):
return False
return True

@staticmethod
def get_eckey_from_password(password):
secret = pbkdf2.PBKDF2(password, '', iterations=1024, macmodule=hmac, digestmodule=hashlib.sha512).read(64)
Expand Down

0 comments on commit a3aec8e

Please sign in to comment.