mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-05 00:55:10 -05:00
disable fingerprint unlock when unlocking fails with invalid key
This commit is contained in:
parent
b3416410f0
commit
aed1d88f75
@ -51,31 +51,41 @@ namespace keepass2android
|
||||
{
|
||||
try
|
||||
{
|
||||
StatusLogger.UpdateMessage(UiStringKey.loading_database);
|
||||
//get the stream data into a single stream variable (databaseStream) regardless whether its preloaded or not:
|
||||
MemoryStream preloadedMemoryStream = _databaseData == null ? null : _databaseData.Result;
|
||||
MemoryStream databaseStream;
|
||||
if (preloadedMemoryStream != null)
|
||||
databaseStream = preloadedMemoryStream;
|
||||
else
|
||||
try
|
||||
{
|
||||
using (Stream s = _app.GetFileStorage(_ioc).OpenFileForRead(_ioc))
|
||||
{
|
||||
databaseStream = new MemoryStream();
|
||||
s.CopyTo(databaseStream);
|
||||
databaseStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
//ok, try to load the database. Let's start with Kdbx format and retry later if that is the wrong guess:
|
||||
_format = new KdbxDatabaseFormat(KdbpFile.GetFormatToUse(_ioc));
|
||||
TryLoad(databaseStream);
|
||||
|
||||
StatusLogger.UpdateMessage(UiStringKey.loading_database);
|
||||
//get the stream data into a single stream variable (databaseStream) regardless whether its preloaded or not:
|
||||
MemoryStream preloadedMemoryStream = _databaseData == null ? null : _databaseData.Result;
|
||||
MemoryStream databaseStream;
|
||||
if (preloadedMemoryStream != null)
|
||||
databaseStream = preloadedMemoryStream;
|
||||
else
|
||||
{
|
||||
using (Stream s = _app.GetFileStorage(_ioc).OpenFileForRead(_ioc))
|
||||
{
|
||||
databaseStream = new MemoryStream();
|
||||
s.CopyTo(databaseStream);
|
||||
databaseStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
//ok, try to load the database. Let's start with Kdbx format and retry later if that is the wrong guess:
|
||||
_format = new KdbxDatabaseFormat(KdbpFile.GetFormatToUse(_ioc));
|
||||
TryLoad(databaseStream);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Exception = e;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (KeyFileException)
|
||||
{
|
||||
Kp2aLog.Log("KeyFileException");
|
||||
Finish(false, /*TODO Localize: use Keepass error text KPRes.KeyFileError (including "or invalid format")*/
|
||||
_app.GetResourceString(UiStringKey.keyfile_does_not_exist));
|
||||
_app.GetResourceString(UiStringKey.keyfile_does_not_exist), Exception);
|
||||
}
|
||||
catch (AggregateException e)
|
||||
{
|
||||
@ -86,25 +96,30 @@ namespace keepass2android
|
||||
// Override the message shown with the last (hopefully most recent) inner exception
|
||||
Kp2aLog.Log("Exception: " + innerException);
|
||||
}
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + message);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + message, Exception);
|
||||
return;
|
||||
}
|
||||
catch (DuplicateUuidsException e)
|
||||
{
|
||||
Kp2aLog.Log("Exception: " + e);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError)+" " +e.Message+ _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional));
|
||||
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception);
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.Log("Exception: " + e);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message);
|
||||
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, Exception);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds the exception which was thrown during execution (if any)
|
||||
/// </summary>
|
||||
public Exception Exception { get; set; }
|
||||
|
||||
private void TryLoad(MemoryStream databaseStream)
|
||||
{
|
||||
//create a copy of the stream so we can try again if we get an exception which indicates we should change parameters
|
||||
|
@ -26,10 +26,12 @@ namespace keepass2android
|
||||
{
|
||||
protected bool Success;
|
||||
protected String Message;
|
||||
protected Exception Exception;
|
||||
|
||||
protected OnFinish BaseOnFinish;
|
||||
protected Handler Handler;
|
||||
private ProgressDialogStatusLogger _statusLogger = new ProgressDialogStatusLogger(); //default: no logging but not null -> can be used whenever desired
|
||||
|
||||
|
||||
public ProgressDialogStatusLogger StatusLogger
|
||||
{
|
||||
@ -37,12 +39,11 @@ namespace keepass2android
|
||||
set { _statusLogger = value; }
|
||||
}
|
||||
|
||||
protected OnFinish() {
|
||||
}
|
||||
|
||||
protected OnFinish(Handler handler) {
|
||||
BaseOnFinish = null;
|
||||
Handler = handler;
|
||||
|
||||
}
|
||||
|
||||
protected OnFinish(OnFinish finish, Handler handler) {
|
||||
@ -55,9 +56,10 @@ namespace keepass2android
|
||||
Handler = null;
|
||||
}
|
||||
|
||||
public void SetResult(bool success, String message) {
|
||||
public void SetResult(bool success, string message, Exception exception) {
|
||||
Success = success;
|
||||
Message = message;
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
public void SetResult(bool success) {
|
||||
@ -67,7 +69,7 @@ namespace keepass2android
|
||||
public virtual void Run() {
|
||||
if (BaseOnFinish == null) return;
|
||||
// Pass on result on call finish
|
||||
BaseOnFinish.SetResult(Success, Message);
|
||||
BaseOnFinish.SetResult(Success, Message, Exception);
|
||||
|
||||
if ( Handler != null ) {
|
||||
Handler.Post(BaseOnFinish.Run);
|
||||
|
@ -34,9 +34,9 @@ namespace keepass2android
|
||||
set { _onFinishToRun = value; }
|
||||
}
|
||||
|
||||
protected void Finish(bool result, String message) {
|
||||
protected void Finish(bool result, String message, Exception exception = null) {
|
||||
if ( OnFinishToRun != null ) {
|
||||
OnFinishToRun.SetResult(result, message);
|
||||
OnFinishToRun.SetResult(result, message, exception);
|
||||
OnFinishToRun.Run();
|
||||
}
|
||||
}
|
||||
|
@ -968,7 +968,7 @@ namespace keepass2android
|
||||
//re-init fingerprint unlock in case something goes wrong with opening the database
|
||||
InitFingerprintUnlock();
|
||||
//fire
|
||||
OnOk();
|
||||
OnOk(true);
|
||||
}, 1000);
|
||||
|
||||
|
||||
@ -1138,13 +1138,16 @@ namespace keepass2android
|
||||
FindViewById<Button>(Resource.Id.change_db).Click += (sender, args) => GoToFileSelectActivity();
|
||||
}
|
||||
|
||||
private void OnOk()
|
||||
private void OnOk(bool usedFingerprintUnlock = false)
|
||||
{
|
||||
UsedFingerprintUnlock = usedFingerprintUnlock;
|
||||
App.Kp2a.GetFileStorage(_ioConnection)
|
||||
.PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), _ioConnection,
|
||||
RequestCodePrepareDbFile, false);
|
||||
}
|
||||
|
||||
public bool UsedFingerprintUnlock { get; set; }
|
||||
|
||||
private void InitializeTogglePasswordButton()
|
||||
{
|
||||
ImageButton btnTogglePassword = (ImageButton) FindViewById(Resource.Id.toggle_password);
|
||||
@ -1932,6 +1935,22 @@ namespace keepass2android
|
||||
|
||||
GC.Collect(); // Ensure temporary memory used while loading is collected
|
||||
}
|
||||
|
||||
|
||||
if (Exception is InvalidCompositeKeyException)
|
||||
{
|
||||
if (_act.UsedFingerprintUnlock)
|
||||
{
|
||||
//disable fingerprint unlock if master password changed
|
||||
_act.ClearFingerprintUnlockData();
|
||||
_act.InitFingerprintUnlock();
|
||||
|
||||
Message = _act.GetString(Resource.String.fingerprint_disabled_wrong_masterkey);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ((Message != null) && (Message.Length > 150)) //show long messages as dialog
|
||||
{
|
||||
@ -1956,7 +1975,7 @@ namespace keepass2android
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
_act._performingLoad = false;
|
||||
|
||||
|
@ -93,6 +93,7 @@
|
||||
<string name="enable_fingerprint_quickunlock">Enable Fingerprint Unlock for QuickUnlock</string>
|
||||
<string name="fingerprint_unlock_hint">Touch sensor to unlock database</string>
|
||||
<string name="fingerprint_unlock_failed">Fingerprint Unlock failed. Decryption key was invalidated by Android OS. This usually happens if a new fingerprint was enrolled or security settings were changed. Please unlock with your password and then re-enabled Fingerprint Unlock in the database settings.</string>
|
||||
<string name="fingerprint_disabled_wrong_masterkey">Unlocking the database failed: Invalid composite key. Fingerprint Unlock was disabled because apparently the stored master password is no longer valid. Please unlock with your password and then re-enabled Fingerprint Unlock in the database settings.</string>
|
||||
|
||||
<string name="enable_fingerprint_unlock_Info">
|
||||
This will store your master password on this device,
|
||||
|
Loading…
Reference in New Issue
Block a user