Building a Status Keycard simulator

After winning the first place in this, i was really excited to see what comes next Gitcoin hackathon.

Looking thought the challenge list, there’s one that catch my eye: Create A New SDK Or Development Tool Facilitating Integration Of Keycard

status1

The reasons are:

What will i create? They have already got Java and Go SDK, two programing languages that i use most often. Maybe i will create a Javascript SDK.

But first i need to set up the development enviroment. The problem is i don’t have any smartcard or card reader.

The funder offer Keycard here, but it will takes 10-14 days to ship to my place, i may not receive the card before the hackathon ends. For card reader, i could find them in local stores. There’re so many type, price range from $10 to $60, due to my lack of knowledge, i’m not sure which one is suitable.

So i try a faster and cheaper way, using smartcard and card reader simulator.

In status-keycard, they use a folk of jCardSim for simulator test. jCardSim got BixVReaderCard class that seems promising but BixVReader driver is only support Windows. Searching for alternatives, i found vpcd which support Linux, Windows and MacOS. Great!

Install vpcd is pretty easy, on my Ubuntu, it took just a few steps:

# install linux dependency
$ sudo apt-get install pcscd libpcsclite-dev
# download vsmartcard
$ git clone https://github.com/frankmorgner/vsmartcard.git
$ cd vsmartcard/virtualsmartcard
# install vpcd
$ autoreconf --verbose --install && ./configure && sudo make install
# restart pcscd to load the new reader driver
$ sudo /etc/init.d/pcscd restart

Now i got vpcd as my virtual card reader, and jCardSim as JavaCard simulator. jCardSim connect to vpcd over TCP using VSmartCardTCPProtocol class. One thing left to do is install KeycardApplet to jCardSim:

// Install KeycardApplet
AID appletAID = AIDUtil.create(new byte[]{(byte) 0xA0, 0x00, 0x00, 0x08, 0x04, 0x00, 0x01, 0x01, 0x01});
byte[] aid = new byte[]{0x09, (byte) 0xA0, 0x00, 0x00, 0x08, 0x04, 0x00, 0x01, 0x01, 0x01};
sim.installApplet(appletAID, KeycardApplet.class, aid, (short) 0, (byte) aid.length);

Try it with keycard-cli

asciicast

It works!

There’re till some bugs but at least i could use the simulator to try out status-keycard and maybe even create my Keycard Javascript SDK.

I wrapped all these in this repo, hoping that it will be useful for someone. I didn’t test it on Windows and macOS though. This is my first time working with Smartcard, please let me know if i misunderstood anything.