Smart Card Simulation - xhanulik/OpenSC GitHub Wiki
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
This needs to be done before all below described applet-specific steps.
-
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.
-
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
-
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 usedevcon.exe
from the Windows Driver Kit:devcon.exe disable root\BixVirtualReader devcon.exe enable root\BixVirtualReader
-
Download and Install Java (
java.exe
andjavac.exe
are required) -
Download jCardSim from their website
Now, configure jCardSim to load and run the applet to make it available via PC/SC (see sections below).
Simulating IsoApplet
-
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
-
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
-
Run jCardSim with IsoApplet package:
java -classpath jcardsim-3.0.4-SNAPSHOT.jar;IsoApplet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_isoapplet.cfg
-
Create IsoApplet from the install package:
opensc-tool --card-driver default --send-apdu 80b800001a0cf276a288bcfba69d34f310010cf276a288bcfba69d34f3100100
Simulating OpenPGP
-
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
-
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
-
Run jCardSim with OpenPGP:
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar;ykneo-openpgp\applet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_openpgp.cfg
-
Create OpenPGP applet from the install package:
opensc-tool --card-driver default --send-apdu 80b800002210D276000124010200000000000001000010D276000124010200000000000001000000
Simulating PIV
-
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
-
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
-
Run jCardSim with PivApplet:
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar;PivApplet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_piv.cfg
-
Create PIV applet from the install package:
opensc-tool --card-driver default --send-apdu 80b80000120ba000000308000010000100050000020F0F7f
Simulating GIDS
-
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
-
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
-
Run jCardSim with GidsApplet:
javac -classpath jcardsim-3.0.4-SNAPSHOT.jar;GidsApplet\src com.licel.jcardsim.remote.BixVReaderCard jcardsim_gids.cfg
-
Create GIDS applet from the install package:
opensc-tool --card-driver default --send-apdu 80b80000190bA0000003974254465902010bA00000039742544659020100
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
This needs to be done before all below described applet-specific steps.
-
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
-
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
-
Download the adapted version of jCardSim
git clone https://github.com/arekinath/jcardsim.git
-
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
-
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