remove NfcOtpActivity: not working with current multi-db approach, but also not working since Android has App links

This commit is contained in:
Philipp Crocoll
2018-10-28 07:17:45 +01:00
parent 4f3f18a0ad
commit d9c101debe
3 changed files with 9 additions and 122 deletions

View File

@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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" })]

View File

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

View File

@@ -220,7 +220,6 @@
<Compile Include="FixedDrawerLayout.cs" />
<Compile Include="KpEntryTemplatedEdit.cs" />
<Compile Include="MeasuringRelativeLayout.cs" />
<Compile Include="NfcOtpActivity.cs" />
<Compile Include="PasswordFont.cs" />
<Compile Include="pluginhost\PluginArrayAdapter.cs" />
<Compile Include="pluginhost\PluginDatabase.cs" />