Beispiel #1
0
        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("Must configure TOTP on this entry.  Do you want to do this now?", "Not Configured", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host);
                        form.ShowDialog();
                    }
                }
                else
                {
                    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();
                    }
                }
            }
        }
Beispiel #2
0
        private void AddEdit()
        {
            this.timerUpdateTotp.Enabled = false;
            this.groupboxTotp.Text       = "TOTP";
            this.labelOtp.Text           = "000000";
            this.totp = null;

            var addEditForm = new OtpInformation(this.data, this.entry, this.host);

            var result = addEditForm.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                this.data = OtpAuthUtils.loadData(this.entry);

                if (this.data != null)
                {
                    this.ShowCode();
                }
                else
                {
                    this.Close();
                }
            }
            else if (this.data == null)
            {
                this.Close();
            }
            else
            {
                this.ShowCode();
            }
        }
Beispiel #3
0
        private void AddEdit()
        {
            this.timerUpdateOtp.Enabled = false;
            this.groupboxTotp.Text      = KeeOtp2Statics.TOTP;
            this.labelOtp.Text          = insertSpaceInMiddle("000000");
            this.otp = null;

            OtpInformation addEditForm = new OtpInformation(this.data, this.entry, this.host);

            var result = addEditForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.data = OtpAuthUtils.loadData(this.entry);
                this.otp  = OtpAuthUtils.getOtp(this.data);

                if (this.data != null)
                {
                    this.ShowCode();
                }
                else
                {
                    this.Close();
                }
            }
            else if (this.data == null)
            {
                this.Close();
            }
            else
            {
                this.ShowCode();
            }
        }
Beispiel #4
0
        private void otpConfigureToolStripItem_Click(object sender, EventArgs e)
        {
            PwEntry entry;

            if (GetSelectedSingleEntry(out entry))
            {
                OtpAuthData    data        = OtpAuthUtils.loadData(entry);
                OtpInformation addEditForm = new OtpInformation(data, entry, host);
                addEditForm.ShowDialog();
            }
        }
Beispiel #5
0
        private void backgroundWorkerMigrate_DoWork(object sender, DoWorkEventArgs e)
        {
            PwUuid RecycleBinUuid = this.host.Database.RecycleBinUuid;

            List <PwEntry> entries = new List <PwEntry>();

            entries = this.host.MainWindow.ActiveDatabase.RootGroup.GetEntries(true).ToList();

            int count     = entries.Count;
            int counter   = 0;
            int succeeded = 0;

            labelMigrationStatus.Text = String.Format("Loaded {0} entrie(s)!", count);


            foreach (PwEntry entry in entries)
            {
                if (entry.ParentGroup.Uuid != RecycleBinUuid)
                {
                    if (OtpAuthUtils.checkKeeOtp1Mode(entry))
                    {
                        if (this.migrateAutoType)
                        {
                            entry.AutoType.DefaultSequence = entry.AutoType.DefaultSequence.Replace("{TOTP}", "{TIMEOTP}");
                            foreach (KeePassLib.Collections.AutoTypeAssociation ata in entry.AutoType.Associations)
                            {
                                ata.Sequence = ata.Sequence.Replace("{TOTP}", "{TIMEOTP}");
                            }
                        }

                        OtpAuthData data = OtpAuthUtils.loadData(entry);
                        if (data != null)
                        {
                            OtpAuthUtils.purgeLoadedFields(data, entry);
                            OtpAuthUtils.migrateToBuiltInOtp(data, entry);
                            entry.Touch(true);
                            succeeded++;
                        }
                        else
                        {
                            MessageBox.Show(String.Format("Cant migrate \"{0}\" - \"{1}\"\n(Username: {2})\n\nJust check the format of the \"key\" string.", entry.ParentGroup.Name, entry.Strings.ReadSafe(PwDefs.TitleField), entry.Strings.ReadSafe(PwDefs.UserNameField)), "Migration Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                counter++;
                labelMigrationStatus.Text = String.Format("Done {0} of {1} entries!", counter, count);
            }

            if (succeeded > 0)
            {
                this.host.MainWindow.ActiveDatabase.Modified = true;
                this.host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }
        }
Beispiel #6
0
 private void FormWasShown()
 {
     this.data = OtpAuthUtils.loadData(this.entry);
     if (this.data == null)
     {
         this.AddEdit();
     }
     else
     {
         ShowCode();
     }
 }
Beispiel #7
0
 private void linkLabelIncorrectNext_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
     {
         Troubleshooting troubleshooting = new Troubleshooting(this.host);
         troubleshooting.ShowDialog();
     }
     else if (data.Type == OtpType.Hotp)
     {
         OtpAuthUtils.increaseHotpCounter(host, data, entry);
         this.data = OtpAuthUtils.loadData(this.entry);
     }
 }
Beispiel #8
0
        void SprEngine_FilterCompile(object sender, SprEventArgs e)
        {
            if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
            {
                if (e.Text.IndexOf(totpPlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    OtpAuthData data = OtpAuthUtils.loadData(e.Context.Entry);
                    if (data != null)
                    {
                        var totp = new Totp(data.Key, step: data.Step, mode: data.OtpHashMode, totpSize: data.Size);
                        var text = totp.ComputeTotp().ToString().PadLeft(data.Size, '0');

                        e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, "{TOTP}", text);
                    }
                }
            }
        }
Beispiel #9
0
 // If built-in {TIMEOTP} placeholder is used, but KeeOtp1 Save Mode is used
 private void SprEngine_FilterCompilePre(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
     {
         string currentPlaceHolder = null;
         if (e.Text.IndexOf(BuiltInTotpPlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             currentPlaceHolder = BuiltInTotpPlaceHolder;
         }
         else if (e.Text.IndexOf(BuiltInHotpPlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             currentPlaceHolder = BuiltInHotpPlaceHolder;
         }
         if (!string.IsNullOrEmpty(currentPlaceHolder))
         {
             PwEntry     entry = e.Context.Entry;
             OtpAuthData data  = OtpAuthUtils.loadData(entry);
             if (data != null)
             {
                 if (!OtpAuthUtils.checkBuiltInMode(entry) ||
                     (OtpAuthUtils.checkEntry(entry) && OtpTime.getOverrideBuiltInTime() && (OtpTime.getTimeType() == OtpTimeType.FixedOffset || OtpTime.getTimeType() == OtpTimeType.CustomNtpServer)) ||
                     !data.Proprietary)
                 {
                     OtpBase otp = OtpAuthUtils.getOtp(data);
                     if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
                     {
                         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, currentPlaceHolder, otp.getTotpString(OtpTime.getTime()));
                     }
                     else if (data.Type == OtpType.Hotp)
                     {
                         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, currentPlaceHolder, otp.getHotpString(data.Counter));
                         OtpAuthUtils.increaseHotpCounter(host, data, entry);
                     }
                 }
             }
         }
     }
 }
Beispiel #10
0
        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);
                    }
                }
            }
        }
Beispiel #11
0
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
     {
         if (e.Text.IndexOf(KeeOtp1PlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             PwEntry     entry = e.Context.Entry;
             OtpAuthData data  = OtpAuthUtils.loadData(entry);
             if (data != null)
             {
                 OtpBase otp = OtpAuthUtils.getOtp(data);
                 if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
                 {
                     e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, KeeOtp1PlaceHolder, otp.getTotpString(OtpTime.getTime()));
                 }
                 else if (data.Type == OtpType.Hotp)
                 {
                     e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, KeeOtp1PlaceHolder, otp.getHotpString(data.Counter));
                     OtpAuthUtils.increaseHotpCounter(host, data, entry);
                 }
             }
         }
     }
 }
Beispiel #12
0
        private void backgroundWorkerMigrate_DoWork(object sender, DoWorkEventArgs e)
        {
            PwUuid RecycleBinUuid = this.host.Database.RecycleBinUuid;

            List <PwEntry> entries = new List <PwEntry>();

            entries = this.host.MainWindow.ActiveDatabase.RootGroup.GetEntries(true).ToList();

            int count     = entries.Count;
            int counter   = 0;
            int succeeded = 0;

            labelStatus.Text = String.Format(KeeOtp2Statics.SettingsLoadedNEntries, count);

            foreach (PwEntry entry in entries)
            {
                if (entry.ParentGroup.Uuid != RecycleBinUuid)
                {
                    if (checkEntryMigratable(entry, currentMigrationProfile.migrationMode))
                    {
                        OtpAuthData data = OtpAuthUtils.loadData(entry);
                        if (data != null)
                        {
                            entry.CreateBackup(this.host.Database);
                            switch (currentMigrationProfile.migrationMode)
                            {
                            case MigrationMode.KeeOtp1ToBuiltIn:
                                if (!data.isForcedKeeOtp1Mode())
                                {
                                    OtpAuthUtils.migrateToBuiltInOtp(data, entry);
                                    if (OtpAuthUtils.loadDataFromKeeOtp1String(entry) != null)
                                    {
                                        if (removeAfterMigration)
                                        {
                                            OtpAuthUtils.purgeLoadedFields(data, entry);
                                        }
                                    }
                                }
                                else
                                {
                                    encounteredForcedKeeOtp1Entries = true;
                                }
                                break;

                            case MigrationMode.BuiltInToKeeOtp1:
                                OtpAuthUtils.migrateToKeeOtp1String(data, entry);
                                if (OtpAuthUtils.loadDataFromKeeOtp1String(entry) != null)
                                {
                                    if (removeAfterMigration)
                                    {
                                        OtpAuthUtils.purgeLoadedFields(data, entry);
                                    }
                                }
                                break;

                            default:
                                break;
                            }

                            if (migrateAutoType)
                            {
                                foreach (string currentPlaceholder in currentMigrationProfile.findPlaceholder.Values)
                                {
                                    OtpAuthUtils.replacePlaceholder(entry, currentPlaceholder, currentMigrationProfile.replacePlaceholder[data.Type]);
                                }
                            }
                            entry.Touch(true);
                            succeeded++;
                        }
                        else
                        {
                            this.Invoke((Action)(() =>
                            {
                                if (MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxCantParseEntry, entry.ParentGroup.Name, entry.Strings.ReadSafe(PwDefs.TitleField), entry.Strings.ReadSafe(PwDefs.UserNameField)), KeeOtp2Statics.Migration, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                                {
                                    backgroundWorkerMigrate.CancelAsync();
                                }
                            }));
                        }
                    }
                }
                counter++;
                labelStatus.Text = String.Format(KeeOtp2Statics.SettingsDoneNofNEntries, counter, count);
            }

            if (succeeded > 0)
            {
                this.host.MainWindow.ActiveDatabase.Modified = true;
                this.host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }
        }