1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-17 15:27:43 +01:00

read yubikey otp via nfc

This commit is contained in:
Kyle Spearrin 2017-06-27 23:33:13 -04:00
parent e2a3e55a17
commit cf41b524b0
2 changed files with 41 additions and 0 deletions

View File

@ -15,6 +15,7 @@ using Xamarin.Forms;
using System.Threading.Tasks;
using Bit.App.Models.Page;
using Bit.App;
using Android.Nfc;
namespace Bit.Android
{
@ -26,6 +27,7 @@ namespace Bit.Android
{
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
private DateTime? _lastAction;
private Java.Util.Regex.Pattern _otpPattern = Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$");
protected override void OnCreate(Bundle bundle)
{
@ -102,6 +104,12 @@ namespace Bit.Android
{
LaunchApp(args);
});
MessagingCenter.Subscribe<Xamarin.Forms.Application>(
Xamarin.Forms.Application.Current, "ListenYubiKeyOTP", (sender) =>
{
ListenYubiKey();
});
}
private void ReturnCredentials(VaultListPageModel.Login login)
@ -228,5 +236,37 @@ namespace Bit.Android
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);
}
}
}
}
}

View File

@ -3,6 +3,7 @@
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
<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.USE_FINGERPRINT" />
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />