add compatibility with steam encoding for OTPs (e.g. otpauth://totp/test:test@example.com?secret=63BEDWCQZKTQWPESARIERL5DTTQFCJTK&issuer=Valve&algorithm=SHA1&digits=5&period=30&encoder=steam)

This commit is contained in:
Philipp Crocoll
2019-11-06 04:50:29 +01:00
parent b5fe3b8ce4
commit 0639201b4c
2 changed files with 14 additions and 5 deletions

View File

@@ -30,13 +30,18 @@ namespace keepass2android
res.TotpSeed = parsedQuery.Get("secret"); res.TotpSeed = parsedQuery.Get("secret");
res.Length = parsedQuery.Get("digits"); res.Length = parsedQuery.Get("digits");
res.Duration = parsedQuery.Get("period"); res.Duration = parsedQuery.Get("period");
res.Encoder = parsedQuery.Get("encoder");
//set defaults according to https://github.com/google/google-authenticator/wiki/Key-Uri-Format //set defaults according to https://github.com/google/google-authenticator/wiki/Key-Uri-Format
if (res.Length == null) if (res.Length == null)
res.Length = "6"; res.Length = "6";
if (res.Duration == null) if (res.Duration == null)
res.Duration = "30"; res.Duration = "30";
if (res.Encoder == null)
res.Encoder = TotpData.EncoderRfc6238;
} }
catch (Exception) catch (Exception e)
{ {
return res; return res;
} }

View File

@@ -3,18 +3,22 @@ using System.Collections.Generic;
namespace PluginTOTP namespace PluginTOTP
{ {
struct TotpData struct TotpData
{ {
public bool IsTotpEnry { get; set; } public const string EncoderSteam = "steam";
public const string EncoderRfc6238 = "rfc6238";
public bool IsTotpEnry { get; set; }
public string TotpSeed { get; set; } public string TotpSeed { get; set; }
public string Duration { get; set; } public string Duration { get; set; }
public string Length { get; set; } public string Encoder { get; set; }
public string Length { get; set; }
public string Url { get; set; } public string Url { get; set; }
public string[] Settings public string[] Settings
{ {
get get
{ {
List<string> settings = new List<string>() { Duration, Length}; List<string> settings = new List<string>() { Duration, Encoder == EncoderSteam ? "S" : Length};
if (Url != null) if (Url != null)
settings.Add(Url); settings.Add(Url);
return settings.ToArray(); return settings.ToArray();