def call_password_authentication(self, event): getLogger(__name__).debug("authenticating... - direction: %s", event.GetDirection()) if event.GetDirection(): # going forwards if not self.is_authenticated: if gui_utils.is_valid_input( self.username) and gui_utils.is_valid_input( self.password): try: success = self.parent.localbox_client.authenticator.authenticate_with_password( self.username, self.password) except Exception as error: success = False getLogger(__name__).exception( 'Problem authenticating with password: %s-%s' % (error.__class__, error)) if success: self.passphrase_page(event) else: title = _('Error') error_msg = _("Username/Password incorrect") gui_utils.show_error_dialog(message=error_msg, title=title) event.Veto() else: event.Veto()
def store_keys(self, event): try: if event.GetDirection(): if self._entry_repeat_passphrase.IsShown( ) and self.passphrase != self.repeat_passphrase: gui_utils.show_error_dialog( message=_('Passphrases are not equal'), title=_('Error')) event.Veto() return # going forward if gui_utils.is_valid_input(self.passphrase): getLogger(__name__).debug("storing keys") if not LoginController().store_keys( localbox_client=self.parent.localbox_client, pubkey=self.pubkey, privkey=self.privkey, passphrase=self.passphrase): gui_utils.show_error_dialog( message=_('Wrong passphase'), title=_('Error')) event.Veto() return sync_item = self._add_new_sync_item() create_watchdog(sync_item) else: event.Veto() except Exception as err: getLogger(__name__).exception('Error storing keys %s' % err)
def check_server_connection(self, server): try: getLogger(__name__).debug("Connecting to server %s, %s", server.url, server.label) self.parent.localbox_client = LocalBox(server.url, server.label, None) except (URLError, InvalidURL, ValueError) as error: getLogger(__name__).debug("Can't access server") gui_utils.show_error_dialog( message=_('Can\'t connect to server given by URL'), title=_('Can\'t connect to server')) self.parent.localbox_client = None return except (BadStatusLine, auth.AlreadyAuthenticatedError) as error: getLogger(__name__).debug("error with authentication url thingie") getLogger(__name__).exception(error) gui_utils.show_error_dialog(message=_( 'Can\'t authenticate with given username and password.'), title=_('Can\'t authenticate.')) self.parent.localbox_client = None return except SocketError as e: if e.errno != errno.ECONNRESET: raise # Not the error we are looking for getLogger(__name__).error( 'Failed to connect to server, maybe forgot https? %s', e) self.parent.localbox_client = None return finally: self.parent.box_label = server.label
def validate_new_sync_inputs(self, event): # step 1 label = self.label url = self.url path = self.path if gui_utils.is_valid_input(label) and gui_utils.is_valid_input( url) and gui_utils.is_valid_input(path): self.sync_item = SyncItem(label=label, url=url, path=path) try: self.parent.localbox_client = LocalBox(url, label) except (URLError, BadStatusLine, ValueError, auth.AlreadyAuthenticatedError) as error: getLogger(__name__).debug( "error with authentication url thingie") getLogger(__name__).exception(error) except SocketError as e: if e.errno != errno.ECONNRESET: raise # Not error we are looking for getLogger(__name__).error( 'Failed to connect to server, maybe forgot https? %s', e) self.parent.box_label = label self.parent.path = path if not self.parent.localbox_client: getLogger(__name__).error('%s is not a valid URL' % url) gui_utils.show_error_dialog( message=_('%s is not a valid URL') % url, title=_('Invalid URL')) event.Veto() else: event.Veto()
def validate_new_sync_inputs(self, event): # step 1 label = self.label path = self.path # Always allow to go back if not event.GetDirection(): return True # Validate the inputs if not gui_utils.is_valid_input(label): gui_utils.show_error_dialog(message=_('%s is not a valid label') % label, title=_('Invalid Label')) event.Veto() return if not gui_utils.is_valid_input(path): gui_utils.show_error_dialog(message=_('%s is not a valid path') % path, title=_('Invalid Path')) event.Veto() return # Check if the label of the directory are already in the Syncs if not SyncsController().check_uniq_label(label): gui_utils.show_error_dialog( message=_('Label "%s" already exists') % label, title=_('Invalid Label')) event.Veto() return try: SyncsController().check_uniq_path(path) except PathDoesntExistsException as e: msg = _("Path '{}' doesn't exist").format(e.path) gui_utils.show_error_dialog(message=msg, title=_('Invalid Path')) event.Veto() return except PathColisionException as e: msg = _("Path '{}' collides with path '{}' of sync {}").format( e.path, e.sync_label, e.sync_path) gui_utils.show_error_dialog(message=msg, title=_('Path Collision')) event.Veto() return #self.label = self.parent.box_label self.parent.box_label = label self.parent.path = path self.parent.localbox_client.authenticator.label = self.label self.parent.localbox_client.label = self.label self.parent.localbox_client.authenticator.save_client_data()
def store_keys(self, event): if event.GetDirection(): if self._entry_repeat_passphrase.IsShown( ) and self.passphrase != self.repeat_passphrase: gui_utils.show_error_dialog( message=_('Passphrases are not equal'), title=_('Error')) event.Veto() return super(NewPassphraseWizardPage, self).store_keys(event)
def select_dir(self, wx_event): try: path = gui_utils.select_directory(cwd=self.localbox_path) if path: path = get_localbox_path( SyncsController().get(self.selected_localbox).path, path) # get meta to verify if path is a valid LocalBox path # this will later problems, because for the sharing to work the files must exist in the server self.localbox_client.get_meta(path) self._selected_dir.SetValue(path) except InvalidLocalBoxPathError: gui_utils.show_error_dialog( _('Invalid LocalBox path. Please make sure that you are selecting a directory inside LocalBox and ' 'that the directory has been uploaded. Or try a different directory.' ), 'Error')
def OnClickOk(self, event): if event.Id == self._btn_ok.Id: try: LoginController().store_passphrase( passphrase=self._passphrase.Value, user=self._username, label=self._label) self.parent.Destroy() except InvalidPassphraseError: gui_utils.show_error_dialog(message=_('Wrong passphase'), title=_('Error')) except Exception as err: getLogger(__name__).exception(err) gui_utils.show_error_dialog(message=_( 'Could not authenticate. Please contact the administrator' ), title=_('Error'))
def store_keys(self, event): try: if event.GetDirection(): # going forward if gui_utils.is_valid_input(self.passphrase): getLogger(__name__).debug("storing keys") if not LoginController().store_keys( localbox_client=self.parent.localbox_client, pubkey=self.parent.pubkey, privkey=self.parent.privkey, passphrase=self.passphrase): gui_utils.show_error_dialog( message=_('Wrong passphase'), title=_('Error')) event.Veto() return self.add_new_sync_item() else: event.Veto() except Exception as err: getLogger(__name__).exception('Error storing keys %s' % err)
def OnClickOk(self, event): path = self._selected_dir.GetValue() lox_label = self.choice.GetString(self.choice.GetSelection()) if gui_utils.is_valid_input( path) and self.list.GetSelectedItemCount() > 0: user_list = self.list.get_users() share_path = path.replace(self.localbox_path, '', 1) if self.localbox_client.create_share( localbox_path=share_path, passphrase=LoginController().get_passphrase( self.localbox_client.label), user_list=user_list): item = ShareItem(user=self.localbox_client.username, path=share_path, url=self.localbox_client.url, label=lox_label) SharesController().add(item) self.parent.ctrl.populate(SharesController().get_list()) else: gui_utils.show_error_dialog( _('Server error creating the share'), _('Error')) self.parent.Destroy()
def open_file(data_dic, memory=False): # Get passphrase passphrase = LoginController().get_passphrase(data_dic["label"]) if not passphrase: passphrase = gui_utils.get_user_secret_input( "YourLocalBox - Enter Passphrase", "Please provide the passphrase to unlock file.") if not passphrase: gui_utils.show_error_dialog(_('No passphrase provided. aborting'), 'Error', standalone=True) return None # Stat local box instance localbox_client = LocalBox(data_dic["url"], data_dic["label"], "") # Attempt to decode the file # print data_dic, passphrase try: decoded_contents = localbox_client.decode_file( data_dic["localbox_filename"], data_dic["filename"], passphrase) # If there was a failure, answer wit ha 404 to state that the file doesn't exist except Exception as e: gui_utils.show_error_dialog( _('Failed to decode contents. aborting : {}').format(e), 'Error', standalone=True) getLogger(__name__).info( 'failed to decode contents. aborting : {}'.format(e)) return None # If the file was decoded, write it to disk tmp_decoded_filename = \ os_utils.remove_extension(data_dic["filename"], defaults.LOCALBOX_EXTENSION) getLogger(__name__).info('tmp_decoded_filename: %s' % tmp_decoded_filename) if os.path.exists(tmp_decoded_filename): os.remove(tmp_decoded_filename) if not memory: memory = LocalBoxMemoryFS() if not memory: localfile = open(tmp_decoded_filename, 'wb') localfile.write(decoded_contents) localfile.close() else: tmp_decoded_filename = memory.createfile( tmp_decoded_filename.split('/')[-1], decoded_contents) # Keep file in list of opened files openfiles_ctrl.add(tmp_decoded_filename) return tmp_decoded_filename
def run_file_decryption(filename): try: getLogger(__name__).info('Decrypting and opening file: %s', filename) # verify if the file belongs to any of the configured syncs sync_list = sync_ctrl.list localbox_client = None localbox_filename = None for sync_item in sync_list: getLogger(__name__).debug('sync path: %s' % sync_item.path) sync_path = sync_item.path if sync_item.path.endswith( '/') else sync_item.path + os.path.sep if filename.startswith(sync_path): localbox_filename = os_utils.remove_extension( filename.replace(sync_item.path, ''), defaults.LOCALBOX_EXTENSION) localbox_client = LocalBox(sync_item.url, sync_item.label) break if not localbox_client or not localbox_filename: gui_utils.show_error_dialog( _('%s does not belong to any configured localbox') % filename, 'Error', True) getLogger(__name__).error( '%s does not belong to any configured localbox' % filename) exit(1) # get passphrase label = localbox_client.authenticator.label passphrase = LoginController().get_passphrase(label, remote=True) if not passphrase: gui_wx.ask_passphrase(localbox_client.username, label) passphrase = LoginController().get_passphrase(label, remote=False) if not passphrase: gui_utils.show_error_dialog( _('Failed to get passphrase for label: %s.') % label, 'Error', True) getLogger(__name__).error( 'failed to get passphrase for label: %s. Exiting..' % label) exit(1) # decode file try: decoded_contents = localbox_client.decode_file( localbox_filename, filename, passphrase) except URLError: gui_utils.show_error_dialog(_('Failed to decode contents'), 'Error', standalone=True) getLogger(__name__).info('failed to decode contents. aborting') return 1 # write file tmp_decoded_filename = os_utils.remove_extension( filename, defaults.LOCALBOX_EXTENSION) getLogger(__name__).info('tmp_decoded_filename: %s' % tmp_decoded_filename) if os.path.exists(tmp_decoded_filename): os.remove(tmp_decoded_filename) localfile = open(tmp_decoded_filename, 'wb') localfile.write(decoded_contents) localfile.close() # open file open_file_ext(tmp_decoded_filename) openfiles_ctrl.add(tmp_decoded_filename) getLogger(__name__).info('Finished decrypting and opening file: %s', filename) except Exception as ex: getLogger(__name__).exception(ex)
def run_file_decryption(filename, memory=False): try: getLogger(__name__).info('Decrypting and opening file: %s', filename) # verify if the file belongs to any of the configured syncs sync_list = sync_ctrl.list localbox_client = None localbox_filename = None try: filename = filename.decode('utf-8') except UnicodeEncodeError: # on purpose, it's already an utf-8 string pass for sync_item in sync_list: getLogger(__name__).debug('sync path: %s' % sync_item.path) sync_path = sync_item.path if sync_item.path.endswith( '/') else sync_item.path + os.path.sep if filename.startswith(sync_path): localbox_filename = os_utils.remove_extension( filename.replace(sync_item.path, ''), defaults.LOCALBOX_EXTENSION) localbox_client = LocalBox(sync_item.url, sync_item.label, sync_item.path) break if not localbox_client or not localbox_filename: gui_utils.show_error_dialog( _('%s does not belong to any configured localbox') % filename, 'Error', True) getLogger(__name__).error( '%s does not belong to any configured localbox' % filename) #exit(1) # Request file to be opened data_dic = { "url": sync_item.url, "label": localbox_client.authenticator.label, "filename": filename, "localbox_filename": localbox_filename } name = "LocalBoxApp-{}".format(wx.GetUserId()) instance = wx.SingleInstanceChecker(name) app_is_running = instance.IsAnotherRunning() if app_is_running: file_to_open = Notifs().openFileReq(data_dic) else: file_to_open = open_file(data_dic, memory) if file_to_open is not None and os.path.exists(file_to_open): open_file_ext(file_to_open) getLogger(__name__).info( 'Finished decrypting and opening file: %s', filename) else: gui_utils.show_error_dialog(_('Failed to decode contents'), 'Error', standalone=True) getLogger(__name__).info('failed to decode contents. aborting') except Exception as ex: getLogger(__name__).exception(ex) gui_utils.show_error_dialog(_('Exception {}').format(ex), 'Error', standalone=True)