11# -*- coding: utf-8 -*-
22"""Frame for the main window."""
33
4+ ## PyAuth - Google Authenticator desktop application
5+ ## Copyright (C) 2016 Todd T Knarr <tknarr@silverglass.org>
6+
7+ ## This program is free software: you can redistribute it and/or modify
8+ ## it under the terms of the GNU General Public License as published by
9+ ## the Free Software Foundation, either version 3 of the License, or
10+ ## (at your option) any later version.
11+
12+ ## This program is distributed in the hope that it will be useful,
13+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ ## GNU General Public License for more details.
16+
17+ ## You should have received a copy of the GNU General Public License
18+ ## along with this program. If not, see http://www.gnu.org/licenses/
19+
420import math
521import sysconfig
622import pkg_resources
1632from ChangeDatabasePasswordDialog import ChangeDatabasePasswordDialog
1733from HTMLTextDialog import HTMLTextDialog
1834from Logging import GetLogger
35+ from Errors import DecryptionError , PasswordError
1936
2037class AuthTaskbarIcon ( wx .TaskBarIcon ):
2138 """Notification tray icon."""
@@ -205,13 +222,22 @@ def OnCreate( self, event ):
205222 break
206223 try :
207224 self .auth_store = AuthenticationStore ( Configuration .GetDatabaseFilename (), password )
208- except ValueError :
225+ except DecryptionError as e :
226+ GetLogger ().error ( str ( e ) )
227+ GetLogger ().error ( "Failure decrypting database." )
209228 retry = True
210- else :
229+ except PasswordError as e :
230+ GetLogger ().error ( str ( e ) )
231+ GetLogger ().error ( "Password problem decrypting database." )
232+ retry = True
233+ except Exception as e :
234+ GetLogger ().error ( str ( e ) )
235+ GetLogger ().critical ( "Unexpected exception decrypting database." )
211236 retry = False
212237 finally :
213238 if self .auth_store != None :
214239 authentication_store_ok = True
240+ retry = False
215241 if not authentication_store_ok :
216242 GetLogger ().critical ( "Database could not be opened" )
217243 self .do_not_save = True
@@ -427,7 +453,14 @@ def OnCloseWindow( self, event ):
427453 self .timer = None
428454 if not self .do_not_save :
429455 if self .auth_store != None :
430- self .auth_store .Save ()
456+ try :
457+ self .auth_store .Save ()
458+ except PasswordError :
459+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
460+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
461+ dlg .SetExtendedMessage ( "The database could not be properly saved." )
462+ dlg .ShowModal ()
463+ dlg .Destroy ()
431464 wp = self .GetPosition ()
432465 Configuration .SetLastWindowPosition ( wp )
433466 if self .displayed :
@@ -503,7 +536,12 @@ def OnMenuNewEntry( self, event ):
503536 GetLogger ().debug ( "AF NE account %s" , account )
504537 GetLogger ().debug ( "AF NE digits %d" , digits )
505538 GetLogger ().debug ( "AF NE orig lbl %s" , original_label )
506- entry = self .auth_store .Add ( provider , account , secret , digits , original_label )
539+ try :
540+ entry = self .auth_store .Add ( provider , account , secret , digits , original_label )
541+ sts = ''
542+ except PasswordError :
543+ entry = None
544+ sts = 'password'
507545 if entry != None :
508546 GetLogger ().debug ( "AF NE new panel: %d" , entry .GetGroup () )
509547 # If all we have is the dummy entry then replace it, otherwise add the new entry at the end
@@ -524,10 +562,15 @@ def OnMenuNewEntry( self, event ):
524562 ## unicode( panel.GetMinSize() ) )
525563 self .UpdatePanelSize ()
526564 else :
527- GetLogger ().debug ( "AF NE duplicate item" )
528- dlg = wx .MessageDialog ( self , "That entry already exists." , "Error" ,
529- style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
530- dlg .SetExtendedMessage ( "Provider: {0}\n Account: {1}" .format ( provider , account ) )
565+ if sts == 'password' :
566+ GetLogger ().debug ( "AF NE password error" )
567+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
568+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
569+ else :
570+ GetLogger ().debug ( "AF NE duplicate item" )
571+ dlg = wx .MessageDialog ( self , "That entry already exists." , "Error" ,
572+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
573+ dlg .SetExtendedMessage ( "Provider: {0}\n Account: {1}" .format ( provider , account ) )
531574 dlg .ShowModal ()
532575 dlg .Destroy ()
533576
@@ -568,10 +611,14 @@ def OnMenuEditEntry( self, event ):
568611 GetLogger ().debug ( "AF UE updating entry" )
569612 status = self .auth_store .Update ( entry .GetGroup (), provider , account , secret , digits )
570613 if status < 0 :
571- dlg = wx .MessageDialog ( self , "Database is corrupted." , "Error" ,
572- style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
573- dlg .SetExtendedMessage ( "Multiple copies of the entry were found.\n " +
574- "The database is likely corrupted and needs repaired." )
614+ if status == - 100 :
615+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
616+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
617+ else :
618+ dlg = wx .MessageDialog ( self , "Database is corrupted." , "Error" ,
619+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
620+ dlg .SetExtendedMessage ( "Multiple copies of the entry were found.\n " +
621+ "The database is likely corrupted and needs repaired." )
575622 dlg .ShowModal ()
576623 dlg .Destroy ()
577624 elif status == 0 :
@@ -779,7 +826,13 @@ def OnMenuReindex( self, event ):
779826 """Handle a request to reindex the database from the menu."""
780827 GetLogger ().debug ( "AF menu Reindex command" )
781828 GetLogger ().info ( "Database reindex ordered" )
782- self .auth_store .Reindex ()
829+ try :
830+ self .auth_store .Reindex ()
831+ except PasswordError :
832+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
833+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
834+ dlg .ShowModal ()
835+ dlg .Destroy ()
783836 self .depopulate_entries_window ()
784837 self .populate_entries_window ()
785838 self .UpdatePanelSize ()
@@ -788,7 +841,13 @@ def OnMenuRegroup( self, event ):
788841 """Handle a request to re-group the database from the menu."""
789842 GetLogger ().debug ( "AF menu Regroup command" )
790843 GetLogger ().info ( "Database regroup and reindex ordered" )
791- self .auth_store .Regroup ()
844+ try :
845+ self .auth_store .Regroup ()
846+ except PasswordError :
847+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
848+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
849+ dlg .ShowModal ()
850+ dlg .Destroy ()
792851 self .depopulate_entries_window ()
793852 self .populate_entries_window ()
794853 self .UpdatePanelSize ()
0 commit comments