From 55c42666350224385e98a1b7b74a9c3285f5377e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20K=C3=B6gel?= Date: Sat, 14 Aug 2021 17:55:51 +0200 Subject: [PATCH] Prioritize legacy totp generation to provide correct totp for steam (keetray totp plugin) --- KeePassNatMsg/Entry/EntrySearch.cs | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/KeePassNatMsg/Entry/EntrySearch.cs b/KeePassNatMsg/Entry/EntrySearch.cs index eb60a9f..ab7897c 100644 --- a/KeePassNatMsg/Entry/EntrySearch.cs +++ b/KeePassNatMsg/Entry/EntrySearch.cs @@ -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)