Ejemplo n.º 1
0
        /// <summary>
        /// Smartcard removed handler
        /// </summary>
        /// <param name="e">Smartcard event args</param>
        private void DoCardRemoved(SmartcardEventArgs e)
        {
            var processor = new ActionProcessor();
            var certs     = this.certificateCache[e.ReaderName];

            // Find matching actions
            foreach (var subj in certs)
            {
                var certActions = this.configuration.Certificates.Where(x => x.Subject == subj).ToList();

                foreach (var action in certActions)
                {
                    var removeActions = action.Actions.Where(act => (act.OnEvent & Config.Action.SmartcardAction.Remove) == Config.Action.SmartcardAction.Remove);
                    processor.AddActions(e.SmartCard, null, removeActions);
                }
            }

            // Any actions allocated to this smartcard?
            if (processor.ActionCount == 0)
            {
                return;
            }

            processor.ProcessRemoveActions();
            this.certificateCache.Remove(e.ReaderName);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Smartcard inserted handler
        /// </summary>
        /// <param name="e">Smartcard event args</param>
        private void DoCardInserted(SmartcardEventArgs e)
        {
            var processor = new ActionProcessor();
            var certList  = new List <string>();

            // Find matching actions
            foreach (var cardCert in e.SmartCard.CertificateStore.Certificates)
            {
                var subj        = cardCert.Subject;
                var certActions = this.configuration.Certificates.Where(x => x.Subject == subj).ToList();
                certList.Add(subj);

                foreach (var action in certActions)
                {
                    var insertActions = action.Actions.Where(act => (act.OnEvent & Config.Action.SmartcardAction.Insert) == Config.Action.SmartcardAction.Insert);
                    processor.AddActions(e.SmartCard, cardCert, insertActions);
                }
            }

            this.certificateCache.Add(e.ReaderName, certList);

            // Any actions allocated to this smartcard?
            if (processor.ActionCount == 0)
            {
                return;
            }

            // Do any actions want the PIN?
            if (processor.PinRequired)
            {
                var mre = new ManualResetEvent(false);
                this.requestPinForm.Invoke((MethodInvoker)(() => this.requestPinForm.ShowPinWindow(mre)));
                mre.WaitOne();
                processor.ProcessInsertActions(this.requestPinForm.PinPassback);
            }
            else
            {
                processor.ProcessInsertActions(null);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Receive smartcard remove events and queue them for processing
 /// </summary>
 /// <param name="o">Sender of the event</param>
 /// <param name="e">Smartcard event arguments</param>
 private void CardRemovedEventHandler(object o, SmartcardEventArgs e)
 {
     this.eventQueue.Add(new EventParams {
         Action = EventType.Remove, EventArgs = e
     });
 }