I am currently trying to hack my way into Smart Cards but I am now stuck at reading anything useful from the Card. I am trying to send a SELECT FILE Command (0x6F, 0xB, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x04, 0x0c, 0x06, 0xd2, 0x76, 0x00, 0x00, 0x01, 0x02
) to my Card (after PC_to_RDR_IccPowerOn, which returns the correct ATR) with the PC_to_RDR_XfrBlock Command.
But my response has the bmICCStatus
Flag set to 0x40
which indicates the "ICC is present and inactive (not activated or shut down by hardware error)" but I am not quite sure what to do with that information. How am I supposed to activate the Card? I thought powering it was all there was to it.
It is very much possible that I am just blind and it is written in the Specification but I was not able to find it and my Google Searches lead me to exactly 1 SO Question, which didn't really corrolate with my problem.
I am using libusb 1.0 and C, but I don't think that this is relevant to the question.
Edit:
I've added an code example, but you have to select your device for yourself, if you want to run it.
#include <stdio.h>
#include <stdlib.h>
#include <libusb-1.0/libusb.h>
#include <string.h>
#define TIMEOUT 1000
void print_bytes(unsigned char * arr, int len) {
for(int i = 0; i < len; ++i) {
printf("%0.2x ", arr[i]);
}
printf("\n");
}
int main() {
/* I have some logic which is not included to find the apropriate sc-reader. */
/* Please use libusb_get_device_list() or similar to select your device. */
libusb_device * egk_sc_reader = NULL;
libusb_device_handle * handle = NULL;
int k = libusb_open(egk_sc_reader, &handle);
int transferred = 0;
libusb_claim_interface(handle, 0);
unsigned char cmd_pwr_on[] = {
0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char cmd_select_file[] = {
// CMD (1), LEN (4), Slot (1), Seq (1), Block Wait Time (1), Level Parameter (2), abData (LEN)
0x6F, 0xB, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x04, 0x0c, 0x06, 0xd2, 0x76, 0x00, 0x00, 0x01, 0x02
};
int buf_in_len = 128;
unsigned char buf_in[buf_in_len];
memset(buf_in, 0, buf_in_len);
// Write power on
libusb_bulk_transfer(handle, 0x05, cmd_pwr_on, sizeof(cmd_pwr_on), &transferred, TIMEOUT);
// read atr
libusb_bulk_transfer(handle, 0x86, buf_in, buf_in_len, &transferred, TIMEOUT);
print_bytes(buf_in, buf_in_len);
memset(buf_in, 0, 128);
// Write select command
libusb_bulk_transfer(handle, 0x05, cmd_select_file, sizeof(cmd_select_file), &transferred, TIMEOUT);
// read answer
libusb_bulk_transfer(handle, 0x86, buf_in, buf_in_len, &transferred, TIMEOUT);
print_bytes(buf_in, buf_in_len);
libusb_release_interface(handle, 0);
libusb_close(handle);
return 0;
}
This Code example tries to mimic my actual code. It is not exactly the same but the result matches my problem As the stdout is:
80 0e 00 00 00 00 00 00 80 00 3b d3 96 ff 81 b1 fe 45 1f 07 80 81 05 2d 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 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
80 00 00 00 00 00 01 40 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 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 00 00 00 00 00 00 00 00 00 00
The Reader I am using is the USB SMARTCARD READER
from WD Plus GmbH
and the Smart Card is the EGK (Elektronische Gesundheitskarte) (en: Electronic Healtcare Card)
from the Bahn BKK
. The Card supports T=0 and T=1 (Gematik Specification: https://fachportal.gematik.de/fileadmin/user_upload/fachportal/files/Spezifikationen/Basis-Rollout/Elektronische_Gesundheitskarte/gemLF_Impl_eGK_V160.pdf)
Just sending the APDU returns me an 'Index of not supported / incorrect message parameter' Error. Which makes sense, when I think about it.
Thanks in advance
Cediwelli
According to the ATR your card is T=1 only https://smartcard-atr.apdu.fr/parse?ATR=3BD396FF81B1FE451F078081052D
I don't know the reader you use. If the reader works in TPDU and not APDU it is more complex than just sending the APDU. You have to implement T=1 in your code.
I guess the missing CCID command is PC_to_RDR_SetParameters to configure the reader with the correct parameters.
I would really suggest to use already existing software. Like my CCID driver https://ccid.apdu.fr/ for Unix.