Chipdrive - Reading chipcards
(Latest source code for accessing the Medical Insurance Card)
- Chipcard types
- Chipdrive micro 120 - the Linux pack
- Driver installation
- The CTAPI
- Source code for accessing the medical insurance card
- Program structure
- More application opportunities for chipcards
Have you ever wanted to know what is on your medical insurance card? Are you interested in chipcard technology under Linux? If so, this article is a fine introduction for you!
Meanwhile, there are many chipdrives that are supported by
Linux. Among others, the drives from Towitoko (http://www.towitoko.de) are
supported, which have the term CHIPDRIVE in their names and get
connected to the serial port. Other manufacturers of low priced
chipcard terminals are:
- Towitoko http://www.towitoko.de/
- Kobil http://www.kobil.de/
- Schlumberger http://www.cardstore.slb.com/
Three basic card types do exist:
- Magnetic cards
- Processor cards
- Memory cards
Since the drives listed above only support the last two types, we will not dwell on magnetic cards (e.g. EC-cards, credit cards).
Processor cards are chipcards that have an own microprocessor, RAM, ROM and EEPROM (Electronically Erasable Read Only Memory) to execute sophisticated applications. Usually these cards are programmed in JAVA or BASIC; the programs are stored in the EEPROM.
Memory cards do not have any intelligence except for protecting saved data from unauthorized access. These cards are used as medical insurance cards or phone cards, for example.
But there are also contactless cards, e.g. by Legic (http://www.legic.de). These are especially suitable for security-sensitive sectors such as authentication or cashless payments. These cards are much more complex and the necessary hardware is much more expensive. They are mentioned here only for the sake of completeness.
More information on types of chipcards can be found at http://www.heise.de/ ix/artikel/2000/12/152/04.shtml.
Chipdrive micro 120 the Linux pack
Because we own two pieces of Towitoko Chipdrive micro 120 (the
Linux pack from Towitoko's online store), the following
implementations refer to these models. The Linux pack contains
a memory card with 256 bytes and a processor card with 2048 bytes capacity. With these, you can do some nice experiments.
If you are a customer of the Dresdner Bank, you can register for online banking and get a Chipdrive micro 120 for free. You do not have to use it for online banking (if you are somehow paranoid or you do not trust online banking ;-).
To use the chipdrive under Linux, you need a driver for it. The driver is used to manage the serial port and it provides a comfortable API (Application Programming Interface) known as the CTAPI (Card Terminal Application Programming Interface). The driver is available here (or on our server).
The driver can be unpacked by:
>> tar -zxvf towitoko.tar.gz
and then configured and compiled by:
>> ./configure && make
in the Towitoko directory.
Now become root and enter:
to copy the driver to the right location.
If the medical card reader complains about a missing library, you have to copy the libraries from /usr/local/towitoko/lib/ to /usr/lib or add the path /usr/local/towitoko/lib/ to the LD_LIBRARY_PATH.
Afterwards, you should execute:
to make sure that the new library is found by the system.
You can now start developing your own programs. You should look at the test program that comes with the Towitoko drivers. Many chipcard accessing functions are already implemented there - but not well documented. It is adviseable to read the CTAPI documentation. In this documentation, all available commands are documented extensively. Programming is easy because there are only three commands:
- CT_init - Initialize the card terminal and start communication with the terminal.
- CT_data - Chipcard access; send commands to the chipcard
- CD_close - Stop communication; equivalent to CT_init
The basic structure of the CT_data command looks as follows:
the parameters are defined as:
- ctn: Logical Card Terminal Nummer
- dad: Destination Address
- sad: Source Address
- commands: Number of commands
- command: commands to the chipdrive
- response: Response to command from the chipdrive
You can find an exact specification in the API.
Since we have not found any working program on freshmeat.net (http://www.freshmeat.net) to read our medical insurance card quickly, we have used this as an example.
Source code for accessing the medical insurance card
The documentation can be found in the source code. The dependencies are:
- Necessary libraries:
- Necessary headers:
The basic structure of the program is:
- REQUEST ICC
A chipcard is requested
- Terminal reset
- READ BINARY
Read the relevant data area of the card
- EJECT ICC
The chipcard is ejected.
We did not implement any functions for writing to the chipcard because the insurance cards do not have any write protection. If you consider manipulating the data on the card, you have to pay attention to writing the correct checksum. How to calculate this checksum is explained at http://themen02.mytoday .de/user/member/chipcard/ (download at the bottom).
The source code provided there does not compile (on our system) but the function for calculating the checksum is included. Oh, . . . it takes about two weeks until your medical insurance company sends you a new card....*sigh*
More application opportunities for chipcards
As further applications for chipcards you can imagine:
- user authentication
- saving crypto keys (e.g. for PGP, RSA, etc.)
- deduction and payment procedures
Have fun with playing and programming,
- Towitoko driver: Homepage at http://www.geocities.com/cprados/ and driver at http://www. geocities.com/cprados/files/towitoko-2.0.5.tar.gz
- http://www.linuxnet.com/software.h tml
- Complete documentation: http://www.panstruga.d e/ct-api/spec/spec_v09.html
- CT-API specifications: https://ww w.secure.trusted-[...]API/CTAPI11.pdf
Information on chipdrives:
- Many good links - also to c't articles: http://www.cgan.de/projects /kartenleser.html
Information on medical insurance cards and phone cards:
- Application software and more drivers: http://www.linuxnet.com/software.h tml
- Application software and libraries: http://freshmeat.net/[...]ard§ion=projects
- My own smartcard page: http://smartcards.price-of-freedo m.de/
- Source code for accessing the medical insurance card: http://smartcards.price-of-freedom.de/[...]-card-reader.tar.gz
Enter Own Comment