support otpauth:// URIs in otp field as used by KeeWeb (closes #118)
This commit is contained in:
43
src/keepass2android/Totp/KeeWebOtpPluginAdapter.cs
Normal file
43
src/keepass2android/Totp/KeeWebOtpPluginAdapter.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Android.Content;
|
||||
using PluginTOTP;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
internal class KeeWebOtpPluginAdapter : ITotpPluginAdapter
|
||||
{
|
||||
public TotpData GetTotpData(IDictionary<string, string> entryFields, Context ctx, bool muteWarnings)
|
||||
{
|
||||
TotpData res = new TotpData();
|
||||
string data;
|
||||
if (!entryFields.TryGetValue("otp", out data))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
string otpUriStart = "otpauth://totp/";
|
||||
|
||||
if (!data.StartsWith(otpUriStart))
|
||||
return res;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Uri myUri = new Uri(data);
|
||||
var parsedQuery = HttpUtility.ParseQueryString(myUri.Query);
|
||||
res.TotpSeed = parsedQuery.Get("secret");
|
||||
res.Length = parsedQuery.Get("digits");
|
||||
res.Duration = parsedQuery.Get("period");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
res.IsTotpEnry = true;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Android.App;
|
||||
@@ -11,7 +10,7 @@ namespace keepass2android
|
||||
class Kp2aTotp
|
||||
{
|
||||
|
||||
readonly ITotpPluginAdapter[] _pluginAdapters = new ITotpPluginAdapter[] { new TrayTotpPluginAdapter(), new KeeOtpPluginAdapter() };
|
||||
readonly ITotpPluginAdapter[] _pluginAdapters = new ITotpPluginAdapter[] { new TrayTotpPluginAdapter(), new KeeOtpPluginAdapter(), new KeeWebOtpPluginAdapter() };
|
||||
|
||||
public void OnOpenEntry()
|
||||
{
|
||||
|
||||
@@ -102,6 +102,7 @@
|
||||
<Reference Include="Java.Interop" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Mono.Android" />
|
||||
@@ -255,6 +256,7 @@
|
||||
<Compile Include="Totp\Base32.cs" />
|
||||
<Compile Include="Totp\ITotpPluginAdapter.cs" />
|
||||
<Compile Include="Totp\KeeOtpPluginAdapter.cs" />
|
||||
<Compile Include="Totp\KeeWebOtpPluginAdapter.cs" />
|
||||
<Compile Include="Totp\Kp2aTotp.cs" />
|
||||
<Compile Include="Totp\TimeCorrectionProvider.cs" />
|
||||
<Compile Include="Totp\TotpData.cs" />
|
||||
|
||||
Reference in New Issue
Block a user