Пример #1
0
 private void timerUpdateTotp_Tick(object sender, EventArgs e)
 {
     if (textBoxKey.Text.Length > 0)
     {
         try
         {
             OtpAuthData data = readData();
             OtpBase     otp  = OtpAuthUtils.getOtp(data);
             if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
             {
                 groupBoxKey.Text = String.Format(KeeOtp2Statics.OtpInformationKeyUriTotpPreview, otp.getTotpString(OtpTime.getTime()), otp.getRemainingSeconds(OtpTime.getTime()));
             }
             else if (data.Type == OtpType.Hotp)
             {
                 groupBoxKey.Text = String.Format(KeeOtp2Statics.OtpInformationKeyUriHotpPreview, otp.getHotpString(data.Counter));
             }
         }
         catch
         {
             groupBoxKey.Text = KeeOtp2Statics.OtpInformationKeyUriInvalid;
         }
     }
     else
     {
         groupBoxKey.Text = KeeOtp2Statics.OtpInformationKeyUri;
     }
 }
Пример #2
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();
            }
        }
Пример #3
0
 private void ShowCode()
 {
     this.otp = OtpAuthUtils.getOtp(data);
     if (data.Type == OtpType.Hotp)
     {
         increaseHotpAfterClosing = true;
     }
     this.timerUpdateOtp.Enabled = true;
 }
Пример #4
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);
                     }
                 }
             }
         }
     }
 }
Пример #5
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);
                    }
                }
            }
        }
Пример #6
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);
                 }
             }
         }
     }
 }