Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        private void manageKeysToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            YubikeysSection keysSection = (YubikeysSection)config.GetSection("tokens");
            KeyManagement   window      = new KeyManagement(keysSection.Keys);

            if (!this.Visible)
            {
                window.ShowInTaskbar = true;
            }
            window.ShowDialog();
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("tokens");
            PopulateKeyList();
        }
Exemplo n.º 3
0
        private void PopulateKeyList()
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            YubikeysSection keysSection = (YubikeysSection)config.GetSection("tokens");

            lock (cboKeys)
            {
                this.cboKeys.SelectedIndexChanged   -= _indexChangedHandler;
                this.cmcboKeys.SelectedIndexChanged -= _contextMenuIndexChangedHandler;
                YubikeySettings selectedItem = (YubikeySettings)this.cboKeys.SelectedItem;
                this.cboKeys.DataSource = null;
                foreach (YubikeySettings key in keysSection.Keys)
                {
                    key.StartTime = DateTime.Now;
                }

                this.cmcboKeys.Items.AddRange(keysSection.Keys.GetAll());
                this.cboKeys.DataSource    = keysSection.Keys;
                this.cboKeys.ValueMember   = "Name";
                this.cboKeys.DisplayMember = "Name";
                if (selectedItem == null)
                {
                    this.cboKeys.SelectedIndex   = -1;
                    this.cmcboKeys.SelectedIndex = -1;
                }
                else
                {
                    int selectedIndex = keysSection.Keys.IndexOf(selectedItem);
                    this.cboKeys.SelectedIndex   = selectedIndex;
                    this.cmcboKeys.SelectedIndex = selectedIndex;
                }
                this.cboKeys.SelectedIndexChanged   += _indexChangedHandler;
                this.cmcboKeys.SelectedIndexChanged += _contextMenuIndexChangedHandler;
            }
            IncrementSession();
        }