Clarifying JCOP Card Setup: Keys, Tools, and APDUs
No problem — I'll break this down step-by-step based on your questions. You're diving into some nitty-gritty Java Card/GlobalPlatform (GP) details, which can be tricky at first. Remember, this is all for legitimate development/testing (e.g., EMV applet prototyping in a secure lab). I'll reference official sources and provide actionable steps. If you're new to this, start with a cheap JCOP dev card and a PC/SC reader to experiment safely.
1. Understanding the -keyEnc in external_authenticate (and How to Know the Right Key)
The command in the GPShell script:
Code:
external_authenticate -keyEnc 404142434445464748494A4B4C4D4E4F // Default keys
is part of establishing a
secure channel with the card's Issuer Security Domain (ISD). This authenticates your tool (e.g., GPShell or GlobalPlatformPro) to the card so you can delete files, install applets, or manage security without errors like 6982 (security status not satisfied).
- What is -keyEnc?
- It's the Encryption Key (ENC) for the initial authentication in GlobalPlatform's Secure Channel Protocol (SCP01/SCP02/SCP03). This key is used to derive session keys for encrypting APDUs.
- The value 404142434445464748494A4B4C4D4E4F is hexadecimal for the ASCII string "ABCDEFGHIJKLMNO". This is the default test key hardcoded on most virgin (unpersonalized) Java Cards, including JCOP J2A040. It's a 16-byte (128-bit) key for 3DES or AES, depending on the card's config.
- How Do You Know the Right Key?
- For New/Blank Cards: Use the default (404142...4F) — it works out-of-the-box on JCOP cards from NXP. No need to guess; it's standard for development.
- If the Card is Already Personalized: The keys might have been changed (e.g., by a manufacturer or previous dev). You'll get errors like 6982 or 63CX (auth failed). To recover:
- Check the card's spec sheet (e.g., NXP JCOP 2.4.2R datasheet) for factory defaults.
- Use a tool like GlobalPlatformPro (GPP) to probe: Run gp --info or gp -k — it will warn if defaults fail and suggest alternatives.
- If locked, you might need the card's Key Diversification Value (KDV) or Initialization Vector (IV) from the issuer. For dev cards, reset via full erase (if supported) or contact NXP support.
- Best Practice: Always specify keys explicitly in scripts to avoid defaults in production. For testing, diversify with your PAN or ATC: SessionKey = 3DES(IMK, Diversifier).
- Pro Tip: Tools like GPP auto-use defaults if omitted (gp -install ... warns: "no keys given, defaulting to 404142...").
If auth still fails, share the exact Status Word (SW) error (e.g., from pcsc_scan), and I can troubleshoot.
2. Finding and Installing JCOP English Plugin + GlobalPlatformPro (GPP) Scripts
You're right — it's not always straightforward, especially since these are enterprise tools. The Eclipse Marketplace doesn't host them because they're proprietary (NXP) or open-source (GPP) but require direct downloads. Formatting a card (setting up the file system, security domain, etc.)
is possible without JCOP English using GPP + scripts, but it's more manual. I'll guide you through both.
- JCOP English (Eclipse Plugin):
- Why Not in Marketplace? It's NXP's secure toolset (part of JCOP Tools), distributed via their developer portal under NDA (Non-Disclosure Agreement) for eval users. You need an NXP account.
- How to Get It:
- Sign up for a free NXP account at nxp.com (under "MyNXP" > Secure Login).
- Search for "JCOP Tools" in the secure files section (requires NDA acceptance — quick online form for devs).
- Download the ZIP (e.g., JCOP Tools 3.0.3 or later for Eclipse 2023-09). It's a plugin bundle: Unzip and point Eclipse to the folder via Help > Install New Software > Add > Local ZIP.
- Eclipse Version: Use Eclipse IDE for Java Developers (e.g., 2024-06 or Juno SR2 for older JCOP).
- Once Installed: Use "Card Explorer" for GUI-based format (Tools > Format Card > Set ISD AID A000000003000000).
- Alternative if Stuck: NXP's training video: JCOP Tools Overview.
- GlobalPlatformPro (GPP) for Scripting (Easier Alternative to Full Format):
- GPP is open-source, CLI-based, and great for beginners — no Eclipse needed. It handles 80% of formatting tasks (delete/install) without JCOP English.
- Installation (Windows/Mac/Linux):
- Download the JAR from GitHub: github.com/martinpaljak/GlobalPlatformPro (e.g., GlobalPlatformPro-22.11.jar).
- Install Java 8+ (GPP runs on it).
- Run: java -jar GlobalPlatformPro.jar --help (or alias gp).
- Wiki for Setup: Getting Started — covers PC/SC reader config (e.g., install pcsc-lite on Linux).
- Scripts and Examples(GPP Uses Simple Commands, No Separate "Script Files" Needed):
- GPP is "DWIM" (Do What I Mean) — commands are scripts in one line. Save as .gp files for reuse.
- Delete Files/Applets: gp --delete A0000000031010 (e.g., Visa AID). For all: gp --delete-all.
- Set ATR: Not directly supported (GPP focuses on applets), but use gp --atr to read current, then external tools like pcsc_scan. For setting, fall back to GPShell or applet install with ATR params.
- Install Applets: As in your script: gp -install yourApplet.cap --default (uses defaults; add -key-enc 404142... if needed).
- Full "Format" Equivalent:
- Erase: gp --erase (resets to virgin state if unlocked).
- List/Verify: gp -l (shows ISD/apps like in the example output).
- Secure Channel: gp --install ... -secure (auto-auths with defaults).
- Example Script File (save as format.gp, run gp -s format.gp):
Code:
# Connect and auth
-v # Verbose
-l # List current state
--delete-all # Wipe applets
--erase # Factory reset if possible
-install EMVKernel.cap --privs SecurityDomain --params 010203... # Install base
- For JCOP-Specific: GPP works with JCOP, but for full FS format (e.g., create DFs/EFs), combine with custom applet or use NXP's tools. Community examples: GitHub wiki's "Keys" page.
- Why This Solves 'Impossible Format': GPP + a basic script gets you 90% there without Eclipse. If you hit reader issues (e.g., PC/SC), check GPP Wiki: Troubleshooting.
If downloads fail, search NXP Community forums — they have step-by-steps.
3. Finding the Right APDU for Creating an Elementary File (EF)[
No, the APDU 80 E0 00 00 0A 01 01 00 14 00 is
not always the same — it's specific to your use case (e.g., creating a 20-byte transparent EF for Track 2 data). It's a standard
CREATE FILE command under GlobalPlatform, but you customize params based on the file type, size, and structure.
- Breakdown of This APDU:
- CLA=80: GlobalPlatform proprietary (secure messaging).
- INS=E0: Create File (ISO 7816-8 / GP extension).
- P1=00, P2=00: Default params (P1=00 for EF, P2=SFI or 00).
- Lc=0A (10 bytes data): File control information.
- Data: 01 01 00 14 00 (example decode):
- 01 01: File ID (FID) = 0x0101 (unique identifier for the EF).
- 00: SFI (Short File Identifier) = 0 (or 1-30 for EMV).
- 14 00: Size = 0x0014 (20 bytes).
- Trailing 00: File type (transparent) or security attribs.
- Expected SW: 9000 on success; else 6985 (conditions not met, e.g., no auth).
- How to Find/Customize Your APDU:
- Base from Standards: Use ISO 7816-4 (CREATE FILE) + GP Card Spec (v2.3.1). For EMV, EF for tracks are under DF (Application DF AID A0000000031010).
- Steps to Generate:
- Select Parent DF First: 80 A4 04 00 <Lc> <DF AID> (e.g., for ISD: 80 A4 04 00 07 A0 00 00 00 03 00 00 00).
- Auth: Run external_authenticate first.
- Create EF: Adapt the template:
- For Transparent EF (raw bytes, like Track 2): 80 E0 00 00 08 <FID1> <FID2> <SFI> <SizeH> <SizeL>.
- For Cyclic EF (logs, like transaction certs): Add C0 type byte.
- Example for 37-byte Track 1 EF (FID=0x1A01, SFI=1): 80 E0 00 00 08 1A 01 01 25 00.
- Tools to Build/Test:
- GPP: gp --create <fid> <size> <type> (high-level; auto-generates APDU).
- PySCard: Python script:
Python:
from smartcard.System import readers
from smartcard.util import toHexString
r = readers()[0].createConnection()
r.connect()
SELECT_ISD = [0x80, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00]
data, sw1, sw2 = r.transmit(SELECT_ISD)
print(f"SW: {sw1:02X}{sw2:02X}")
CREATE_EF = [0x80, 0xE0, 0x00, 0x00, 0x0A, 0x01, 0x01, 0x00, 0x14, 0x00, 0x00] # Your example
data, sw1, sw2 = r.transmit(CREATE_EF)
print(toHexString(data), f"SW: {sw1:02X}{sw2:02X}")
- CardPeek: GUI for scripting APDUs visually.
- EMV-Specific: For track data, use SFI=1 (Track 2 Eqv.), size=037 (37 bytes max). See EMV Book 3 for tags (e.g., 9Fxx for auth).
- Common Errors: 6A80 (invalid params) — check FID uniqueness. 6986 (no current EF) — select DF first.
| APDU Param | Purpose | Example Value | When to Change |
|---|
| FID (2 bytes) | Unique file ID | 01 01 | Per file; avoid conflicts (e.g., EMV uses 1Axx) |
| SFI (1 byte) | Quick access index | 00 | 01-1E for EMV records |
| Size (2 bytes) | Max bytes | 14 00 (20) | Match your data (e.g., Track 2=19-20 bytes) |
| Type | Structure | 00 (transparent) | 01 cyclic, 02 linear |
In short: Defaults work for starters, but tweak via tools. For your setup, try GPP first — it's free and scriptable. If you paste your full error log or card model, I can give exact commands. What's next — testing the track write? Keep building!