1616from ChangeDatabasePasswordDialog import ChangeDatabasePasswordDialog
1717from HTMLTextDialog import HTMLTextDialog
1818from Logging import GetLogger
19+ from Errors import DecryptionError , PasswordError
1920
2021class AuthTaskbarIcon ( wx .TaskBarIcon ):
2122 """Notification tray icon."""
@@ -205,13 +206,22 @@ def OnCreate( self, event ):
205206 break
206207 try :
207208 self .auth_store = AuthenticationStore ( Configuration .GetDatabaseFilename (), password )
208- except ValueError :
209+ except DecryptionError as e :
210+ GetLogger ().error ( str ( e ) )
211+ GetLogger ().error ( "Failure decrypting database." )
209212 retry = True
210- else :
213+ except PasswordError as e :
214+ GetLogger ().error ( str ( e ) )
215+ GetLogger ().error ( "Password problem decrypting database." )
216+ retry = True
217+ except Exception as e :
218+ GetLogger ().error ( str ( e ) )
219+ GetLogger ().critical ( "Unexpected exception decrypting database." )
211220 retry = False
212221 finally :
213222 if self .auth_store != None :
214223 authentication_store_ok = True
224+ retry = False
215225 if not authentication_store_ok :
216226 GetLogger ().critical ( "Database could not be opened" )
217227 self .do_not_save = True
@@ -427,7 +437,14 @@ def OnCloseWindow( self, event ):
427437 self .timer = None
428438 if not self .do_not_save :
429439 if self .auth_store != None :
430- self .auth_store .Save ()
440+ try :
441+ self .auth_store .Save ()
442+ except PasswordError :
443+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
444+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
445+ dlg .SetExtendedMessage ( "The database could not be properly saved." )
446+ dlg .ShowModal ()
447+ dlg .Destroy ()
431448 wp = self .GetPosition ()
432449 Configuration .SetLastWindowPosition ( wp )
433450 if self .displayed :
@@ -503,7 +520,12 @@ def OnMenuNewEntry( self, event ):
503520 GetLogger ().debug ( "AF NE account %s" , account )
504521 GetLogger ().debug ( "AF NE digits %d" , digits )
505522 GetLogger ().debug ( "AF NE orig lbl %s" , original_label )
506- entry = self .auth_store .Add ( provider , account , secret , digits , original_label )
523+ try :
524+ entry = self .auth_store .Add ( provider , account , secret , digits , original_label )
525+ sts = ''
526+ except PasswordError :
527+ entry = None
528+ sts = 'password'
507529 if entry != None :
508530 GetLogger ().debug ( "AF NE new panel: %d" , entry .GetGroup () )
509531 # If all we have is the dummy entry then replace it, otherwise add the new entry at the end
@@ -524,10 +546,15 @@ def OnMenuNewEntry( self, event ):
524546 ## unicode( panel.GetMinSize() ) )
525547 self .UpdatePanelSize ()
526548 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 ) )
549+ if sts == 'password' :
550+ GetLogger ().debug ( "AF NE password error" )
551+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
552+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
553+ else :
554+ GetLogger ().debug ( "AF NE duplicate item" )
555+ dlg = wx .MessageDialog ( self , "That entry already exists." , "Error" ,
556+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
557+ dlg .SetExtendedMessage ( "Provider: {0}\n Account: {1}" .format ( provider , account ) )
531558 dlg .ShowModal ()
532559 dlg .Destroy ()
533560
@@ -568,10 +595,14 @@ def OnMenuEditEntry( self, event ):
568595 GetLogger ().debug ( "AF UE updating entry" )
569596 status = self .auth_store .Update ( entry .GetGroup (), provider , account , secret , digits )
570597 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." )
598+ if status == - 100 :
599+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
600+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
601+ else :
602+ dlg = wx .MessageDialog ( self , "Database is corrupted." , "Error" ,
603+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
604+ dlg .SetExtendedMessage ( "Multiple copies of the entry were found.\n " +
605+ "The database is likely corrupted and needs repaired." )
575606 dlg .ShowModal ()
576607 dlg .Destroy ()
577608 elif status == 0 :
@@ -779,7 +810,13 @@ def OnMenuReindex( self, event ):
779810 """Handle a request to reindex the database from the menu."""
780811 GetLogger ().debug ( "AF menu Reindex command" )
781812 GetLogger ().info ( "Database reindex ordered" )
782- self .auth_store .Reindex ()
813+ try :
814+ self .auth_store .Reindex ()
815+ except PasswordError :
816+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
817+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
818+ dlg .ShowModal ()
819+ dlg .Destroy ()
783820 self .depopulate_entries_window ()
784821 self .populate_entries_window ()
785822 self .UpdatePanelSize ()
@@ -788,7 +825,13 @@ def OnMenuRegroup( self, event ):
788825 """Handle a request to re-group the database from the menu."""
789826 GetLogger ().debug ( "AF menu Regroup command" )
790827 GetLogger ().info ( "Database regroup and reindex ordered" )
791- self .auth_store .Regroup ()
828+ try :
829+ self .auth_store .Regroup ()
830+ except PasswordError :
831+ dlg = wx .MessageDialog ( self , "A database password is required." , "Error" ,
832+ style = wx .OK | wx .ICON_ERROR | wx .STAY_ON_TOP | wx .CENTRE )
833+ dlg .ShowModal ()
834+ dlg .Destroy ()
792835 self .depopulate_entries_window ()
793836 self .populate_entries_window ()
794837 self .UpdatePanelSize ()
0 commit comments