private void linkLabelLoadUriScanQR_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (scanQRMode) { if (MessageBox.Show(KeeOtp2Statics.MessageBoxScanQrCode, KeeOtp2Statics.OtpInformationScanQr, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { scanQRCode(); } } else { try { this.data = OtpAuthUtils.uriToOtpAuthData(new Uri(textBoxKey.Text)); loadData(); } catch (InvalidBase32FormatException ex) { MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidBase32Format, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidUriFormat ex) { MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidUriFormat, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxException, ex.Message), KeeOtp2Statics.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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(); } }
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; } }
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(); } } } }
public OtpInformation(OtpAuthData data, KeePassLib.PwEntry entry, IPluginHost host) { InitializeComponent(); this.Shown += (sender, e) => FormWasShown(); pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width, pictureBoxBanner.Height, KeePass.UI.BannerStyle.Default, Resources.lock_key.GetThumbnailImage(32, 32, null, IntPtr.Zero), "Configuration", "Set up the key for generating one time passwords"); this.Icon = host.MainWindow.Icon; this.Data = data; this.entry = entry; this.host = host; if (this.Data != null && this.Data.KeeOtp1Mode) { buttonMigrate.Visible = true; pictureBoxMigrateQuestionmark.Visible = true; pictureBoxMigrateQuestionmark.Image = SystemIcons.Question.ToBitmap(); ToolTip toolTip = new ToolTip(); toolTip.ToolTipTitle = "Why am I seeing this?"; toolTip.IsBalloon = true; toolTip.SetToolTip(buttonMigrate, "Since KeePass 2.47, TOTPs can generated by a built-in function.\nYou can use this button to easily migrate to the built-in function.\n\n(It is also recommended!)"); toolTip.SetToolTip(pictureBoxMigrateQuestionmark, "Since KeePass 2.47, TOTPs can generated by a built-in function.\nYou can use this button to easily migrate to the built-in function.\n\n(It is also recommended!)"); } }
public static Uri otpAuthDataToUri(PwEntry entry, OtpAuthData data) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = uriScheme; uriBuilder.Host = data.Type.ToString().ToLower(); uriBuilder.Path = String.Format("{0}:{1}", entry.Strings.ReadSafe(PwDefs.TitleField), entry.Strings.ReadSafe(PwDefs.UserNameField)); List <string> parameters = new List <string>(); parameters.Add(String.Format("{0}={1}", uriSecretKey, data.GetPlainSecret())); parameters.Add(String.Format("{0}={1}", uriIssuerKey, Uri.EscapeDataString(entry.Strings.ReadSafe(PwDefs.TitleField)))); if (data.Algorithm != OtpHashMode.Sha1) { parameters.Add(String.Format("{0}={1}", uriAlgorithmKey, data.Algorithm.ToString())); } if (data.Digits != 6) { parameters.Add(String.Format("{0}={1}", uriDigitsKey, data.Digits)); } if (data.Type == OtpType.Hotp) { parameters.Add(String.Format("{0}={1}", uriCounterKey, data.Counter)); } if (data.Period != 30) { parameters.Add(String.Format("{0}={1}", uriPeriodKey, data.Period)); } uriBuilder.Query = String.Join("&", parameters.ToArray()); return(uriBuilder.Uri); }
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(); } }
public static OtpAuthData uriToOtpAuthData(Uri uri) { if (uri.Scheme == "otpauth") { OtpAuthData data = new OtpAuthData(); data.Type = (OtpType)Enum.Parse(typeof(OtpType), uri.Host, true); string query = uri.Query; if (query.StartsWith("?")) { query = query.TrimStart('?'); } NameValueCollection parameters = ParseQueryString(query); if (parameters[uriSecretKey] != null) { if (data.Type == OtpType.Totp && parameters[KeeOtp1EncoderParameter] != null) { data.Type = (OtpType)Enum.Parse(typeof(OtpType), parameters[KeeOtp1EncoderParameter], true); } data.Encoding = OtpSecretEncoding.Base32; string secret = correctPlainSecret(parameters[uriSecretKey], data.Encoding); // Validate secret (catch) OtpAuthUtils.validatePlainSecret(secret, data.Encoding); data.SetPlainSecret(secret); if (parameters[uriAlgorithmKey] != null) { data.Algorithm = (OtpHashMode)Enum.Parse(typeof(OtpHashMode), parameters[uriAlgorithmKey], true); } if (data.Type == OtpType.Totp) { data.Period = GetIntOrDefault(parameters, uriPeriodKey, 30); } else if (data.Type == OtpType.Hotp) { data.Counter = GetIntOrDefault(parameters, uriCounterKey, 0); } data.Digits = GetIntOrDefault(parameters, uriDigitsKey, 6); return(data); } else { throw new InvalidUriFormat("The Uri does not contain a secret. A secret is required!"); } } else { throw new InvalidUriFormat("Given Uri does not start with 'otpauth://'!"); } }
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); } }
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(); } }
private void FormWasShown() { this.data = OtpAuthUtils.loadData(this.entry); if (this.data == null) { this.AddEdit(); } else { ShowCode(); } }
public static string getOtpString(OtpAuthData data) { if (data.Type == OtpType.Totp || data.Type == OtpType.Steam) { return(getTotpString(data, DateTime.UtcNow)); } else if (data.Type == OtpType.Hotp) { return(getOtp(data).getHotpString(data.Counter)); } throw new InvalidOtpConfiguration(); }
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); } }
public static PwEntry purgeLoadedFields(OtpAuthData data, PwEntry entry) { if (data != null && data.loadedFields != null) { foreach (string field in data.loadedFields) { if (entry.Strings.Exists(field)) { entry.Strings.Remove(field); } } } return(entry); }
public static PwEntry migrateToKeeOtp1String(OtpAuthData data, PwEntry entry) { NameValueCollection collection = new NameValueCollection(); collection.Add(KeeOtp1KeyParameter, data.GetPlainSecret()); if (data.Type != OtpType.Totp) { collection.Add(KeeOtp1TypeParameter, data.Type.ToString()); } if (data.Type == OtpType.Hotp) { collection.Add(KeeOtp1CounterParameter, data.Counter.ToString()); } else if (data.Type == OtpType.Totp) { if (data.Period != 30) { collection.Add(KeeOtp1StepParameter, data.Period.ToString()); } } if (data.Digits != 6) { collection.Add(KeeOtp1SizeParameter, data.Digits.ToString()); } if (data.Algorithm != OtpHashMode.Sha1) { collection.Add(KeeOtp1OtpHashModeParameter, data.Algorithm.ToString()); } if (data.Encoding != OtpSecretEncoding.Base32) { collection.Add(KeeOtp1EncodingParameter, data.Encoding.ToString()); } string output = string.Empty; foreach (var key in collection.AllKeys) { output += string.Format("{0}={1}&", key, collection[key]); } entry.Strings.Set(StringDictionaryKey, new ProtectedString(true, output.TrimEnd('&'))); return(entry); }
public static void increaseHotpCounter(IPluginHost host, OtpAuthData data, PwEntry entry) { data.Counter = data.Counter + 1; if (data.KeeOtp1Mode) { migrateToKeeOtp1String(data, entry); } else { migrateToBuiltInOtp(data, entry); } entry.Touch(true); host.MainWindow.ActiveDatabase.Modified = true; host.MainWindow.UpdateUI(false, null, false, null, false, null, true); }
public static OtpBase getOtp(OtpAuthData data) { if (data.Type == OtpType.Totp) { return(new OtpTotp(data)); } else if (data.Type == OtpType.Hotp) { return(new OtpHotp(data)); } else if (data.Type == OtpType.Steam) { return(new OtpSteam(data)); } throw new InvalidOtpConfiguration(); }
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); } } } }
public ShowQrCode(OtpAuthData data, PwEntry entry, IPluginHost host) { InitializeComponent(); pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width, pictureBoxBanner.Height, KeePass.UI.BannerStyle.Default, Resources.qr_white, KeeOtp2Statics.ShowQr, KeeOtp2Statics.ShowQrSubline); this.Icon = host.MainWindow.Icon; this.TopMost = host.MainWindow.TopMost; this.data = data; this.uri = OtpAuthUtils.otpAuthDataToUri(entry, data); this.entry = entry; this.host = host; groupBoxQRCode.Text = KeeOtp2Statics.ShowQrDisclamer; buttonOk.Text = KeeOtp2Statics.OK; copyUriToolTip = new ToolTip(); copyUriToolTip.ToolTipTitle = KeeOtp2Statics.ShowQrCopyUri; copyUriToolTip.IsBalloon = true; string toolTipCopyUri = String.Format(KeeOtp2Statics.ToolTipShowQrCodeCopyUri, this.uri.AbsoluteUri); copyUriToolTip.SetToolTip(buttonCopyUriReload, toolTipCopyUri); reloadToolTip = new ToolTip(); reloadToolTip.ToolTipTitle = KeeOtp2Statics.ShowQr; reloadToolTip.IsBalloon = true; string toolTipReload = KeeOtp2Statics.ToolTipShowQrCodeReload; reloadToolTip.SetToolTip(buttonCopyUriReload, toolTipReload); }
public static OtpAuthData loadData(PwEntry entry) { try { if (checkKeeOtp1Mode(entry)) { OtpAuthData data = loadDataFromKeeOtp1String(entry); data.KeeOtp1Mode = true; return(data); } else if (checkBuiltInMode(entry)) { OtpAuthData data = loadDataFromBuiltInOtp(entry); return(data); } return(null); } catch { return(null); } }
private void scanQRCode() { Uri uri = null; IBarcodeReader reader = new BarcodeReader(); Bitmap bmpScreenshot; Graphics gfxScreenshot; this.Hide(); foreach (Screen sc in Screen.AllScreens) { bmpScreenshot = new Bitmap(sc.Bounds.Width, sc.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); gfxScreenshot = Graphics.FromImage(bmpScreenshot); gfxScreenshot.CopyFromScreen(sc.Bounds.X, sc.Bounds.Y, 0, 0, sc.Bounds.Size, CopyPixelOperation.SourceCopy); var result = reader.Decode(bmpScreenshot); if (result != null) { if (result.ToString().StartsWith("otpauth")) { uri = new Uri(result.ToString()); } } } this.Show(); if (uri != null) { MessageBox.Show(KeeOtp2Statics.MessageBoxQrCodeFound, KeeOtp2Statics.OtpInformationScanQr, MessageBoxButtons.OK, MessageBoxIcon.Information); this.data = OtpAuthUtils.uriToOtpAuthData(uri); loadData(); } else { if (MessageBox.Show(KeeOtp2Statics.MessageBoxQrCodeNotFound, KeeOtp2Statics.OtpInformationScanQr, MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) { scanQRCode(); } } }
private void comboBoxType_SelectionChangeCommitted(object sender, EventArgs e) { bool timerEnabled = timerUpdateTotp.Enabled; timerUpdateTotp.Stop(); timerUpdateTotp.Dispose(); OtpType type = comboBoxTypeIndexValue[comboBoxType.SelectedIndex]; try { this.data = readData(true); } catch { this.data = new OtpAuthData(); } if (type == OtpType.Totp) { this.data.Proprietary = true; this.data.Type = OtpType.Totp; } else if (type == OtpType.Hotp) { this.data.Proprietary = true; this.data.Digits = 6; this.data.Type = OtpType.Hotp; } else if (type == OtpType.Steam) { this.data.Proprietary = false; this.data.Digits = 5; this.data.KeeOtp1Mode = true; this.data.Type = OtpType.Steam; } loadData(); timerUpdateTotp.Enabled = timerEnabled; }
// 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); } } } } } }
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); } } } } }
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); } } } }
public OtpHotp(OtpAuthData data) : base(data) { this.hotp = new Hotp(data.Key.ReadData(), data.Algorithm, data.Digits); }
public OtpTotp(OtpAuthData data) : base(data) { this.totp = new Totp(data.Key.ReadData(), data.Period, data.Algorithm, data.Digits, null); }
public OtpBase(OtpAuthData data) { this.data = data; }
public OtpSteam(OtpAuthData data) : base(data) { }
private void loadData() { bool timerEnabled = timerUpdateTotp.Enabled; bool comboBoxLengthEnabled = comboBoxLength.Enabled; bool comboBoxTypeEnabled = comboBoxType.Enabled; timerUpdateTotp.Enabled = false; comboBoxLength.Enabled = false; comboBoxType.Enabled = false; if (this.data == null) { this.data = new OtpAuthData(); } this.textBoxKey.Text = this.data.GetPlainSecret(); if (this.data.Period != 30 || this.data.KeeOtp1Mode || this.data.Encoding != OtpSecretEncoding.Base32 || this.data.Digits != 6 || this.data.Type != OtpType.Totp || this.data.Algorithm != OtpHashMode.Sha1) { this.checkBoxCustomSettings.Checked = true; } if (this.data.Type == OtpType.Totp || this.data.Type == OtpType.Steam) { this.textBoxPeriodCounter.Text = this.data.Period.ToString(); groupBoxPeriodCounter.Text = KeeOtp2Statics.Period; labelPeriodCounter.Text = KeeOtp2Statics.OtpInformationPeriodSeconds; } else if (this.data.Type == OtpType.Hotp) { this.textBoxPeriodCounter.Text = this.data.Counter.ToString(); groupBoxPeriodCounter.Text = KeeOtp2Statics.Counter; labelPeriodCounter.Text = KeeOtp2Statics.Counter; } this.checkboxOldKeeOtp.Checked = this.data.KeeOtp1Mode; this.comboBoxLength.SelectedIndex = comboBoxLengthIndexValue.FirstOrDefault(x => x.Value == this.data.Digits).Key; this.comboBoxType.SelectedIndex = comboBoxTypeIndexValue.FirstOrDefault(x => x.Value == this.data.Type).Key; if (this.data.Encoding == OtpSecretEncoding.Base64) { this.radioButtonBase32.Checked = false; this.radioButtonBase64.Checked = true; this.radioButtonHex.Checked = false; this.radioButtonUtf8.Checked = false; } else if (this.data.Encoding == OtpSecretEncoding.Hex) { this.radioButtonBase32.Checked = false; this.radioButtonBase64.Checked = false; this.radioButtonHex.Checked = true; this.radioButtonUtf8.Checked = false; } else if (this.data.Encoding == OtpSecretEncoding.UTF8) { this.radioButtonBase32.Checked = false; this.radioButtonBase64.Checked = false; this.radioButtonHex.Checked = false; this.radioButtonUtf8.Checked = true; } else // default encoding { this.radioButtonBase32.Checked = true; this.radioButtonBase64.Checked = false; this.radioButtonHex.Checked = false; this.radioButtonUtf8.Checked = false; } if (this.data.Algorithm == OtpHashMode.Sha256) { this.radioButtonSha1.Checked = false; this.radioButtonSha256.Checked = true; this.radioButtonSha512.Checked = false; } else if (this.data.Algorithm == OtpHashMode.Sha512) { this.radioButtonSha1.Checked = false; this.radioButtonSha256.Checked = false; this.radioButtonSha512.Checked = true; } else // default hashmode { this.radioButtonSha1.Checked = true; this.radioButtonSha256.Checked = false; this.radioButtonSha512.Checked = false; } if (this.data != null && this.data.KeeOtp1Mode && !this.data.isForcedKeeOtp1Mode()) { linkLabelMigrate.Visible = true; linkLabelMigrate.Enabled = true; ToolTip toolTip = new ToolTip(); toolTip.ToolTipTitle = KeeOtp2Statics.ToolTipMigrateHeadline; toolTip.IsBalloon = true; toolTip.SetToolTip(linkLabelMigrate, KeeOtp2Statics.ToolTipMigrate); } else { linkLabelMigrate.Visible = false; linkLabelMigrate.Enabled = false; } timerUpdateTotp.Enabled = timerEnabled; comboBoxLength.Enabled = comboBoxLengthEnabled; comboBoxType.Enabled = comboBoxTypeEnabled; SetCustomSettingsState(); }