public Form1() { InitializeComponent(); Cursor.Hide(); if (!GoogleVasLicense.AutoLoad()) { Logger.Info("No Google VAS license file"); } if (!AppleVasLicense.AutoLoad()) { Logger.Info("No Apple VAS license file"); } readerList = new List <string>(); googleConfig = GoogleVasConfig.SpringCardDemo(); const string TestMerchantName = "pass.com.springcard.springblue.generic"; const string TestKeyPrivate = "MHcCAQEEICp+PT7K8FQSOi2HED1Ar5RqxxN2EkiKJMCSfaL4htYNoAoGCCqGSM49AwEHoUQDQgAE9RCZaHxXUIjQFQnwKmq6+cVqFBNO6ZKQmekosMQRZmutPs8szUsiLokILdaiT/7F5qUl8qSfEvlocYy6z98jIw=="; string json = $@"{{ ""P2"" : ""FullVAS"", ""Capabilities"": ""SingleMode"", ""Merchants"" : [ {{ ""Name"" : ""{TestMerchantName}"", ""PrivateKey"" : ""{TestKeyPrivate}"", ""Url"": ""https://springpass.springcard.com"" }} ], ""Description"" : ""FullVAS, DualMode, 2 merchant IDs with 2nd matching, merchants have an URL"" }}"; appleConfig = AppleVasTerminalConfig.LoadFromJson(json); LoadReaders(); if (readerList.Count > 0) { string reader = readerList[0]; Logger.Trace("Starting..."); resetUiEvent(); activeReader = new SCardReader(reader); activeReader.StartWaitCard(new SCardReader.CardConnectedCallback(CardConnectedCallback), new SCardReader.CardRemovedCallback(CardRemovedCallback)); } else { ShowResult("No reader found"); } }
private void btnPlay_Click(object sender, EventArgs e) { if (cbReaders.SelectedIndex >= 0) { btnPlay.Enabled = false; EnableControls(false); string reader = cbReaders.Text; Logger.Trace("Starting..."); ShowResult("Waiting for NFC mobile...", null, true); activeReader = new SCardReader(reader); activeReader.StartWaitCard(new SCardReader.CardConnectedCallback(CardConnectedCallback), new SCardReader.CardRemovedCallback(CardRemovedCallback)); btnPause.Enabled = true; } }
int Run(string[] args) { ConsoleTitle(ProgName); if (!ParseArgs(args)) { Console.WriteLine("Try " + ProgName + " --help"); return(1); } if (Action == ActionE.Help) { Usage(); return(0); } if (!AppleVasLicense.AutoLoad()) { Logger.Info("No license file"); } if (Action == ActionE.Version) { ConsoleColor(ConsoleColorScheme.Info); Console.WriteLine("SpringCard.AppleVAS library version: {0}", SpringCard.AppleVas.Library.ModuleInfo.LongVersion); ConsoleColor(); return(0); } if (Action == ActionE.SelfTest) { if (!AppleVasTerminal.SelfTest()) { ConsoleColor(ConsoleColorScheme.Error); Console.WriteLine("SpringCard.AppleVAS self-test failed"); ConsoleColor(); return(1); } else { ConsoleColor(ConsoleColorScheme.Success); Console.WriteLine("SpringCard.AppleVAS self-test OK"); ConsoleColor(); return(0); } } if (Action == ActionE.KeyId) { uint keyId = AppleVasCrypto.ECC.ComputeKeyIdFromPem(KeyInputFile); Console.WriteLine("{0:X08}", keyId); return(0); } Logger.Debug("Loading the list of PC/SC readers"); string[] ReaderNames = (new SCardReaderList()).Readers; if (Action == ActionE.ListReaders) { Console.WriteLine(string.Format("{0} PC/SC Reader(s) found", ReaderNames.Length)); for (int i = 0; i < ReaderNames.Length; i++) { Console.WriteLine(string.Format("{0}: {1}", i, ReaderNames[i])); } return(0); } if (!File.Exists(ConfigFile)) { ConsoleColor(ConsoleColorScheme.Error); Console.WriteLine("File {0} not found", ConfigFile); ConsoleColor(); return(1); } try { terminalConfig = AppleVasTerminalConfig.LoadFromJsonFile(ConfigFile); } catch (Exception e) { ConsoleColor(ConsoleColorScheme.Error); Console.WriteLine("Failed to load the configuration"); Console.WriteLine("Error: {0}", e.Message); ConsoleColor(); return(1); } ConsoleColor(ConsoleColorScheme.Info); Console.WriteLine(terminalConfig.Description); ConsoleColor(); if (ReaderName == null) { if (ReaderIndex < 0) { ReaderIndex = 0; } Logger.Debug("Selecting the PC/SC reader at index {0}", ReaderIndex); if ((ReaderIndex >= ReaderNames.Length)) { ConsoleColor(ConsoleColorScheme.Error); Console.WriteLine("No PC/SC Reader at index {0}", ReaderIndex); Console.WriteLine("Use " + ProgName + " --list-readers to show the available reader(s)"); ConsoleColor(); return(1); } ReaderName = ReaderNames[ReaderIndex]; } Logger.Debug("Using PC/SC reader {0}", ReaderName); if (Stress) { timerFieldOff = new System.Timers.Timer(1000 * FieldOffAfter); timerFieldOff.Elapsed += RfFieldOff; timerFieldOff.AutoReset = true; timerFieldOff.Enabled = false; timerFieldOn = new System.Timers.Timer(1000 * FieldOffLength); timerFieldOn.Elapsed += RfFieldOn; timerFieldOn.AutoReset = true; timerFieldOn.Enabled = false; } SCardChannel directChannel = new SCardChannel(ReaderName); if (directChannel.ConnectDirect()) { directChannel.Control(new byte[] { 0x58, 0x23, 0x00 }); directChannel.DisconnectLeave(); } terminalReader = new SCardReader(ReaderName); terminalReader.StartWaitCard(new SCardReader.CardConnectedCallback(CardConnectedCallback), new SCardReader.CardRemovedCallback(CardRemovedCallback)); Console.WriteLine("Press any key to exit."); Console.ReadKey(true); Console.WriteLine("Exit required..."); terminalReader.StopWaitCard(); Console.WriteLine("Bye."); return(0); }