예제 #1
0
 public static void loadConfig()
 {
     registerHotKey();
     if (OtpTime.getTimeType() == OtpTimeType.CustomNtpServer)
     {
         OtpTime.pollCustomNtpServer();
     }
 }
예제 #2
0
파일: Settings.cs 프로젝트: tiuub/KeeOtp2
        private void loadConfig()
        {
            textBoxHotKeySequence.Text = KeeOtp2Config.HotKeySequence;
            Keys hotKey = KeeOtp2Config.HotKeyKeys;

            hotKeyControlExGlobalHotkey.HotKey = hotKey;
            if (KeeOtp2Config.UseHotKey && hotKey != Keys.None)
            {
                checkBoxUseHotkey.Checked           = true;
                textBoxHotKeySequence.Enabled       = true;
                hotKeyControlExGlobalHotkey.Enabled = true;
            }
            else
            {
                checkBoxUseHotkey.Checked           = false;
                textBoxHotKeySequence.Enabled       = false;
                hotKeyControlExGlobalHotkey.Enabled = false;
            }

            radioButtonSystemTime.Checked                         =
                radioButtonFixedTimeOffset.Checked                =
                    numericUpDownFixedTimeOffset.Enabled          =
                        radioButtonCustomNtpServer.Checked        =
                            textBoxCustomNTPServerAddress.Enabled = false;
            switch (OtpTime.getTimeType())
            {
            case OtpTimeType.SystemTime:
                radioButtonSystemTime.Checked = true;
                break;

            case OtpTimeType.FixedOffset:
                radioButtonFixedTimeOffset.Checked   = true;
                numericUpDownFixedTimeOffset.Enabled = true;
                break;

            case OtpTimeType.CustomNtpServer:
                radioButtonCustomNtpServer.Checked    = true;
                textBoxCustomNTPServerAddress.Enabled = true;
                OtpTime.pollCustomNtpServer();
                break;

            default:
                radioButtonSystemTime.Checked = true;
                break;
            }
            numericUpDownFixedTimeOffset.Value  = OtpTime.getFixedTimeOffset();
            textBoxCustomNTPServerAddress.Text  = OtpTime.getCustomNtpServer();
            checkBoxOverrideBuiltInTime.Checked = OtpTime.getOverrideBuiltInTime();
        }
예제 #3
0
        private void UpdateDisplay()
        {
            if (reloadCount > reloadDataDelay * (1000 / timerUpdateOtp.Interval))
            {
                loadData();
                reloadCount = 0;
            }
            reloadCount++;

            if (this.otp != null)
            {
                if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
                {
                    this.linkLabelIncorrectNext.Text = KeeOtp2Statics.ShowOtpIncorrect;
                    this.labelOtp.Text     = insertSpaceInMiddle(otp.getTotpString(OtpTime.getTime()));
                    this.groupboxTotp.Text = String.Format(KeeOtp2Statics.ShowOtpNextRemaining, otp.getRemainingSeconds(OtpTime.getTime()).ToString().PadLeft(2, '0'), insertSpaceInMiddle(otp.getTotpString(OtpTime.getTime().AddSeconds(data.Period))));
                }
                else if (data.Type == OtpType.Hotp)
                {
                    this.linkLabelIncorrectNext.Text = KeeOtp2Statics.ShowOtpNextCode;
                    this.labelOtp.Text     = insertSpaceInMiddle(otp.getHotpString(data.Counter));
                    this.groupboxTotp.Text = String.Format(KeeOtp2Statics.ShowOtpNextCounter, data.Counter, insertSpaceInMiddle(otp.getHotpString(data.Counter + 1)));
                }
                if (labelOtp.Width - TextRenderer.MeasureText(labelOtp.Text, new Font(labelOtp.Font.FontFamily, labelOtp.Font.Size, labelOtp.Font.Style)).Width > 30)
                {
                    labelOtp.Font = new Font(labelOtp.Font.FontFamily, 48f, labelOtp.Font.Style);
                }
                else
                {
                    while (labelOtp.Width < TextRenderer.MeasureText(labelOtp.Text, new Font(labelOtp.Font.FontFamily, labelOtp.Font.Size, labelOtp.Font.Style)).Width)
                    {
                        labelOtp.Font = new Font(labelOtp.Font.FontFamily, labelOtp.Font.Size - 0.5f, labelOtp.Font.Style);
                    }
                }
            }
            else
            {
                if (MessageBox.Show(KeeOtp2Statics.MessageBoxOtpNotConfigured, KeeOtp2Statics.ShowOtp, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    AddEdit();
                }
                else
                {
                    this.Close();
                }
            }
        }
예제 #4
0
파일: Settings.cs 프로젝트: tiuub/KeeOtp2
        private void timerClock_Tick(object sender, EventArgs e)
        {
            DateTime dateTime;

            if (radioButtonSystemTime.Checked)
            {
                dateTime = OtpTime.getTime(OtpTimeType.SystemTime);
            }
            else if (radioButtonFixedTimeOffset.Checked)
            {
                dateTime = OtpTime.getTimeFixedOffset((long)numericUpDownFixedTimeOffset.Value);
            }
            else if (radioButtonCustomNtpServer.Checked)
            {
                dateTime = OtpTime.getTimeCustomNTPServer(true);
            }
            else
            {
                dateTime = OtpTime.getTime();
            }
            labelTime.Text = String.Format(KeeOtp2Statics.SettingsPreviewUtc, dateTime.ToLongTimeString());
        }
예제 #5
0
파일: KeeOtp2Ext.cs 프로젝트: tiuub/KeeOtp2
 // 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);
                     }
                 }
             }
         }
     }
 }
예제 #6
0
        private void Client_TimeReceived(object sender, NtpTimeReceivedEventArgs e)
        {
            this.buttonPingNTPServer.Visible = true;

            TimeSpan timeDifference = OtpTime.getTime().Subtract(e.CurrentTime);

            this.Invoke((Action)(() =>
            {
                if (-5000 < timeDifference.TotalMilliseconds && timeDifference.TotalMilliseconds < 5000)
                {
                    MessageBox.Show(String.Format(KeeOtp2Statics.TroubleshootingPingResultOk, Math.Round(Math.Abs(timeDifference.TotalMilliseconds)), Math.Round(Math.Abs((float)timeDifference.TotalMilliseconds / 1000), 1), (timeDifference.TotalMilliseconds < 0 ? "behind" : "before")), "NTP Request", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (-30000 < timeDifference.TotalMilliseconds && timeDifference.TotalMilliseconds < 30000)
                {
                    MessageBox.Show(String.Format(KeeOtp2Statics.TroubleshootingPingResultModerate, Math.Round(Math.Abs(timeDifference.TotalMilliseconds)), Math.Round(Math.Abs((float)timeDifference.TotalMilliseconds / 1000), 1), (timeDifference.TotalMilliseconds < 0 ? "behind" : "before")), "NTP Request", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(String.Format(KeeOtp2Statics.TroubleshootingPingResultBad, Math.Round(Math.Abs(timeDifference.TotalMilliseconds)), Math.Round(Math.Abs((float)timeDifference.TotalMilliseconds / 1000), 1), (timeDifference.TotalMilliseconds < 0 ? "behind" : "before")), "NTP Request", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }));
            this.Enabled = true;
        }
예제 #7
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;
     }
 }
예제 #8
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);
                    }
                }
            }
        }
예제 #9
0
파일: KeeOtp2Ext.cs 프로젝트: tiuub/KeeOtp2
 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);
                 }
             }
         }
     }
 }
예제 #10
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();
 }
예제 #11
0
파일: Settings.cs 프로젝트: tiuub/KeeOtp2
 private void buttonCustomNTPServerOK_Click(object sender, EventArgs e)
 {
     textBoxCustomNTPServerAddress.Enabled = false;
     OtpTime.pollCustomNtpServer(textBoxCustomNTPServerAddress.Text);
     textBoxCustomNTPServerAddress.Enabled = true;
 }