Skip to content

Latest commit

 

History

History
161 lines (116 loc) · 3.89 KB

File metadata and controls

161 lines (116 loc) · 3.89 KB

Java Card Applet Dev Workspace

This directory is the starter workspace for Java Card applet development.

1) Current Status (recorded on 2026-03-06)

Checked on this machine:

  • OS: macOS 26.3 (Apple Silicon)
  • Installed: opensc, pcsc-lite, opensc-tool, pcsc_scan, python3, node, npm
  • Missing for Java Card applet dev: java, javac, ant, gp (GlobalPlatformPro)
  • JAVA_HOME: not set
  • Reader check: pcsc_scan returned No reader found
  • Java Card SDK downloaded and extracted at: tools/sdk-2.2.2

2) Directory Layout

kf/javacard-applet/
  build.xml
  README.md
  src/com/example/jc/HelloApplet.java
  scripts/check_env.sh
  scripts/install_notes_template.md
  docs/
  build/

3) Install Steps

Step A: Install JDK 8 and Ant

# If Rosetta is not installed yet (needed by temurin@8 on Apple Silicon)
softwareupdate --install-rosetta --agree-to-license

# Install Java 8
brew install --cask temurin@8

# Install Ant
brew install ant

Step B: Install GlobalPlatformPro (gp)

Homebrew does not provide an official globalplatformpro package. Use one of these methods:

  1. Download gp.jar from GlobalPlatformPro releases, then create a wrapper script named gp in your PATH.
  2. Keep gp.jar in a tools directory and run java -jar /path/to/gp.jar ....

Example wrapper script (/usr/local/bin/gp):

#!/usr/bin/env bash
exec java -jar "$HOME/tools/globalplatformpro/gp.jar" "$@"

Make it executable:

chmod +x /usr/local/bin/gp

Step C: Install Java Card SDK (manual download)

Java Card SDK typically needs manual download due to licensing/distribution. You already downloaded and extracted SDK 2.2.2 into this project:

kf/javacard-applet/tools/sdk-2.2.2

Optional: export JC_HOME explicitly (recommended):

export JC_HOME="/Users/sunm15/Documents/VScode/kf/javacard-applet/tools/sdk-2.2.2"

Or source helper script:

source kf/javacard-applet/scripts/use_local_sdk.sh

Add this to your shell rc file (~/.zshrc) if needed.

1) 进入项目

cd /Users/sunm15/Documents/VScode/kf/javacard-applet

2) (可选) 设置 Java Card SDK 路径

export JC_HOME="/Users/sunm15/Documents/VScode/kf/javacard-applet/tools/sdk-2.2.2"

3) 环境检查

./scripts/check_env.sh ant check-env

4) 编译 + 生成 CAP

ant clean ant compile ant package-cap

5) 确认 CAP 文件已生成

ls -l build/cap/com/example/jc/javacard/jc.cap

6) 下载/安装 CAP 到卡(这个时候要检查卡里是否有旧的应用,如果有就要删除)

# 1) 查看现状(当时已看到同 AID applet/package)
# gp -l
# 2) 删除旧 applet 实例
# gp -delete A00000006203010C0101
# 3) 删除旧 package
# gp -delete A00000006203010C01

然后再开始安装

gp -install build/cap/com/example/jc/javacard/jc.cap

7) 查看卡上应用列表(确认安装成功)

gp -l

8) 功能测试:选择 Applet + 发送业务指令

gp -a 00A404000AA00000006203010C0101 -a 8010000000

4) Verify Environment

cd kf/javacard-applet
chmod +x scripts/check_env.sh
./scripts/check_env.sh

Expected: java, ant, gp available and JC_HOME set.

5) Build Starter Applet

Current sample applet: src/com/example/jc/HelloApplet.java

Try:

cd kf/javacard-applet
ant check-env
ant compile
ant package-cap

Note:

  • build.xml now defaults to tools/sdk-2.2.2 if JC_HOME is not set.
  • For Java Card 2.2.2, classpath uses ${JC_HOME}/lib/api.jar.
  • ant package-cap generates CAP/EXP/JCA output in build/cap/.

6) APDU Test Plan (after CAP packaging and install)

  • SELECT applet by AID
  • Send CLA=0x80, INS=0x10
  • Expect response payload: Hello, JavaCard!

7) Next Actions

  1. Finish Step A/B/C installations.
  2. Confirm reader appears in pcsc_scan.
  3. Install gp wrapper and add CAP loading script.
  4. Load CAP to card and verify APDU response.
  5. Start implementing your real applet logic.