Exemplo n.º 1
0
        /// <inheritdoc />
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            switch (InteractiveController.Mode)
            {
            case InteractiveMode.Replay:
            {
                var nextAction = InteractiveController.ActionsList[InteractiveController.ActionsListId] as TransmitAction;

                if (nextAction == null || nextAction.Command != command.ToString())
                {
                    return(ErrorCode.UnsupportedFeature);
                }

                // Retrieve response to send
                response.Parse(nextAction.Response.FromHexa());
                // Seek id to next action and check limits
                if (++InteractiveController.ActionsListId == InteractiveController.ActionsList.Count)
                {
                    InteractiveController.Mode = InteractiveMode.Transparent;
                }

                return(ErrorCode.Success);
            }

            default:
                var ret = stack.RequestLayer(this, SearchMode.Next).Transmit(command, response);

                if (InteractiveController.Mode == InteractiveMode.Record)
                {
                    InteractiveController.ActionsList.Add(new TransmitAction(command.ToString(), response.ToString()));
                }

                return(ret);
            }
        }
Exemplo n.º 2
0
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            ErrorCode ret;
            var       cAPDU = (CommandAPDU)command;

            if ((cAPDU.Ins == 0xA4) && cAPDU.IsCc4)
            {
                var le = cAPDU.Le;
                cAPDU.HasLe = false;
                // As an example, direct use of the layer to transmit the command
                ret = stack.RequestLayer(this, SearchMode.Next).Transmit(command, response);
                var rAPDU = (ResponseAPDU)response;
                if ((ret == ErrorCode.Success) && (rAPDU.Sw1 == 0x61))
                {
                    if (le > rAPDU.Sw2)
                    {
                        le = rAPDU.Sw2;
                    }
                    // As an example, use of a CommandResponsePair object to manage the dialog
                    var crpGetResponse = new CommandResponsePair(new GetResponseCommand(le))
                    {
                        RApdu = rAPDU
                    };
                    ret = crpGetResponse.Transmit(stack.RequestLayer(this, SearchMode.Next));
                }
            }
            else
            {
                ret = stack.RequestLayer(this, SearchMode.Next).Transmit(command, response);
            }

            return(ret);
        }
        /// <summary>
        /// Returns the APDU buffer byte array.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public static byte[] GetBuffer(this ICardCommand command)
        {
            _buffer = new byte[300];

            Array.Copy(command.BinaryCommand, 0, _buffer, 0, command.BinaryCommand.Length);

            return(_buffer);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public virtual ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            var recvSize = Primitives.Api.AutoAllocate;

            byte[] recvBuffer = null;
            var    ret        = __transmit(command, ref recvBuffer, ref recvSize);

            response.Parse(recvBuffer, recvSize);
            return(ret);
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public virtual ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            var result = _fakeCard.ExecuteCommand(new CommandAPDU(command.BinaryCommand));

            if (result.ErrorCode == ErrorCode.Success)
            {
                var rApdu = result.RApdu;
                response.Parse(rApdu.Udr.Concat(new byte[] { rApdu.Sw1, rApdu.Sw2 }).ToArray());
            }

            return(result.ErrorCode);
        }
Exemplo n.º 6
0
 public void NotifyTransmit(ICardChannel cardChannel, ICardCommand cardCommand, ICardResponse cardResponse, ErrorCode errorCode)
 {
     if (errorCode == ErrorCode.Success)
     {
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> Error: {0}\n", errorCode));
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> RAPDU: [{0}]\n", cardResponse));
     }
     else
     {
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> Error: {0}\n", errorCode));
     }
 }
Exemplo n.º 7
0
 public void NotifyTransmit(ICardChannel cardChannel, ICardCommand cardCommand, byte[] recvBuffer, UInt32 recvSize, ErrorCode errorCode)
 {
     if (errorCode == ErrorCode.Success)
     {
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> Error: {0}\n", errorCode));
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> RAPDU: [{0}]\n", recvBuffer.ToHexa((int)recvSize)));
     }
     else
     {
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> Error: {0}\n", errorCode));
     }
 }
Exemplo n.º 8
0
        /// <inheritdoc />
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            BeforeTransmitEvent.Raise(this, new BeforeTransmitEventArgs {
                Command = command, Response = response
            });

            var ret = channel.Transmit(command, response);

            AfterTransmitEvent.Raise(this, new AfterTransmitEventArgs {
                Command = command, Response = response, ReturnValue = ret
            });

            return(ret);
        }
        /// <summary>
        /// This is the "convenience" send method.
        /// </summary>
        /// <param name="offset">Offset into APDU buffer.</param>
        /// <param name="length">Bytelength of the data to send.</param>
        public static IFakeCardFeedback SetOutgoingAndSend(this ICardCommand _, short offset, short length)
        {
            _offset = offset;
            _length = length;

            Util.setShort(_buffer, bOff: (short)(_offset + _length), unchecked ((short)0x9000));
            _length += 2;

            var responseBytes = new byte[_length];

            Array.Copy(_buffer, _offset, responseBytes, 0, _length);

            return(FakeCardFeedback.FromSuccess(responseBytes));
        }
Exemplo n.º 10
0
        /// <inheritdoc />
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            ErrorCode ret;

            // Adapt APDU for T=0 smartcards
            if (Protocol == Protocol.T0)
            {
                ret = TransmitT0((CommandAPDU)command, (ResponseAPDU)response);
            }
            // T=1 smartcards
            else
            {
                ret = _cardChannel.Transmit(command, response);
            }

            return(ret);
        }
Exemplo n.º 11
0
        private ErrorCode __transmit(ICardCommand command, ref byte[] recvBuffer, ref UInt32 recvSize)
        {
            var sendPci = Primitives.Api.CreateIoRequestInstance(_protocol);
            var recvPci = Primitives.Api.CreateIoRequestInstance(_protocol);

            var ret = Primitives.Api.SCardTransmit(
                _card,
                ref sendPci,
                command.BinaryCommand,
                (UInt32)command.BinaryCommand.Length,
                ref recvPci,
                ref recvBuffer,
                ref recvSize
                );

            return(ret);
        }
Exemplo n.º 12
0
 public void BeforeTransmit(ICardChannel cardChannel, ICardCommand cardCommand, ICardResponse cardResponse)
 {
     gui.guiDetailedLogs.SelectionColor = highlightColor;
     gui.guiDetailedLogs.AppendText(String.Format(header + "transmit({0})\n", cardCommand));
     gui.guiDetailedLogs.SelectionColor = standardColor;
 }
Exemplo n.º 13
0
 /// <inheritdoc/>
 public ErrorCode Transmit(ICardCommand command, ICardResponse response)
 {
     return(cardChannel.Transmit(command, response));
 }
Exemplo n.º 14
0
 private static void PrintCommand(ICardCommand command)
 {
     Console.WriteLine($"C-CAPDU: {command}");
 }
Exemplo n.º 15
0
 public APDU(ICardCommand command)
 {
     _command = command;
 }
 /// <summary>
 /// Sets the actual length of response data. If a length of 0 is specified, no data will be output.
 /// </summary>
 /// <param name="command"></param>
 /// <param name="le">Length of response data.</param>
 /// <returns></returns>
 public static void SetOutgoingLength(this ICardCommand command, short le)
 {
     // TODO
 }
Exemplo n.º 17
0
 /// <inheritdoc />
 public ErrorCode Transmit(ICardCommand command, ICardResponse response)
 {
     return(RequestLayer(null, SearchMode.Top).Transmit(command, response));
 }
 /// <summary>
 /// This is the primary receive method.
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public static short SetIncomingAndReceive(this ICardCommand command)
 {
     return(0);
 }
Exemplo n.º 19
0
 public void BeforeTransmit(ICardChannel cardChannel, ICardCommand cardCommand, byte[] recvBuffer, UInt32 recvSize)
 {
     gui.guiDetailedLogs.SelectionColor = highlightColor;
     gui.guiDetailedLogs.AppendText(String.Format(header + "transmit({0})\n", cardCommand));
     gui.guiDetailedLogs.SelectionColor = standardColor;
 }
        /// <summary>
        /// This method is used to set the data transfer direction to outbound and to obtain the expected length of response (Ne).
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public static short SetOutgoing(this ICardCommand command)
        {
            var cApdu = (CommandAPDU)command;

            return((short)cApdu.Le);
        }