コード例 #1
0
        private void FieldAction(ToolStripMenuItem Item, string FieldName, FIELD_ACTION action)
        {
            if (Item == null)
            {
                return;
            }

            PwEntry Entry = (PwEntry)Item.Tag;

            if (Entry == null)
            {
                return;
            }
            SetLastOne(Item);
            if (FieldName == PwDefs.PasswordField && PwDefs.IsTanEntry(Entry))
            {
                Entry.ExpiryTime = DateTime.Now;
                Entry.Expires    = true;
                Host.MainWindow.RefreshEntriesList();
                Host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }

            if (action == FIELD_ACTION.CLIPBOARD_COPY)
            {
                ClipboardUtil.CopyAndMinimize(Entry.Strings.GetSafe(FieldName),
                                              true, Program.Config.MainWindow.MinimizeAfterClipboardCopy ?
                                              Host.MainWindow : null, Entry, Host.MainWindow.DocumentManager.ActiveDatabase);
                Host.MainWindow.StartClipboardCountdown();
            }
            else if (action == FIELD_ACTION.DRAG_DROP)
            {
                Item.DoDragDrop(Entry.Strings.ReadSafe(FieldName), DragDropEffects.Copy);
            }
        }
コード例 #2
0
        void otpCopyToolStripItem_Click(object sender, EventArgs e)
        {
            PwEntry entry;

            if (this.GetSelectedSingleEntry(out entry))
            {
                if (!entry.Strings.Exists(OtpAuthData.StringDictionaryKey))
                {
                    if (MessageBox.Show("Must configure TOTP on this entry.  Do you want to do this now?", "Not Configured", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host);
                        form.ShowDialog();
                    }
                }
                else
                {
                    var data = OtpAuthData.FromString(entry.Strings.Get(OtpAuthData.StringDictionaryKey).ReadString());
                    var totp = new Totp(data.Key, step: data.Step, mode: data.OtpHashMode, totpSize: data.Size);
                    var text = totp.ComputeTotp().ToString().PadLeft(data.Size, '0');

                    if (ClipboardUtil.CopyAndMinimize(new KeePassLib.Security.ProtectedString(true, text), true, this.host.MainWindow, entry, this.host.Database))
                    {
                        this.host.MainWindow.StartClipboardCountdown();
                    }
                }
            }
        }
コード例 #3
0
 protected override void CopyCommand(RowObject rowObject)
 {
     if (ClipboardUtil.CopyAndMinimize(rowObject.Value, true, mMainForm, Entry, Database))
     {
         mMainForm.StartClipboardCountdown();
     }
 }
コード例 #4
0
 private void buttonCopyTotp_Click(object sender, EventArgs e)
 {
     if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, this.totp.ComputeTotp().ToString().PadLeft(data.Size, '0')), true, this.host.MainWindow, entry, this.host.Database))
     {
         this.host.MainWindow.StartClipboardCountdown();
     }
     this.Close();
 }
コード例 #5
0
 protected override void CopyCommand(RowObject rowObject)
 {
     if (!IsMultiValuedField(rowObject) &&
         ClipboardUtil.CopyAndMinimize(rowObject.Value, true, mMainForm, Entries.First(), Database))
     {
         mMainForm.StartClipboardCountdown();
     }
 }
コード例 #6
0
 private bool CopyCharToClipboard(char character)
 {
     return(ClipboardUtil.CopyAndMinimize(
                character.ToString(),
                false,
                this,
                null,
                null));
 }
コード例 #7
0
 private bool CopyToClipboard(String characters)
 {
     return(ClipboardUtil.CopyAndMinimize(
                characters,
                false,
                this,
                null,
                null));
 }
コード例 #8
0
 private void OnCopyUrl(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(sURL))
     {
         return;
     }
     if (ClipboardUtil.CopyAndMinimize(sURL, true, this, PasswordChangeAssistantExt.SelectedEntry, Program.MainForm.ActiveDatabase))
     {
         Program.MainForm.StartClipboardCountdown();
     }
 }
コード例 #9
0
        private void btnCopyUser_Click(object sender, EventArgs e)
        {
            MainForm main = m_host.MainWindow;

            if (main.InvokeRequired)
            {
                EventHandler handler = new EventHandler(btnCopyUser_Click);
                main.BeginInvoke(handler, sender, e);
                return;
            }
            ClipboardUtil.CopyAndMinimize(m_entryConfig.User, true, null,
                                          m_entryConfig.Entry, m_host.Database);
            main.StartClipboardCountdown();
        }
コード例 #10
0
        void m_dynCustomStrings_MenuClick(object sender, DynamicMenuEventArgs e)
        {
            PwEntry pe = m_host.MainWindow.GetSelectedEntry(false);

            if (pe == null)
            {
                return;
            }

            if (ClipboardUtil.CopyAndMinimize(pe.Strings.ReadSafe((string)e.Tag), true, m_host.MainWindow, pe, m_host.Database))
            {
                m_host.MainWindow.StartClipboardCountdown();
            }
        }
コード例 #11
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);
     }
 }
コード例 #12
0
        private void buttonCopyUriReload_Click(object sender, EventArgs e)
        {
            if (sharingExpired)
            {
                showQrCodeImage();
            }
            else
            {
                if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, this.uri.AbsoluteUri), true, this.host.MainWindow, this.entry, this.host.Database))
                {
                    this.host.MainWindow.StartClipboardCountdown();
                }

                this.Close();
            }
        }
コード例 #13
0
        internal static void PasswordCopy(ProtectedString ps)
        {
            /* The password string may contain special chars and/or field references
             * Easiest way is to set the provided value as new string field
             * and have KeePass do the rest
             */

            bool bUseFallback = Tools.KeePassVersion < new Version(2, 43);

            if (bUseFallback)
            {
                //Set MinimizeAfterClipboardCopy to false and restore afterwards
                //to ensure neither PwEntryForm nor PCADialog is closed because of minimizing the main window
                bool bMACC = Program.Config.MainWindow.MinimizeAfterClipboardCopy;
                if (bMACC)
                {
                    Program.Config.MainWindow.MinimizeAfterClipboardCopy = false;
                }
                try
                {
                    SetPasswordField(ps);
                    if (ClipboardUtil.CopyAndMinimize(Config.PCAPluginFieldRef, true, Program.MainForm,
                                                      SelectedEntry, Program.MainForm.ActiveDatabase))
                    {
                        Program.MainForm.StartClipboardCountdown();
                    }
                    SetPasswordField(null);
                }
                catch { }
                if (bMACC)
                {
                    Program.Config.MainWindow.MinimizeAfterClipboardCopy = bMACC;
                }
            }
            else
            {
                SetPasswordField(ps);
                if (ClipboardUtil.CopyAndMinimize(Config.PCAPluginFieldRef, true, GlobalWindowManager.TopWindow,
                                                  SelectedEntry, Program.MainForm.ActiveDatabase))
                {
                    Program.MainForm.StartClipboardCountdown();
                }
                SetPasswordField(null);
            }
        }
コード例 #14
0
 private void CopyOtpAndClose()
 {
     if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
     {
         if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, this.otp.getTotpString(OtpTime.getTime())), true, this.host.MainWindow, entry, this.host.Database))
         {
             this.host.MainWindow.StartClipboardCountdown();
         }
     }
     else if (data.Type == OtpType.Hotp)
     {
         if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, this.otp.getHotpString(data.Counter)), true, this.host.MainWindow, entry, this.host.Database))
         {
             this.host.MainWindow.StartClipboardCountdown();
         }
     }
     this.Close();
 }
コード例 #15
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))
                {
                    string[] Settings = SettingsGet(pe);

                    TOTPProvider TOTPGenerator = new TOTPProvider(Settings, ref this.TimeCorrections);

                    string InvalidCharacters;
                    if (SeedValidate(pe, out InvalidCharacters))
                    {
                        pe.Touch(false);

                        string totp = TOTPGenerator.Generate(SeedGet(pe).ReadString().ExtWithoutSpaces());

                        ClipboardUtil.CopyAndMinimize(totp, true, m_host.MainWindow, pe, m_host.MainWindow.ActiveDatabase);
                        m_host.MainWindow.StartClipboardCountdown();
                    }
                    else
                    {
                        MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                    }
                    if (TOTPGenerator.TimeCorrectionError)
                    {
                        MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadUrl);
                    }
                }
                else
                {
                    MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSet);
                }
            }
            else
            {
                MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningNotSet);
            }
        }
コード例 #16
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>
        internal void TOTPCopyToClipboard(PwEntry pe)
        {
            if (TOTPEntryValidator.HasSeed(pe))
            {
                if (TOTPEntryValidator.SettingsValidate(pe))
                {
                    string[] settings = TOTPEntryValidator.SettingsGet(pe);

                    TOTPProvider totpGenerator = new TOTPProvider(settings, this.TimeCorrections);

                    string invalidCharacters;
                    if (TOTPEntryValidator.SeedValidate(pe, out invalidCharacters))
                    {
                        pe.Touch(false);

                        string totp = totpGenerator.Generate(TOTPEntryValidator.SeedGet(pe).ReadString().ExtWithoutSpaces());

                        ClipboardUtil.CopyAndMinimize(totp, true, PluginHost.MainWindow, pe, PluginHost.MainWindow.ActiveDatabase);
                        PluginHost.MainWindow.StartClipboardCountdown();
                    }
                    else
                    {
                        MessageService.ShowWarning(Localization.Strings.ErrorBadSeed + invalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                    }
                    if (totpGenerator.TimeCorrectionError)
                    {
                        MessageService.ShowWarning(Localization.Strings.WarningBadURL);
                    }
                }
                else
                {
                    MessageService.ShowWarning(Localization.Strings.ErrorBadSettings);
                }
            }
            else
            {
                MessageService.ShowWarning(Localization.Strings.ErrorNoSeed);
            }
        }
コード例 #17
0
        internal static bool CopyOTP(PwEntry pe)
        {
            if (!OTPDAO.EnsureOTPUsagePossible(pe))
            {
                PluginDebug.AddError("Copy OTP failed", 0, "Uuid: " + pe.Uuid.ToHexString(), "OTP db not unlocked");
                return(false);
            }
            KPOTP myOTP = OTPDAO.GetOTP(pe);

            if (!myOTP.Valid)
            {
                PluginDebug.AddError("Copy OTP failed", 0, "Uuid: " + pe.Uuid.ToHexString());
                return(false);
            }
            ClipboardUtil.CopyAndMinimize(myOTP.GetOTP(false, true), true, Program.MainForm, pe, Program.MainForm.DocumentManager.SafeFindContainerOf(pe));
            Program.MainForm.StartClipboardCountdown();
            PluginDebug.AddInfo("Copy OTP success", 0, "Uuid: " + pe.Uuid.ToString());
            if (myOTP.Type == KPOTPType.HOTP)
            {
                myOTP.HOTPCounter++;
                OTPDAO.SaveOTP(myOTP, pe);
            }
            return(true);
        }
コード例 #18
0
ファイル: KeeOtp2Ext.cs プロジェクト: tiuub/KeeOtp2
        private void otpCopyToolStripItem_Click(object sender, EventArgs e)
        {
            PwEntry entry;

            if (this.GetSelectedSingleEntry(out entry))
            {
                OtpAuthData data = OtpAuthUtils.loadData(entry);
                if (data == null)
                {
                    if (MessageBox.Show(KeeOtp2Statics.MessageBoxOtpNotConfigured, KeeOtp2Statics.PluginName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host);
                        form.ShowDialog();
                    }
                }
                else
                {
                    OtpBase otp = OtpAuthUtils.getOtp(data);
                    if (data.Type == OtpType.Totp)
                    {
                        if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, otp.getTotpString(OtpTime.getTime())), true, this.host.MainWindow, entry, this.host.Database))
                        {
                            this.host.MainWindow.StartClipboardCountdown();
                        }
                    }
                    else if (data.Type == OtpType.Hotp)
                    {
                        if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, otp.getHotpString(data.Counter)), true, this.host.MainWindow, entry, this.host.Database))
                        {
                            this.host.MainWindow.StartClipboardCountdown();
                        }
                        OtpAuthUtils.increaseHotpCounter(host, data, entry);
                    }
                }
            }
        }