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
679 stars 210 forks source link

Cannot list apps or install applets to a newly card after unlocking. #270

Closed bob-613 closed 1 year ago

bob-613 commented 3 years ago

I have a SmartCafe card. I was able to unlock using

gp -env -unlock

But nothing else is working

gp -l -v -d
#
# gp -l -v -d
[DEBUG] TerminalManager - Selected the only reader with a card
SCardConnect("......", T=*) -> T=1, 3BF71800008031FE45736674652D6E66C4
# GlobalPlatformPro 325fe84
# Running on Windows 10 10.0 amd64, Java 11.0.11 by Oracle Corporation
A>> T=1 (4+0000) 00A40400 00
A<< (0018+2) (57ms) 6F108408A000000003000000A5049F6501FF 9000
[DEBUG] GPSession - Auto-detected ISD: A000000003000000
Warning: no keys given, defaulting to 404142434445464748494A4B4C4D4E4F
[INFO] GPSession - Using card master keys with version 0 for setting up session [MAC]
A>> T=1 (4+0008) 80500000 08 1981321E96F22288 00
A<< (0028+2) (117ms) 000021619600578C45050102000AFFC466C57E3628B386F61BF9032C 9000
[DEBUG] GPSession - SSC: 000A
[DEBUG] GPSession - Host challenge: 1981321E96F22288
[DEBUG] GPSession - Card challenge: 000AFFC466C57E36
[DEBUG] GPSession - Card reports SCP02 with key version 1 (0x01)
[INFO] GPSession - Diversified card keys: ENC=404142434445464748494A4B4C4D4E4F (KCV: 8BAF47) MAC=404142434445464748494A4B4C4D4E4F (KCV: 8BAF47) DEK=404142434445464748494A4B4C4D4E4F (KCV: 8BAF47) for SCP02
[INFO] GPSession - Session keys: ENC=339F1D7F5D5841EB034F5CE234557894 MAC=C6713F31B8DC1F8905DFECB4065CB81E RMAC=3CAEE5A2731AD052690BC8B5A10F3401
[DEBUG] GPSession - Verified card cryptogram: 28B386F61BF9032C
[DEBUG] GPSession - Calculated host cryptogram: 04B81C12283A9F91
A>> T=1 (4+0016) 84820100 10 04B81C12283A9F91E1EF9A40C88CFB52
A<< (0000+2) (42ms) 9000
A>> T=1 (4+0010) 84F28002 0A 4F00D32EDFEC37F32EC0 00
A<< (0000+2) (47ms) 6A86
A>> T=1 (4+0010) 84F28000 0A 4F0013D258A773F23C26 00
A<< (0011+2) (50ms) 08A000000003000000079E 9000
Error: At position 1 the len is more then 3 [32]
java.lang.IllegalStateException: At position 1 the len is more then 3 [32]
        at com.payneteasy.tlv.BerTlvParser.getDataLength(BerTlvParser.java:205)
        at com.payneteasy.tlv.BerTlvParser.parseWithResult(BerTlvParser.java:85)
        at com.payneteasy.tlv.BerTlvParser.parse(BerTlvParser.java:53)
        at com.payneteasy.tlv.BerTlvParser.parse(BerTlvParser.java:44)
        at pro.javacard.gp.GPRegistry.populate_tags(GPRegistry.java:151)
        at pro.javacard.gp.GPRegistry.parse_and_populate(GPRegistry.java:211)
        at pro.javacard.gp.GPSession.getStatus(GPSession.java:1022)
        at pro.javacard.gp.GPSession.getRegistry(GPSession.java:963)
        at pro.javacard.gp.GPTool.run(GPTool.java:665)
        at pro.javacard.gp.GPTool.main(GPTool.java:107)
SCardDisconnect("Identiv uTrust 4701 F Contact Reader 0", true) tx:72/rx:67

Maybe it's related to the protocol?

martinpaljak commented 3 years ago

Can you try with master?

bob-613 commented 3 years ago

Same issue on the newest commit on master

# gp -vdl
[DEBUG] TerminalManager - Selected the only reader with a card
SCardConnect("Identiv uTrust 4701 F Contact Reader 0", T=*) -> T=1, 3BF71800008031FE45736674652D6E66C4
# GlobalPlatformPro 325fe84
# Running on Windows 10 10.0 amd64, Java 11.0.11 by Oracle Corporation
A>> T=1 (4+0000) 00A40400 00
A<< (0018+2) (49ms) 6F108408A000000003000000A5049F6501FF 9000
[DEBUG] GPSession - Auto-detected ISD: A000000003000000
Warning: no keys given, defaulting to 404142434445464748494A4B4C4D4E4F
[INFO] GPSession - Using card master keys with version 0 for setting up session [MAC]
A>> T=1 (4+0008) 80500000 08 4829472B004EDB24 00
A<< (0028+2) (120ms) 000021619600596445050102000D1F447029E7B49E8F04E15E06741C 9000
[DEBUG] GPSession - SSC: 000D
[DEBUG] GPSession - Host challenge: 4829472B004EDB24
[DEBUG] GPSession - Card challenge: 000D1F447029E7B4
[DEBUG] GPSession - Card reports SCP02 with key version 1 (0x01)
[INFO] GPSession - Diversified card keys: ENC=404142434445464748494A4B4C4D4E4F (KCV: 8BAF47) MAC=404142434445464748494A4B4C4D4E4F (KCV: 8BAF47) DEK=404142434445464748494A4B4C4D4E4F (KCV: 8BAF47) for SCP02
[INFO] GPSession - Session keys: ENC=217ABF8CC47294B2411871F381D7534E MAC=07EFCCEB0BB0CC01A22E0CE1E1E395F8 RMAC=1AC383888CDEAF2F8EF67E16F815ACCB
[DEBUG] GPSession - Verified card cryptogram: 9E8F04E15E06741C
[DEBUG] GPSession - Calculated host cryptogram: 42D90E3378BD0FA9
A>> T=1 (4+0016) 84820100 10 42D90E3378BD0FA9A7FFEC344973A51A
A<< (0000+2) (43ms) 9000
A>> T=1 (4+0010) 84F28002 0A 4F00CD1D2555D31D5CFD 00
A<< (0000+2) (48ms) 6A86
A>> T=1 (4+0010) 84F28000 0A 4F00EBD261D230B5FF7E 00
A<< (0011+2) (52ms) 08A000000003000000079E 9000
Error: At position 1 the len is more then 3 [32]
java.lang.IllegalStateException: At position 1 the len is more then 3 [32]
        at com.payneteasy.tlv.BerTlvParser.getDataLength(BerTlvParser.java:205)
        at com.payneteasy.tlv.BerTlvParser.parseWithResult(BerTlvParser.java:85)
        at com.payneteasy.tlv.BerTlvParser.parse(BerTlvParser.java:53)
        at com.payneteasy.tlv.BerTlvParser.parse(BerTlvParser.java:44)
        at pro.javacard.gp.GPRegistry.populate_tags(GPRegistry.java:151)
        at pro.javacard.gp.GPRegistry.parse_and_populate(GPRegistry.java:211)
        at pro.javacard.gp.GPSession.getStatus(GPSession.java:1022)
        at pro.javacard.gp.GPSession.getRegistry(GPSession.java:963)
        at pro.javacard.gp.GPTool.run(GPTool.java:665)
        at pro.javacard.gp.GPTool.main(GPTool.java:107)
SCardDisconnect("Identiv uTrust 4701 F Contact Reader 0", true) tx:72/rx:67
Aminadav commented 3 years ago

Maybe it can help:

https://stackoverflow.com/questions/68087131/cannot-list-or-install-cap-files-in-javacard-after-unlocking-why-and-how-to-so

martinpaljak commented 1 year ago

The -P old should do the trick.