I was asked help with configuring a smart card reader on a government computer running Windows 7, but this made me wonder what would happen if I connected the card reader to my Ubuntu laptop and whether I’d be able to read content from a Thai ID card.
EZ100PU Smart Card Reader
Let’s have a look at the card reader itself first.
It’s a FAST ID EZ100PU smart card reader compliant with ISO7816 standard. That’s the product page of the specific model, but a search for EZ100PU only reveals the manufacturer may be InfoThink Technology based on Taiwan.
The USB smart card reader comes with a CD that includes drivers for Windows, Linux, Mac OS, and Android, as well as an SDK with a demo program and sample code in C++, Visual Basic .NET, and C#. As we’ll see further below, the Linux driver is not needed as it works out of the box.
The design of the board (RX-N99B-2) is very simple with just the main chip: Alcor AU9560 USB smart card controller. We can also see the area that interfaces with the smart card’s chip on the bottom left side of the PCB.
The other side of the board just has a smart card slot.
Using the Smart Card Reader in Ubuntu 18.04
Let’s connect the reader to my laptop, and insert a Thai ID card (contact smart card).
The good news is that the smart card is automatically detected by the kernel as an EMV Smartcard Reader.
1 2 3 4 5 |
[ 3024.839989] usb 3-2: new full-speed USB device number 3 using xhci_hcd [ 3025.020314] usb 3-2: New USB device found, idVendor=058f, idProduct=9540, bcdDevice= 1.20 [ 3025.020317] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 3025.020320] usb 3-2: Product: EMV Smartcard Reader [ 3025.020322] usb 3-2: Manufacturer: Generic |
I needed to do a web search from here, and I found a post on Linuxmint explaining how to do based on an earlier post about Spanish ID cards.
We’ll need to install a few packages (note: not all may be needed but the important ones are pcscd and pcsc-tools):
1 |
sudo apt install libccid pcscd pinentry-gtk2 pcsc-tools libpcsclite-dev libreadline-dev coolkey |
Now we can run a scan on the card reader:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
pcsc_scan PC/SC device scanner V 1.5.2 (c) 2001-2017, Ludovic Rousseau <ludovic.rousseau@free.fr> Using reader plug'n play mechanism Scanning present readers... 0: Alcor Micro AU9560 00 00 Sat Aug 10 10:23:50 2019 Reader 0: Alcor Micro AU9560 00 00 Card state: Card inserted, ATR: 3B 79 96 00 00 54 48 20 4E 49 44 20 31 32 ATR: 3B 79 96 00 00 54 48 20 4E 49 44 20 31 32 + TS = 3B --> Direct Convention + T0 = 79, Y(1): 0111, K: 9 (historical bytes) TA(1) = 96 --> Fi=512, Di=32, 16 cycles/ETU 250000 bits/s at 4 MHz, fMax for Fi = 5 MHz => 312500 bits/s TB(1) = 00 --> VPP is not electrically connected TC(1) = 00 --> Extra guard time: 0 + Historical bytes: 54 48 20 4E 49 44 20 31 32 Category indicator byte: 54 (proprietary format) Possibly identified card (using /usr/share/pcsc/smartcard_list.txt): NONE Updating /home/jaufranc/.cache/smartcard_list.txt using http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt Possibly identified card (using /home/jaufranc/.cache/smartcard_list.txt): 3B 79 96 00 00 54 48 20 4E 49 44 20 31 32 Thai (passport) |
An Alcor Micro AU9560 is detected, and it somehow it detects Thai passport, possibly because the program used to create the card was misconfigured?
There are several other codes specifically for Thai ID cards in smartcard_list.txt. You may want to check that file to see all kind of card support. Here are the ones with “Thai” string for reference:
Thai GSM UICC (Telecommunication)
Thai id card (Other)
Seven-Eleven Value Card / Smart Purse – Thailand (Other)
Thailand National ID (eID)
Thai National ID Card (eID)
Thai National ID Card (eID)
Thai (passport)
Truemove H Thailand (Telecommunication)
True Money Touch Sim (Thailand)
Seven-Eleven Value Card / Smart Purse – Thailand (Contactless) (Other)
Thai Passport 2010, 2011
Thai Passport 2005
Reading and Decoding Data from the ID Card
I can access the hardware with the reader and get the type of card. That’s all good, but it would be good to be able to access and decode the data inside the Thai ID card. Github’s user Bouroo wrote code to do just that in Python and NodeJS.
I’ll do that with the Python script. We first need to install some dependencies:
1 2 |
sudo apt install swig python3-pip libncurses-dev pip install readers pyscard |
We can now run the script, and it will extract the data accordingly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
python thai-id-card.py Available readers: (0, 'Alcor Micro AU9560 00 00') Select reader[0]: 0 Using: Alcor Micro AU9560 00 00 ATR: 3B 79 96 00 00 54 48 20 4E 49 44 20 31 32 Select Applet: 61 0A CID: TH Fullname: EN Fullname: Date of birth: Gender: Card Issuer: Issue Date: Expire Date: Address: |
I removed personal data from the output, but everything was displayed properly in the console including name and address using the Thai language. The script will also save the photo stored inside the ID card using <CID>.jpg file name with CID being the Card IDentification number.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
The “historical bytes” dump contains “54 48 20 4E 49 44 20 31 32” which is the hex representation of “TH NID 12” so it’ probably the string you have to put in the file to make it recognized as an ID card.
From the small amount of the card that’s visible the card looks a lot like my Japanese residence card. Maybe the same company makes the blanks? My card has an NFC tag in it though.
Is this a Java Card type?