I was snooping through various Java Specification Requests (JSR) at the Java Community Process (JCP) and came across JSR-268: Java Smart Card I/O API. This JSR didn’t make it into the official Java 6 release but Sun included it with their JDK anyway. Reading through the JSR took me back to the good ol’ days of IC One, eExpo, and smart cards.
I still have a bunch of old smart cards kicking around as well as my American Express Blue card. I thought it might be fun to play around with my old smart cards as well as play with the JSR-268 APIs. I have a built in smart card reader in both my Dell Latitude 810 and my Latitude 820. Just in case I couldn’t get the built-in smart reader to work in Linux, I dug up my trusty old GCR 410 that I inherited from IC One. Remember the GCR 410? The smart card reader that plugged into your serial port and your keyboard port to get power. Fortunately my docking station has both the old school serial and keyboard ports on it.
I’m running Ubuntu which I highly recommend to everyone, especially those of you running Windows. The JSR-268 API requires that PC/SC be installed. To install PC/SC on Ubuntu just do ‘sudo apt-get install pcscd pcsc-tools‘ from the command-line (or use Synaptic if you like the slow GUI way of doing things) and everything you need to use PC/SC will be installed. pcsc-tools is optional. It provides a nice utility called pcsc_scan for debugging which might make your life a little easier.
After installing PC/SC, I ran pcsc_scan. It successfully found my built-in smart card reader and indicated that there were no cards in the smart card reader. I inserted my blue card into the slot and voila! It detected the presence of a smart card and told me that it was a blue card based on the ATR. Now if only I could remember what ATR and APDU stand for…
After looking at the output from pcsc_scan, I realized that it didn’t find my GCR 410. So much for my trusty backup. It’s still sitting next to my computer though. The green LED is blinking on and off. I put a smart card into it and the LED didn’t stay on. Too bad. On with our story.
With PC/SC working, it was time to try and get things working from Java. I started out with a simple program like:
TerminalFactory tf = TerminalFactory.getDefault();
CardTerminals terminals = tf.terminals();
List<CardTerminal> terminalsList = terminals.list();
if (terminalsList.size() == 0) {
System.out.println("No terminals available");
return;
}
Much to my dismay, Java wasn’t able to find my card reader. After Googling around for a bit, I discovered that JSR-268 expects libpcsclite.so to be in my library path. I looked in /usr/lib and found libpcsclite.so.1.0.0 and a symlink to that library called libpcsclite.so.1. I create a second symlink called libpcsclite.so and everything started working in Java.
I soon had a Java program that would display “Card inserted!” when I inserted a smart card and “Card removed!” whenever I removed the smart card. It was at that point that I couldn’t think of anything really useful to do so I wrote this blog entry.
Leave a Reply
You must be logged in to post a comment.