private IKp2aApp PerformLoad(string filenameWithoutDir, string password, string keyfile) { Android.Util.Log.Debug("KP2ATest", "Starting for " + filenameWithoutDir + " with " + password + "/" + keyfile); IKp2aApp app = new TestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; var key = CreateKey(password, keyfile); string loadErrorMessage = ""; LoadDb task = new LoadDb(app, new IOConnectionInfo {Path = TestDbDirectory + filenameWithoutDir}, null, key, keyfile, new ActionOnFinish((success, message) => { loadErrorMessage = message; if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-( " + loadErrorMessage); return app; }
public void LoadAndSaveFromRemote1And1Ftp() { var ioc = RemoteIoc1and1Ftp; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! var app = new TestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("test"), null, new ActionOnFinish((success, message) => { if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-("); Assert.IsTrue(TrySaveDatabase(app), "didn't successfully save database."); }
public void LoadWithAcceptedCertificateTrustFailure() { var ioc = RemoteCertFailureIoc; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! var app = new TestKp2aApp(); app.ServerCertificateErrorResponse = true; app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("test"), null, new ActionOnFinish((success, message) => { if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "database should be loaded because invalid certificates are accepted"); }
public void LoadFromRemoteWithDomain() { //warning, looks like credentials are no longer valid var ioc = RemoteDomainIoc; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! var app = new TestKp2aApp(); app.ServerCertificateErrorResponse = true; //accept invalid cert app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("a"), null, new ActionOnFinish((success, message) => { if (!success) Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-("); }
public void LoadFromRemote1And1WrongCredentials() { var ioc = RemoteIoc1and1WrongCredentials; //note: this property is defined in "TestLoadDbCredentials.cs" which is deliberately excluded from Git because the credentials are not public! IKp2aApp app = new TestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; bool gotError = false; LoadDb task = new LoadDb(app, ioc, null, CreateKey("test"), null, new ActionOnFinish((success, message) => { if (!success) { Android.Util.Log.Debug("KP2ATest", "error loading db: " + message); gotError = true; } loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); Android.Util.Log.Debug("KP2ATest", "Running ProgressTask"); pt.Run(); pt.JoinWorkerThread(); Android.Util.Log.Debug("KP2ATest", "PT.run finished"); Assert.IsFalse(loadSuccesful); Assert.IsTrue(gotError); }
protected TestKp2aApp LoadDatabase(string filename, string password, string keyfile) { var app = CreateTestKp2aApp(); app.CreateNewDatabase(); bool loadSuccesful = false; LoadDb task = new LoadDb(app, new IOConnectionInfo() { Path = filename }, null, CreateKey(password, keyfile), keyfile, new ActionOnFinish((success, message) => { if (!success) Kp2aLog.Log(message); loadSuccesful = success; }) ); ProgressTask pt = new ProgressTask(app, Application.Context, task); pt.Run(); pt.JoinWorkerThread(); Assert.IsTrue(loadSuccesful); return app; }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); _keepPasswordInOnResume = true; Kp2aLog.Log("PasswordActivity.OnActivityResult "+resultCode+"/"+requestCode); AppTask.TryGetFromActivityResult(data, ref AppTask); //NOTE: original code from k eepassdroid used switch ((Android.App.Result)requestCode) { (but doesn't work here, although k eepassdroid works) switch(resultCode) { case KeePass.ExitNormal: // Returned to this screen using the Back key if (PreferenceManager.GetDefaultSharedPreferences(this) .GetBoolean(GetString(Resource.String.LockWhenNavigateBack_key), false)) { App.Kp2a.LockDatabase(); } //by leaving the app with the back button, the user probably wants to cancel the task //The activity might be resumed (through Android's recent tasks list), then use a NullTask: AppTask = new NullTask(); Finish(); break; case KeePass.ExitLock: // The database has already been locked, and the quick unlock screen will be shown if appropriate _rememberKeyfile = _prefs.GetBoolean(GetString(Resource.String.keyfile_key), Resources.GetBoolean(Resource.Boolean.keyfile_default)); //update value if ((KeyProviderType == KeyProviders.KeyFile) && (_rememberKeyfile)) { //check if the keyfile was changed (by importing to internal directory) var newKeyFile = GetKeyFile(_ioConnection.Path); if (newKeyFile != _keyFileOrProvider) { _keyFileOrProvider = newKeyFile; UpdateKeyfileIocView(); } } break; case KeePass.ExitCloseAfterTaskComplete: // Do not lock the database SetResult(KeePass.ExitCloseAfterTaskComplete); Finish(); break; case KeePass.ExitClose: SetResult(KeePass.ExitClose); Finish(); break; case KeePass.ExitReloadDb: if (App.Kp2a.GetDb().Loaded) { //remember the composite key for reloading: var compositeKey = App.Kp2a.GetDb().KpDatabase.MasterKey; //lock the database: App.Kp2a.LockDatabase(false); //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(); } break; case Result.Ok: if (requestCode == RequestCodeSelectKeyfile) { IOConnectionInfo ioc = new IOConnectionInfo(); SetIoConnectionFromIntent(ioc, data); _keyFileOrProvider = IOConnectionInfo.SerializeToString(ioc); UpdateKeyfileIocView(); } break; case (Result)FileStorageResults.FileUsagePrepared: if (requestCode == RequestCodePrepareDbFile) { if (KeyProviderType == KeyProviders.KeyFile) { var iocKeyfile = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider); App.Kp2a.GetFileStorage(iocKeyfile) .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile, RequestCodePrepareKeyFile, false); } else PerformLoadDatabase(); } if (requestCode == RequestCodePrepareKeyFile) { PerformLoadDatabase(); } if (requestCode == RequestCodePrepareOtpAuxFile) { GetAuxFileLoader().LoadAuxFile(true); } break; } if (requestCode == RequestCodeSelectAuxFile && resultCode == Result.Ok) { IOConnectionInfo auxFileIoc = new IOConnectionInfo(); SetIoConnectionFromIntent(auxFileIoc, data); PreferenceManager.GetDefaultSharedPreferences(this).Edit() .PutString("KP2A.PasswordAct.AuxFileIoc" + IOConnectionInfo.SerializeToString(_ioConnection), IOConnectionInfo.SerializeToString(auxFileIoc)) .Apply(); GetAuxFileLoader().LoadAuxFile(false); } if (requestCode == RequestCodeChallengeYubikey && resultCode == Result.Ok) { try { _challengeProv = new KeeChallengeProv(); byte[] challengeResponse = data.GetByteArrayExtra("response"); _challengeSecret = _challengeProv.GetSecret(_chalInfo, challengeResponse); Array.Clear(challengeResponse, 0, challengeResponse.Length); } catch (Exception e) { Kp2aLog.Log(e.ToString()); Toast.MakeText(this, "Error: " + e.Message, ToastLength.Long).Show(); return; } UpdateOkButtonState(); FindViewById(Resource.Id.otpInitView).Visibility = ViewStates.Gone; if (_challengeSecret != null) { new LoadingDialog<object, object, object>(this, true, //doInBackground delegate { //save aux file try { ChallengeInfo temp = _challengeProv.Encrypt(_challengeSecret); IFileStorage fileStorage = App.Kp2a.GetOtpAuxFileStorage(_ioConnection); IOConnectionInfo iocAux = fileStorage.GetFilePath(fileStorage.GetParentPath(_ioConnection), fileStorage.GetFilenameWithoutPathAndExt(_ioConnection) + ".xml"); if (!temp.Save(iocAux)) { Toast.MakeText(this, Resource.String.ErrorUpdatingChalAuxFile, ToastLength.Long).Show(); return false; } } catch (Exception e) { Kp2aLog.Log(e.ToString()); } return null; } , delegate { }).Execute(); } else { Toast.MakeText(this, Resource.String.bad_resp, ToastLength.Long).Show(); return; } } }