void CardConnectedCallback(SCardChannel cardChannel)
        {
            /* The CardConnected function is called as a delegate (callback) by the SCardReader object */
            /* within its backgroung thread. Therefore it is not allowed to use the UI objects.        */

            Logger.Trace("Card connected - Trying to run the transaction");


            if (!AppleVasLicense.ReadDeviceId(cardChannel))
            {
                Logger.Error("Read device ID error");
                ShowResult("Not a SpringCard device?", null, true);
                return;
            }

            if (!AppleVasLicense.Allowed(out string msg2))
            {
                Logger.Error("Not allowed to execute");
                ShowResult(string.Format("Not allowed to execute ({0})", msg2), null, true);
                return;
            }

            AppleVasTerminal terminal = new AppleVasTerminal();

            foreach (AppleVasConfig merchConfig in appleConfig.Merchants)
            {
                terminal.AddConfig(merchConfig);
            }

            if (terminal.DoTransaction(cardChannel, out AppleVasData data, out AppleVasError error))
            {
                ShowResult(null, data, true);
            }
        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");
            }
        }
Exemple #3
0
 private bool CanPlay()
 {
     // TODO check apple and google config
     if (cbReaders.SelectedIndex >= 0)
     {
         if (GoogleVasLicense.Loaded() && AppleVasLicense.Loaded())
         {
             return(true);
         }
     }
     return(false);
 }
 private bool CanPlay()
 {
     if (cbReaders.SelectedIndex >= 0)
     {
         // TODO check config
         //if ((merchant1Id != null) && (merchant1PrivateKey != null))
         if (AppleVasLicense.Loaded())
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            if (ShowSplash)
            {
                Logger.Trace("Showing splash form");
                SplashForm.DoShowDialog(this, FormStyle.ModernRed);
            }

            LicenseData licenseDataGoogle = GoogleVasLicense.Get();
            LicenseData licenseDataApple  = AppleVasLicense.Get();

            ApplyLicense(licenseDataGoogle);
            ApplyLicense(licenseDataApple);
        }
        static void Main(string[] args)
        {
            SystemConsole.ReadArgs(args);
            Logger.ReadArgs(args);

            Logger.Info("SpringCard.AppleVAS library version: {0}", Library.ModuleInfo.LongVersion);

            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (!AppleVasLicense.AutoLoad())
            {
                Logger.Info("No license file");
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new MainForm(args));
        }
Exemple #7
0
        static void Main(string[] args)
        {
            SystemConsole.ReadArgs(args);
            Logger.ReadArgs(args);

            string ConfigFileName = null;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].StartsWith("-"))
                {
                    continue;
                }
                if (ConfigFileName == null)
                {
                    ConfigFileName = args[i];
                }
            }

            if (!GoogleVasLicense.AutoLoad())
            {
                Logger.Info("No Google VAS license file");
            }

            if (!AppleVasLicense.AutoLoad())
            {
                Logger.Info("No Apple VAS license file");
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm f = new MainForm(args);

            /* if (ConfigFileName != null)
             *   f.LoadConfigFromFile(ConfigFileName);*/
            Application.Run(f);
        }
        int Run(string[] args)
        {
            if (!ParseArgs(args))
            {
                return(1);
            }

            if (!AppleVasLicense.AutoLoad())
            {
                Logger.Info("No license file");
            }

            Logger.Debug("Loading the list of PC/SC readers");

            string[] ReaderNames = (new SCardReaderList()).Readers;

            if (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 (ReaderName == null)
            {
                if (ReaderIndex < 0)
                {
                    ReaderIndex = 0;
                }

                Logger.Debug("Selecting the PC/SC reader at index {0}", ReaderIndex);

                if ((ReaderIndex >= ReaderNames.Length))
                {
                    Console.WriteLine("No PC/SC Reader at index {0}", ReaderIndex);
                    Console.WriteLine("Use " + ProgName + " --list-readers");
                    return(1);
                }

                ReaderName = ReaderNames[ReaderIndex];
            }

            Logger.Debug("Using PC/SC reader {0}", ReaderName);

            if (MerchantName != null)
            {
                Logger.Debug("Translating the merchant name");

                MerchantID = AppleVasConfig.ComputeId(MerchantName);
                if (!Quiet)
                {
                    Console.WriteLine("Merchant ID={0}", StrUtils.Base64UrlEncode(MerchantID));
                }
            }

            AppleVasConfig         merchantConfig = new AppleVasConfig(MerchantID);
            AppleVasTerminalConfig terminalConfig = new AppleVasTerminalConfig();

            terminalConfig.Merchants.Add(merchantConfig);

            Logger.Debug("Opening the PC/SC reader");

            SCardReader reader = new SCardReader(ReaderName);

            Logger.Debug("Expecting to find a 'smartcard'");

            SCardChannel channel = new SCardChannel(reader);

            if (!channel.CardPresent)
            {
                ConsoleError("No NFC card or smartphone on the reader");
                return(1);
            }

            Logger.Debug("Connecting to the 'smartcard'");

            if (!channel.Connect())
            {
                ConsoleError("Failed to open the communication with the NFC card or smartphone");
                return(1);
            }

            if (!AppleVasLicense.ReadDeviceId(channel))
            {
                ConsoleError("Failed to read the device ID - is it a SpringCard device?");
                return(1);
            }

            if (!AppleVasLicense.Allowed(out string msg))
            {
                ConsoleError(string.Format("Not allowed to execute ({0})", msg));
                return(1);
            }

            AppleVasError error;

            AppleVasTerminal terminal = new AppleVasTerminal(terminalConfig);

            Logger.Debug("SelectOSE APDU");

            if (!terminal.SelectOSE(channel, out error))
            {
                OutputError("SelectOSE failed", error);
                channel.Disconnect();
                return(2);
            }

            Logger.Debug("GetVasData APDU");

            if (!terminal.GetVasData(channel, terminalConfig, merchantConfig, out byte[] buffer, out error))
Exemple #9
0
        int Run(string[] args)
        {
            if (!ParseArgs(args))
            {
                return(1);
            }

            if (!AppleVasLicense.AutoLoad())
            {
                Logger.Info("No license file");
            }

            if (MerchantName != null)
            {
                Logger.Debug("Translating the merchant name");

                MerchantID = AppleVasConfig.ComputeId(MerchantName);
                if (!Quiet)
                {
                    Console.WriteLine("Merchant ID={0}", StrUtils.Base64UrlEncode(MerchantID));
                }
            }

            AppleVasConfig config = new AppleVasConfig(MerchantID);

            config.AddPrivateKey(PrivateKey);

            AppleVasData OutputMessage = AppleVasData.Create(config, InputMessage, out AppleVasError error);

            if (OutputMessage == null)
            {
                OutputError("Failed to extract VAS message", error);
                return(2);
            }

            if (Json)
            {
                Console.WriteLine("{");
                OutputField("result", error.ToString());
            }

            if (OutputText > 0)
            {
                OutputField("nfcMessage", OutputMessage.Text);
            }
            if (OutputHex > 0)
            {
                OutputField("nfcMessage", OutputMessage.HexBytes);
            }
            if (OutputBase64 > 0)
            {
                OutputField("nfcMessage", OutputMessage.Base64Bytes);
            }
            OutputField("nfcTimestamp", OutputMessage.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ"), true);

            if (Json)
            {
                Console.WriteLine("}");
            }

            return(0);
        }
        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);
        }
        void CardConnectedCallback(SCardChannel cardChannel)
        {
            /* The CardConnected function is called as a delegate (callback) by the SCardReader object */
            /* within its backgroung thread. Therefore it is not allowed to use the UI objects.        */


            /* Apple exhange */

            if (!AppleVasLicense.ReadDeviceId(cardChannel))
            {
                Logger.Error("Read device ID error");
                ShowResult("Not a SpringCard device?");
                return;
            }

            if (!AppleVasLicense.Allowed(out string msg2))
            {
                Logger.Error("Not allowed to execute");
                ShowResult(string.Format("Not allowed to execute ({0})", msg2));
                return;
            }

            AppleVasTerminal appleTerminal = new AppleVasTerminal();

            foreach (AppleVasConfig merchConfig in appleConfig.Merchants)
            {
                appleTerminal.AddConfig(merchConfig);
            }

            if (appleTerminal.DoTransaction(cardChannel, out AppleVasData data2, out AppleVasError error2, out RAPDU selectOseresponseApple))
            {
                ShowResult("Apple Wallet\n" + data2.Text);
                Task.Delay(5000).ContinueWith(t => resetUiEvent());
                return;
            }

            if (!GoogleVasLicense.ReadDeviceId(cardChannel))
            {
                Logger.Error("Read device ID error");
                ShowResult("Not a SpringCard device?");
                return;
            }

            if (!GoogleVasLicense.LoadCollectorId(googleConfig.CollectorId_4))
            {
                Logger.Error("Wrong Collector ID");
                ShowResult("Wrong Collector ID?");
                return;
            }

            if (!GoogleVasLicense.Allowed(out string msg1))
            {
                Logger.Error("Not allowed to execute");
                ShowResult(string.Format("Not allowed to execute ({0})", msg1));
                return;
            }

            Logger.Trace("Card connected - Trying to run the transaction");

            /* Google exhange */

            GoogleVasTerminal googleTerminal = new GoogleVasTerminal(googleConfig);

            /* Provide selectOseResponseApple to speed up the transaction */
            if (googleTerminal.DoTransaction(cardChannel, out GoogleVasData data1, out GoogleVasError error1, selectOseresponseApple))
            {
                /* Convert JSON to SpringPass data with regex */
                Regex rx = new Regex(@"[0-9a-zA-Z]+\|[a-z0-9.-_]+@[a-z.]+", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                MatchCollection matches = rx.Matches(data1.GetJsonString());

                if (matches.Count >= 1)
                {
                    ShowResult("Google Smart Tap\n" + matches[0].Value);
                    Task.Delay(5000).ContinueWith(t => resetUiEvent());
                }
                else
                {
                    ShowResult("Read succeded but no SpringPass data found");
                }
                return;
            }
        }