Search code examples
c#apdupcscevm

GET PROCESSING OPTIONS To get Data Bank Card (pscs-sharp)


In my case I'm using pcsc-sharp project.

I'm going to expose what I'm doing

  1. Select AID (In this example, a Visa Card)

Request: 00 A4 04 00 A0000000031010 00

var array_byte = StringToByteArray("A0000000031010"); //VISA
       
        var contextFactory = ContextFactory.Instance;
        using (var ctx = contextFactory.Establish(SCardScope.System)) {
            using (var isoReader = new IsoReader(ctx, "HID Global OMNIKEY 3x21 Smart Card Reader 0", SCardShareMode.Shared, SCardProtocol.Any, false)) {

                var apdu = new CommandApdu(IsoCase.Case4Short, isoReader.ActiveProtocol) {
                    CLA = 0x00, // Class
                    Instruction = InstructionCode.SelectFile, //0xA4
                    P1 = 0x04, // Parameter 1
                    P2 = 0x00, // Parameter 2,
                    Data = array_byte,
                    Le = 0x00 // Expected length of the returned data
                };

                var response = isoReader.Transmit(apdu);
                Console.WriteLine("SW1 SW2 = {0:X2} {1:X2}", response.SW1, response.SW2);
                Console.WriteLine(response.HasData ? BitConverter.ToString(response.GetData()) : "No data");
                Console.ReadKey();
            }
        }

Result:

SW1 SW2 = 90 00
6F-43-84-07-A0-00-00-00-03-10-10-A5-38-50-0C-56-49-53-41-20-43-52-45-44-49-54-4F-87-01-01-9F-38-03-9F-1A-02-5F-2D-08-65-73-70-74-65-6E-66-72-9F-12-0F-43-52-45-44-4F-4D-41-54-49-43-20-56-49-53-41-9F-11-01-01

I check the tag '9F38'(PDOL) in the response:

03-9F-1A-02

If I'm right this PDOL translates to this:

  • 03 -> bytes long
  • 9F-1A -> Tag Terminal Country Code
  • 02 -> Length of the field value that is to be returned

And I'm trying to do this:

  1. Get Processing Option

Request: 80 A8 00 00 8302 00

var array_byte = StringToByteArray("8302"); 

            var contextFactory = ContextFactory.Instance;
            using (var ctx = contextFactory.Establish(SCardScope.System)) {
                using (var isoReader = new IsoReader(ctx, "HID Global OMNIKEY 3x21 Smart Card Reader 0", SCardShareMode.Shared, SCardProtocol.Any, false)) {

                    var apdu = new CommandApdu(IsoCase.Case4Short, isoReader.ActiveProtocol) {
                        CLA = 0x80, // Class
                        Instruction = InstructionCode.GetProcessingOption, //0xA8
                        P1 = 0x00, // Parameter 1
                        P2 = 0x00, // Parameter 2,
                        Data = array_byte,
                        Le = 0x00 // Expected length of the returned data
                    };

                    var response = isoReader.Transmit(apdu);
                    Console.WriteLine("SW1 SW2 = {0:X2} {1:X2}", response.SW1, response.SW2);
                    Console.WriteLine(response.HasData ? BitConverter.ToString(response.GetData()) : "No data");
                    Console.ReadKey();
                }
            }

Result:

SW1 SW2 = 6D 00

No data

I tested different Data(8302, 8300, 83020000) but I always get 6D 00 response. I also tested a apdu tool pyResMan to execute this, but same result.

I referred to this link get processing options but I'm sill in doubt.

I'm not sure what I'm doing wrong in my APDU command, o there is something that I am missing, but I need to execute GPO to get AFL and read all card's data that I need(PAN, expiration date, etc...).

Thanks in advance. Regards.


Solution

  • Finally, I found the solution, I need to select AID before execute the GPO. (It's Mandatory, it doesn't work if you try to execute GPO directly)

    1. Request AID --> 00 A4 04 00 A0000000031010 00
    2. Request GPO --> 80 A8 00 00 8302 00

    After that, I was able to get GPO response.

    I hope it'll help