Skip to content

Smart Card Simulation

Conrado Gouvea edited this page Sep 26, 2020 · 9 revisions

Smart Card Simulation

This guide uses jCardSim to simulate the following Open Source Java Card Applets:

The description can easily be adapted for other applets as well.

Simulation on Windows

This section describes how to get the official version of jCardSim to work through a PC/SC virtual reader on Windows.

Prepare the Virtual Smart Card Reader

  1. Install virtual smart card reader: Either use the original source code and follow its manual or use the pre-built installer, BixVReaderInstaller.msi, from the Virtual Smart Card project.

  2. Enable the Pipe Reader: Change C:\Windows\BixVReader.ini to something like this

[Driver]
NumReaders=1

[Reader0]
RPC_TYPE=0
VENDOR_NAME=Fabio Ottavi
VENDOR_IFD_TYPE=Pipe Reader
DECIVE_UNIT=0
  1. Reload the configuration: In the Device Manager, deactivate and activate the Bix Virtual Smart Card Reader to load the modification of BixVReader.ini. Alternatively, you can use devcon.exe from the Windows Driver Kit:
devcon.exe disable root\BixVirtualReader
devcon.exe enable  root\BixVirtualReader
  1. Download and Install Java (java.exe and javac.exe are required)
  2. Download jCardSim

Now, configure jCardSim to load and run the applet to make it available via PC/SC (see sections below).

Simulating IsoApplet

  1. Download and build IsoApplet:
git clone https://github.com/philipWendland/IsoApplet
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar IsoApplet\src\net\pwendland\javacard\pki\isoapplet\*.java
  1. Create jcardsim_isoapplet.cfg for IsoApplet:
com.licel.jcardsim.card.applet.0.AID=F276A288BCFBA69D34F31001
com.licel.jcardsim.card.applet.0.Class=net.pwendland.javacard.pki.isoapplet.IsoApplet
com.licel.jcardsim.card.ATR=3B80800101
  1. Run jCardSim with IsoApplet package:
java -classpath jcardsim-3.0.4-SNAPSHOT.jar;IsoApplet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_isoapplet.cfg
  1. Create IsoApplet from the install package:
opensc-tool --card-driver default --send-apdu 80b800001a0cf276a288bcfba69d34f310010cf276a288bcfba69d34f3100100
  1. Initialize the IsoApplet as usual

Simulating OpenPGP

  1. Download and build OpenPGP applet:
git clone https://github.com/Yubico/ykneo-openpgp
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar ykneo-openpgp\applet\src\openpgpcard\*.java
  1. Create jcardsim_openpgp.cfg for OpenPGP applet:
com.licel.jcardsim.card.applet.0.AID=D2760001240102000000000000010000
com.licel.jcardsim.card.applet.0.Class=openpgpcard.OpenPGPApplet
com.licel.jcardsim.card.ATR=3B80800101
  1. Run jCardSim with OpenPGP:
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar;ykneo-openpgp\applet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_openpgp.cfg
  1. Create OpenPGP applet from the install package:
opensc-tool --card-driver default --send-apdu 80b800002210D276000124010200000000000001000010D276000124010200000000000001000000
  1. Initialize the OpenPGP applet as usual

Simulating PIV

  1. Download and build PivApplet:
git clone https://github.com/arekinath/PivApplet
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar PivApplet\src\net\cooperi\pivapplet\*.java
  1. Create jcardsim_piv.cfg for OpenPGP applet:
com.licel.jcardsim.card.applet.0.AID=A000000308000010000100
com.licel.jcardsim.card.applet.0.Class=net.cooperi.pivapplet.PivApplet
com.licel.jcardsim.card.ATR=3B80800101
  1. Run jCardSim with PivApplet:
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar;PivApplet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_piv.cfg
  1. Create PIV applet from the install package:
opensc-tool --card-driver default --send-apdu 80b80000120ba000000308000010000100050000020F0F7f
  1. Initialize the PivApplet as usual

Simulating GIDS

  1. Download and build GidsApplet:
git clone https://github.com/vletoux/GidsApplet
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar GidsApplet\src\com\mysmartlogon\gidsApplet\*.java
  1. Create jcardsim_gids.cfg for GIDS applet:
com.licel.jcardsim.card.applet.0.AID=A000000397425446590201
com.licel.jcardsim.card.applet.0.Class=com.mysmartlogon.gidsApplet.GidsApplet
com.licel.jcardsim.card.ATR=3B80800101
  1. Run jCardSim with GidsApplet:
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar;GidsApplet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_gids.cfg
  1. Create GIDS applet from the install package:
opensc-tool --card-driver default --send-apdu 80b80000190bA0000003974254465902010bA00000039742544659020100
  1. Initialize the GidsApplet as usual

Simulation on Linux

On Linux, jCardSim needs to be compiled with support for a different virtual reader backend (vpcd)

Prepare the Virtual Smart Card Reader

  1. Download and build the virtual smart card and its reader driver
git clone https://github.com/frankmorgner/vsmartcard.git
cd vsmartcard/virtualsmartcard
autoreconf -vis && ./configure && sudo make install
  1. Restart pcscd to load the new reader driver. On Debian based systems, you could do the following:
sudo /etc/init.d/pcscd restart;

Compile jCardSim with support for vpcd

  1. Download the adapted version of jCardSim
git clone https://github.com/arekinath/jcardsim.git
  1. Fetch Java Card Classic Development Kit
git clone https://github.com/martinpaljak/oracle_javacard_sdks.git
export JC_CLASSIC_HOME=$PWD/oracle_javacard_sdks/jc305u3_kit
  1. Build jcardsim-3.0.5-SNAPSHOT.jar as described here:
git clone https://github.com/arekinath/jcardsim.git
cd jcardsim
mvn initialize && mvn clean install

Simulate Java Card Applet

For actually simulating the Applets, the steps are almost identical as described in the sections for Windows above (IsoApplet, OpenPGP, PIV, GIDS) with the following modifications:

  • Make sure to use to use jcardsim-3.0.5-SNAPSHOT.jar built for vpcd
  • Add the following lines to your jCardSim configuration file (jcardsim_*.cfg):
com.licel.jcardsim.vsmartcard.host=localhost
com.licel.jcardsim.vsmartcard.port=35963
  • When running jcardsim, use VSmartCard, e.g.
java -classpath 'jcardsim-3.0.5-SNAPSHOT.jar:IsoApplet/src' com.licel.jcardsim.remote.VSmartCard jcardsim_isoapplet.cfg
Clone this wiki locally