コード例 #1
0
 public override void Run()
 {
     try
     {
         if (App.Kp2a.GetDb().LastOpenedEntry == null)
         {
             return;                     //DB was locked
         }
         Dictionary <string, string> entryFields = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString());
         //mute warnings to avoid repeated display of the toasts
         TotpData totpData = _adapter.GetTotpData(entryFields, _context, true /*mute warnings*/);
         if (totpData.IsTotpEnry)
         {
             //generate a new totp
             Totp_Provider prov = new Totp_Provider(totpData.Duration, totpData.Length);
             string        totp = prov.Generate(Base32.Decode(totpData.TotpSeed));
             //update entry and keyboard
             UpdateEntryData(totp);
             //broadcast new field value (update EntryActivity). this might result in another keyboard
             //update, but that's inexpensive and relatively rare
             BroadcastNewTotp(totp);
             //restart timer
             new Timer().Schedule(new UpdateTotpTimerTask(_context, _adapter), 1000 * prov.Timer);
         }
     }
     catch (Exception e)
     {
         Android.Util.Log.Debug(_totp, e.ToString());
     }
 }
コード例 #2
0
 /// <summary>
 /// Copies the specified entry's generated TOTP to the clipboard using the KeePass's clipboard function.
 /// </summary>
 /// <param name="pe">Password Entry.</param>
 private void TotpCopyToClipboard(PwEntry pe)
 {
     if (SettingsCheck(pe) && SeedCheck(pe))
     {
         bool ValidInterval; bool ValidLength; bool ValidUrl;
         if (SettingsValidate(pe, out ValidInterval, out ValidLength, out ValidUrl))
         {
             bool     NoTimeCorrection = false;
             string[] Settings         = SettingsGet(pe);
             var      TotpGenerator    = new Totp_Provider(Convert.ToInt16(Settings[0]), Convert.ToInt16(Settings[1]));
             if (ValidUrl)
             {
                 var CurrentTimeCorrection = TimeCorrections[Settings[2]];
                 if (CurrentTimeCorrection != null)
                 {
                     TotpGenerator.TimeCorrection = CurrentTimeCorrection.TimeCorrection;
                 }
                 else
                 {
                     TotpGenerator.TimeCorrection = TimeSpan.Zero;
                     NoTimeCorrection             = true;
                 }
             }
             string InvalidCharacters;
             if (SeedValidate(pe, out InvalidCharacters))
             {
                 pe.Touch(false);
                 ClipboardUtil.CopyAndMinimize(TotpGenerator.Generate(Base32.Decode(SeedGet(pe).ReadString().ExtWithoutSpaces())), true, m_host.MainWindow, pe, m_host.MainWindow.ActiveDatabase);
                 m_host.MainWindow.StartClipboardCountdown();
             }
             else
             {
                 MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
             }
             if (NoTimeCorrection)
             {
                 MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadUrl);
             }
         }
         else
         {
             MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSet);
         }
     }
     else
     {
         MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningNotSet);
     }
 }
コード例 #3
0
 /// <summary>
 /// Tells KeePass what to display in the column.
 /// </summary>
 /// <param name="strColumnName"></param>
 /// <param name="pe"></param>
 /// <returns>String displayed in the columns.</returns>
 public override string GetCellData(string strColumnName, PwEntry pe)
 {
     if (strColumnName == null)
     {
         throw new ArgumentNullException("strColumnName");
     }
     if (pe == null)
     {
         throw new ArgumentNullException("pe");
     }
     if (plugin.SettingsCheck(pe) && plugin.SeedCheck(pe))
     {
         bool ValidInterval;
         bool ValidLength;
         bool ValidUrl;
         if (plugin.SettingsValidate(pe, out ValidInterval, out ValidLength, out ValidUrl))
         {
             string[] Settings      = plugin.SettingsGet(pe);
             var      TotpGenerator = new Totp_Provider(Convert.ToInt16(Settings[0]), Convert.ToInt16(Settings[1]));
             if (ValidUrl)
             {
                 var TimeCorrection = plugin.TimeCorrections[Settings[2]];
                 if (TimeCorrection == null)
                 {
                     return(TrayTotp_CustomColumn_Localization.strWarningBadUrl);
                 }
                 TotpGenerator.TimeCorrection = TimeCorrection.TimeCorrection;
             }
             if (plugin.SeedValidate(pe))
             {
                 return(TotpGenerator.Generate(Base32.Decode(plugin.SeedGet(pe).ReadString().ExtWithoutSpaces())) + (m_host.CustomConfig.GetBool(setname_bool_TotpColumnTimer_Visible, true) ? TotpGenerator.Timer.ToString().ExtWithParenthesis().ExtWithSpaceBefore() : string.Empty));
             }
             return(TrayTotp_CustomColumn_Localization.strWarningBadSeed);
         }
         return(TrayTotp_CustomColumn_Localization.strWarningBadSet);
     }
     return(plugin.SettingsCheck(pe) || plugin.SeedCheck(pe) ? TrayTotp_CustomColumn_Localization.strWarningStorage : string.Empty);
 }
コード例 #4
0
 /// <summary>
 /// Auto-Type Function.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
     {
         if (e.Text.IndexOf(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             if (SettingsCheck(e.Context.Entry) && SeedCheck(e.Context.Entry))
             {
                 bool ValidInterval = false; bool ValidLength = false; bool ValidUrl = false;
                 if (SettingsValidate(e.Context.Entry, out ValidInterval, out ValidLength, out ValidUrl))
                 {
                     bool     NoTimeCorrection = false;
                     string[] Settings         = SettingsGet(e.Context.Entry);
                     var      TotpGenerator    = new Totp_Provider(Convert.ToInt16(Settings[0]), Convert.ToInt16(Settings[1]));
                     if (ValidUrl)
                     {
                         var CurrentTimeCorrection = TimeCorrections[Settings[2]];
                         if (CurrentTimeCorrection != null)
                         {
                             TotpGenerator.TimeCorrection = CurrentTimeCorrection.TimeCorrection;
                         }
                         else
                         {
                             TotpGenerator.TimeCorrection = TimeSpan.Zero;
                             NoTimeCorrection             = true;
                         }
                     }
                     string InvalidCharacters;
                     if (SeedValidate(e.Context.Entry, out InvalidCharacters))
                     {
                         e.Context.Entry.Touch(false);
                         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), TotpGenerator.Generate(Base32.Decode(SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces())));
                     }
                     else
                     {
                         e.Text = string.Empty;
                         MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                     }
                     if (NoTimeCorrection)
                     {
                         MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadUrl);
                     }
                 }
                 else
                 {
                     e.Text = string.Empty;
                     MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSet);
                 }
             }
             else
             {
                 e.Text = string.Empty;
                 MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningNotSet);
             }
         }
     }
 }