1
votes

I´m developing a personal application, using EMV reader and Javax SmartCardIO, I´m trying to get all the plain data from a SmartCard, I've been reading the specification and some tutorials, even reading some questions here but I came up with a problem:

I'm trying to get the size of a record in the SFI in order to iterate all the records with that information.

I've read in some tutorials that I need to send a request with length 0 and the chip is going to answer with an error code and the correct length of the record("6C XX"), however in my cards (Visa and AMEX) is returning another response which translates to the type of card ("VISA ELECTRON and AMERICAN EXPRESS") and I'm not getting the "6c xx" error.

My code so far looks like this:

byte[] commandArr = {(byte)0x00, (byte)0xB2, (byte)0x01, (byte)0x0C, (byte)0x00};
CommandAPDU commandTest = new CommandAPDU(commandArr);
ResponseAPDU test = this.channel.transmit(commandTest);
System.out.println(hexToAscii(bytesToHex(test.getBytes())));

Both cards have the SFI for the first PSE record in 01 (got that with the select PSE command after the 88 tag).

I'm new using this technology and I'm kind of lost right now, any help is welcome.

Thanks!

2

2 Answers

2
votes

When you establish connection with the card in contact mode, you choose one of two transmission protocol T0 or T1. The main function of them is equal - communicate with card, but realisation and interface are different. Cart may support one of these protocols or both. The one of differenes is how to get responce from card. In T0 responce may constit of two parts (commands). When you got SW=61XX where xx length of response you need perform command GetResponce 00C00000XX to "read" response data. In T1 you get all data with SW at once.

In your case it seems using T1, so card return all data without SW=61XX.

Some parts of documentation:

public abstract Card connect(String protocol) throws CardException

The protocol to use ("T=0", "T=1", or "T=CL"), or "*" to connect using any available protocol.

public abstract ResponseAPDU transmit(CommandAPDU command) throws CardException

Implementations should transparently handle artifacts of the transmission protocol. For example, when using the T=0 protocol, the following processing should occur as described in ISO/IEC 7816-4:

  • if the response APDU has an SW1 of 61, the implementation should issue a GET RESPONSE command using SW2 as the Lefield. This process is repeated as long as an SW1 of 61 is received. The response body of these exchanges is concatenated to form the final response body.
  • if the response APDU is 6C XX, the implementation should reissue the command using XX as the Le field.
3
votes

In addition to Alexander Vaganov's answer -- javax.smartcardio package handles the 61XX and 6CXX cases automatically, unless told not to do so (by sun.security.smartcardio.t0GetResponse and sun.security.smartcardio.t1GetResponse system properties).

Setting this properties to false should result in the expected behavior (i.e. getting the 6CXX status word).

I am not aware of any documentation for this, so have a look into the source code.

To disable the abovementioned automatic handling of 61XX and 6CXX cases add the following arguments to the java command line:

-Dsun.security.smartcardio.t0GetResponse=false -Dsun.security.smartcardio.t1GetResponse=false

Good luck!