1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-11 13:53:29 +00:00

listen to yubikey

This commit is contained in:
Kyle Spearrin
2019-05-28 09:54:08 -04:00
parent 822fc7f308
commit 58d101659a
4 changed files with 121 additions and 6 deletions

View File

@@ -32,6 +32,8 @@ namespace Bit.Droid
private IBroadcasterService _broadcasterService;
private PendingIntent _lockAlarmPendingIntent;
private AppOptions _appOptions;
private Java.Util.Regex.Pattern _otpPattern =
Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$");
protected override void OnCreate(Bundle savedInstanceState)
{
@@ -70,9 +72,38 @@ namespace Bit.Droid
{
Finish();
}
else if(message.Command == "listenYubiKeyOTP")
{
ListenYubiKey((bool)message.Data);
}
});
}
protected override void OnPause()
{
base.OnPause();
ListenYubiKey(false);
}
protected override void OnResume()
{
base.OnResume();
if(_deviceActionService.SupportsNfc())
{
try
{
_messagingService.Send("resumeYubiKey");
}
catch { }
}
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
ParseYubiKey(intent.DataString);
}
public async override void OnRequestPermissionsResult(int requestCode, string[] permissions,
[GeneratedEnum] Permission[] grantResults)
{
@@ -191,5 +222,19 @@ namespace Bit.Droid
}
return options;
}
private void ParseYubiKey(string data)
{
if(data == null)
{
return;
}
var otpMatch = _otpPattern.Matcher(data);
if(otpMatch.Matches())
{
var otp = otpMatch.Group(1);
_messagingService.Send("gotYubiKeyOTP", otp);
}
}
}
}