Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize legacy totp generation to provide correct totp for steam (keetray totp plugin) #75

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions KeePassNatMsg/Entry/EntrySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,37 +204,41 @@ orderby e.entry.UsageCount
return resp;
}

private void CheckTotp(PwEntryDatabase item, JObject obj)
{
var totp = GetTotpFromEntry(item);
if (!string.IsNullOrEmpty(totp))
{
obj.Add("totp", totp);
}
}

internal string GetTotp(string uuid)
{
var dbEntry = FindEntry(uuid);

if (dbEntry == null || !HasTotp(dbEntry.entry))
if (dbEntry == null)
return null;

var ctx = new SprContext(dbEntry.entry, dbEntry.database, SprCompileFlags.All, false, false);

return SprEngine.Compile(TotpPlaceholder, ctx);
return GetTotpFromEntry(dbEntry);
}

private void CheckTotp(PwEntryDatabase item, JObject obj)
private string GetTotpFromEntry(PwEntryDatabase item)
{
string totp = null;

if (HasTotp(item.entry))
{
// add support for keepass totp
// https://keepass.info/help/base/placeholders.html#otp
totp = GenerateTotp(item, TotpPlaceholder);
}
else if (HasLegacyTotp(item.entry))
if (HasLegacyTotp(item.entry))
{
totp = GenerateTotp(item, TotpLegacyPlaceholder);
}

if (!string.IsNullOrEmpty(totp))
if (string.IsNullOrEmpty(totp) && HasTotp(item.entry))
{
obj.Add("totp", totp);
// add support for keepass totp
// https://keepass.info/help/base/placeholders.html#otp
totp = GenerateTotp(item, TotpPlaceholder);
}
return totp;
}

private string GenerateTotp(PwEntryDatabase item, string placeholder)
Expand Down