From f26fce63ade57c333742fab03a3bc3114b4f5f19 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Mon, 25 Mar 2019 09:08:32 +0100 Subject: [PATCH] avoid crash when ROM does not support fingerprint encryption, closes https://github.com/PhilippC/keepass2android/issues/155 --- src/keepass2android/FingerprintModule.cs | 2 +- .../FingerprintSetupActivity.cs | 30 ++++++++++++++----- .../Resources/values/strings.xml | 4 ++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/keepass2android/FingerprintModule.cs b/src/keepass2android/FingerprintModule.cs index 33103345..1c1a6776 100644 --- a/src/keepass2android/FingerprintModule.cs +++ b/src/keepass2android/FingerprintModule.cs @@ -227,7 +227,7 @@ namespace keepass2android public string Encrypt(string textToEncrypt) { Kp2aLog.Log("FP: Encrypting"); - return Base64.EncodeToString(_cipher.DoFinal(System.Text.Encoding.UTF8.GetBytes(textToEncrypt)), 0); + return Base64.EncodeToString(_cipher.DoFinal(System.Text.Encoding.UTF8.GetBytes(textToEncrypt)), 0); } diff --git a/src/keepass2android/FingerprintSetupActivity.cs b/src/keepass2android/FingerprintSetupActivity.cs index f0f2fe1e..ca648b08 100644 --- a/src/keepass2android/FingerprintSetupActivity.cs +++ b/src/keepass2android/FingerprintSetupActivity.cs @@ -186,14 +186,28 @@ namespace keepass2android } else { - if (_unlockMode == FingerprintUnlockMode.FullUnlock) - { - var userKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey.GetUserKey(); - _enc.StoreEncrypted(userKey != null ? userKey.Password.ReadString() : "", CurrentPreferenceKey, edit); - } - else - _enc.StoreEncrypted("QuickUnlock" /*some dummy data*/, CurrentPreferenceKey, edit); - } + try + { + if (_unlockMode == FingerprintUnlockMode.FullUnlock) + { + var userKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey.GetUserKey(); + _enc.StoreEncrypted(userKey != null ? userKey.Password.ReadString() : "", CurrentPreferenceKey, edit); + } + else + _enc.StoreEncrypted("QuickUnlock" /*some dummy data*/, CurrentPreferenceKey, edit); + } + catch (Exception e) + { + new AlertDialog.Builder(this) + .SetTitle(GetString(Resource.String.ErrorOcurred)) + .SetMessage(GetString(Resource.String.FingerprintSetupFailed)) + .SetCancelable(false) + .SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { }) + .Show(); + + } + + } edit.PutString(App.Kp2a.CurrentDb.CurrentFingerprintModePrefKey, _unlockMode.ToString()); edit.Commit(); } diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index 17f2e2e0..735e6309 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -105,6 +105,7 @@ Please re-enable Fingerprint Unlock for the new master password. Please unlock with your password and then re-enable Fingerprint Unlock in the database settings. Failed to initialize fingerprint sensor. + Failed to encrypt data. This can happen if you add or remove fingerprints in the system settings while Keepass2Android is listening for your fingerprint. This will store your master password on this device, encrypted with the Android Keystore and protected using fingerprint authentication. Allows to unlock your database only with your fingerprint. @@ -744,6 +745,7 @@ Configure child databases… Child databases unspecified + Child databases are other databases which can be opened automatically when you open the parent database. Therefore, the child\'s master password and file location are stored in the parent. This feature allows to share some of your passwords with another person. The implementation is compatible with KeeAutoExec for PC. Enabled on this device Enable on this device @@ -782,7 +784,7 @@ Version 1.07-pre\n * Fixes for crashes on Samsung\'s Android 9\n - * Allow to open more than one database, compatible to KeeAutoExec\n + * Allow to open more than one database, compatible with KeeAutoExec\n * SFTP: Allow public key authentication, check if host key changed\n * Introduce pCloud support - thanks to gilbsgilbs!\n * Make Nextcloud support explicit\n