public static void WriteI2CExampleAt24C16(string readerName)
        {
            try
            {
                var i2c = new Readers.AViatoR.Components.SynchronusI2C();
                ISmartCardReader smartCardReader = Connect(readerName);

                if (!smartCardReader.IsConnected)
                {
                    return;
                }

                // Write 1 byte to address 0x0000, AT24C16 card
                ushort address = 0x0000;
                byte   numberOfBytesToWrite = 0x01;
                string data = "01";

                string command  = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data);
                string response = smartCardReader.Transmit(command);
                PrintData($"I2C Write {numberOfBytesToWrite} byte to address 0x{address:X6}", command, response, "");

                // Write 10 bytes to address 0x0010, AT24C16 card
                address = 0x0010;
                numberOfBytesToWrite = 0x0A;
                data     = "FFFFFFFFFFFFFFFFFFFF";
                command  = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data);
                response = smartCardReader.Transmit(command);
                PrintData($"I2C Write {numberOfBytesToWrite} bytes starting from address 0x{address:X6}", command, response, "");

                // Write 32 bytes to address 0x0400, AT24C16 card
                // AT24C16 card has page size of 16 bytes so write operation need to be done twice
                address = 0x0400;
                numberOfBytesToWrite = 0x10;
                data     = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                command  = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data);
                response = smartCardReader.Transmit(command);
                PrintData($"I2C Write {numberOfBytesToWrite} bytes starting from address 0x{address:X6}", command, response, "");
                // second part of write operation
                address += 16;
                numberOfBytesToWrite = 0x10;
                data     = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                command  = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data);
                response = smartCardReader.Transmit(command);
                PrintData($"I2C Write {numberOfBytesToWrite} bytes starting from address 0x{address:X6}", command, response, "");

                smartCardReader.Disconnect(CardDisposition.Unpower);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
        private void GetChallange()
        {
            _sessionStatus = SessionStatus.GetChallengePhase;

            string getChallangeApdu = "FF7200" + _keySlot.ToString("X2") + "00";

            var response = _smartCardReader.Transmit(getChallangeApdu);

            if (response.Substring(response.Length - 4) != "9000")
            {
                _sessionStatus = SessionStatus.NotEstablished;
                throw new Exception($"Establish secure session failed at {_sessionStatus}\nSend: {getChallangeApdu}\nRecived apdu: {response}");
            }
            _readerNonce = response.Substring(0, NonceLength * 2);
        }
예제 #3
0
        public static void SetContactSlotEnable(string readerName)
        {
            var contactSlot = new Readers.AViatoR.Components.ContactSlotConfiguration();

            ISmartCardReader smartCardReader = Connect(readerName);

            if (!smartCardReader.IsConnected)
            {
                return;
            }

            string command;
            string response;

            //enable
            command  = contactSlot.ContactSlotEnable.SetApdu(true);
            response = smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            PrintData("Set Contact Slot", command, response, "Enable");

            //disable
            // command = contactSlot.ContactSlotEnable.SetApdu(false);
            // response = reader.ConnectionMode != ReaderSharingMode.Direct ? reader.Transmit(command) : reader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            // PrintData("Set Contact Slot", command, response, "Disable");

            smartCardReader.Disconnect(CardDisposition.Unpower);
        }
예제 #4
0
        public static void SetVoltageSequence(string readerName)
        {
            var contactSlot = new Readers.AViatoR.Components.ContactSlotConfiguration();

            ISmartCardReader smartCardReader = Connect(readerName);

            if (!smartCardReader.IsConnected)
            {
                return;
            }

            string command;
            string response;

            // Device Driver decides
            command  = contactSlot.VoltageSequence.SetAutomaticSequenceApdu();
            response = smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            PrintData("Set Voltage Sequence", command, response, "Device driver decides");

            // High Mid Low
            // command = contactSlot.VoltageSequence.SetApdu(VoltageSequenceFlags.High, VoltageSequenceFlags.Mid, VoltageSequenceFlags.Low);
            // response = reader.ConnectionMode != ReaderSharingMode.Direct ? reader.Transmit(command) : reader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            // PrintData("Voltage Sequence", command, response, "High -> Mid -> Low");

            // Low Mid High
            // command = contactSlot.VoltageSequence.SetApdu(VoltageSequenceFlags.Low, VoltageSequenceFlags.Mid, VoltageSequenceFlags.High);
            // response = reader.ConnectionMode != ReaderSharingMode.Direct ? reader.Transmit(command) : reader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            // PrintData("Voltage Sequence", command, response, "Low -> Mid -> High");

            smartCardReader.Disconnect(CardDisposition.Unpower);
        }
예제 #5
0
        public static void SetOperatingMode(string readerName)
        {
            var contactSlot = new Readers.AViatoR.Components.ContactSlotConfiguration();

            ISmartCardReader smartCardReader = Connect(readerName);

            if (!smartCardReader.IsConnected)
            {
                return;
            }

            string command;
            string response;

            // Set ISO7816 mode
            command  = contactSlot.OperatingMode.SetApdu(OperatingModeFlags.Iso7816);
            response = smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            PrintData("Set Operating Mode", command, response, "ISO 7816 mode");

            // Set EMVco mode
            // command = contactSlot.OperatingMode.SetApdu(OperatingModeFlags.EMVCo);
            // response = reader.ConnectionMode != ReaderSharingMode.Direct ? reader.Transmit(command) : reader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            // PrintData("Set Operating Mode", command, response, "EMVco mode");

            smartCardReader.Disconnect(CardDisposition.Unpower);
        }
        public static void ReadProtectionMemory2WbpExample(string readerName)
        {
            try
            {
                var twoWireBusProtocol           = new Readers.AViatoR.Components.Synchronus2WBP();
                ISmartCardReader smartCardReader = Connect(readerName);

                if (!smartCardReader.IsConnected)
                {
                    return;
                }

                byte notUsed = 0x00;

                string command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.ReadProtectionMemory, notUsed, notUsed);
                string response = smartCardReader.Transmit(command);
                if (response.StartsWith("9D04") && response.EndsWith("9000"))
                {
                    string data = response.Substring(4, 8);
                    PrintData("Read Protection Memory", command, response, $"Value 0x{data}");
                }
                else
                {
                    PrintData("Read Protection Memory", command, response, "Error Response");
                }
                smartCardReader.Disconnect(CardDisposition.Unpower);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public static void UpdateMainMemory3WbpExample(string readerName)
        {
            try
            {
                var threeWireBusProtocol         = new Readers.AViatoR.Components.Synchronus3WBP();
                ISmartCardReader smartCardReader = Connect(readerName);

                if (!smartCardReader.IsConnected)
                {
                    return;
                }
                // Following code is commented to prevent usage of incorrect Pin code, which can lead to blocking the synchronus card if done several times in row
                // Verification with correct pin code is necessary to write any data into card memory
                // Be advice not to use VerifyUser2Wbp command if correct pin code is not known

                /*
                 * string pin = "FFFF";
                 *
                 * byte firstPinByte = byte.Parse(pin.Substring(0, 2), NumberStyles.HexNumber);
                 * byte secondPinByte = byte.Parse(pin.Substring(2, 2), NumberStyles.HexNumber);
                 *
                 * VerifyUser3Wbp(reader, firstPinByte, secondPinByte);
                 *
                 * //*/

                ushort address = 0x01FF;
                byte   data    = 0xAB;

                string command  = threeWireBusProtocol.GetApdu(Synchronus3WBP.ControlByte.WriteAndEraseWithoutProtectBit, address, data);
                string response = smartCardReader.Transmit(command);
                PrintData($"Write Main Memory, address: 0x{address:X4}, data: 0x{data:X2}", command, response, response.Equals("9D009000") ? "Success" : "Error Response");

                address  = 0x01FF;
                data     = 0xCC;
                command  = threeWireBusProtocol.GetApdu(Synchronus3WBP.ControlByte.WriteAndEraseWithoutProtectBit, address, data);
                response = smartCardReader.Transmit(command);
                PrintData($"Write Main Memory, address: 0x{address:X4}, data: 0x{data:X2}", command, response, response.Equals("9D009000") ? "Success" : "Error Response");


                smartCardReader.Disconnect(CardDisposition.Unpower);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #8
0
        public static void ReadBinaryMifareCommand(ISmartCardReader smartCardReader, string description, byte blockNumber, byte expectedlength)
        {
            var readBinaryCommand = new Readers.AViatoR.Components.ReadBinaryCommand();

            string input  = readBinaryCommand.GetMifareReadApdu(blockNumber, expectedlength);
            string output = smartCardReader.Transmit(input);

            ConsoleWriter.Instance.PrintCommand(description + "0x" + blockNumber.ToString("X2"), input, output);
        }
예제 #9
0
        public static void ReadBinaryiClassCommand(ISmartCardReader smartCardReader, string description, ReadBinaryCommand.ReadOption readOption, byte blockNumber, byte expectedlength, BookNumber book = BookNumber.Book0, PageNumber page = PageNumber.Page0)
        {
            var readBinaryCommand = new Readers.AViatoR.Components.ReadBinaryCommand();

            string input  = readBinaryCommand.GetiClassReadApdu(readOption, blockNumber, expectedlength, book, page);
            string output = smartCardReader.Transmit(input);

            ConsoleWriter.Instance.PrintCommand(description + "0x" + blockNumber.ToString("X2"), input, output);
        }
예제 #10
0
        public static void UpdateBinaryCommand(ISmartCardReader smartCardReader, UpdateBinaryCommand.Type type, byte blockNumber, string data)
        {
            var updateBinaryCommand = new UpdateBinaryCommand();

            string input = updateBinaryCommand.GetApdu(Readers.AViatoR.Components.UpdateBinaryCommand.Type.Plain,
                                                       blockNumber, data);
            string output = smartCardReader.Transmit(input);

            Console.WriteLine($"0x{blockNumber.ToString("X2")}  Input: {input}  Output: {output}");
        }
예제 #11
0
        public static void UpdateBinaryCommand(ISmartCardReader smartCardReader, string description, UpdateBinaryCommand.Type type, byte blockNumber, string data)
        {
            var updateBinaryCommand = new UpdateBinaryCommand();

            string input = updateBinaryCommand.GetApdu(Readers.AViatoR.Components.UpdateBinaryCommand.Type.Plain,
                                                       blockNumber, data);
            string output = smartCardReader.Transmit(input);

            ConsoleWriter.Instance.PrintCommand(description + "0x" + blockNumber.ToString("X2"), input, output);
        }
예제 #12
0
        public static void GeneralAuthenticateMifare(ISmartCardReader smartCardReader, string description, byte blockNumber, GeneralAuthenticateCommand.MifareKeyType keyType, byte keySlot)
        {
            var generalAuthenticateCommand = new Readers.AViatoR.Components.GeneralAuthenticateCommand();

            string input =
                generalAuthenticateCommand.GetMifareApdu(blockNumber, keyType, keySlot);
            string output = smartCardReader.Transmit(input);

            ConsoleWriter.Instance.PrintCommand(description + keySlot.ToString("X2"), input, output);
        }
예제 #13
0
        public static void GeneralAuthenticateiClass(ISmartCardReader smartCardReader, string description, BookNumber book, PageNumber page, GeneralAuthenticateCommand.ImplicitSelection implicitSelection, GeneralAuthenticateCommand.iClassKeyType keyType, byte keySlot)
        {
            var generalAuthenticateCommand = new Readers.AViatoR.Components.GeneralAuthenticateCommand();

            string input =
                generalAuthenticateCommand.GetiClassApdu(book, page, implicitSelection, keyType, keySlot);
            string output = smartCardReader.Transmit(input);

            ConsoleWriter.Instance.PrintCommand(description + keySlot.ToString("X2"), input, output);
        }
            void SendUpdateBinaryCommand(ISmartCardReader smartCardReader, UpdateBinaryCommand.Type type, byte blockNumber, string data)
            {
                ConsoleWriter.Instance.PrintMessage($"Update Binary NXP iCode card, block number: 0x{blockNumber:X2}, with data :{data}");

                var    updateBinary = new UpdateBinaryCommand();
                string input        = updateBinary.GetApdu(type, blockNumber, data);
                var    output       = smartCardReader.Transmit(input);

                ConsoleWriter.Instance.PrintCommand(string.Empty, input, output);
            }
예제 #15
0
        public static void GeneralAuthenticateMifare(ISmartCardReader smartCardReader, byte blockNumber, GeneralAuthenticateCommand.MifareKeyType keyType, byte keySlot)
        {
            var generalAuthenticateCommand = new Readers.AViatoR.Components.GeneralAuthenticateCommand();

            string input =
                generalAuthenticateCommand.GetMifareApdu(blockNumber, keyType, keySlot);
            string output = smartCardReader.Transmit(input);

            Console.WriteLine($"0x {blockNumber.ToString("X2")} Input   {input} Output:  {output}");
        }
            void SendReadBinaryCommand(ISmartCardReader smartCardReader, byte msb, byte lsb, byte expectedLength)
            {
                ConsoleWriter.Instance.PrintMessage($"Read Binary NXP iCode card, address: 0x{msb:X2}{lsb:X2}");

                var    readBinary = new ReadBinaryCommand();
                string input      = readBinary.GetApdu(msb, lsb, expectedLength);
                var    output     = smartCardReader.Transmit(input);

                ConsoleWriter.Instance.PrintCommand(string.Empty, input, output);
            }
        public static void ReadI2CExampleAt24C128(string readerName)
        {
            try
            {
                var i2c = new Readers.AViatoR.Components.SynchronusI2C();
                ISmartCardReader smartCardReader = Connect(readerName);

                if (!smartCardReader.IsConnected)
                {
                    return;
                }

                // Read 1 byte from address 0x0000 from AT24C128 card
                ushort address     = 0x0000;
                byte   bytesToRead = 0x01;

                string command  = i2c.GetReadCommandApdu(SynchronusI2C.MemorySize._16384, address, bytesToRead);
                string response = smartCardReader.Transmit(command);
                PrintData($"I2C Read {bytesToRead} byte from address 0x{address:X6}", command, response, "");

                // Read 10 bytes from address 0x0010 from AT24C128 card
                address     = 0x0010;
                bytesToRead = 0x0A;
                command     = i2c.GetReadCommandApdu(SynchronusI2C.MemorySize._16384, address, bytesToRead);
                response    = smartCardReader.Transmit(command);
                PrintData($"I2C Read {bytesToRead} bytes starting from address 0x{address:X6}", command, response, "");

                // Read 32 bytes from address 0x0400 from AT24C128 card
                address     = 0x0400;
                bytesToRead = 0x20;
                command     = i2c.GetReadCommandApdu(SynchronusI2C.MemorySize._16384, address, bytesToRead);
                response    = smartCardReader.Transmit(command);
                PrintData($"I2C Read {bytesToRead} bytes starting from address 0x{address:X6}", command, response, "");

                smartCardReader.Disconnect(CardDisposition.Unpower);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #18
0
        public static void ReadContactSlotConfiguration(string readerName)
        {
            var contactSlot = new Readers.AViatoR.Components.ContactSlotConfiguration();

            ISmartCardReader smartCardReader = Connect(readerName);

            if (!smartCardReader.IsConnected)
            {
                return;
            }

            string command;
            string response;

            // Read contact slot enable
            command  = contactSlot.ContactSlotEnable.GetApdu;
            response = smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            PrintData("Contact Slot", command, response, contactSlot.ContactSlotEnable.TranslateGetResponse(response));

            // Read operating mode
            command  = contactSlot.OperatingMode.GetApdu;
            response = smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            PrintData("Operating Mode", command, response, contactSlot.OperatingMode.TranslateGetResponse(response).ToString());

            // Read contact slot enable
            command  = contactSlot.VoltageSequence.GetApdu;
            response = smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command);
            List <VoltageSequenceFlags> voltageSequenceList = contactSlot.VoltageSequence.TranslateGetResponse(response);

            if (voltageSequenceList.Count == 0)
            {
                PrintData("Voltage Sequence", command, response, "Device driver decides.");
            }
            else
            {
                PrintData("Voltage Sequence", command, response, voltageSequenceList.Select(item => item.ToString()).ToArray());
            }

            // close connection
            smartCardReader.Disconnect(CardDisposition.Unpower);
        }
예제 #19
0
        public void Terminate()
        {
            if (!IsSessionActive)
            {
                return;
            }

            string wrapedTerminateCommand = Wrap("FF70076B04A102A200");
            string command  = $"FF70076B{wrapedTerminateCommand.Length / 2:X2}" + wrapedTerminateCommand + "00";
            string response = _smartCardReader.Transmit(command);

            _smartCardReader.Disconnect();

            ClearFields();
            if (response == "9D0290009000")
            {
                return;
            }

            throw new Exception($"Server response to terminate session request mismatch, \nExpected: 9D0290009000, Actual: {response}");
        }
예제 #20
0
        public static void GetDataCommand(ISmartCardReader smartCardReader, string description, GetDataCommand.Type type)
        {
            var getData = new GetDataCommand();

            ConsoleWriter.Instance.PrintMessage(description);

            string input  = getData.GetApdu(type);
            string output = smartCardReader.Transmit(input);

            ConsoleWriter.Instance.PrintCommand(string.Empty, input, output,
                                                $"Data: {output.Substring(0, output.Length - 4)}");
        }
        private static void VerifyUser2Wbp(ISmartCardReader smartCardReader, byte firstPinByte, byte secondPinByte, byte thirdPinByte)
        {
            var twoWireBusProtocol = new Readers.AViatoR.Components.Synchronus2WBP();

            byte notUsed = 0x00;
            byte newErrorCounter;

            Console.WriteLine("User Verification");

            // Read Error Counter
            string command             = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.ReadSecurityMemory, notUsed, notUsed);
            string response            = smartCardReader.Transmit(command);
            string currentErrorCounter = response.Substring(4, 2);

            PrintData("Read Error Counter", command, response, $"0x{currentErrorCounter}");

            // decrement counter
            switch (currentErrorCounter)
            {
            case "07":
                newErrorCounter = 0x06;
                break;

            case "06":
                newErrorCounter = 0x04;
                break;

            case "04":
                newErrorCounter = 0x00;
                break;

            default:
                Console.WriteLine("Returned error counter is not correct or card is blocked");
                return;
            }
            command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.UpdateSecurityMemory, 0x00, newErrorCounter);
            response = smartCardReader.Transmit(command);
            PrintData("Write new Error Counter", command, response, $"0x{newErrorCounter:X2}");

            // Compare verification data - first part
            command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.CompareVerificationData, 0x01, firstPinByte);
            response = smartCardReader.Transmit(command);
            PrintData("Compare verification data - first part", command, response, $"{firstPinByte:X2}");

            // Compare verification data - second part
            command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.CompareVerificationData, 0x02, secondPinByte);
            response = smartCardReader.Transmit(command);
            PrintData("Compare verification data - second part", command, response, $"{secondPinByte:X2}");

            // Compare verification data - third part
            command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.CompareVerificationData, 0x03, thirdPinByte);
            response = smartCardReader.Transmit(command);
            PrintData("Compare verification data - third part", command, response, $"{thirdPinByte:X2}");

            // Reset Error Counter
            command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.UpdateSecurityMemory, 0x00, 0xFF);
            response = smartCardReader.Transmit(command);
            PrintData("Reset Error Counter", command, response, "");
        }
        public static void ReadMainMemory3WbpExample(string readerName)
        {
            try
            {
                var threeWireBusProtocol         = new Readers.AViatoR.Components.Synchronus3WBP();
                ISmartCardReader smartCardReader = Connect(readerName);

                if (!smartCardReader.IsConnected)
                {
                    return;
                }

                // address of first byte to be read
                ushort address    = 0x00;
                byte   notUsed    = 0x00;
                string cardMemory = string.Empty;

                // read data from addresses 0x0000 - 0x03FF
                for (int i = 0x00; i < 0x0400; i++)
                {
                    string command  = threeWireBusProtocol.GetApdu(Synchronus3WBP.ControlByte.Read9BitsDataWithProtectBit, address, notUsed);
                    string response = smartCardReader.Transmit(command);

                    if (response.StartsWith("9D02") && response.EndsWith("9000"))
                    {
                        string data           = response.Substring(4, 2);
                        string protectionByte = response.Substring(6, 2);
                        string bitSet         = protectionByte != "00" ? "not set" : "set";
                        PrintData($"Read Main Memory, Address 0x{address:X4}", command, response,
                                  $"Value 0x{data}, {protectionByte} -> protection bit {bitSet}");
                        cardMemory += data;
                    }
                    else
                    {
                        PrintData($"Read Main Memory, Address 0x{address:X4}", command, response, "Error Response");
                    }
                    address++;
                }
                Console.WriteLine($"\nMain Memory starting from address 0x0000 to address 0x03FF:\n{cardMemory}\n");
                smartCardReader.Disconnect(CardDisposition.Unpower);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public static void ReadMainMemory2WbpExample(string readerName)
        {
            try
            {
                var twoWireBusProtocol           = new Readers.AViatoR.Components.Synchronus2WBP();
                ISmartCardReader smartCardReader = Connect(readerName);

                if (!smartCardReader.IsConnected)
                {
                    return;
                }

                // address of first byte to be read
                byte   address    = 0x20;
                byte   notUsed    = 0x00;
                string cardMemory = string.Empty;
                for (int i = 32; i < 256; i++)
                {
                    string command  = twoWireBusProtocol.GetApdu(Synchronus2WBP.ControlByte.ReadMainMemory, address, notUsed);
                    string response = smartCardReader.Transmit(command);
                    if (response.StartsWith("9D01") && response.EndsWith("9000"))
                    {
                        string data = response.Substring(4, 2);
                        PrintData($"Read Main Memory, Address 0x{address:X2}", command, response, $"Value 0x{data}");
                        cardMemory += data;
                    }
                    else
                    {
                        PrintData($"Read Main Memory, Address 0x{address:X2}", command, response, "Error Response");
                    }
                    address++;
                }
                Console.WriteLine($"\nMain Memory starting from address 0x20 to address 0xFF:\n{cardMemory}\n");

                smartCardReader.Disconnect(CardDisposition.Unpower);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        private static void VerifyUser3Wbp(ISmartCardReader smartCardReader, byte firstPinByte, byte secondPinByte)
        {
            var threeWireBusProtocol = new Readers.AViatoR.Components.Synchronus3WBP();

            byte newErrorCounter;

            Console.WriteLine("User Verification");

            // Read Error Counter
            string command             = threeWireBusProtocol.ReadErrorCounterApdu();
            string response            = smartCardReader.Transmit(command);
            string currentErrorCounter = response.Substring(4, 2);

            PrintData("Read Error Counter", command, response, $"0x{currentErrorCounter}");

            // decrement counter
            switch (currentErrorCounter)
            {
            case "7F":
                newErrorCounter = 0x7E;
                break;

            case "7E":
                newErrorCounter = 0x7C;
                break;

            case "7C":
                newErrorCounter = 0x78;
                break;

            case "78":
                newErrorCounter = 0x70;
                break;

            case "70":
                newErrorCounter = 0x60;
                break;

            case "60":
                newErrorCounter = 0x40;
                break;

            case "40":
                newErrorCounter = 0x00;
                break;

            default:
                Console.WriteLine("Returned error counter is not correct or card is blocked");
                return;
            }
            command  = threeWireBusProtocol.WriteErrorCounterApdu(newErrorCounter);
            response = smartCardReader.Transmit(command);
            PrintData("Write new Error Counter", command, response, $"0x{newErrorCounter:X2}");

            // Verify pin first byte
            command  = threeWireBusProtocol.VerifyFirstPinByte(firstPinByte);
            response = smartCardReader.Transmit(command);
            PrintData("Verify first pin byte", command, response, $"{firstPinByte:X2}");

            // Verify pin second byte
            command  = threeWireBusProtocol.VerifySecondPinByte(secondPinByte);
            response = smartCardReader.Transmit(command);
            PrintData("Verify second pin byte", command, response, $"{secondPinByte:X2}");

            // Reset Error Counter
            command  = threeWireBusProtocol.ResetErrorCounterApdu();
            response = smartCardReader.Transmit(command);
            PrintData("Reset Error Counter", command, response, "");
        }
예제 #25
0
 public static string SendCommand(ISmartCardReader smartCardReader, string command)
 {
     return(smartCardReader.ConnectionMode != ReaderSharingMode.Direct ? smartCardReader.Transmit(command) : smartCardReader.Control(ReaderControlCode.IOCTL_CCID_ESCAPE, command));
 }