Exemple #1
0
        /// <summary>
        /// Function to train the application to trust a specified card
        /// </summary>
        /// <param name="isTrusted"></param>
        public async void TrustDevice(CallBacks.Trusted isTrusted)
        {
            _isTrusted = isTrusted;
            await Task.Factory.StartNew(() =>
            {
                TrainMode = true;

                for (int i = 0; i < 10; i++)
                {
                    Task.Delay(1000).Wait();
                    Console.Beep(5100, 200);
                    if (!TrainMode)
                    {
                        break;
                    }
                }
                if (TrustedDevice == null)
                {
                    TrustedDevice = new AltsInfo()
                    {
                        Authenticated = false, AuthDeviceId = null
                    };
                }
                _isTrusted(TrustedDevice);
                TrainMode = false;
            });
        }
Exemple #2
0
        /// <summary>
        /// Check AltsInfo if the card is trusted or not
        /// </summary>
        /// <param name="devToken"></param>
        /// <returns>True for trusted smart card</returns>
        public bool isTrusted(AltsInfo devToken)
        {
            if (TrustedDevice == null)
            {
                return(false);
            }
            if (TrustedDevice.Authenticated == false || string.IsNullOrEmpty(TrustedDevice.AuthDeviceId))
            {
                return(false);
            }


            if (devToken == null)
            {
                return(false);
            }
            if (devToken.Authenticated == false || string.IsNullOrEmpty(devToken.AuthDeviceId))
            {
                return(false);
            }

            if (devToken.Authenticated && TrustedDevice.Authenticated)
            {
                return(devToken.AuthDeviceId == TrustedDevice.AuthDeviceId);
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Read the smart card and authenticate it using EMVCO rules
        /// </summary>
        /// <param name="readerName"></param>
        /// <returns>AltsInfo Authenticated True or false</returns>
        private AltsInfo Authenticate(string readerName)
        {
            AltsInfo ok = new AltsInfo();

            try
            {
                SmartCard        sa   = new SmartCard(readerName);
                var              res  = sa.GetAIDs(true);
                SmartApplication sapp = sa.Applications[0];
                sapp.SelectApplication();
                sapp.GetProcessingOptions();
                sapp.ReadRecords();


                OfflineAuth oa = new OfflineAuth(sapp);

                string cardNumber = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5A");
                string expdate    = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5F25");
                ///Keep the hash data of cardnumber and expiryDate
                string token = HashData(cardNumber + expdate, oa.ICC_KEY_HASH);

                ok.Authenticated = !string.IsNullOrEmpty(token);
                ok.AuthDeviceId  = token;
            }
            catch (Exception ex)
            {
                ok.Authenticated = false;
                ok.AuthDeviceId  = ex.Message;
            }
            return(ok);
        }
Exemple #4
0
        private void TrustDevice(string readerName)
        {
            SmartCard        sa   = new SmartCard(readerName);
            var              res  = sa.GetAIDs(true);
            SmartApplication sapp = sa.Applications[0];

            sapp.SelectApplication();
            sapp.GetProcessingOptions();
            sapp.ReadRecords();
            OfflineAuth oa = new OfflineAuth(sapp);

            string cardNumber = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5A");
            string expdate    = sapp.GetTagValue(EmvConstants.ResponceType.ReaderRecord, "5F25");
            ///Keep the hash data of cardnumber and expiryDate
            string token = HashData(cardNumber + expdate, oa.ICC_KEY_HASH);

            AltsInfo ok = new AltsInfo()
            {
                AuthDeviceId = token, Authenticated = !string.IsNullOrEmpty(token)
            };

            if (ok.Authenticated)
            {
                TrustedDevice = ok;
            }
        }
Exemple #5
0
        /// <summary>
        /// Callback called by the InterfaceAltSecurity interface implementation
        /// </summary>
        /// <param name="result">The authentication info provided to the callback</param>
        private async void okCallBack(AltsInfo result)
        {
            await this.Dispatcher.Invoke(async() =>
            {
                var dm = this.DataContext as ViewModel;
                dm.Log($"okCallBack");
                if (result.Authenticated)
                {
                    dm.AltsStatus = Status.Unlocked;
                    dm.Log($"Unlock Success");

                    await Task.Delay(5000);
                    dm.Log($"Resetting lock");
                    dm.AltsStatus = Status.Locked;
                }
                else
                {
                    dm.Log($"Unlock Failed");
                }
            });
        }
Exemple #6
0
        /// <summary>
        ///  Callback called by the InterfaceAltSecurity interface implementation
        /// </summary>
        /// <param name="result">The authentication info provided to the callback</param>
        private void trustCallBack(AltsInfo result)
        {
            this.Dispatcher.Invoke(() =>
            {
                var dm = this.DataContext as ViewModel;

                dm.Log($"Trust CallBack ");
                if (result.Authenticated)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        dm.AltsStatus = Status.Unlocked;
                        Task.Delay(1000);
                        dm.AltsStatus = Status.Locked;
                        Task.Delay(1000);
                    }
                }
                dm.Log($"Trust CallBack result => {result.Authenticated}");

                dm.AltsStatus = Status.Locked;
            });
        }
Exemple #7
0
 /// <summary>
 /// Function to Untrust device. Nor yet implemented.
 /// </summary>
 /// <param name="devInfo"></param>
 public void UnTrustDevice(AltsInfo devInfo)
 {
     throw new NotImplementedException();
 }