예제 #1
0
        private void eMerchant2Name_TextChanged(object sender, EventArgs e)
        {
            if (eMerchant2Name.Text == "")
            {
                merchant2Id       = null;
                eMerchant2Id.Text = "";
                AppConfig.WriteSettingString("MerchantName2", "");
                return;
            }

            merchant2Id = AppleVasConfig.ComputeId(eMerchant2Name.Text);
            Logger.Trace("MerchantId#2={0}", BinConvert.ToHex(merchant2Id));
            eMerchant2Id.Text = BinConvert.ToHex_nice(merchant2Id, ":", "", 0);
            AppConfig.WriteSettingString("MerchantName2", eMerchant2Name.Text);
        }
예제 #2
0
        private void ePrivateKey1_TextChanged(object sender, EventArgs e)
        {
            merchant1PrivateKey = null;
            ePublicKey1.Text    = "";

            if (ePrivateKey1.Text == "")
            {
                AppConfig.WriteSettingString("PrivateKey", "");
                return;
            }

            string str = ePrivateKey1.Text;

            str = str.Replace(Environment.NewLine, "");
            str = str.Trim();

            if (str.Length == 0)
            {
                return;
            }

            try
            {
                merchant1PrivateKey = StrUtils.Base64Decode(str);
            }
            catch
            {
                return;
            }

            if (AppleVasConfig.ValidatePrivateKey(merchant1PrivateKey, out uint keyId, out byte[] publicKey))
            {
                Logger.Trace("PrivateKey#1={0}", BinConvert.ToHex(merchant1PrivateKey));
                Logger.Trace("KeyId#1={0}", BinConvert.ToHex(keyId));
                Logger.Trace("PublicKey#1(raw)={0}", BinConvert.ToHex(publicKey));
                byte[] publicKeyPem = AppleVasConfig.EncodePublicKeyPem(publicKey);
                Logger.Trace("PublicKey#1(pem)={0}", BinConvert.ToHex(publicKeyPem));
                ePublicKey1.Text = StrUtils.Base64Encode(publicKeyPem);
                AppConfig.WriteSettingString("PrivateKey", ePrivateKey1.Text);
            }
예제 #3
0
        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))
예제 #4
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);
        }