From d9c101debe25561f8f1892a1d16fbbc3bf30cac9 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Sun, 28 Oct 2018 07:17:45 +0100 Subject: [PATCH] remove NfcOtpActivity: not working with current multi-db approach, but also not working since Android has App links --- src/keepass2android/KeePass.cs | 22 ++--- src/keepass2android/NfcOtpActivity.cs | 108 --------------------- src/keepass2android/keepass2android.csproj | 1 - 3 files changed, 9 insertions(+), 122 deletions(-) delete mode 100644 src/keepass2android/NfcOtpActivity.cs diff --git a/src/keepass2android/KeePass.cs b/src/keepass2android/KeePass.cs index c9099215..93aea4e0 100644 --- a/src/keepass2android/KeePass.cs +++ b/src/keepass2android/KeePass.cs @@ -36,24 +36,20 @@ using String = System.String; * =================================== * * Keepass2Android comprises quite a number of different activities and entry points: The app can be started - * using the launcher icon (-> Activity "Keepass"), or by sending a URL (-> FileSelect), opening a .kdb(x)-file (->Password), - * swiping a YubikeyNEO (NfcOtpActivity). - * There is either only the KeePass activity on stack (no db loaded then) or the first activity - * After opening a database (in Password), Password is always the root of the stack (exception: after creating a database, - * FileSelect is the root without Password being open). - * Another exception: QueryCredentialsActivity is root of the stack if an external app is querying credentials. - * QueryCredentialsActivity checks the plugin access permissions, then launches FileSelectActivity (which starts - * the normal stack.) + * using the launcher icon (-> Activity "Keepass"), or by sending a URL (-> SelectCurrentDb) or opening a .kdb(x)-file (->SelectCurrentDb) + * There is either only the KeePass activity on stack (no db loaded then) or the first activity on Stack is SelectCurrentDb * * Some possible stacks: - * Password -> Group ( -> Group (subgroups) ... ) -> EntryView -> EntryEdit + * SelectCurrentDb -> Group ( -> Group (subgroups) ... ) -> EntryView -> EntryEdit * (AdvancedSearch Menu) -> Search -> SearchResults -> EntryView -> EntryEdit * (SearchWidget) -> SearchResults -> EntryView -> EntryEdit - * Password -> ShareUrlResults -> EntryView - * FileSelect -> Group (after Create DB) + * SelectCurrentDb -> ShareUrlResults -> EntryView + * SelectCurrentDb -> Password / CreateDb * + * If the current database changes (e.g. by selecting a search result from another database), the Group/Entry activities of the previously selected database close automatically. + * SelectCurrentDb is only noticable by the user if there are actually several databases, otherwises it either closes or starts another activity when it resumes. * - * In each of these activities, an AppTask may be present and must be passed to started activities and ActivityResults + * In each of the activities SelectCurrentDb/Group/Entry (but not Password/CreateDb/FileSelect), an AppTask may be present and must be passed to started activities and ActivityResults * must be returned. Therefore, if any Activity calls { StartActivity(newActivity);Finish(); }, it must specify FLAG_ACTIVITY_FORWARD_RESULT. * * Further sub-activities may be opened (e.g. Settings -> ExportDb, ...), but these are not necesarrily @@ -70,7 +66,7 @@ using String = System.String; namespace keepass2android { /// - /// Launcher activity of Keepass2Android. This activity usually forwards to FileSelect but may show the revision dialog after installation or updates. + /// Launcher activity of Keepass2Android. This activity usually forwards to SelectCurrentDb but may show the revision dialog after installation or updates. /// [Activity(Label = AppNames.AppName, MainLauncher = false, Theme = "@style/MyTheme_Blue")] [IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { "android.intent.category.LAUNCHER", "android.intent.category.MULTIWINDOW_LAUNCHER" })] diff --git a/src/keepass2android/NfcOtpActivity.cs b/src/keepass2android/NfcOtpActivity.cs deleted file mode 100644 index 0c73c7a1..00000000 --- a/src/keepass2android/NfcOtpActivity.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using Android.App; -using Android.Content; -using Android.Content.PM; -using Android.Nfc; -using Android.OS; -using Android.Widget; -using Java.Util; -using Java.Util.Regex; -using Keepass2android.Yubiclip.Scancode; - -namespace keepass2android -{ - [Activity(Label = "@string/app_name", - ConfigurationChanges = ConfigChanges.Orientation | - ConfigChanges.KeyboardHidden, - NoHistory = true, - ExcludeFromRecents = true, - Theme = "@android:style/Theme.Dialog")] - [IntentFilter(new[] { "android.nfc.action.NDEF_DISCOVERED" }, - Label = "@string/app_name", - Categories = new[] { Intent.CategoryDefault }, - DataHost = "my.yubico.com", - DataPathPrefix = "/neo", - DataScheme = "https")] - public class NfcOtpActivity : Activity - { - private String GetOtpFromIntent(Intent intent) - { - String data = intent.DataString; - Matcher matcher = OtpPattern.Matcher(data); - if (matcher.Matches()) - { - String otp = matcher.Group(1); - return otp; - } - else - { - IParcelable[] raw = Intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages); - - byte[] bytes = ((NdefMessage) raw[0]).ToByteArray(); - bytes = Arrays.CopyOfRange(bytes, DATA_OFFSET, bytes.Length); - String layout = "US"; - KeyboardLayout kbd = KeyboardLayout.ForName(layout); - String otp = kbd.FromScanCodes(bytes); - return otp; - } - return null; - } - - - //private static readonly Java.Util.Regex.Pattern OtpPattern = Java.Util.Regex.Pattern.Compile("^https://my\\.yubico\\.com/neo/(.+)$"); - private static readonly Java.Util.Regex.Pattern OtpPattern = Java.Util.Regex.Pattern.Compile("^https://my\\.yubico\\.com/neo/([a-zA-Z0-9!]+)$"); - private const int DATA_OFFSET = 23; - - private ActivityDesign _design; - - public NfcOtpActivity() - { - _design = new ActivityDesign(this); - } - - protected override void OnCreate(Bundle bundle) - { - _design.ApplyTheme(); - base.OnCreate(bundle); - - - Intent i = new Intent(this, typeof (PasswordActivity)); - i.SetAction(Intents.StartWithOtp); - - //things to consider: - // PasswordActivity should be resumed if currently active -> this is why single top is used and why PasswordActivity is started - // If PasswordActivity is not open already, it may be the wrong place to send our OTP to because maybe the user first needs to select - // a file (which might require UI action like entering credentials, all of which is handled in FileSelectActivity) - // FileSelectActivity is not on the back stack, it finishes itself. - // -> PasswordActivity needs to handle this and return to FSA. - - - i.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop); - try - { - string otp = GetOtpFromIntent(Intent); - if (otp == null) - throw new Exception("Otp must not be null!"); - i.PutExtra(Intents.OtpExtraKey, otp); - } - catch (Exception e) - { - Kp2aLog.LogUnexpectedError(e); - Toast.MakeText(this, "No Yubikey OTP found!", ToastLength.Long).Show(); - Finish(); - return; - } - - StartActivity(i); - Finish(); - - } - - protected override void OnResume() - { - base.OnResume(); - _design.ReapplyTheme(); - } - - } -} \ No newline at end of file diff --git a/src/keepass2android/keepass2android.csproj b/src/keepass2android/keepass2android.csproj index 48f7113b..10fc1839 100644 --- a/src/keepass2android/keepass2android.csproj +++ b/src/keepass2android/keepass2android.csproj @@ -220,7 +220,6 @@ -