From f1c01d295540be3b7c4af33ac4f352e803d1b7ca Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Fri, 19 Dec 2014 21:26:18 +0100 Subject: [PATCH] automatically reload database at ExitReloadDb -> fixes https://keepass2android.codeplex.com/workitem/274 (if loading fails, old key is not visible in UI) --- src/keepass2android/PasswordActivity.cs | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index 3fa3bc46..1a274ed6 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -257,28 +257,29 @@ namespace keepass2android Finish(); break; case KeePass.ExitReloadDb: - //if the activity was killed, fill password/keyfile so the user can directly hit load again + if (App.Kp2a.GetDb().Loaded) { - if (App.Kp2a.GetDb().KpDatabase.MasterKey.ContainsType(typeof(KcpPassword))) - { + //remember the composite key for reloading: + var compositeKey = App.Kp2a.GetDb().KpDatabase.MasterKey; - KcpPassword kcpPassword = (KcpPassword)App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof(KcpPassword)); - String password = kcpPassword.Password.ReadString(); + //lock the database: + App.Kp2a.LockDatabase(false); - SetEditText(Resource.Id.password, password); - - } - if (App.Kp2a.GetDb().KpDatabase.MasterKey.ContainsType(typeof(KcpKeyFile))) - { - - KcpKeyFile kcpKeyfile = (KcpKeyFile)App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof(KcpKeyFile)); - _keyFileOrProvider = IOConnectionInfo.SerializeToString(kcpKeyfile.Ioc); - UpdateKeyfileIocView(); - } + //reload the database (without most other stuff performed in PerformLoadDatabase. + // We're assuming that the db file (and if appropriate also the key file) are still available + // and there's no need to re-init the file storage. if it is, loading will fail and the user has + // to retry with typing the full password, but that's intended to avoid showing the password to a + // a potentially unauthorized user (feature request https://keepass2android.codeplex.com/workitem/274) + Handler handler = new Handler(); + OnFinish onFinish = new AfterLoad(handler, this); + _performingLoad = true; + LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish); + _loadDbTask = null; // prevent accidental re-use + new ProgressTask(App.Kp2a, this, task).Run(); } - App.Kp2a.LockDatabase(false); + break; case Result.Ok: if (requestCode == RequestCodeSelectKeyfile)