Sten Wessel
Sten Wessel

Reputation: 195

APDU 6E00 status for every class

I am new to APDU and smartcard communications and I can't figure out how to successfully send APDU commands. When I try for example this command:

00 A4 00 00 02 3F 00 00

I get a 6E 00 response. I tried to figure out which class I had to use for my card, but for every class I tried in in the range 00-FF, I always get the 'Class not supported' error.

I figured this maybe has to do with some authentication in the card, but I have no idea how to do this right.

I used the following Python (pyscard) code:

from smartcard.System import readers
from smartcard.util import toHexString

r = readers()
con = r[0].createConnection()
con.connect()

for c in range(0x00, 0xFF):
    comm = [c, 0xA4, 0x00, 0x00, 0x02, 0x3F00, 0x00]
    data, sw1, sw2 = con.transmit(comm)

    if sw1 != 0x6e:
        print comm
        print 'Response:'
        print data, '\n'
        print 'Status:'
        print '%x %x' % (sw1, sw2)

EDIT: The ATR of the card is 3B 04 49 32 43 2E

Upvotes: 0

Views: 3447

Answers (3)

Sten Wessel
Sten Wessel

Reputation: 195

Solved the issue, my card is a I2C card, so the APDU commands won't work with it. I got it working with the Synchronous API of Omnisoft, via C++. Not really what I had in mind, but so far it seems the only option.

Thanks to all who helped me!

Upvotes: 2

mictter
mictter

Reputation: 1418

Since you are attempting to send a SELECT APDU, why not try the simplest one, i.e. selecting the Issuer Security Domain?

Try this command:

00 A4 04 00 00

You don't need to be concerned about authentication at this point. SELECT should work in all security levels.

Upvotes: 0

Hugh Bothwell
Hugh Bothwell

Reputation: 56654

Not an expert, but looking at the pyscard documentation, I think you are playing with the wrong bytes. In the given example (which your code appears to be based on), it says

SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]
data, sw1, sw2 = connection.transmit( SELECT + DF_TELECOM )

where it looks like A0 A4 00 00 02 is the command (which should not be modified) and 7F 10 identifies the type of card to talk to (which is almost certainly different depending on what sort of card you have).

Try instead:

from itertools import product

for x,y in product(range(256), repeat=2):
    data, sw1, sw2 = con.transmit([0xA0, 0xA4, 0x00, 0x00, 0x02, x, y])

    if sw1 != 0x6e:
        print("Your card responds to {:02X} {:02X}".format(x, y))
        print("Response: {}".format(data))
        print("Status: {:02X} {:02X}".format(sw1, sw2))

I also found a summary table of commands; hope you find it useful.

Upvotes: 0

Related Questions