Setting: I need to read data form an eID smartcard using a built in reader from the android device in java.
I first try to power on the device. This returns me a lot of 0 bytes. This makes me think it already fails here? When I try to perform a read command I again get 0 bytes for the data part. Am I misunderstanding how to perform these instructions or is there a key part that I am missing?
This is all new to me and not my usual cup of tea.
public void readCard() {
powerOnReader();
getPermission();
setDevice();
setEndpoints();
sendPowerOnCCIDCommand();
sendReadCCIDCommand();
}
First I send the poweron command to the endpoint:
public void sendPowerOnCCIDCommand() {
int dataTransferred = 0;
byte[] PC_to_RDR_IccPowerOn = hexStringToByteArray("62" + "00000000" + "00" + "00" + "00" + "0000");
if (epOut != null) {
dataTransferred = smartCardConnection.bulkTransfer(epOut, PC_to_RDR_IccPowerOn, PC_to_RDR_IccPowerOn.length, 2000);
}
write(smartCardConnection, epOut, PC_to_RDR_IccPowerOn);
read(smartCardConnection, epIn);
}
This returns the following:
80 00 00 00 00 00 00 41 FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Next I try to perform a read operation:
the APDU instruction for this read operation should be the following:
00 A4 08 0C 06 3F00 DF01 4031
public void sendReadCCIDCommand() {
Log.d(LOG_TAG, "SENDREAD");
byte[] command = hexStringToByteArray("6F" + "0C000000" + "00" + "01" + "00" + "0000" + "00" + "A4" + "08" + "0C" + "06" +"3F00" +"DF01" + "4031");
write(smartCardConnection, epOut, command);
read(smartCardConnection, epIn);
}
This returns the following:
80 00 00 00 00 00 01 41 FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
The read and write functions:
public int read(UsbDeviceConnection connection, UsbEndpoint epIn) {
StringBuilder result = new StringBuilder();
final byte[] buffer = new byte[epIn.getMaxPacketSize()];
int byteCount = 0;
byteCount = connection.bulkTransfer(epIn, buffer, buffer.length, 500);
if (byteCount >= 0) {
for (byte bb : buffer) {
result.append(String.format(" %02X ", bb));
}
}
return byteCount;
}
public void write(UsbDeviceConnection connection, UsbEndpoint epOut, byte[] command) {
StringBuilder result = new StringBuilder();
connection.bulkTransfer(epOut, command, command.length, 1000);
for (byte bb : command) {
result.append(String.format(" %02X ", bb));
}
}