Пример #1
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);
        }
        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);
            }
        }
Пример #3
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);
        }
Пример #4
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);
        }
        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, "");
        }
Пример #6
0
            void SendDecrementCommand(ISmartCardReader smartCardReader, int value, byte blockNumber)
            {
                var    decrementCommand = new DecrementCommand();
                string input            = decrementCommand.GetApdu(blockNumber, value);
                string output           = ReaderHelper.SendCommand(smartCardReader, input);

                Console.WriteLine("Input: ", input, "\n Output: ", output);
            }
Пример #7
0
        public static void InitWebReader()
        {
            WebContext = ContextHandler.Instance;
            IReadOnlyList <string> myreaders = WebContext.ListReaders();
            string readername = myreaders[0];

            WebReader = new SmartCardReader(readername);
        }
Пример #8
0
            void SendDecrementCommand(ISmartCardReader smartCardReader, string description, int value, byte blockNumber)
            {
                var    decrementCommand = new IncrementDecrementCommand();
                string input            = decrementCommand.GetApdu(IncrementDecrementCommand.OperationType.Decrement, blockNumber, value);
                string output           = ReaderHelper.SendCommand(smartCardReader, input);

                ConsoleWriter.Instance.PrintCommand(description + blockNumber.ToString("X2"), input, output);
            }
Пример #9
0
        Invoke(object input)
        {
            var InitMifareBackEnd      = new MifareAPI.InitReader();
            ISmartCardReader WebReader = InitMifareBackEnd.RunInitReader();

            WebReader = InitMifareBackEnd.RunInitReader();
            return(WebReader.PcscReaderName);
        }
Пример #10
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);
        }
            private void ReadEepromCommand(ISmartCardReader smartCardReader, string comment, ushort offset, byte dataLength)
            {
                var eepromCommands = new Readers.AViatoR.Components.ReaderEeprom();

                string input  = eepromCommands.ReadCommand(offset, dataLength);
                string output = ReaderHelper.SendCommand(smartCardReader, input);

                PrintCommand(comment, input, output);
            }
Пример #12
0
        public async Task <object> Invoke(object input)
        {
            WebContext = ContextHandler.Instance;
            IReadOnlyList <string> myreaders = WebContext.ListReaders();
            string readername = myreaders[0];

            WebReader = new SmartCardReader(readername);
            return(WebReader.PcscReaderName);
        }
Пример #13
0
            private void LoadKeyCommand(ISmartCardReader smartCardReader, string description, byte keySlot, LoadKeyCommand.KeyType keyType, LoadKeyCommand.Persistence persistence, LoadKeyCommand.Transmission transmission, LoadKeyCommand.KeyLength keyLength, string key)
            {
                var loadKeyCommand = new Readers.AViatoR.Components.LoadKeyCommand();

                string input  = loadKeyCommand.GetApdu(keySlot, keyType, persistence, transmission, keyLength, key);
                string output = ReaderHelper.SendCommand(smartCardReader, input);

                ConsoleWriter.Instance.PrintCommand(description + key, input, output);
            }
Пример #14
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);
        }
            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);
            }
            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);
            }
Пример #17
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}");
        }
Пример #18
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}");
        }
Пример #19
0
        public SamSecureSession(ISmartCardReader smartCardReader)
        {
            IsSessionActive = false;
            if (smartCardReader == null)
            {
                throw new ArgumentNullException(nameof(smartCardReader));
            }

            _smartCardReader = smartCardReader;
        }
Пример #20
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);
        }
        Invoke(dynamic input)
        {
            byte             _input            = Byte.Parse(input, NumberStyles.HexNumber);
            var              _read             = new MifareAPI.ReadMifareClassic1k();
            var              InitMifareBackEnd = new MifareAPI.InitReader();
            ISmartCardReader WebReader         = InitMifareBackEnd.RunInitReader();

            WebReader = InitMifareBackEnd.RunInitReader();
            return(_read.RunReadMifare(_input));
        }
 void ExecuteExample(ISmartCardReader smartCardReader)
 {
     WriteEepromCommand(smartCardReader, "Write 1 byte of FF with offset address 0x0001", 0x0001, "FF");
     WriteEepromCommand(smartCardReader, "Write 16 bytes of FF with offset address 0x0001", 0x0001, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
     WriteEepromCommand(smartCardReader, "Write 128 bytes of FF with offset address 0x0001", 0x0001,
                        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +
                        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +
                        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +
                        "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
 }
Пример #23
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);
        }
Пример #24
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);
        }
Пример #25
0
        Invoke(dynamic input)
        {
            var              _write            = new MifareAPI.UpdateMifareClassic1k();
            var              InitMifareBackEnd = new MifareAPI.InitReader();
            string           _input            = (string)input._input;
            byte             _blockinput       = Byte.Parse(input._blockinput, NumberStyles.HexNumber);
            ISmartCardReader WebReader         = InitMifareBackEnd.RunInitReader();

            WebReader = InitMifareBackEnd.RunInitReader();
            return(_write.RunWriteMifare(_input, _blockinput));
        }
Пример #26
0
            private void ApplySettingsCommand(ISmartCardReader smartCardReader)
            {
                var applySettings = new Readers.AViatoR.Components.ApplySettings();

                ConsoleWriter.Instance.PrintMessage("Apply Settings");

                string input  = applySettings.GetApdu;
                string output = ReaderHelper.SendCommand(smartCardReader, input);

                PrintCommand(string.Empty, input, output);
            }
Пример #27
0
            private void RestoreFactoryDefaultsCommand(ISmartCardReader smartCardReader)
            {
                var resotoreFactoryDefaults = new Readers.AViatoR.Components.ResotoreFactoryDefaults();

                ConsoleWriter.Instance.PrintMessage("Restore Factory Defaults");

                string input  = resotoreFactoryDefaults.GetApdu;
                string output = ReaderHelper.SendCommand(smartCardReader, input);

                PrintCommand(string.Empty, input, output);
            }
Пример #28
0
            private void RebootDeviceCommand(ISmartCardReader smartCardReader)
            {
                var rebootDevice = new Readers.AViatoR.Components.RebootDevice();

                ConsoleWriter.Instance.PrintMessage("Reboot Device");

                string input  = rebootDevice.GetApdu;
                string output = ReaderHelper.SendCommand(smartCardReader, input);

                PrintCommand(string.Empty, input, output);
            }
Пример #29
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)}");
        }
Пример #30
0
            private void ReadEepromCommand(ISmartCardReader smartCardReader, string comment, ushort offset, byte dataLength)
            {
                var eepromCommands = new Readers.AViatoR.Components.ReaderEeprom();

                string input  = eepromCommands.ReadCommand(offset, dataLength);
                string output = ReaderHelper.SendCommand(smartCardReader, input);
                int    index  = output.IndexOf(ToHexString("~"));
                string data   = output.Substring(10, index - 10);
                string save   = FromHexString(data);

                PrintCommand(comment, input, save);
            }