@@ -30,7 +30,9 @@ public class KeyStoreCipherMarshmallow extends KeyStoreCipher {
3030 private KeyStore keyStore ;
3131 private String alias ;
3232 private boolean requireUserAuthentication ;
33-
33+ private boolean wasNotAccessible = false ;
34+ private boolean wasPermanentlyInvalidated = false ;
35+
3436 KeyStoreCipherMarshmallow (String alias , boolean requireUserAuthentication ) {
3537 this .alias = alias + "_M" ;
3638 this .requireUserAuthentication = requireUserAuthentication ;
@@ -89,15 +91,34 @@ private boolean isKeyAccessible() {
8991 IvParameterSpec ivParameterSpec = new IvParameterSpec (FIXED_IV );
9092 Key key = keyStore .getKey (alias , null );
9193 c .init (Cipher .ENCRYPT_MODE , key , ivParameterSpec );
94+ logWasNotAccessible ();
9295 return true ;
9396 } catch (UserNotAuthenticatedException e ) {
97+ logWasNotAccessible ();
9498 return true ;
95- } catch (Exception e ) {
96- Logger .errorEvent ("KeyStore inaccessible: " + e .getClass ().getName () + ": " + e .getMessage ());
99+ } catch (KeyPermanentlyInvalidatedException e ) {
100+ wasPermanentlyInvalidated = true ;
101+ Logger .errorEvent ("KeyStore permanently invalidated " + e .getClass ().getName () + ": " + e .getMessage ());
97102 return false ;
103+ } catch (Exception e ) {
104+ wasNotAccessible = true ;
105+ Logger .logEvent ("KeyStore inaccessible: " + e .getClass ().getName () + ": " + e .getMessage ());
106+ return true ;
98107 }
99108 }
109+
110+ private void logWasNotAccessible () {
111+ if (wasNotAccessible ) {
112+ Logger .logEvent ("KeyStore was not accessible, but is now accessible again" );
113+ wasNotAccessible = false ;
114+ }
100115
116+ if (wasPermanentlyInvalidated ) {
117+ Logger .logEvent ("KeyStore was permanently invalidated, but is now recreated" );
118+ wasPermanentlyInvalidated = false ;
119+ }
120+ }
121+
101122 @ Override
102123 public String id () {
103124 try {
0 commit comments