private void LoadConfigFromRegistry()
        {
            RegistryCfgFile registry = RegistryCfgFile.OpenApplicationSectionReadOnly("TerminalSettings");

            config = new GoogleVasConfig();
            config.Load(registry);
        }
Exemplo n.º 2
0
        private void NumToConfig(GoogleVasConfig config, NumericUpDown control)
        {
            string name = control.Name;

            if (name.StartsWith("num"))
            {
                name = name.Substring(3);

                try
                {
                    config.SetFieldValue(name, (uint)control.Value);
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}, trying to cast to ushort", name);
                    try
                    {
                        config.SetFieldValue(name, (ushort)control.Value);
                    }
                    catch
                    {
                        Logger.Warning("Unknown config property: {0}, trying to cast to byte", name);
                        try
                        {
                            config.SetFieldValue(name, (byte)control.Value);
                        }
                        catch
                        {
                            Logger.Warning("Unknown config property: {0}", name);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ConfigToForm(GoogleVasConfig config)
        {
            switch (config.SmartTapVersion)
            {
            case 0x0000:
                rbVersion20.Checked = true;
                break;

            case 0x0001:
                rbVersion21.Checked = true;
                break;

            case 0x0002:
                rbVersion22.Checked = true;
                break;

            default:
                Logger.Warning("Unsupported SmartTapVersion {0:X04}", config.SmartTapVersion);
                rbVersion21.Checked = true;
                break;
            }

            ConfigToControl(config, this);
            EnableSecureElementControl(config.UseSecureElement);
        }
Exemplo n.º 4
0
        private void lkSetGoogleConfiguration_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoogleVASConfigForm f = new GoogleVASConfigForm();

            f.ShowDialog();
            googleConfig    = f.GetConfig();
            btnPlay.Enabled = (cbReaders.SelectedIndex >= 0) ? googleConfig.IsValid() : false;
        }
Exemplo n.º 5
0
        private void ConfigForm_Load(object sender, EventArgs e)
        {
            RegistryCfgFile registry = RegistryCfgFile.OpenApplicationSectionReadOnly("TerminalSettings");
            GoogleVasConfig config   = new GoogleVasConfig();

            config.Load(registry);
            ConfigToForm(config);
        }
Exemplo n.º 6
0
        public GoogleVasConfig GetConfig()
        {
            RegistryCfgFile registry = RegistryCfgFile.OpenApplicationSectionReadOnly("TerminalSettings");
            GoogleVasConfig config   = new GoogleVasConfig();

            config.Load(registry);
            return(config);
        }
Exemplo n.º 7
0
 private void lkLoadFromFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     dlgOpenFile.InitialDirectory = AppUtils.BaseDirectory + Path.DirectorySeparatorChar + "conf";
     if (dlgOpenFile.ShowDialog() == DialogResult.OK)
     {
         GoogleVasConfig config = GoogleVasConfig.LoadFromJsonFile(dlgOpenFile.FileName);
         ConfigToForm(config);
     }
 }
Exemplo n.º 8
0
        private void lkClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoogleVasConfig config = new GoogleVasConfig();

            FormToConfig(config);
            RegistryCfgFile registry = RegistryCfgFile.OpenApplicationSectionReadWrite("TerminalSettings");

            config.Save(registry);
            Close();
        }
Exemplo n.º 9
0
        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");
            }
        }
Exemplo n.º 10
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            /* Load configurations */
            GoogleVASConfigForm googleConfigForm = new GoogleVASConfigForm();

            googleConfig = googleConfigForm.GetConfig();
            AppleVASConfigForm appleConfigForm = new AppleVASConfigForm();

            appleConfig = appleConfigForm.GetConfig();

            /* Load readers list */
            lkRefresh_LinkClicked(sender, null);
        }
Exemplo n.º 11
0
        private void ConfigToNum(GoogleVasConfig config, NumericUpDown control)
        {
            string name = control.Name;

            if (name.StartsWith("num"))
            {
                name = name.Substring(3);

                try
                {
                    uint value = (uint)config.GetFieldValue(name);
                    Logger.Debug("- {0}: {1}", name, value);
                    control.Value   = value;
                    control.Enabled = true;
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}, trying to cast to ushort", name);
                    try
                    {
                        ushort value = (ushort)config.GetFieldValue(name);
                        Logger.Debug("- {0}: {1}", name, value);
                        control.Value   = value;
                        control.Enabled = true;
                    }
                    catch
                    {
                        Logger.Warning("Unknown config property: {0}, trying to cast to byte", name);
                        try
                        {
                            byte value = (byte)config.GetFieldValue(name);
                            Logger.Debug("- {0}: {1}", name, value);
                            control.Value   = value;
                            control.Enabled = true;
                        }
                        catch
                        {
                            Logger.Warning("Unknown config property: {0}", name);
                            control.Value   = 0;
                            control.Enabled = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void CheckboxToConfig(GoogleVasConfig config, CheckBox control)
        {
            string name = control.Name;

            if (name.StartsWith("cb"))
            {
                name = name.Substring(2);

                try
                {
                    config.SetFieldValue(name, control.Checked);
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}", name);
                }
            }
        }
Exemplo n.º 13
0
 private void ControlToConfig(GoogleVasConfig config, Control control)
 {
     foreach (Control childControl in control.Controls)
     {
         ControlToConfig(config, childControl);
     }
     if (control is CheckBox)
     {
         CheckboxToConfig(config, control as CheckBox);
     }
     else if (control is TextBox)
     {
         TextToConfig(config, control as TextBox);
     }
     else if (control is NumericUpDown)
     {
         NumToConfig(config, control as NumericUpDown);
     }
 }
Exemplo n.º 14
0
 private void ConfigToControl(GoogleVasConfig config, Control control)
 {
     foreach (Control childControl in control.Controls)
     {
         ConfigToControl(config, childControl);
     }
     if (control is CheckBox)
     {
         ConfigToCheckbox(config, control as CheckBox);
     }
     else if (control is TextBox)
     {
         ConfigToText(config, control as TextBox);
     }
     else if (control is NumericUpDown)
     {
         ConfigToNum(config, control as NumericUpDown);
     }
 }
Exemplo n.º 15
0
        private void FormToConfig(GoogleVasConfig config)
        {
            if (rbVersion20.Checked)
            {
                config.SmartTapVersion = 0x0000;
            }
            else
            if (rbVersion21.Checked)
            {
                config.SmartTapVersion = 0x0001;
            }
            else
            if (rbVersion21.Checked)
            {
                config.SmartTapVersion = 0x0002;
            }

            ControlToConfig(config, this);
        }
Exemplo n.º 16
0
        private void TextToConfig(GoogleVasConfig config, TextBox control)
        {
            string name = control.Name;

            if (name.StartsWith("ehex"))
            {
                name = name.Substring(4);

                byte[] value;
                try
                {
                    value = BinConvert.HexToBytes(control.Text);
                }
                catch
                {
                    Logger.Trace("Invalid hex value for  {0}", name);
                    value = null;
                }

                try
                {
                    config.SetFieldValue(name, value);
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}", name);
                }
            }
            else if (name.StartsWith("estr"))
            {
                name = name.Substring(4);

                try
                {
                    config.SetFieldValue(name, control.Text);
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}", name);
                }
            }
        }
Exemplo n.º 17
0
        private void ConfigToText(GoogleVasConfig config, TextBox control)
        {
            string name = control.Name;

            if (name.StartsWith("ehex"))
            {
                name = name.Substring(4);

                try
                {
                    byte[] value = (byte[])config.GetFieldValue(name);
                    Logger.Debug("- {0}: {1}", name, BinConvert.ToHex(value));
                    control.Text    = BinConvert.ToHex(value);
                    control.Enabled = true;
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}", name);
                    control.Text    = "";
                    control.Enabled = false;
                }
            }
            else if (name.StartsWith("estr"))
            {
                name = name.Substring(4);

                try
                {
                    string value = (string)config.GetFieldValue(name);
                    Logger.Debug("- {0}: {1}", name, value);
                    control.Text    = value;
                    control.Enabled = true;
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}", name);
                    control.Text    = "";
                    control.Enabled = false;
                }
            }
        }
Exemplo n.º 18
0
        private void ConfigToCheckbox(GoogleVasConfig config, CheckBox control)
        {
            string name = control.Name;

            if (name.StartsWith("cb"))
            {
                name = name.Substring(2);

                try
                {
                    bool value = (bool)config.GetFieldValue(name);
                    Logger.Debug("- {0}: {1}", name, value);
                    control.Checked = value;
                    control.Enabled = true;
                }
                catch
                {
                    Logger.Warning("Unknown config property: {0}", name);
                    control.Checked = false;
                    control.Enabled = false;
                }
            }
        }
Exemplo n.º 19
0
 public bool LoadConfigFromFile(string FileName)
 {
     config = GoogleVasConfig.LoadFromJsonFile(FileName);
     return(true);
 }
Exemplo n.º 20
0
        int Run(string[] args)
        {
            if (!ParseArgs(args))
            {
                return(1);
            }

            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 (!GoogleVasLicense.AutoLoad())
            {
                Logger.Info("No license file");
            }

            GoogleVasConfig config;

            if (ConfigFileName != null)
            {
                config = GoogleVasConfig.LoadFromJsonFile(ConfigFileName);
            }
            else
            {
                config = GoogleVasConfig.GoogleDemo();
            }

            if (ExportedFileName != null)
            {
                GoogleVasConfig.SaveToSpringCoreConfigFile(config, ExportedFileName);
                Logger.Info("Export done, treminate program");
                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);

            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 (!GoogleVasLicense.ReadDeviceId(channel))
            {
                ConsoleError("Not a SpringCard device?");
                return(1);
            }

            if (!GoogleVasLicense.LoadCollectorId(config.CollectorId_4))
            {
                ConsoleError("Wrong Collector ID?");
                return(1);
            }

            GoogleVasError error;

            GoogleVasTerminal terminal = new GoogleVasTerminal(config);

            if (terminal.DoTransaction(channel, out GoogleVasData data, out error))
            {
                Logger.Debug($"Message is OK, transaction done in {terminal.TransactionDuration} ms");
            }
Exemplo n.º 21
0
        private void lkLoadDefault_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoogleVasConfig config = GoogleVasConfig.SpringCardDemo();

            ConfigToForm(config);
        }
Exemplo n.º 22
0
        private void lkLoadGoogleDemo_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            GoogleVasConfig config = GoogleVasConfig.GoogleDemo();

            ConfigToForm(config);
        }