Skip to content

Commit

Permalink
Indicate possible otp usage (api change of https://twofactorauth.org/)
Browse files Browse the repository at this point in the history
Update to API version 2 of https://twofactorauth.org/
Version 1 is deprecated and might be removed anytime
  • Loading branch information
Rookiestyle committed Dec 14, 2020
1 parent dc1b294 commit 5a99703
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
27 changes: 18 additions & 9 deletions src/DAO/TFASites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace KeePassOTP
{
public static class TFASites
{
const string TFA_JSON_FILE = "https://twofactorauth.org/api/v2/tfa.json";
public enum TFAPossible
{
Unknown,
Expand Down Expand Up @@ -37,6 +38,7 @@ private enum TFALoadProcess
NotStarted,
Loading,
Loaded,
FileNotFound,
Error
}

Expand Down Expand Up @@ -99,16 +101,17 @@ private static void ReadOTPSites(object s)
{
if (m_LoadState == TFALoadProcess.Loading) return;
if (m_LoadState == TFALoadProcess.Loaded) return;
if (m_LoadState == TFALoadProcess.FileNotFound) return;
m_LoadState = TFALoadProcess.Loading;
}
m_dTFA.Clear();
JsonObject j = null;
bool bException = false;
IOConnectionInfo ioc = IOConnectionInfo.FromPath(TFA_JSON_FILE);
try
{
IOConnectionInfo ioc = IOConnectionInfo.FromPath("https://twofactorauth.org/data.json");
byte[] b = IOConnection.ReadFile(ioc);
j = new JsonObject(new CharStream(StrUtil.Utf8.GetString(b)));
if (b != null) j = new JsonObject(new CharStream(StrUtil.Utf8.GetString(b)));
}
catch (Exception ex)
{
Expand All @@ -117,7 +120,12 @@ private static void ReadOTPSites(object s)
}
if (j == null)
{
lock (m_TFAReadLock) { m_LoadState = TFALoadProcess.Error; }
if (!IOConnection.FileExists(ioc))
{
lock (m_TFAReadLock) { m_LoadState = TFALoadProcess.FileNotFound; }
Tools.ShowError("Error reading OTP sites: File does not exist\n\n" + TFA_JSON_FILE);
}
else lock (m_TFAReadLock) { m_LoadState = TFALoadProcess.Error; }
if (!bException) PluginDebug.AddError("Error reading OTP sites", 0);
return;
}
Expand All @@ -129,16 +137,17 @@ private static void ReadOTPSites(object s)
{
JsonObject k = (kvp.Value as JsonObject).GetValue<JsonObject>(keys[i]);
TFAData tfa = new TFAData();
tfa.tfa = k.GetValue<bool>("tfa", false);
var tfaDetails = k.GetValueArray<string>("tfa");
tfa.tfa = tfaDetails != null && tfaDetails.Length > 0;
if (!tfa.tfa) continue;
tfa.name = k.GetValue<string>("name");
tfa.sms = k.GetValue<bool>("sms", false);
tfa.sms = tfaDetails.Contains("sms") || k.GetValue<bool>("sms", false);
tfa.email = tfaDetails.Contains("email") || k.GetValue<bool>("email", false);
tfa.phone = tfaDetails.Contains("phone") || k.GetValue<bool>("phone", false);
tfa.software = tfaDetails.Contains("software") || k.GetValue<bool>("software", false);
tfa.hardware = tfaDetails.Contains("hardwar") || k.GetValue<bool>("hardware", false);
tfa.url = k.GetValue<string>("url");
tfa.img = k.GetValue<string>("img");
tfa.email = k.GetValue<bool>("email", false);
tfa.phone = k.GetValue<bool>("phone", false);
tfa.software = k.GetValue<bool>("software", false);
tfa.hardware = k.GetValue<bool>("hardware", false);
tfa.doc = k.GetValue<string>("doc");
tfa.category = kvp.Key;
m_dTFA[CreatePattern(tfa.url)] = tfa;
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.22")]
[assembly: AssemblyFileVersion("0.22")]
[assembly: AssemblyVersion("0.23")]
[assembly: AssemblyFileVersion("0.23")]
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
KeePassOTP:0.22
KeePassOTP:0.23
KeePassOTP!de:11
KeePassOTP!fr:3
:

0 comments on commit 5a99703

Please sign in to comment.