public void Run(string readerName)
            {
                var reader        = new SmartCardReader(readerName);
                var secureChannel = new Readers.SecureSession.SecureChannel(reader);

                try
                {
                    ConsoleWriter.Instance.PrintSplitter();
                    ConsoleWriter.Instance.PrintTask("Establishing Secure Session");

                    if (!IsValidSessionKeyFormat(EncKey) || !IsValidSessionKeyFormat(MacKey))
                    {
                        throw new ArgumentException("Secure session key format is incorrect, correct format of session key string is 32 character long hexadecimal string without hex specifier. Example: \"00000000000000000000000000000000\"");
                    }

                    secureChannel.Establish(EncKey + MacKey, KeyRelatedAccesRight);

                    if (secureChannel.IsSessionActive)
                    {
                        ConsoleWriter.Instance.PrintMessage("Session established");
                        ConsoleWriter.Instance.PrintSplitter();

                        ReaderHelper.GeneralAuthenticateiClass(secureChannel,
                                                               "Authenticate without implicit selection. Key from slot: ", BookNumber.Book0,
                                                               PageNumber.Page0, GeneralAuthenticateCommand.ImplicitSelection.Off,
                                                               GeneralAuthenticateCommand.iClassKeyType.PicoPassCreditKeyKC, 0x21);

                        ReaderHelper.UpdateBinaryCommand(secureChannel, "Update binary, target block nr: ",
                                                         UpdateBinaryCommand.Type.Plain, 0x14, "BACDEF0122345678");

                        ConsoleWriter.Instance.PrintSplitter();
                    }
                    else
                    {
                        ConsoleWriter.Instance.PrintError("Failed to establish session");
                    }
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (secureChannel.IsSessionActive)
                    {
                        secureChannel.Terminate();
                        ConsoleWriter.Instance.PrintMessage("Secure Session terminated.");
                    }
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                        ConsoleWriter.Instance.PrintMessage("Reader connection closed");
                    }
                    ConsoleWriter.Instance.PrintSplitter();
                }
            }
예제 #2
0
            public void Run(string readerName)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    ConsoleWriter.Instance.PrintSplitter();
                    ConsoleWriter.Instance.PrintTask($"Connecting to {reader.PcscReaderName}");

                    ReaderHelper.ConnectToReaderWithCard(reader);

                    ConsoleWriter.Instance.PrintMessage($"Connected\nConnection Mode: {reader.ConnectionMode}");
                    ConsoleWriter.Instance.PrintSplitter();

                    ReaderHelper.GeneralAuthenticateMifare(reader, "Authenticate with key from slot nr ", 0x04,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x02);
                    ReaderHelper.UpdateBinaryCommand(reader, "Update Binary block nr ", UpdateBinaryCommand.Type.Plain, 0x04, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");

                    ReaderHelper.GeneralAuthenticateMifare(reader, "Authenticate with key from slot nr ", 0x05,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x02);
                    ReaderHelper.UpdateBinaryCommand(reader, "Update Binary block nr ", UpdateBinaryCommand.Type.Plain, 0x05, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");

                    ReaderHelper.GeneralAuthenticateMifare(reader, "Authenticate with key from slot nr ", 0x06,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x02);
                    ReaderHelper.UpdateBinaryCommand(reader, "Update Binary block nr ", UpdateBinaryCommand.Type.Plain, 0x06, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");

                    ConsoleWriter.Instance.PrintSplitter();
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                        ConsoleWriter.Instance.PrintMessage("Reader connection closed");
                    }
                    ConsoleWriter.Instance.PrintSplitter();
                }
            }
예제 #3
0
            public void Run(string readerName)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    ConsoleWriter.Instance.PrintSplitter();
                    ConsoleWriter.Instance.PrintTask($"Connecting to {reader.PcscReaderName}");

                    ReaderHelper.ConnectToReaderWithCard(reader);

                    ConsoleWriter.Instance.PrintMessage($"Connected\nConnection Mode: {reader.ConnectionMode}");
                    ConsoleWriter.Instance.PrintSplitter();

                    ReaderHelper.GeneralAuthenticateMifare(reader, "Authenticate with key from slot nr ", 0x04,
                                                           GeneralAuthenticateCommand.MifareKeyType.MifareKeyA, 0x02);
                    // Update block 4 with write operation in value block format:
                    // 4 byte value LSByte first, 4 byte bit inverted represetaton of value LSByte first, 4 byte value LSByte first, 1 byte block address, 1 byte bit inverted block address, 1 byte block address, 1 byte bit inverted block address
                    string valueTypeData = GetMifareValueTypeData(1234567, 0x04);
                    ReaderHelper.UpdateBinaryCommand(reader, "Create value type in block nr ",
                                                     UpdateBinaryCommand.Type.Plain, 0x04, valueTypeData);

                    SendDecrementCommand(reader, "Decrement value in block nr: ", 1, 0x04);

                    ConsoleWriter.Instance.PrintSplitter();
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                        ConsoleWriter.Instance.PrintMessage("Reader connection closed");
                    }
                    ConsoleWriter.Instance.PrintSplitter();
                }
            }
            public void Run(string readerName)
            {
                var reader = new SmartCardReader(readerName);

                try
                {
                    ConsoleWriter.Instance.PrintSplitter();
                    ConsoleWriter.Instance.PrintTask($"Connecting to {reader.PcscReaderName}");

                    ReaderHelper.ConnectToReaderWithCard(reader);

                    ConsoleWriter.Instance.PrintMessage($"Connected\nConnection Mode: {reader.ConnectionMode}");
                    ConsoleWriter.Instance.PrintSplitter();

                    ReaderHelper.GeneralAuthenticateiClass(reader,
                                                           "Authenticate with implicit selection. Key from slot: ", BookNumber.Book0,
                                                           PageNumber.Page0, GeneralAuthenticateCommand.ImplicitSelection.On,
                                                           GeneralAuthenticateCommand.iClassKeyType.PicoPassCreditKeyKC, 0x23);

                    ReaderHelper.UpdateBinaryCommand(reader, "Update binary with plain data, target block nr: ",
                                                     UpdateBinaryCommand.Type.Plain, 0x14, "BACDEF0122345678");

                    ConsoleWriter.Instance.PrintSplitter();
                }
                catch (Exception e)
                {
                    ConsoleWriter.Instance.PrintError(e.Message);
                }
                finally
                {
                    if (reader.IsConnected)
                    {
                        reader.Disconnect(CardDisposition.Unpower);
                        ConsoleWriter.Instance.PrintMessage("Reader connection closed");
                    }
                    ConsoleWriter.Instance.PrintSplitter();
                }
            }