mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 02:18:27 +03:00
read yubikey otp via nfc
This commit is contained in:
parent
e2a3e55a17
commit
cf41b524b0
2 changed files with 41 additions and 0 deletions
|
@ -15,6 +15,7 @@ using Xamarin.Forms;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bit.App.Models.Page;
|
using Bit.App.Models.Page;
|
||||||
using Bit.App;
|
using Bit.App;
|
||||||
|
using Android.Nfc;
|
||||||
|
|
||||||
namespace Bit.Android
|
namespace Bit.Android
|
||||||
{
|
{
|
||||||
|
@ -26,6 +27,7 @@ namespace Bit.Android
|
||||||
{
|
{
|
||||||
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
|
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
|
||||||
private DateTime? _lastAction;
|
private DateTime? _lastAction;
|
||||||
|
private Java.Util.Regex.Pattern _otpPattern = Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$");
|
||||||
|
|
||||||
protected override void OnCreate(Bundle bundle)
|
protected override void OnCreate(Bundle bundle)
|
||||||
{
|
{
|
||||||
|
@ -102,6 +104,12 @@ namespace Bit.Android
|
||||||
{
|
{
|
||||||
LaunchApp(args);
|
LaunchApp(args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
MessagingCenter.Subscribe<Xamarin.Forms.Application>(
|
||||||
|
Xamarin.Forms.Application.Current, "ListenYubiKeyOTP", (sender) =>
|
||||||
|
{
|
||||||
|
ListenYubiKey();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReturnCredentials(VaultListPageModel.Login login)
|
private void ReturnCredentials(VaultListPageModel.Login login)
|
||||||
|
@ -228,5 +236,37 @@ namespace Bit.Android
|
||||||
StartActivity(launchIntent);
|
StartActivity(launchIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ListenYubiKey()
|
||||||
|
{
|
||||||
|
var intent = new Intent(this, Class);
|
||||||
|
intent.AddFlags(ActivityFlags.SingleTop);
|
||||||
|
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);
|
||||||
|
|
||||||
|
// register for all NDEF tags starting with http och https
|
||||||
|
var ndef = new IntentFilter(NfcAdapter.ActionNdefDiscovered);
|
||||||
|
ndef.AddDataScheme("http");
|
||||||
|
ndef.AddDataScheme("https");
|
||||||
|
|
||||||
|
// register for foreground dispatch so we'll receive tags according to our intent filters
|
||||||
|
var adapter = NfcAdapter.GetDefaultAdapter(this);
|
||||||
|
adapter.EnableForegroundDispatch(this, pendingIntent, new IntentFilter[] { ndef }, null);
|
||||||
|
|
||||||
|
var data = Intent.DataString;
|
||||||
|
if(data != null)
|
||||||
|
{
|
||||||
|
var otpMatch = _otpPattern.Matcher(data);
|
||||||
|
if(otpMatch.Matches())
|
||||||
|
{
|
||||||
|
var otp = otpMatch.Group(1);
|
||||||
|
Console.WriteLine("Got OTP: " + otp);
|
||||||
|
MessagingCenter.Send(Xamarin.Forms.Application.Current, "GotYubiKeyOTP", otp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Data from ndef didn't match, it was: " + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
|
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||||
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
|
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
|
||||||
|
|
Loading…
Reference in a new issue