/// <summary> /// /// </summary> /// <param name="tagId"></param> /// <param name="tlv"></param> /// <param name="tagsManager"></param> private static void WriteTlv(UInt32 tagId, TlvData tlv, TlvDictionary tagsManager) { Console.WriteLine(" >> Contains tag {0:X2}: {1} [ {2} ]", tagId, tlv.HasTag(tagId), tlv.GetTag(tagId)); if (tlv.HasTag(tagId) && (tagsManager.CreateInstance(tlv.GetTag(tagId)) != null)) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(" >> {0:N}: {0}", tagsManager.CreateInstance(tlv.GetTag(tagId))); Console.ForegroundColor = ConsoleColor.Gray; } }
/// <summary> /// /// </summary> /// <param name="tagId"></param> /// <param name="tlv"></param> /// <param name="tagsManager"></param> private void WriteTlv(UInt32 tagId, TlvData tlv, TlvDictionary tagsManager) { gui.guiDetailedLogs.AppendText(String.Format(" >> TLV {0:X2}: [ {1} ]\n", tagId, tlv.GetTag(tagId))); if (!tlv.HasTag(tagId) || (tagsManager.CreateInstance(tlv.GetTag(tagId)) == null)) { return; } gui.guiDetailedLogs.SelectionColor = highlightColor; gui.guiDetailedLogs.AppendText(String.Format(" >> {0:N}: {0}\n", tagsManager.CreateInstance(tlv.GetTag(tagId)))); gui.guiDetailedLogs.SelectionColor = standardColor; }
private static TreeNode ConvertTlvDataToTreeNode(TlvData tlv, TlvDictionary tlvManager) { TreeNode tlvNode; if (tlvManager != null && tlvManager.Get(String.Format("{0:T}", tlv)) != null) { var tlvObject = tlvManager.CreateInstance(tlv); tlvObject.Tlv = tlv; tlvNode = new TreeNode(String.Format("{0:N}: {0}", tlvObject)); } else { tlvNode = new TreeNode(String.Format("T:{0:T} L:{0:L} V:{0:Vh}", tlv)); } foreach (var subTLV in tlv.InnerTlvs) { tlvNode.Nodes.Add(ConvertTlvDataToTreeNode(subTLV, tlvManager)); } return(tlvNode); }
public Gui() { InitializeComponent(); Icon = Common.Resources.Icons.WSCT; _pluginConfiguration = SerializedObject <PluginConfiguration> .LoadFromXml(@"Config.EMVExplorer.xml"); _tlvDictionary = SerializedObject <TlvDictionary> .LoadFromXml(@"Dictionary.EMVTag.xml"); _certificationAuthorityRepository = _pluginConfiguration.terminalConfiguration.CertificationAuthorityRepository; _detailedLogs = new DetailedLogs(this); _detailedLogs.TlvDictionary = _tlvDictionary; guiPSEName.DataSource = _pluginConfiguration.terminalConfiguration.TerminalCapabilities.SupportedPses; guiPSEName.DisplayMember = "name"; guiAC1Type.DataSource = Enum.GetValues(typeof(CryptogramType)); guiAC1Type.SelectedItem = CryptogramType.TC; _emvApplications = new List <EmvApplication>(); }
private void Run() { Console.WriteLine("=========== S o m e T L V D a t a e x a m p l e s"); #region >> TLV Example Console.WriteLine("88 01 02".ToTlvData()); var tlv1 = "88 01 02".ToTlvData(); var tlv2 = "5F 2D 03 01 02 03".ToTlvData(); var ltlv = new List <TlvData>(); ltlv.Add(tlv1); ltlv.Add(tlv2); Console.WriteLine(ltlv.ToTlvData(0x20)); Console.WriteLine(ltlv.ToTlvData(0x20).GetTag(0x88)); Console.WriteLine(ltlv.ToTlvData(0x20).GetTag(0x5F2D)); #endregion Console.WriteLine(); Console.WriteLine("=========== I n i t i a l i z i n g P C / S C"); xmlRoot = new XElement("WinSCard"); xmlDoc = new XDocument(xmlRoot); #region >> ConsoleObserver var logger = new ConsoleObserver(); #endregion #region >> CardContext ICardContext context = new CardContext(); logger.ObserveContext((CardContextObservable)context); if (context.Establish() != ErrorCode.Success) { Console.WriteLine("Erreur: establish() failed"); return; } context.ListReaderGroups(); if (context.GroupsCount == 0) { Console.WriteLine("Error: no reader group found"); context.Release(); return; } context.ListReaders(context.Groups[0]); if (context.ReadersCount == 0) { Console.WriteLine("Error: no reader found"); context.Release(); return; } #endregion Console.WriteLine(); Console.WriteLine("=========== C a r d i n s e r t i o n d e t e c t i o n"); #region >> StatusChangeMonitor var monitor = new StatusChangeMonitor(context); logger.ObserveMonitor(monitor); var readerState = monitor.WaitForCardPresence(0); if (readerState == null) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(">> Insert a card in one of the {0} readers (time out in 15s)", context.ReadersCount); readerState = monitor.WaitForCardPresence(15000); } if (readerState == null) { Console.WriteLine(">> Time Out! No card found"); return; } #endregion #region >> CardChannel ICardChannel rawCardChannel = new CardChannel(context, readerState.ReaderName); logger.ObserveChannel((CardChannelObservable)rawCardChannel); var cardChannel = new CardChannelIso7816(rawCardChannel); if (cardChannel.Connect(ShareMode.Shared, Protocol.Any) != ErrorCode.Success) { Console.WriteLine("Erreur: connect() failed"); return; } var buffer = new byte[0]; cardChannel.GetAttrib(Attrib.AtrString, ref buffer); if (cardChannel.Reconnect(ShareMode.Shared, Protocol.Any, Disposition.ResetCard) != ErrorCode.Success) { Console.WriteLine("Erreur: reconnect() failed"); return; } cardChannel.GetAttrib(Attrib.AtrString, ref buffer); #endregion #region >> TagsManager tagsManager = SerializedObject <TlvDictionary> .LoadFromXml(@"Dictionary.EMVTag.xml"); #endregion #region >> PSE Analysis var pse = new PaymentSystemEnvironment(cardChannel); pse.BeforeSelectEvent += BeforePseSelection; pse.AfterSelectEvent += AfterPseSelection; pse.BeforeReadEvent += BeforePseRead; pse.AfterReadEvent += AfterPseRead; if (pse.Select() == 0x9000) { if (pse.TlvFci.HasTag(0x88)) { pse.Read(); } } #endregion emvApplications = new List <EmvApplication>(); foreach (var emvFound in pse.GetApplications()) { emvApplications.Add(emvFound); } #region >> AID selection foreach (var emv in emvApplications) { emv.BeforeSelectEvent += BeforeApplicationSelection; emv.AfterSelectEvent += AfterApplicationSelection; emv.BeforeGetProcessingOptionsEvent += BeforeGetProcessingOptions; emv.AfterGetProcessingOptionsEvent += AfterGetProcessingOptions; emv.BeforeReadApplicationDataEvent += BeforeReadApplicationData; emv.AfterReadApplicationDataEvent += AfterReadApplicationData; emv.BeforeGetDataEvent += BeforeGetData; emv.AfterGetDataEvent += AfterGetData; if (emv.Select() == 0x9000) { if (emv.GetProcessingOptions() == 0x9000) { emv.ReadApplicationData(); emv.GetData(); } } } #endregion Console.WriteLine(); Console.WriteLine("=========== T e r m i n a t i n g"); cardChannel.Disconnect(Disposition.UnpowerCard); xmlDoc.Save(new FileStream("EMV.TLV.xml", FileMode.Create, FileAccess.ReadWrite)); Console.WriteLine(); Console.WriteLine("=========== C a r d r e m o v a l d e t e c t i o n"); #region >> StatusChangeMonitor Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(">> Waiting for a change since last call (time out in 10s)"); // "unpower" change should be fired for the previously used reader monitor.WaitForChange(10000); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(">> Remove the card in one of the readers {0} (time out in 10s)", readerState.ReaderName); // Wait for another change monitor.WaitForChange(10000); #endregion Console.WriteLine(); context.Release(); }