catch exception when decrypting key fails, fixes #50

This commit is contained in:
Philipp Crocoll
2017-12-02 16:41:57 +01:00
parent d40656b69a
commit db74e573d1
2 changed files with 34 additions and 14 deletions

View File

@@ -1054,10 +1054,19 @@ namespace keepass2android
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
btn.SetImageResource(Resource.Drawable.ic_fingerprint_success);
var masterPassword = _fingerprintDec.DecryptStored(Database.GetFingerprintPrefKey(_ioConnection));
_password = FindViewById<EditText>(Resource.Id.password_edit).Text = masterPassword;
try
{
var masterPassword = _fingerprintDec.DecryptStored(Database.GetFingerprintPrefKey(_ioConnection));
_password = FindViewById<EditText>(Resource.Id.password_edit).Text = masterPassword;
}
catch (Java.Security.GeneralSecurityException ex)
{
HandleFingerprintKeyInvalidated();
return;
}
btn.PostDelayed(() =>
{
//re-init fingerprint unlock in case something goes wrong with opening the database
@@ -1961,12 +1970,7 @@ namespace keepass2android
}
else
{
//key invalidated permanently
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
btn.Tag = GetString(Resource.String.fingerprint_unlock_failed);
_fingerprintDec = null;
ClearFingerprintUnlockData();
HandleFingerprintKeyInvalidated();
return false;
}
}
@@ -1982,6 +1986,17 @@ namespace keepass2android
}
private void HandleFingerprintKeyInvalidated()
{
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
//key invalidated permanently
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
btn.Tag = GetString(Resource.String.fingerprint_unlock_failed);
_fingerprintDec = null;
ClearFingerprintUnlockData();
}
private void InitializeOptionCheckboxes() {
CheckBox cbQuickUnlock = (CheckBox)FindViewById(Resource.Id.enable_quickunlock);
cbQuickUnlock.Checked = _prefs.GetBoolean(GetString(Resource.String.QuickUnlockDefaultEnabled_key), true);

View File

@@ -285,11 +285,7 @@ namespace keepass2android
else
{
Kp2aLog.Log("failed to initialize fingerprint.");
//key invalidated permanently
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
btn.Tag = GetString(Resource.String.fingerprint_unlock_failed);
_fingerprintIdentifier = null;
HandleFingerprintKeyInvalidated();
}
}
catch (Exception e)
@@ -304,6 +300,15 @@ namespace keepass2android
}
private void HandleFingerprintKeyInvalidated()
{
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
//key invalidated permanently
btn.SetImageResource(Resource.Drawable.ic_fingerprint_error);
btn.Tag = GetString(Resource.String.fingerprint_unlock_failed);
_fingerprintIdentifier = null;
}
private void ClearFingerprintUnlockData()
{
ISharedPreferencesEditor edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit();