disable fingerprint unlock when unlocking fails with invalid key

This commit is contained in:
Philipp Crocoll
2016-01-02 21:57:49 +01:00
parent b3416410f0
commit aed1d88f75
5 changed files with 67 additions and 30 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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();
}
}