Attempting to read and write a string to a smart card using the smart card I / O API

I am using an ACS AET65 card reader trying to save a string on a smart card and then read it. I am using the Iphone API of the smart card and I can get the terminal and connect to the card. However, I read the ISO 7816 specification and I really got lost.

All I have to do is write a 3K line to the card and then read it back. It. From what I explored, it seems that applets should be installed on these cards, but I'm sure there should be a way to just write a simple byte array and return it.

I do not know ho to create APDU commands for this. I tried READING BINARS, WRITE BINARS, MAKE SURE BINARS, but of course, I am doing something wrong. It always returns 0x6E and 0x00 as bytes of the response SW1 and SW2, which means an error. Here is a snippet of the part where I send test commands to the applet with a small line:

Card card = cardTerminal.connect("*"); card.beginExclusive(); System.out.println("Card protocol: "+card.getProtocol()); CardChannel channel = card.getBasicChannel(); String jsonStr = "small test string"; byte[] totalData = new byte[256]; byte[] data = jsonStr.getBytes(); System.arraycopy(data, 0, totalData, 0, data.length); CommandAPDU eraseCommand = new CommandAPDU(0x00, 0x0E, 0x00, 0x00, data, 0x00); ResponseAPDU eraseCommandResponse = channel.transmit(eraseCommand); int eSw1 = eraseCommandResponse.getSW1(); int eSw2 = eraseCommandResponse.getSW2(); // returns 6E00, error System.out.println("Erase Response SW1: " + toHexString(eSw1) + " and SW2: " + toHexString(eSw2)); CommandAPDU writeCommand = new CommandAPDU(0x00, 0xD0, 0x00, 0x00, data, 0x00); ResponseAPDU commandResponse = channel.transmit(writeCommand); int sw1 = commandResponse.getSW1(); int sw2 = commandResponse.getSW2(); // returns 6E00, error System.out.println("Write Response SW1: " + toHexString(sw1) + " and SW2: " + toHexString(sw2)); byte[] totalReadData = new byte[255]; CommandAPDU readCommand = new CommandAPDU(0x00, 0xB0, 0x00, 0x00, totalReadData, 0); ResponseAPDU readCommandResponse = channel.transmit(readCommand); int rSw1 = readCommandResponse.getSW1(); int rSw2 = readCommandResponse.getSW2(); // returns 6E00, error System.out.println("Read Response SW1: " + toHexString(rSw1) + " and SW2: " + toHexString(rSw2)); byte[] totalReadData2 = readCommandResponse.getData(); // always returns an empty array System.out.println("Total data read: "+totalReadData2.length); card.endExclusive(); 

How can I accomplish this using the smart card API?

Thanks! Eduardo

+4
source share
1 answer

Smart cards come in many forms. The ISO 7816-4 specification defines a structure for cards based on files and records. Many maps and applets comply with this specification, at least to a certain extent.

Smart cards are basically systems on a chip, although they are generally extremely limited in terms of I / O functions and specifications. These smart cards run operating systems. Sometimes these operating systems merge with the application layer, providing basic functionality and the ISO 7816-4 file system. Other cards only offer an operating system that provides APIs for applications and load / run functions for these applications. The Java map is an example of this; basically, the whole APDU team that you send is processed by Java Card applets, with the exception of those listed on the Global Platform (which deals with managing cards and downloading applications on most Java cards).

With this information, you will realize that simply sending an APDU command — including ERASE BINARY (often not supported on new cards), READ BINARY or UPDATE BINARY APDU — is not the way to go. You will need more information about your card to continue, and yes, you may need to download the Applet if you have a Java Card implementation before you can send APDUs at the application level.

+3
source

Source: https://habr.com/ru/post/1479173/


All Articles