private void btnDeleteKey_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0 && dataGridView1.SelectedCells.Count == 0) { return; } YubikeysCollection keys = (YubikeysCollection)dataGridView1.DataSource; if (dataGridView1.SelectedRows.Count == 0) { foreach (DataGridViewCell cell in dataGridView1.SelectedCells) { keys.Remove((YubikeySettings)dataGridView1.Rows[cell.RowIndex].DataBoundItem); } } else { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { keys.Remove((YubikeySettings)row.DataBoundItem); } } dataGridView1.DataSource = null; dataGridView1.Invalidate(); dataGridView1.DataSource = keys; }
private void IncrementSession() { if (cboKeys.SelectedIndex < 0) { return; } System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); YubikeysSection keysSection = (YubikeysSection)config.GetSection("tokens"); YubikeySettings key = keysSection.Keys[((YubikeySettings)cboKeys.SelectedItem).Name]; ++key.SessionCounter; key.UseCounter = 0; key.StartTime = DateTime.Now; byte[] buffer = new byte[3]; RNGCryptoServiceProvider.Create().GetBytes(buffer); key.TimeStamp = (((int)buffer[0]) << 16) | (((int)buffer[1]) << 8) | (int)buffer[2]; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("tokens"); int index = cboKeys.SelectedIndex; YubikeysCollection keys = ((YubikeysCollection)cboKeys.DataSource); keys[index] = key; cboKeys.DataSource = keys; }
public KeyManagement(YubikeysCollection keys) { InitializeComponent(); this.cboKeyFormat.SelectedIndex = 0; this.dataGridView1.AutoGenerateColumns = false; this.Width = _contractedWidth; this.cboAddKeyFormat.SelectedIndex = 0; this.cbPressEnter.Checked = true; this.panel1.Enabled = false; this.panel1.Visible = false; this.dataGridView1.DataSource = keys; }
bool AddKey(string name, byte[] secret, byte[] tokenID, byte[] privateID, int sessionCounter, bool pressEnter) { YubikeySettings key = new YubikeySettings(); key.Name = name; key.Secret = secret; key.TokenID = tokenID; key.PrivateID = privateID; key.SessionCounter = sessionCounter; key.PressEnter = pressEnter; YubikeysCollection keys = (YubikeysCollection)dataGridView1.DataSource; if (keys.Contains(key)) { return(false); } keys.Add(key); dataGridView1.DataSource = null; dataGridView1.Invalidate(); dataGridView1.DataSource = keys; return(true); }