mirror of
https://github.com/bitwarden/mobile
synced 2025-12-11 13:53:29 +00:00
listen to yubikey
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user