martinpaljak / GlobalPlatformPro

🌐 πŸ” Manage applets and keys on JavaCard-s like a pro (via command line or from your Java project)
https://javacard.pro/globalplatform
GNU Lesser General Public License v3.0
673 stars 210 forks source link

Error: Index 4 out of bounds for length 4 when using the debug flag #347

Closed reynico closed 6 months ago

reynico commented 6 months ago

Describe the bug

When sending a raw APDU with the debug flag (-d) enabled, gp says Error: Index 4 out of bounds for length 4

java -jar tool/target/gp.jar --applet 0F00BA0000000101 -a "80 00 00 00"  -d
# gp --applet 0F00BA0000000101 -a 80 00 00 00 -d
# GlobalPlatformPro v21.12.31-55-g52c3581
# Running on Mac OS X 14.2.1 aarch64, Java 17.0.7 by Oracle Corporation
# SCardConnect("ACS ACR1252 Dual Reader PICC", T=*) -> T=1, 3B8580018073C821100E
A>> T=1 (4+0008) 00A40400 08 0F00BA0000000101
A<< (0000+2) (18ms) 9000
Error: Index 4 out of bounds for length 4
# SCardDisconnect("ACS ACR1252 Dual Reader PICC", false) tx:13/rx:2 in 97ms

using the verbose -v flag works as expected

java -jar tool/target/gp.jar --applet 0F00BA0000000101 -a "80 00 00 00"  -v
# gp --applet 0F00BA0000000101 -a 80 00 00 00 -v
# GlobalPlatformPro v21.12.31-55-g52c3581
# Running on Mac OS X 14.2.1 aarch64, Java 17.0.7 by Oracle Corporation
# Selecting 0F00BA0000000101
48656c6c6f
# Warning: no keys given, defaulting to 404142434445464748494A4B4C4D4E4F

other commands such as --list works as expected with the debug flag.

java -jar tool/target/gp.jar -l -key c212e073ff8b4bbfaff4de8ab655221f -d
# gp -l -key c212e073ff8b4bbfaff4de8ab655221f -d
# GlobalPlatformPro v21.12.31-55-g52c3581
# Running on Mac OS X 14.2.1 aarch64, Java 17.0.7 by Oracle Corporation
# SCardConnect("ACS ACR1252 Dual Reader PICC", T=*) -> T=1, 3B8580018073C821100E
...
ignored data
...

# SCardDisconnect("ACS ACR1252 Dual Reader PICC", false) tx:104/rx:276 in 239ms

Information about your card and used reader

As much information as you have:

  1. Card Vendor: NXP
  2. Card Product Name: JCOP 4
  3. Card Platform Version: 3.0.5
  4. Reader model/name: ACS ACR1252

Full log

Re-run your command with -d -v -i switches and:

java -jar tool/target/gp.jar --applet 0F00BA0000000101 -a "80 00 00 00" -d -v -i
# gp --applet 0F00BA0000000101 -a 80 00 00 00 -d -v -i
# GlobalPlatformPro v21.12.31-55-g52c3581
# Running on Mac OS X 14.2.1 aarch64, Java 17.0.7 by Oracle Corporation
[DEBUG] TerminalManager - Processing 1 readers with null as preferred and null as ignored
# SCardConnect("ACS ACR1252 Dual Reader PICC", T=*) -> T=1, 3B8580018073C821100E
# Selecting 0F00BA0000000101
A>> T=1 (4+0008) 00A40400 08 0F00BA0000000101
A<< (0000+2) (17ms) 9000
Error: Index 4 out of bounds for length 4
# SCardDisconnect("ACS ACR1252 Dual Reader PICC", false) tx:13/rx:2 in 96ms

Additional context

martinpaljak commented 6 months ago

Append 0x00 to the apdu.

See also: https://stackoverflow.com/questions/43823009/javacard-and-t-1-protocol-distinguish-between-apdu-cases

reynico commented 6 months ago

thanks!