Command Line Tutorial, Beginner - martinpaljak/JCardEngine GitHub Wiki

Not unlike GlobalPlatformPro

$ java -jar jcard.jar --help
Non-option arguments:                              
[File] -- path to .cap or .jar or classes directory

Option                          Description                           
------                          -----------                           
-V, --version                   Show version                          
--aid <String>                  Applet AID                            
--applet <String>               Applet class to install               
--atr <String>                  ATR to use (hex) (default: 3B80800101)
-c, --control                   Start control interface               
-h, --help                      Show this help                        
--jcsdk                         Run a JCSDK server                    
--jcsdk-atr <String>            JCSDK ATR (default: 3B80800101)       
--jcsdk-host <String>           JCSDK host (default: 0.0.0.0)         
--jcsdk-port <Integer>          JCSDK port (default: 9025)            
--jcsdk-protocol <String>       JCSDK protocol (default: *)           
--params <String>               Installation parameters               
--protocol <String>             Protocol to use (default: T=1)        
--vsmartcard                    Run a VSmartCard client               
--vsmartcard-atr <String>       VSmartCard ATR (default: 3B80800101)  
--vsmartcard-host <String>      VSmartCard host (default: 127.0.0.1)  
--vsmartcard-port <Integer>     VSmartCard port (default: 35963)      
--vsmartcard-protocol <String>  VSmartCard protocol (default: *)             

Supported PC/SC adapters

Adapter Windows macOS Linux
vsmartcard yes yes yes
Oracle JavaCard SDK N/A N/A yes

Note

The operating system column tells where the PC/SC adapter can be used. JCardEngine itself can run on any (local or remote) host.

Using any of the --vsmartcard* options will enable the vsmartcard adapter with default parameters and specific override. Same for --jcsdk*.

Control interface

By default jcard runs the applet in a mode where the card seems always connected to the reader, and the calling application can control card state by deciding whether to power off the card or not with SCardDisconnect() (or Card.disconnect(boolean) in Java). With --control the utility will install the epplet and wait for keypresses, and do the following:

  • reset the card when 't' is pressed (emulating a fresh tap on a NFC reader)
  • toggle the "card connected" state when 'c' is pressed
  • quit the utility when 'q' or Esc is pressed

Selecting the protocol

By default T=0 is used (might change for T=1). To enforce the applet to see the interface as contactless (type A), use --protocol T=CL

Setting up vsmartcard on Linux

Setting up vsmartcard on macOS

brew install autoconf automake libtool help2man
git clone --recursive [email protected]:frankmorgner/vsmartcard
autoreconf -ivf
./configure --enable-plist
# Install the resulting .pkg
# edit Info.plist, add hub VID/PID, re-plug normal reader

Setting up vsmartcard on Windows

As per original instructions:

  • run certlm.msc, select Trusted Root Certification Authorities, Certificates, right click, select All Tasks, Import.... Browse to the .cer in vsmartcard distribution .zip
  • run the installer
  • validate that there is just ONE BiXVReader with mmc devmgmt.msc under Smart Card Readers. If you tried installing before having the certificate in place, there would be non-functional items there. Remove all and install again (assuming you have installed the certificate)

Setting up Oracle JavaCard SDK PC/SC driver on Linux

With Debian and derivatives:

# Add support for i386
sudo dpkg --add-architecture i386 && sudo apt update && sudo apt install libc6-i386

# Assumed to be present already ;)
sudo apt install pcscd

# Extract the distribution and set up variables
mkdir -p ~/jcsdksim && tar -C ~/jcsdksim -xzvf ~/Downloads/java_card_devkit_simulator-linux-bin-v25.0-b_474-23-APR-2025.tar.gz
export JC_HOME_SIMULATOR=$HOME/jcsdksim

# Configure reader.conf.d
sudo tee /etc/reader.conf.d/jcsdk <<EOF
FRIENDLYNAME "Oracle JC"
DEVICENAME 127.0.0.1:9025
LIBPATH ${JC_HOME_SIMULATOR}/drivers/IFDHandler/libjcsdkifdh.so 
EOF

# reload pcscd
sudo systemctl restart pcscd

Read the upstream instructions at https://docs.oracle.com/en/java/javacard/3.2/jcdksu/install-and-setup-pcsc-lite-and-ifd-handler.html

Examples

  • Run the single applet from applet.cap with installation parameters

    • java -jar jcard.jar --vsmartcard build/applet.cap --params 01020304
  • Run the single applet from applet.cap with specific AID and installation parameters

    • java -jar jcard.jar --vsmartcard build/applet.cap --aid 010203040506 --params 01020304
  • Run the single applet from applet.cap, connecting to vsmartcard on another host

    • java -jar jcard.jar --vsmartcard-host 192.168.100.47 build/applet.cap --aid 010203040506 --params 01020304
  • Run a specific applet after loading classes to classpath

    • java -jar jcard.jar simulator/target/classes --applet com.example.samples.SampleApplet --aid 010203040506 --params 01020304
  • Run an applet from a .cap file, connecting it to local vsmartcard reader, with the URL converted into HEX for installation parameters, forcing the simulator into contactless mode and running the "control interface" (where pressing 't' triggers a tap and 'c' (dis)connects the virtual card from the virtual reader)

      java -jar jcard.jar URLApplet_D2760000850101FF_63370a8e_2.2.2_jdk11.cap \
      --vsmartcard-protocol T=CL \
      --params `echo -n https://github.com/martinpaljak/jcardengine | xxd -ps -c 0` \
      --control
    

Next steps

See Command Line Tutorial, Advanced.

⚠️ **GitHub.com Fallback** ⚠️